http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java index af51587..0f0804d 100644 --- a/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java +++ b/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java @@ -26,7 +26,6 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Locale; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -184,13 +183,6 @@ public class WhitelistUtilsTest { EasyMock.replay(request); String result = null; -// if (serverName != null && !serverName.isEmpty() && !isLocalhostServerName(serverName) && xForwardedHost == null) { -// try { -// result = doTestDeriveDomainBasedWhitelist(serverName); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } else if (xForwardedHost != null && !xForwardedHost.isEmpty()) { if (xForwardedHost != null && !xForwardedHost.isEmpty()) { try { Method method = WhitelistUtils.class.getDeclaredMethod("deriveDefaultDispatchWhitelist", HttpServletRequest.class); @@ -218,10 +210,6 @@ public class WhitelistUtilsTest { return (String) defineWhitelistMethod.invoke(null, domain); } - private static boolean isLocalhostServerName(final String serverName) { - return LOCALHOST_NAMES.contains(serverName.toLowerCase(Locale.ROOT)); - } - private static GatewayConfig createMockGatewayConfig(final List<String> serviceRoles, final String whitelist) { GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(config.getDispatchWhitelistServices()).andReturn(serviceRoles).anyTimes(); @@ -230,5 +218,4 @@ public class WhitelistUtilsTest { return config; } - }
http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureClusterTest.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureClusterTest.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureClusterTest.java index 5909163..1878653 100644 --- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureClusterTest.java +++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureClusterTest.java @@ -48,11 +48,12 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.security.Principal; import java.util.Locale; import java.util.Properties; @@ -90,7 +91,7 @@ public class SecureClusterTest { private static File baseDir; @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { nameNodeHttpPort = TestUtils.findFreePort(); configuration = new HdfsConfiguration(); baseDir = new File(KeyStoreTestUtil.getClasspathDir(SecureClusterTest.class)); @@ -175,7 +176,7 @@ public class SecureClusterTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { if(kdc != null) { kdc.stop(); } @@ -232,22 +233,23 @@ public class SecureClusterTest { file.delete(); file.createNewFile(); } - Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); - String content = String.format(Locale.ROOT, - "com.sun.security.jgss.initiate {\n" + - "com.sun.security.auth.module.Krb5LoginModule required\n" + - "renewTGT=true\n" + - "doNotPrompt=true\n" + - "useKeyTab=true\n" + - "keyTab=\"%s\"\n" + - "principal=\"%s\"\n" + - "isInitiator=true\n" + - "storeKey=true\n" + - "useTicketCache=true\n" + - "client=true;\n" + - "};\n", keyTabFile, principal); - writer.write(content); - writer.close(); + try(OutputStream outputStream = Files.newOutputStream(file.toPath()); + Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) { + String content = String.format(Locale.ROOT, + "com.sun.security.jgss.initiate {\n" + + "com.sun.security.auth.module.Krb5LoginModule required\n" + + "renewTGT=true\n" + + "doNotPrompt=true\n" + + "useKeyTab=true\n" + + "keyTab=\"%s\"\n" + + "principal=\"%s\"\n" + + "isInitiator=true\n" + + "storeKey=true\n" + + "useTicketCache=true\n" + + "client=true;\n" + + "};\n", keyTabFile, principal); + writer.write(content); + } return file; } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java index fddda57..9e46ff9 100644 --- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java +++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java @@ -38,12 +38,13 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Locale; import java.util.Properties; @@ -72,7 +73,6 @@ import static org.junit.Assert.assertTrue; */ @Category(ReleaseTest.class) public class SecureKnoxShellTest { - private static final String SCRIPT = "SecureWebHdfsPutGet.groovy"; private static MiniKdc kdc; private static String userName; @@ -83,22 +83,14 @@ public class SecureKnoxShellTest { private static String hdfsPrincipal; private static String spnegoPrincipal; private static String keytab; - private static File ticketCache; private static MiniDFSCluster miniDFSCluster; private static GatewayTestDriver driver = new GatewayTestDriver(); - public SecureKnoxShellTest() { - super(); - } - @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { baseDir = new File( KeyStoreTestUtil.getClasspathDir(SecureKnoxShellTest.class)); - ticketCache = new File( - KeyStoreTestUtil.getClasspathDir(SecureKnoxShellTest.class) - + "/ticketCache"); nameNodeHttpPort = TestUtils.findFreePort(); configuration = new HdfsConfiguration(); @@ -117,7 +109,6 @@ public class SecureKnoxShellTest { } private static void initKdc() throws Exception { - final Properties kdcConf = MiniKdc.createConf(); kdc = new MiniKdc(kdcConf, baseDir); kdc.start(); @@ -167,8 +158,7 @@ public class SecureKnoxShellTest { } @AfterClass - public static void cleanupSuite() throws Exception { - + public static void tearDownAfterClass() throws Exception { if(kdc != null) { kdc.stop(); } @@ -178,7 +168,6 @@ public class SecureKnoxShellTest { if(driver != null) { driver.cleanup(); } - } private static File setupJaasConf(File baseDir, String keyTabFile, @@ -190,16 +179,16 @@ public class SecureKnoxShellTest { file.delete(); file.createNewFile(); } - final Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); - String content = String.format(Locale.ROOT, "com.sun.security.jgss.initiate {\n" - + "com.sun.security.auth.module.Krb5LoginModule required\n" - + "renewTGT=true\n" + "doNotPrompt=true\n" + "useKeyTab=true\n" - + "keyTab=\"%s\"\n" + "principal=\"%s\"\n" + "isInitiator=true\n" - + "storeKey=true\n" + "useTicketCache=true\n" + - //"ticketCache=\"%s\"\n" + - "debug=false\n" + "client=true;\n" + "};\n", keyTabFile, principal); - writer.write(content); - writer.close(); + try(OutputStream outputStream = Files.newOutputStream(file.toPath()); + Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) { + String content = String.format(Locale.ROOT, "com.sun.security.jgss.initiate {\n" + + "com.sun.security.auth.module.Krb5LoginModule required\n" + + "renewTGT=true\n" + "doNotPrompt=true\n" + "useKeyTab=true\n" + + "keyTab=\"%s\"\n" + "principal=\"%s\"\n" + "isInitiator=true\n" + + "storeKey=true\n" + "useTicketCache=true\n" + + "debug=false\n" + "client=true;\n" + "};\n", keyTabFile, principal); + writer.write(content); + } return file; } @@ -208,8 +197,7 @@ public class SecureKnoxShellTest { File jaasConf = setupJaasConf(baseDir, keytab, hdfsPrincipal); - System.setProperty("java.security.krb5.conf", - ((MiniKdc) kdc).getKrb5conf().getAbsolutePath()); + System.setProperty("java.security.krb5.conf", kdc.getKrb5conf().getAbsolutePath()); System.setProperty("java.security.auth.login.config", jaasConf.getAbsolutePath()); System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); @@ -317,7 +305,6 @@ public class SecureKnoxShellTest { URL readme = driver.getResourceUrl("README"); File file = new File(readme.toURI()); - //System.out.println(file.exists()); binding.setProperty("file", file.getAbsolutePath()); final GroovyShell shell = new GroovyShell(binding); @@ -326,11 +313,9 @@ public class SecureKnoxShellTest { String status = (String) binding.getProperty("status"); assertNotNull(status); - //System.out.println(status); String fetchedFile = (String) binding.getProperty("fetchedFile"); assertNotNull(fetchedFile); - //`(fetchedFile); assertTrue(fetchedFile.contains("README")); } @@ -340,5 +325,4 @@ public class SecureKnoxShellTest { + resource; return ClassLoader.getSystemResource(filePath); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test-release/webhdfs-test/src/test/java/org/apache/knox/gateway/ShellTest.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-test/src/test/java/org/apache/knox/gateway/ShellTest.java b/gateway-test-release/webhdfs-test/src/test/java/org/apache/knox/gateway/ShellTest.java index 54365d8..fd5cdf3 100644 --- a/gateway-test-release/webhdfs-test/src/test/java/org/apache/knox/gateway/ShellTest.java +++ b/gateway-test-release/webhdfs-test/src/test/java/org/apache/knox/gateway/ShellTest.java @@ -16,6 +16,7 @@ * limitations under the License. */ package org.apache.knox.gateway; + import org.apache.knox.test.category.ReleaseTest; import org.junit.experimental.categories.Category; @@ -46,10 +47,8 @@ import static org.junit.Assert.assertNotNull; import static org.hamcrest.MatcherAssert.assertThat; - @Category(ReleaseTest.class) public class ShellTest { - private static MiniDFSCluster miniDFSCluster; private static HdfsConfiguration configuration; private static int nameNodeHttpPort; @@ -59,7 +58,7 @@ public class ShellTest { private static File baseDir; @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { nameNodeHttpPort = TestUtils.findFreePort(); configuration = new HdfsConfiguration(); baseDir = new File(KeyStoreTestUtil.getClasspathDir(ShellTest.class)); @@ -72,12 +71,12 @@ public class ShellTest { .racks(null) .build(); userName = UserGroupInformation.createUserForTesting("guest", new String[] {"users"}).getUserName(); + assertNotNull(userName); setupKnox(); } private static void setupKnox() throws Exception { - //knox setup System.setProperty("gateway.hadoop.kerberos.secured", "false"); GatewayTestConfig config = new GatewayTestConfig(); config.setGatewayPath( "gateway" ); @@ -88,7 +87,7 @@ public class ShellTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { miniDFSCluster.shutdown(); driver.cleanup(); } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminFuncTest.java index dd739fd..75291f7 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminFuncTest.java @@ -33,8 +33,9 @@ import org.slf4j.LoggerFactory; import javax.ws.rs.core.MediaType; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -43,10 +44,8 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.notNullValue; public class GatewayAdminFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewayAdminFuncTest.class ); - private static Logger LOG = LoggerFactory.getLogger( GatewayAdminFuncTest.class ); - - //public static Enumeration<Appender> appenders; public static GatewayConfig config; public static GatewayServer gateway; public static String gatewayUrl; @@ -54,21 +53,18 @@ public class GatewayAdminFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { TestUtils.LOG_ENTER(); - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); setupGateway(); TestUtils.LOG_EXIT(); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { TestUtils.LOG_ENTER(); gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); TestUtils.LOG_EXIT(); } @@ -89,9 +85,9 @@ public class GatewayAdminFuncTest { deployDir.mkdirs(); File descriptor = new File( topoDir, "test-cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + createTopology().toStream( stream ); + } DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String,String> options = new HashMap<>(); @@ -171,5 +167,4 @@ public class GatewayAdminFuncTest { TestUtils.LOG_EXIT(); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java index 5ffd352..dcc1701 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java @@ -18,15 +18,14 @@ package org.apache.knox.gateway; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.OutputStream; import java.io.StringReader; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Arrays; -import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -52,7 +51,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.knox.test.TestUtils; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -81,10 +79,8 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; public class GatewayAdminTopologyFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewayAdminTopologyFuncTest.class ); - private static Logger LOG = LoggerFactory.getLogger( GatewayAdminTopologyFuncTest.class ); - - public static Enumeration<Appender> appenders; public static GatewayConfig config; public static GatewayServer gateway; public static String gatewayUrl; @@ -92,22 +88,18 @@ public class GatewayAdminTopologyFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); + public static void setUpBeforeClass() throws Exception { driver.setupLdap(0); setupGateway(new GatewayTestConfig()); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); } public static void setupGateway(GatewayTestConfig testConfig) throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); gatewayDir.mkdirs(); @@ -128,14 +120,14 @@ public class GatewayAdminTopologyFuncTest { descriptorsDir.mkdirs(); File descriptor = new File( topoDir, "admin.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createKnoxTopology().toStream( stream ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + createKnoxTopology().toStream(stream); + } File descriptor2 = new File( topoDir, "test-cluster.xml" ); - FileOutputStream stream2 = new FileOutputStream( descriptor2 ); - createNormalTopology().toStream( stream2 ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor2.toPath())) { + createNormalTopology().toStream(stream); + } DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String,String> options = new HashMap<>(); @@ -292,47 +284,40 @@ public class GatewayAdminTopologyFuncTest { } private static String createDescriptor(String clusterName, String providerConfigRef, boolean discovery) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(1024); if (providerConfigRef == null) { providerConfigRef = "sandbox-providers"; } sb.append("{\n"); if (discovery) { - sb.append(" \"discovery-type\":\"AMBARI\",\n"); - sb.append(" \"discovery-address\":\"http://c6401.ambari.apache.org:8080\",\n"); - sb.append(" \"discovery-user\":\"ambariuser\",\n"); - sb.append(" \"discovery-pwd-alias\":\"ambari.discovery.password\",\n"); + sb.append("\"discovery-type\":\"AMBARI\",\n" + + "\"discovery-address\":\"http://c6401.ambari.apache.org:8080\",\n" + + "\"discovery-user\":\"ambariuser\",\n" + + "\"discovery-pwd-alias\":\"ambari.discovery.password\",\n"); } - sb.append(" \"provider-config-ref\":\""); - sb.append(providerConfigRef); - sb.append("\",\n"); - sb.append(" \"cluster\":\""); - sb.append(clusterName); - sb.append("\",\n"); - sb.append(" \"services\":[\n"); - sb.append(" {\"name\":\"NAMENODE\"},\n"); - sb.append(" {\"name\":\"JOBTRACKER\"},\n"); - sb.append(" {\"name\":\"WEBHDFS\"},\n"); - sb.append(" {\"name\":\"WEBHCAT\"},\n"); - sb.append(" {\"name\":\"OOZIE\"},\n"); - sb.append(" {\"name\":\"WEBHBASE\"},\n"); - sb.append(" {\"name\":\"HIVE\"},\n"); - sb.append(" {\"name\":\"RESOURCEMANAGER\"},\n"); - sb.append(" {\"name\":\"AMBARI\", \"urls\":[\"http://c6401.ambari.apache.org:8080\"]}\n"); - sb.append(" ]\n"); - sb.append("}\n"); + sb.append("\"provider-config-ref\":\"") + .append(providerConfigRef) + .append("\",\n\"cluster\":\"") + .append(clusterName) + .append("\",\n" + + "\"services\":[\n" + + "{\"name\":\"NAMENODE\"},\n" + + "{\"name\":\"JOBTRACKER\"},\n" + + "{\"name\":\"WEBHDFS\"},\n" + + "{\"name\":\"WEBHCAT\"},\n" + + "{\"name\":\"OOZIE\"},\n" + + "{\"name\":\"WEBHBASE\"},\n" + + "{\"name\":\"HIVE\"},\n" + + "{\"name\":\"RESOURCEMANAGER\"},\n" + + "{\"name\":\"AMBARI\", \"urls\":[\"http://c6401.ambari.apache.org:8080\"]}\n" + + "]\n}\n"); return sb.toString(); } - //@Test - public void waitForManualTesting() throws IOException { - System.in.read(); - } - @Test( timeout = TestUtils.LONG_TIMEOUT ) - public void testTopologyCollection() throws ClassNotFoundException { + public void testTopologyCollection() { LOG_ENTER(); String username = "admin"; @@ -1161,9 +1146,9 @@ public class GatewayAdminTopologyFuncTest { // Manually write a file to the shared-providers directory File providerConfig = new File(sharedProvidersDir, configFileNames.get(0)); - FileOutputStream stream = new FileOutputStream(providerConfig); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfig.toPath())) { + createProviderConfiguration().toStream(stream); + } // Request a listing of all the provider configs responseBody = given() @@ -1180,9 +1165,9 @@ public class GatewayAdminTopologyFuncTest { // Manually write another file to the shared-providers directory File anotherProviderConfig = new File(sharedProvidersDir, configFileNames.get(1)); - stream = new FileOutputStream(anotherProviderConfig); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(anotherProviderConfig.toPath())) { + createProviderConfiguration().toStream(stream); + } // Request a listing of all the provider configs responseBody = given() @@ -1326,15 +1311,15 @@ public class GatewayAdminTopologyFuncTest { // Manually add two provider config files to the shared-providers directory File providerConfigOneFile = new File(sharedProvidersDir, "deleteme-one-config.xml"); - FileOutputStream stream = new FileOutputStream(providerConfigOneFile); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfigOneFile.toPath())) { + createProviderConfiguration().toStream(stream); + } assertTrue(providerConfigOneFile.exists()); File providerConfigTwoFile = new File(sharedProvidersDir, "deleteme-two-config.xml"); - stream = new FileOutputStream(providerConfigTwoFile); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfigTwoFile.toPath())) { + createProviderConfiguration().toStream(stream); + } assertTrue(providerConfigTwoFile.exists()); // Request a listing of all the provider configs @@ -1404,15 +1389,15 @@ public class GatewayAdminTopologyFuncTest { // Manually add two provider config files to the shared-providers directory File providerConfigOneFile = new File(sharedProvidersDir, "deleteme-one-config.xml"); - FileOutputStream stream = new FileOutputStream(providerConfigOneFile); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfigOneFile.toPath())) { + createProviderConfiguration().toStream(stream); + } assertTrue(providerConfigOneFile.exists()); File providerConfigTwoFile = new File(sharedProvidersDir, "deleteme-two-config.xml"); - stream = new FileOutputStream(providerConfigTwoFile); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfigTwoFile.toPath())) { + createProviderConfiguration().toStream(stream); + } assertTrue(providerConfigTwoFile.exists()); // Request a listing of all the provider configs @@ -1537,15 +1522,15 @@ public class GatewayAdminTopologyFuncTest { // Manually add two provider config files to the shared-providers directory File providerConfigOneFile = new File(sharedProvidersDir, "force-deleteme-one-config.xml"); - FileOutputStream stream = new FileOutputStream(providerConfigOneFile); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfigOneFile.toPath())) { + createProviderConfiguration().toStream(stream); + } assertTrue(providerConfigOneFile.exists()); File providerConfigTwoFile = new File(sharedProvidersDir, "force-deleteme-two-config.xml"); - stream = new FileOutputStream(providerConfigTwoFile); - createProviderConfiguration().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(providerConfigTwoFile.toPath())) { + createProviderConfiguration().toStream(stream); + } assertTrue(providerConfigTwoFile.exists()); // Request a listing of all the provider configs http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java index ad5168f..a8b3684 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java @@ -20,11 +20,7 @@ package org.apache.knox.gateway; import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Properties; import java.util.UUID; @@ -37,7 +33,6 @@ import org.apache.knox.gateway.services.topology.TopologyService; import org.apache.knox.test.TestUtils; import org.apache.knox.test.mock.MockServer; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; import org.hamcrest.MatcherAssert; import org.junit.After; import org.junit.AfterClass; @@ -61,11 +56,9 @@ import static org.xmlmatchers.xpath.HasXPath.hasXPath; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; public class GatewayAppFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewayAppFuncTest.class ); + private static final Class<?> DAT = GatewayAppFuncTest.class; - private static Logger LOG = LoggerFactory.getLogger( GatewayAppFuncTest.class ); - private static Class<?> DAT = GatewayAppFuncTest.class; - - private static Enumeration<Appender> appenders; private static GatewayTestConfig config; private static DefaultGatewayServices services; private static GatewayServer gateway; @@ -78,21 +71,19 @@ public class GatewayAppFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); setupGateway(); LOG_EXIT(); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); gateway.stop(); driver.cleanup(); FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } @@ -105,7 +96,6 @@ public class GatewayAppFuncTest { } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); gatewayDir.mkdirs(); @@ -129,7 +119,6 @@ public class GatewayAppFuncTest { File deployDir = new File( config.getGatewayDeploymentDir() ); deployDir.mkdirs(); - setupMockServers(); startGatewayServer(); } @@ -657,14 +646,4 @@ public class GatewayAppFuncTest { LOG_EXIT(); } - - public static Collection<String> toNames( File[] files ) { - List<String> names = new ArrayList<>( files.length ); - for( File file : files ) { - names.add( file.getAbsolutePath() ); - } - return names; - - } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java index ef4e760..753578c 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java @@ -148,8 +148,7 @@ public class GatewayBasicFuncTest { * @throws Exception Thrown if any failure occurs. */ @BeforeClass - public static void setupSuite() throws Exception { - //Log.setLog( new NoOpLogger() ); + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); GatewayTestConfig config = new GatewayTestConfig(); driver.setResourceBase(GatewayBasicFuncTest.class); @@ -173,7 +172,7 @@ public class GatewayBasicFuncTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); if( CLEANUP_TEST ) { driver.cleanup(); @@ -182,7 +181,7 @@ public class GatewayBasicFuncTest { } @After - public void cleanupTest() { + public void tearDown() { driver.reset(); } @@ -2190,7 +2189,10 @@ public class GatewayBasicFuncTest { String path = "/v1/cluster/apps/"; String resource = "/yarn/apps"; String gatewayPath = driver.getUrl( "RESOURCEMANAGER" ) + path; - StringBuilder gatewayPathQuery = new StringBuilder(driver.isUseGateway() ? "" : "?user.name=" + username); + StringBuilder gatewayPathQuery = new StringBuilder(); + if(!driver.isUseGateway()) { + gatewayPathQuery.append("?user.name=").append(username); + } InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0]; String gatewayHostName = gatewayAddress.getHostName(); String gatewayAddrName = InetAddress.getByName( gatewayHostName ).getHostAddress(); @@ -2213,11 +2215,11 @@ public class GatewayBasicFuncTest { for (Entry<String, String> param : params.entrySet()) { mockRequestMatcher.queryParam( param.getKey(), param.getValue() ); if (gatewayPathQuery.length() == 0) { - gatewayPathQuery.append("?"); + gatewayPathQuery.append('?'); } else { - gatewayPathQuery.append("&"); + gatewayPathQuery.append('&'); } - gatewayPathQuery.append(param.getKey()).append("=").append(param.getValue()); + gatewayPathQuery.append(param.getKey()).append('=').append(param.getValue()); } } @@ -2536,8 +2538,10 @@ public class GatewayBasicFuncTest { String nodeResource = "/yarn/node"; String nodeId = "localhost:45454"; String gatewayPath = driver.getUrl( "RESOURCEMANAGER" ) + path; - StringBuilder gatewayPathQuery = new StringBuilder(driver.isUseGateway() ? "" : "?user.name=" + username); - + StringBuilder gatewayPathQuery = new StringBuilder(); + if(!driver.isUseGateway()) { + gatewayPathQuery.append("?user.name=").append(username); + } MockRequestMatcher mockRequestMatcher = driver.getMock( "RESOURCEMANAGER" ).expect().method( "GET" ) .pathInfo( path ).queryParam( "user.name", username ); @@ -2546,11 +2550,11 @@ public class GatewayBasicFuncTest { for (Entry<String, String> param : params.entrySet()) { mockRequestMatcher.queryParam( param.getKey(), param.getValue() ); if (gatewayPathQuery.length() == 0) { - gatewayPathQuery.append("?"); + gatewayPathQuery.append('?'); } else { - gatewayPathQuery.append("&"); + gatewayPathQuery.append('&'); } - gatewayPathQuery.append(param.getKey()).append("=").append(param.getValue()); + gatewayPathQuery.append(param.getKey()).append('=').append(param.getValue()); } } @@ -4278,24 +4282,6 @@ public class GatewayBasicFuncTest { driver.assertComplete(); } - /* GET /oozie/versions - HTTP/1.1 200 OK - Content-Type: application/json;charset=UTF-8 - Content-Length: 5 - Server: Apache-Coyote/1.1 - Date: Thu, 14 Feb 2013 15:47:51 GMT - See: oozie-versions.json - */ - private void oozieGetVersions( String user, String password ) throws IOException { - given() - .auth().preemptive().basic( user, password ) - .header( "X-XSRF-Header", "jksdhfkhdsf" ) - .then() - .statusCode( 200 ) - .body( "", Matchers.hasItems(0, 1) ) - .when().get( driver.getUrl( "OOZIE" ) + "/versions" + ( driver.isUseGateway() ? "" : "?user.name=" + user ) ).asString(); - } - /* GET /oozie/v1/admin/status HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayCorrelationIdTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayCorrelationIdTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayCorrelationIdTest.java index ecb0461..8d6e386 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayCorrelationIdTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayCorrelationIdTest.java @@ -36,8 +36,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.net.URL; +import java.nio.file.Files; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -57,8 +58,7 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; public class GatewayCorrelationIdTest { - - private static Logger LOG = LoggerFactory.getLogger( GatewayCorrelationIdTest.class ); + private static final Logger LOG = LoggerFactory.getLogger( GatewayCorrelationIdTest.class ); public static GatewayConfig config; public static GatewayServer gateway; @@ -67,7 +67,7 @@ public class GatewayCorrelationIdTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); URL resource = GatewayCorrelationIdTest.class.getClassLoader().getResource("users-dynamic.ldif"); assert resource != null; @@ -78,7 +78,7 @@ public class GatewayCorrelationIdTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); gateway.stop(); driver.cleanup(); @@ -102,9 +102,9 @@ public class GatewayCorrelationIdTest { deployDir.mkdirs(); File descriptor = new File( topoDir, "test-cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + createTopology().toStream(stream); + } DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String,String> options = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java index 03a5d00..0aa8b3a 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java @@ -27,7 +27,6 @@ import org.apache.knox.gateway.services.ServiceLifecycleException; import org.apache.knox.test.TestUtils; import org.apache.knox.test.category.ReleaseTest; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; import org.hamcrest.MatcherAssert; import org.junit.After; import org.junit.AfterClass; @@ -39,10 +38,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.IOException; -import java.util.Enumeration; +import java.io.OutputStream; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -59,10 +58,8 @@ import static org.junit.Assert.assertThat; @Category(ReleaseTest.class) public class GatewayDeployFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewayDeployFuncTest.class ); - private static Logger LOG = LoggerFactory.getLogger( GatewayDeployFuncTest.class ); - - public static Enumeration<Appender> appenders; public static GatewayConfig config; public static GatewayServer gateway; public static File gatewayHome; @@ -71,19 +68,16 @@ public class GatewayDeployFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); LOG_EXIT(); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } @@ -261,9 +255,9 @@ public class GatewayDeployFuncTest { private File writeTestTopology( String name, XMLTag xml ) throws IOException { // Create the test topology. File tempFile = new File( config.getGatewayTopologyDir(), name + ".xml." + UUID.randomUUID() ); - FileOutputStream stream = new FileOutputStream( tempFile ); - xml.toStream( stream ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(tempFile.toPath())) { + xml.toStream(stream); + } File descriptor = new File( config.getGatewayTopologyDir(), name + ".xml" ); tempFile.renameTo( descriptor ); return descriptor; http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayHealthFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayHealthFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayHealthFuncTest.java index 8fc539b..086fe97 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayHealthFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayHealthFuncTest.java @@ -37,8 +37,9 @@ import org.slf4j.LoggerFactory; import javax.ws.rs.core.MediaType; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.nio.file.FileSystems; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; @@ -50,8 +51,7 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.notNullValue; public class GatewayHealthFuncTest { - - private static Logger LOG = LoggerFactory.getLogger(GatewayAdminFuncTest.class); + private static final Logger LOG = LoggerFactory.getLogger(GatewayAdminFuncTest.class); public static GatewayConfig config; public static GatewayServer gateway; @@ -61,7 +61,7 @@ public class GatewayHealthFuncTest { public static TcpTransport ldapTransport; @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { TestUtils.LOG_ENTER(); setupLdap(); setupGateway(); @@ -69,7 +69,7 @@ public class GatewayHealthFuncTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { TestUtils.LOG_ENTER(); gateway.stop(); ldap.stop(true); @@ -108,9 +108,9 @@ public class GatewayHealthFuncTest { deployDir.mkdirs(); File descriptor = new File(topoDir, "test-cluster.xml"); - FileOutputStream stream = new FileOutputStream(descriptor); - createTopology().toStream(stream); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + createTopology().toStream(stream); + } DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String, String> options = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLocalServiceFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLocalServiceFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLocalServiceFuncTest.java index b0432d6..56c0cdf 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLocalServiceFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLocalServiceFuncTest.java @@ -35,7 +35,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; +import java.nio.file.Files; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -49,8 +50,7 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; public class GatewayLocalServiceFuncTest { - - private static Logger LOG = LoggerFactory.getLogger( GatewayTestDriver.class ); + private static final Logger LOG = LoggerFactory.getLogger( GatewayTestDriver.class ); public static Enumeration<Appender> appenders; public static GatewayConfig config; @@ -60,7 +60,7 @@ public class GatewayLocalServiceFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); @@ -69,7 +69,7 @@ public class GatewayLocalServiceFuncTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); gateway.stop(); driver.cleanup(); @@ -80,7 +80,6 @@ public class GatewayLocalServiceFuncTest { } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); gatewayDir.mkdirs(); @@ -96,9 +95,9 @@ public class GatewayLocalServiceFuncTest { deployDir.mkdirs(); File descriptor = new File( topoDir, "cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + createTopology().toStream(stream); + } DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String,String> options = new HashMap<>(); @@ -178,5 +177,4 @@ public class GatewayLocalServiceFuncTest { .when().get( serviceUrl ); LOG_EXIT(); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayMultiFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayMultiFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayMultiFuncTest.java index 046cb0b..40d3458 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayMultiFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayMultiFuncTest.java @@ -19,7 +19,6 @@ package org.apache.knox.gateway; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.directory.server.protocol.shared.transport.TcpTransport; import org.apache.http.HttpHost; import org.apache.http.HttpStatus; import org.apache.http.auth.AuthScope; @@ -41,7 +40,6 @@ import org.apache.knox.gateway.services.topology.TopologyService; import org.apache.knox.test.TestUtils; import org.apache.knox.test.category.ReleaseTest; import org.apache.knox.test.mock.MockServer; -import org.apache.log4j.Appender; import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -53,7 +51,6 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -72,42 +69,36 @@ import static org.xmlmatchers.transform.XmlConverters.the; @Category(ReleaseTest.class) public class GatewayMultiFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewayMultiFuncTest.class ); + private static final Class<?> DAT = GatewayMultiFuncTest.class; - private static Logger LOG = LoggerFactory.getLogger( GatewayMultiFuncTest.class ); - private static Class<?> DAT = GatewayMultiFuncTest.class; - - private static Enumeration<Appender> appenders; private static GatewayTestConfig config; private static DefaultGatewayServices services; private static GatewayServer gateway; private static int gatewayPort; private static String gatewayUrl; - private static TcpTransport ldapTransport; private static Properties params; private static TopologyService topos; private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); setupGateway(); LOG_EXIT(); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); gateway.stop(); driver.cleanup(); FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); gatewayDir.mkdirs(); @@ -436,7 +427,6 @@ public class GatewayMultiFuncTest { LOG_EXIT(); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java index 04c1e68..d36b2c5 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java @@ -24,7 +24,6 @@ import org.apache.knox.gateway.services.DefaultGatewayServices; import org.apache.knox.gateway.services.ServiceLifecycleException; import org.apache.knox.test.TestUtils; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -33,9 +32,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Enumeration; +import java.io.OutputStream; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -47,10 +45,8 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; public class GatewaySampleFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewaySampleFuncTest.class ); - private static Logger LOG = LoggerFactory.getLogger( GatewaySampleFuncTest.class ); - - public static Enumeration<Appender> appenders; public static GatewayConfig config; public static GatewayServer gateway; public static String gatewayUrl; @@ -58,26 +54,22 @@ public class GatewaySampleFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); setupGateway(); LOG_EXIT(); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); gatewayDir.mkdirs(); @@ -93,9 +85,9 @@ public class GatewaySampleFuncTest { deployDir.mkdirs(); File descriptor = new File( topoDir, "test-cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + createTopology().toStream(stream); + } DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String,String> options = new HashMap<>(); @@ -117,7 +109,6 @@ public class GatewaySampleFuncTest { } private static XMLTag createTopology() { - // System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument( true ) .addRoot( "topology" ) .addTag( "gateway" ) @@ -151,13 +142,8 @@ public class GatewaySampleFuncTest { .gotoRoot(); } - //@Test - public void waitForManualTesting() throws IOException { - System.in.read(); - } - @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testTestService() throws ClassNotFoundException { + public void testTestService() { LOG_ENTER(); String username = "guest"; String password = "guest-password"; @@ -173,5 +159,4 @@ public class GatewaySampleFuncTest { .when().get( serviceUrl ); LOG_EXIT(); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySslFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySslFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySslFuncTest.java index 1215f9d..93864ee 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySslFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySslFuncTest.java @@ -25,7 +25,6 @@ import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Arrays; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -62,7 +61,6 @@ import org.apache.http.impl.client.BasicAuthCache; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.apache.log4j.Appender; import org.hamcrest.MatcherAssert; import org.junit.After; import org.junit.AfterClass; @@ -82,11 +80,9 @@ import static org.xmlmatchers.xpath.HasXPath.hasXPath; @Category( ReleaseTest.class ) public class GatewaySslFuncTest { + private static final Logger LOG = LoggerFactory.getLogger( GatewaySslFuncTest.class ); + private static final Class<?> DAT = GatewaySslFuncTest.class; - private static Logger LOG = LoggerFactory.getLogger( GatewaySslFuncTest.class ); - private static Class<?> DAT = GatewaySslFuncTest.class; - - private static Enumeration<Appender> appenders; private static GatewayTestConfig config; private static DefaultGatewayServices services; private static GatewayServer gateway; @@ -99,21 +95,19 @@ public class GatewaySslFuncTest { private static GatewayTestDriver driver = new GatewayTestDriver(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUpAndReturnOriginalAppenders(); driver.setupLdap(0); setupGateway(); LOG_EXIT(); } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); gateway.stop(); driver.cleanup(); FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } @@ -126,7 +120,6 @@ public class GatewaySslFuncTest { } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); gatewayDir.mkdirs(); @@ -279,7 +272,6 @@ public class GatewaySslFuncTest { } public static class TrustAllCerts implements X509TrustManager { - @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s ) throws CertificateException { // Trust all certificates. @@ -302,5 +294,4 @@ public class GatewaySslFuncTest { sslContext.init( null, new TrustManager[]{ new TrustAllCerts() }, new SecureRandom() ); return sslContext; } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java index 0cc9606..71846da 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java @@ -17,7 +17,6 @@ */ package org.apache.knox.gateway; -import java.io.IOException; import java.nio.charset.StandardCharsets; import com.mycila.xmltool.XMLDoc; @@ -31,8 +30,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import static io.restassured.RestAssured.given; import static org.apache.knox.test.TestUtils.LOG_ENTER; @@ -40,17 +37,6 @@ import static org.apache.knox.test.TestUtils.LOG_EXIT; @Category( { VerifyTest.class, MediumTests.class } ) public class GatewayUIFuncTest { - // Uncomment to cause the test to hang after the gateway instance is setup. - // This will allow the gateway instance to be hit directly via some external client. -// @Test -// public void hang() throws IOException { -// System.out.println( "Server on port " + driver.gateway.getAddresses()[0].getPort() ); -// System.out.println(); -// System.in.read(); -// } - - private static Logger log = LoggerFactory.getLogger( GatewayUIFuncTest.class ); - private static GatewayTestDriver driver = new GatewayTestDriver(); // Controls the host name to which the gateway dispatch requests. This may be the name of a sandbox VM @@ -69,10 +55,6 @@ public class GatewayUIFuncTest { // This is frequently used during debugging to keep the GATEWAY_HOME around for inspection. private static final boolean CLEANUP_TEST = true; -// private static final boolean USE_GATEWAY = false; -// private static final boolean USE_MOCK_SERVICES = false; -// private static final boolean CLEANUP_TEST = false; - /** * Creates a deployment of a gateway instance that all test methods will share. This method also creates a * registry of sorts for all of the services that will be used by the test methods. @@ -81,8 +63,7 @@ public class GatewayUIFuncTest { * @throws Exception Thrown if any failure occurs. */ @BeforeClass - public static void setupSuite() throws Exception { - //Log.setLog( new NoOpLogger() ); + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); GatewayTestConfig config = new GatewayTestConfig(); driver.setResourceBase(GatewayUIFuncTest.class); @@ -93,7 +74,7 @@ public class GatewayUIFuncTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); if( CLEANUP_TEST ) { driver.cleanup(); @@ -112,7 +93,6 @@ public class GatewayUIFuncTest { * @return A populated XML structure for a topology file. */ private static XMLTag createTopology() { - //System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument( true ) .addRoot( "topology" ) .addTag( "gateway" ) @@ -153,12 +133,11 @@ public class GatewayUIFuncTest { } @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testOozieUIRoutesAndRewriteRules() throws IOException { + public void testOozieUIRoutesAndRewriteRules() { LOG_ENTER(); String username = "guest"; String password = "guest-password"; String path; - String url = driver.getUrl( "OOZIEUI" ); path = "/oozie-console.css"; driver.getMock("OOZIEUI") @@ -290,5 +269,4 @@ public class GatewayUIFuncTest { driver.assertComplete(); LOG_EXIT(); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java index 1aa44f0..03c7c1e 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java @@ -31,9 +31,10 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -46,8 +47,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; public class KnoxCliLdapFuncTestNegative { - - public static Enumeration<Appender> appenders; public static GatewayTestConfig config; public static GatewayServer gateway; public static String gatewayUrl; @@ -59,7 +58,7 @@ public class KnoxCliLdapFuncTestNegative { private static final String uuid = UUID.randomUUID().toString(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); System.setErr(new PrintStream(errContent, false, StandardCharsets.UTF_8.name())); @@ -69,17 +68,13 @@ public class KnoxCliLdapFuncTestNegative { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); driver.cleanup(); - - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + uuid ); gatewayDir.mkdirs(); @@ -116,14 +111,13 @@ public class KnoxCliLdapFuncTestNegative { descriptor = new File(topoDir, name); } - FileOutputStream stream = new FileOutputStream( descriptor, false ); - if(goodTopology){ - createTopology().toStream( stream ); - } else { - createBadTopology().toStream( stream ); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + if (goodTopology) { + createTopology().toStream(stream); + } else { + createBadTopology().toStream(stream); + } } - stream.close(); - } private static XMLTag createBadTopology(){ @@ -168,8 +162,6 @@ public class KnoxCliLdapFuncTestNegative { } private static XMLTag createTopology() { - - // System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument(true) .addRoot("topology") .addTag("gateway" ) @@ -289,5 +281,4 @@ public class KnoxCliLdapFuncTestNegative { LOG_EXIT(); } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java index 69750d9..e45938b 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java @@ -31,9 +31,10 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -46,8 +47,6 @@ import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertThat; public class KnoxCliLdapFuncTestPositive { - - public static Enumeration<Appender> appenders; public static GatewayTestConfig config; public static GatewayServer gateway; public static String gatewayUrl; @@ -59,7 +58,7 @@ public class KnoxCliLdapFuncTestPositive { private static final String uuid = UUID.randomUUID().toString(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); System.setErr(new PrintStream(errContent, false, StandardCharsets.UTF_8.name())); @@ -69,17 +68,13 @@ public class KnoxCliLdapFuncTestPositive { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); driver.cleanup(); - - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + uuid ); gatewayDir.mkdirs(); @@ -116,18 +111,16 @@ public class KnoxCliLdapFuncTestPositive { descriptor = new File(topoDir, name); } - FileOutputStream stream = new FileOutputStream( descriptor, false ); - if(goodTopology){ - createTopology().toStream( stream ); - } else { - createBadTopology().toStream( stream ); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + if (goodTopology) { + createTopology().toStream(stream); + } else { + createBadTopology().toStream(stream); + } } - stream.close(); - } private static XMLTag createBadTopology(){ - // System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument(true) .addRoot("topology") .addTag( "gateway" ) @@ -164,8 +157,6 @@ public class KnoxCliLdapFuncTestPositive { } private static XMLTag createTopology() { - - // System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument(true) .addRoot("topology") .addTag("gateway") @@ -292,6 +283,4 @@ public class KnoxCliLdapFuncTestPositive { LOG_EXIT(); } - - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java index a8491b4..183fef5 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java @@ -31,9 +31,10 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -45,8 +46,6 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; public class KnoxCliSysBindTest { - - public static Enumeration<Appender> appenders; public static GatewayTestConfig config; public static GatewayServer gateway; public static String gatewayUrl; @@ -58,7 +57,7 @@ public class KnoxCliSysBindTest { private static final String uuid = UUID.randomUUID().toString(); @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { LOG_ENTER(); System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); System.setErr(new PrintStream(errContent, false, StandardCharsets.UTF_8.name())); @@ -68,17 +67,13 @@ public class KnoxCliSysBindTest { } @AfterClass - public static void cleanupSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { LOG_ENTER(); driver.cleanup(); - - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.resetOriginalAppenders( appenders ); LOG_EXIT(); } public static void setupGateway() throws Exception { - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); File gatewayDir = new File( targetDir, "gateway-home-" + uuid ); gatewayDir.mkdirs(); @@ -118,20 +113,16 @@ public class KnoxCliSysBindTest { descriptor = new File(topoDir, name); } - FileOutputStream stream = new FileOutputStream( descriptor, false ); - - if(goodTopology) { - createTopology(user, pass).toStream( stream ); - } else { - createBadTopology().toStream( stream ); + try(OutputStream stream = Files.newOutputStream(descriptor.toPath())) { + if (goodTopology) { + createTopology(user, pass).toStream(stream); + } else { + createBadTopology().toStream(stream); + } } - - stream.close(); - } private static XMLTag createBadTopology(){ - // System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument(true) .addRoot("topology") .addTag( "gateway" ) @@ -168,8 +159,6 @@ public class KnoxCliSysBindTest { } private static XMLTag createTopology(String username, String password) { - - // System.out.println( "GATEWAY=" + xml.toString() ); return XMLDoc.newDocument(true) .addRoot("topology") .addTag("gateway") @@ -246,7 +235,6 @@ public class KnoxCliSysBindTest { cli.run(args2); assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("System LDAP Bind successful")); - // Test 3: Make sure authentication is successful outContent.reset(); String[] args3 = { "system-user-auth-test", "--master", "knox", "--cluster", "test-cluster-3", "--d" }; @@ -270,7 +258,6 @@ public class KnoxCliSysBindTest { assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Warn: main.ldapRealm.contextFactory.systemUsername is not present")); assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Warn: main.ldapRealm.contextFactory.systemPassword is not present")); - // Test 5: Assert that we get a username/password not present error is printed outContent.reset(); String[] args5 = { "system-user-auth-test", "--master", "knox", "--cluster", "not-a-cluster" }; @@ -281,6 +268,4 @@ public class KnoxCliSysBindTest { LOG_EXIT(); } - - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java index e01dcbb..9e766a2 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java @@ -46,11 +46,10 @@ import java.util.Map; import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.capture; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; public class SimpleDescriptorHandlerFuncTest { - - private static final String TEST_PROVIDER_CONFIG = " <gateway>\n" + " <provider>\n" + @@ -212,6 +211,7 @@ public class SimpleDescriptorHandlerFuncTest { // Start a GatewayService with the GatewayServices mock GatewayServer server = GatewayServer.startGateway(config, gatewayServices); + assertNotNull(server); // Invoke the simple descriptor handler, which will also create the credential store // (because it doesn't exist) and the encryptQueryString alias @@ -239,7 +239,6 @@ public class SimpleDescriptorHandlerFuncTest { } } - /////////////////////////////////////////////////////////////////////////////////////////////////////// // Test classes for effectively "skipping" service discovery for this test. /////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -274,5 +273,4 @@ public class SimpleDescriptorHandlerFuncTest { return null; } } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java index 08fe937..3ec5040 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java @@ -19,16 +19,13 @@ package org.apache.knox.gateway.deploy; import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; -import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.UUID; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; @@ -49,8 +46,6 @@ import org.apache.knox.gateway.util.XmlUtils; import org.apache.knox.test.TestUtils; import org.apache.knox.test.log.NoOpAppender; import org.apache.log4j.Appender; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; @@ -67,6 +62,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.xml.HasXPath.hasXPath; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; public class DeploymentFactoryFuncTest { @@ -76,7 +73,7 @@ public class DeploymentFactoryFuncTest { private static final long LONG_TIMEOUT = 10 * MEDIUM_TIMEOUT; @Test( timeout = MEDIUM_TIMEOUT ) - public void testGenericProviderDeploymentContributor() throws ParserConfigurationException, SAXException, IOException, TransformerException { + public void testGenericProviderDeploymentContributor() throws ParserConfigurationException, SAXException, IOException { LOG_ENTER(); GatewayTestConfig config = new GatewayTestConfig(); File targetDir = new File( System.getProperty( "user.dir" ), "target" ); @@ -125,7 +122,6 @@ public class DeploymentFactoryFuncTest { EnterpriseArchive war = DeploymentFactory.createDeployment( config, topology ); Document gateway = XmlUtils.readXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream() ); - //dump( gateway ); //by default the first filter will be the X-Forwarded header filter assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/role", equalTo( "xforwardedheaders" ) ) ); @@ -148,7 +144,7 @@ public class DeploymentFactoryFuncTest { } @Test( timeout = LONG_TIMEOUT ) - public void testInvalidGenericProviderDeploymentContributor() throws ParserConfigurationException, SAXException, IOException, TransformerException { + public void testInvalidGenericProviderDeploymentContributor() { LOG_ENTER(); GatewayTestConfig config = new GatewayTestConfig(); File targetDir = new File( System.getProperty( "user.dir" ), "target" ); @@ -180,12 +176,7 @@ public class DeploymentFactoryFuncTest { provider.setRole( "authentication" ); provider.setName( "generic" ); provider.setEnabled( true ); - Param param; // = new ProviderParam(); - // Missing filter param. - //param.setName( "filter" ); - //param.setValue( "org.opensource.ExistingFilter" ); - //provider.addParam( param ); - param = new Param(); + Param param = new Param(); param.setName( "test-param-name" ); param.setValue( "test-param-value" ); provider.addParam( param ); @@ -197,6 +188,10 @@ public class DeploymentFactoryFuncTest { fail( "Should have throws IllegalArgumentException" ); } catch ( DeploymentException e ) { // Expected. + assertEquals("Failed to contribute provider. Role: authentication Name: generic. " + + "Please check the topology for errors in name and role and that " + + "the provider is on the classpath.", + e.getMessage()); } finally { NoOpAppender.resetOriginalAppenders( appenders ); } @@ -204,7 +199,7 @@ public class DeploymentFactoryFuncTest { } @Test( timeout = MEDIUM_TIMEOUT ) - public void testSimpleTopology() throws IOException, SAXException, ParserConfigurationException, URISyntaxException, TransformerException { + public void testSimpleTopology() throws IOException, SAXException, ParserConfigurationException { LOG_ENTER(); GatewayTestConfig config = new GatewayTestConfig(); //Testing without x-forwarded headers filter @@ -327,7 +322,7 @@ public class DeploymentFactoryFuncTest { @Test( timeout = LONG_TIMEOUT ) - public void testWebXmlGeneration() throws IOException, SAXException, ParserConfigurationException, URISyntaxException { + public void testWebXmlGeneration() throws IOException, SAXException, ParserConfigurationException { LOG_ENTER(); GatewayTestConfig config = new GatewayTestConfig(); File targetDir = new File(System.getProperty("user.dir"), "target"); @@ -435,7 +430,7 @@ public class DeploymentFactoryFuncTest { service = new Service(); service.setRole( "HIVE" ); - service.setUrls( Arrays.asList( new String[]{ "http://hive-host:50001/" } ) ); + service.setUrls(Collections.singletonList("http://hive-host:50001/")); param = new Param(); param.setName( "someparam" ); param.setValue( "somevalue" ); @@ -444,7 +439,7 @@ public class DeploymentFactoryFuncTest { service = new Service(); service.setRole( "WEBHBASE" ); - service.setUrls( Arrays.asList( new String[]{ "http://hbase-host:50002/" } ) ); + service.setUrls(Collections.singletonList("http://hbase-host:50002/")); param = new Param(); param.setName( "replayBufferSize" ); param.setValue( "33" ); @@ -453,7 +448,7 @@ public class DeploymentFactoryFuncTest { service = new Service(); service.setRole( "OOZIE" ); - service.setUrls( Arrays.asList( new String[]{ "http://hbase-host:50003/" } ) ); + service.setUrls(Collections.singletonList("http://hbase-host:50003/")); param = new Param(); param.setName( "otherparam" ); param.setValue( "65" ); @@ -462,7 +457,6 @@ public class DeploymentFactoryFuncTest { EnterpriseArchive war = DeploymentFactory.createDeployment( config, topology ); Document doc = XmlUtils.readXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream() ); - // dump( doc ); Node resourceNode, filterNode, paramNode; String value; @@ -542,7 +536,6 @@ public class DeploymentFactoryFuncTest { doc = XmlUtils.readXml( archive.get( "%2Fminimal-test-app-path/WEB-INF/gateway.xml" ).getAsset().openStream() ); assertThat( doc, notNullValue() ); - //dump( doc ); assertThat( doc, hasXPath("/gateway/resource/pattern", equalTo("/**?**"))); assertThat( doc, hasXPath("/gateway/resource/filter[1]/role", equalTo("xforwardedheaders"))); assertThat( doc, hasXPath("/gateway/resource/filter[1]/name", equalTo("XForwardedHeaderFilter"))); @@ -641,7 +634,7 @@ public class DeploymentFactoryFuncTest { * add AnonymousFilter to the filter chain. */ @Test( timeout = MEDIUM_TIMEOUT ) - public void testServiceAnonAuth() throws IOException, SAXException, ParserConfigurationException, URISyntaxException, TransformerException { + public void testServiceAnonAuth() throws IOException, SAXException, ParserConfigurationException { LOG_ENTER(); final GatewayTestConfig config = new GatewayTestConfig(); config.setXForwardedEnabled(false); @@ -714,7 +707,9 @@ public class DeploymentFactoryFuncTest { final EnterpriseArchive war2 = DeploymentFactory.createDeployment( config, federationTopology ); final Document web = XmlUtils.readXml( war.get( "%2F/WEB-INF/web.xml" ).getAsset().openStream() ); + assertNotNull(web); final Document web2 = XmlUtils.readXml( war2.get( "%2F/WEB-INF/web.xml" ).getAsset().openStream() ); + assertNotNull(web2); /* Make sure AnonymousAuthFilter is added to the chain */ final Document gateway = XmlUtils.readXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream() ); @@ -745,11 +740,9 @@ public class DeploymentFactoryFuncTest { assertThat( gateway2, hasXPath( "/gateway/resource[1]/filter[5]/role", equalTo( "dispatch" ) ) ); assertThat( gateway2, hasXPath( "/gateway/resource[1]/filter[5]/class", equalTo( "org.apache.knox.gateway.dispatch.GatewayDispatchFilter" ) ) ); - LOG_EXIT(); } - private Node node( Node scope, String expression ) throws XPathExpressionException { return (Node)XPathFactory.newInstance().newXPath().compile( expression ).evaluate( scope, XPathConstants.NODE ); } @@ -757,22 +750,4 @@ public class DeploymentFactoryFuncTest { private String value( Node scope, String expression ) throws XPathExpressionException { return XPathFactory.newInstance().newXPath().compile( expression ).evaluate( scope ); } - - private static void dump( org.jboss.shrinkwrap.api.Node node, String prefix ) { - System.out.println( prefix + ": " + node.getPath() ); - Set<org.jboss.shrinkwrap.api.Node> children = node.getChildren(); - if( children != null && !children.isEmpty() ) { - for( org.jboss.shrinkwrap.api.Node child : children ) { - dump( child, prefix + " " ); - } - } - } - - private static void dump( Archive archive ) { - Map<ArchivePath,org.jboss.shrinkwrap.api.Node> content = archive.getContent(); - for( Map.Entry<ArchivePath,org.jboss.shrinkwrap.api.Node> entry : content.entrySet() ) { - dump( entry.getValue(), " " ); - } - } - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-test/src/test/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorTest.java index 231ff73..7839a64 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorTest.java @@ -40,10 +40,11 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.File; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -93,7 +94,7 @@ public class RemoteConfigurationMonitorTest { private static CuratorFramework client; @BeforeClass - public static void setupSuite() throws Exception { + public static void setUpBeforeClass() throws Exception { testTmp = TestUtils.createTempDir(RemoteConfigurationMonitorTest.class.getName()); File confDir = TestUtils.createTempDir(testTmp + "/conf"); providersDir = TestUtils.createTempDir(confDir + "/shared-providers"); @@ -101,7 +102,7 @@ public class RemoteConfigurationMonitorTest { } @AfterClass - public static void tearDownSuite() throws Exception { + public static void tearDownAfterClass() throws Exception { // Delete the working dir testTmp.delete(); } @@ -136,17 +137,18 @@ public class RemoteConfigurationMonitorTest { */ private static File setupDigestSaslConfig(String username, String password) throws Exception { File saslConfigFile = new File(testTmp, "server-jaas.conf"); - Writer fw = new OutputStreamWriter(new FileOutputStream(saslConfigFile), StandardCharsets.UTF_8); - fw.write("Server {\n" + - " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + - " user_" + username + " =\"" + password + "\";\n" + - "};\n" + - "Client {\n" + - " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + - " username=\"" + username + "\"\n" + - " password=\"" + password + "\";\n" + - "};\n"); - fw.close(); + try(OutputStream outputStream = Files.newOutputStream(saslConfigFile.toPath()); + Writer fw = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) { + fw.write("Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_" + username + " =\"" + password + "\";\n" + + "};\n" + + "Client {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"" + username + "\"\n" + + " password=\"" + password + "\";\n" + + "};\n"); + } return saslConfigFile; } @@ -683,5 +685,4 @@ public class RemoteConfigurationMonitorTest { " {\"name\":\"RESOURCEMANAGER\"}\n" + " ]\n" + "}\n"; - } http://git-wip-us.apache.org/repos/asf/knox/blob/89caa5fe/gateway-util-common/src/test/java/org/apache/knox/gateway/audit/AuditLayoutTest.java ---------------------------------------------------------------------- diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/audit/AuditLayoutTest.java b/gateway-util-common/src/test/java/org/apache/knox/gateway/audit/AuditLayoutTest.java index 88c4c2c..57726f4 100644 --- a/gateway-util-common/src/test/java/org/apache/knox/gateway/audit/AuditLayoutTest.java +++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/audit/AuditLayoutTest.java @@ -71,12 +71,12 @@ public class AuditLayoutTest { } @Before - public void setup() { - cleanup(); + public void setUp() { + tearDown(); } @After - public void cleanup() { + public void tearDown() { CollectAppender.queue.clear(); auditService.detachContext(); correlationService.detachContext();
