diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
index 063293573265..3a3c74cd9d10 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
@@ -18,18 +18,22 @@
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.commons.io.FileUtils;
+import org.apache.geode.internal.ClassBuilder;
+import org.apache.geode.management.internal.configuration.utils.ZipUtils;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
import org.junit.Before;
import org.junit.Rule;
+import java.io.File;
+import java.io.IOException;
import java.util.Properties;
public class ClusterConfigBaseTest extends JUnit4DistributedTestCase {
- public static final String CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config.zip";
- public static final String CLUSTER_CONFIG_ZIP_PATH =
- ClusterConfigBaseTest.class.getResource(CLUSTER_CONFIG_ZIP_FILENAME).getPath();
+ public String clusterConfigZipPath;
public static final ConfigGroup CLUSTER = new ConfigGroup("cluster").regions("regionForCluster")
.jars("cluster.jar").maxLogFileSize("5000").configFiles("cluster.properties", "cluster.xml");
@@ -56,6 +60,7 @@ public class ClusterConfigBaseTest extends JUnit4DistributedTestCase {
@Before
public void before() throws Exception {
+ clusterConfigZipPath = buildClusterZipFile();
locatorProps = new Properties();
serverProps = new Properties();
@@ -63,4 +68,62 @@ public void before() throws Exception {
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
serverProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
}
+
+ private String buildClusterZipFile() throws Exception {
+ ClassBuilder classBuilder = new ClassBuilder();
+ File clusterConfigDir = this.lsRule.getTempFolder().newFolder("cluster_config");
+
+ File clusterDir = new File(clusterConfigDir, "cluster");
+ String clusterXml = "\n"
+ + "\n"
+ + "\n"
+ + " \n"
+ + " \n" + "\n";
+ writeFile(clusterDir, "cluster.xml", clusterXml);
+ writeFile(clusterDir, "cluster.properties", "log-file-size-limit=5000");
+ createJarFileWithClass("Cluster", "cluster.jar", clusterDir);
+
+ File group1Dir = new File(clusterConfigDir, "group1");
+ String group1Xml = "\n"
+ + "\n"
+ + "\n"
+ + " \n"
+ + " \n" + "\n";
+ writeFile(group1Dir, "group1.xml", group1Xml);
+ writeFile(group1Dir, "group1.properties", "log-file-size-limit=6000");
+ createJarFileWithClass("Group1", "group1.jar", group1Dir);
+
+
+ File group2Dir = new File(clusterConfigDir, "group2");
+ String group2Xml = "\n"
+ + "\n"
+ + "\n"
+ + " \n"
+ + " \n" + "\n";
+ writeFile(group2Dir, "group1.xml", group2Xml);
+ writeFile(group2Dir, "group2.properties", "log-file-size-limit=7000");
+ createJarFileWithClass("Group2", "group2.jar", group2Dir);
+
+
+ File clusterConfigZip = lsRule.getTempFolder().newFile("cluster_config.zip");
+ ZipUtils.zipDirectory(clusterConfigDir.getCanonicalPath(), clusterConfigZip.getCanonicalPath());
+
+ FileUtils.deleteDirectory(clusterConfigDir);
+ return clusterConfigZip.getCanonicalPath();
+ }
+
+ private File writeFile(File dir, String fileName, String content) throws IOException {
+ dir.mkdirs();
+ File file = new File(dir, fileName);
+ FileUtils.writeStringToFile(file, content);
+
+ return file;
+ }
+
+ protected String createJarFileWithClass(String className, String jarName, File dir)
+ throws IOException {
+ File jarFile = new File(dir, jarName);
+ new ClassBuilder().writeJarFromName(className, jarFile);
+ return jarFile.getCanonicalPath();
+ }
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
index 06e969c2cf76..79f0128ecb87 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
@@ -19,6 +19,7 @@
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.geode.internal.ClassBuilder;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
@@ -30,6 +31,9 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import java.io.File;
+import java.io.IOException;
+
@Category(DistributedTest.class)
public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
private GfshShellConnectionRule gfshConnector;
@@ -39,9 +43,10 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
@Before
public void before() throws Exception {
super.before();
- clusterJar = getClass().getResource("cluster.jar").getPath();
- group1Jar = getClass().getResource("group1.jar").getPath();
- group2Jar = getClass().getResource("group2.jar").getPath();
+
+ clusterJar = createJarFileWithClass("Cluster", "cluster.jar", lsRule.getTempFolder().getRoot());
+ group1Jar = createJarFileWithClass("Group1", "group1.jar", lsRule.getTempFolder().getRoot());
+ group2Jar = createJarFileWithClass("Group2", "group2.jar", lsRule.getTempFolder().getRoot());
}
@After
@@ -53,7 +58,7 @@ public void after() throws Exception {
@Test
public void testDeployToNoServer() throws Exception {
- String clusterJarPath = getClass().getResource("cluster.jar").getPath();
+ String clusterJarPath = clusterJar;
// set up the locator/servers
Locator locator = lsRule.startLocatorVM(0, locatorProps);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
index d8b4cb365613..f68015e5e4f7 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
@@ -83,7 +83,7 @@ public void testImportWithRunningServerWithData() throws Exception {
});
CommandResult result = gfshConnector
- .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH);
+ .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
assertThat(result.getContent().toString()).contains("existing data in regions: " + regionName);
@@ -105,7 +105,7 @@ public void testImportWithRunningServer() throws Exception {
// even though we have a region recreated, we can still import since there is no data
// in the region
CommandResult result = gfshConnector
- .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH);
+ .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
assertThat(result.getStatus()).isEqualTo(Result.Status.OK)
.describedAs(result.getContent().toString());
@@ -130,7 +130,7 @@ public void testImportWithRunningServer() throws Exception {
@Test
public void testImportClusterConfig() throws Exception {
CommandResult result = gfshConnector
- .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH);
+ .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
// Make sure that a backup of the old clusterConfig was created
@@ -164,7 +164,7 @@ public void testImportWithMultipleLocators() throws Exception {
Locator locator2 = lsRule.startLocatorVM(2, locatorProps);
CommandResult result = gfshConnector
- .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH);
+ .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
CONFIG_FROM_ZIP.verify(locator);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java
index fb4aa54fb7f7..c0d22bfc697e 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java
@@ -89,7 +89,7 @@ private Locator startLocatorWithLoadCCFromDir() throws Exception {
// tempFolder/locator-0/cluster_config/cluster/cluster.jar
// tempFolder/locator-0/cluster_config/group1/ {group1.xml, group1.properties, group1.jar}
// tempFolder/locator-0/cluster_config/group2/ ...
- ZipUtils.unzip(CLUSTER_CONFIG_ZIP_PATH, configDir.getCanonicalPath());
+ ZipUtils.unzip(clusterConfigZipPath, configDir.getCanonicalPath());
Properties properties = new Properties();
properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
index 995e18edfa09..388fd9d40cca 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
@@ -21,9 +21,11 @@
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.commons.io.FileUtils;
import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.configuration.utils.ZipUtils;
import org.apache.geode.security.SimpleTestSecurityManager;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
@@ -37,20 +39,12 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import java.io.File;
import java.util.Properties;
@Category({DistributedTest.class, SecurityTest.class})
public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCase {
-
- // the zip file is under test/resource/org/apache/geode/management/internal/configuration
- // it only contains cluster.properites whose content is
- // mcast-port=0
- // log-file-size-limit=8000
- // security-manager=org.apache.geode.example.security.ExampleSecurityManager
-
- public static final String CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config_security.zip";
- public static final String CLUSTER_CONFIG_ZIP_PATH =
- ClusterConfigBaseTest.class.getResource(CLUSTER_CONFIG_ZIP_FILENAME).getPath();
+ public String clusterConfigZipPath;
@Rule
public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
@@ -60,6 +54,8 @@ public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCas
@Before
public void before() throws Exception {
+ clusterConfigZipPath = buildSecureClusterConfigZip();
+
locatorProps = new Properties();
locatorProps.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
locator0 = lsRule.startLocatorVM(0, locatorProps);
@@ -92,7 +88,7 @@ public void testImportNotOverwriteSecurity() throws Exception {
"cluster");
connector.executeAndVerifyCommand(
- "import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH);
+ "import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
locator0.invoke(() -> {
InternalLocator locator = LocatorServerStartupRule.locatorStarter.locator;
@@ -106,4 +102,17 @@ public void testImportNotOverwriteSecurity() throws Exception {
.isEqualTo(SimpleTestSecurityManager.class.getName());
});
}
+
+ private String buildSecureClusterConfigZip() throws Exception {
+ File clusterDir = lsRule.getTempFolder().newFolder("cluster");
+ File clusterSubDir = new File(clusterDir, "cluster");
+
+ String clusterProperties = "mcast-port=0\n" + "log-file-size-limit=8000\n"
+ + "security-manager=org.apache.geode.example.security.ExampleSecurityManager";
+ FileUtils.writeStringToFile(new File(clusterSubDir, "cluster.properties"), clusterProperties);
+ File clusterZip = new File(lsRule.getTempFolder().getRoot(), "cluster_config_security.zip");
+ ZipUtils.zipDirectory(clusterDir.getCanonicalPath(), clusterZip.getCanonicalPath());
+ FileUtils.deleteDirectory(clusterDir);
+ return clusterZip.getCanonicalPath();
+ }
}
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster.jar b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster.jar
deleted file mode 100755
index 9c9541db9328..000000000000
Binary files a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster.jar and /dev/null differ
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config.zip b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config.zip
deleted file mode 100644
index 11fc6bbfa4f3..000000000000
Binary files a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config.zip and /dev/null differ
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip
deleted file mode 100644
index c09114e2437e..000000000000
Binary files a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip and /dev/null differ
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group1.jar b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group1.jar
deleted file mode 100755
index fa105ab50d21..000000000000
Binary files a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group1.jar and /dev/null differ
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group2.jar b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group2.jar
deleted file mode 100755
index b251f0d052c2..000000000000
Binary files a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group2.jar and /dev/null differ