Skip to content

Commit

Permalink
ARTEMIS-4778: clean up configuration test heirarchy, remove hundreds …
Browse files Browse the repository at this point in the history
…of duplicate tests, isolate parameterized tests
  • Loading branch information
gemmellr committed May 21, 2024
1 parent 3c058e9 commit 98e1389
Show file tree
Hide file tree
Showing 9 changed files with 632 additions and 530 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@
import org.junit.Assert;
import org.junit.Test;

public class DefaultsFileConfigurationTest extends ConfigurationImplTest {
public class DefaultsFileConfigurationTest extends AbstractConfigurationTestBase {

@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager("ConfigurationTest-defaults.xml");
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();

return fc;
}

@Test
public void testDefaults() {

Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), conf.getScheduledThreadPoolMaxSize());

Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultThreadPoolMaxSize(), conf.getThreadPoolMaxSize());
Expand Down Expand Up @@ -150,16 +158,4 @@ public void testDefaults() {

Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultLoggingMetrics(), conf.getMetricsConfiguration().isLogging());
}

// Protected ---------------------------------------------------------------------------------------------

@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager("ConfigurationTest-defaults.xml");
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();

return fc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
import org.junit.Assert;
import org.junit.Test;

public class FileConfigurationBrokerConnectionEncryptedTest extends ConfigurationImplTest {
public class FileConfigurationBrokerConnectionEncryptedTest extends AbstractConfigurationTestBase {

protected String getConfigurationName() {
return "ConfigurationTest-broker-connection-encrypted-config.xml";
}

@Override
@Test
public void testDefaults() {
// empty
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
}

@Test
Expand Down Expand Up @@ -71,16 +74,25 @@ public void testAMQPBrokerConfigEncryptedUserAndPassword() {
Assert.assertTrue("enc-test configuration is not present", encTest);
Assert.assertTrue("plain-test configuration is not present", plainTest);
Assert.assertTrue("empty-test configuration is not present", emptyTest);
}

@Test
public void testSetGetAttributes() throws Exception {
doSetGetAttributesTestImpl(conf);
}

@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
@Test
public void testGetSetInterceptors() {
doGetSetInterceptorsTestImpl(conf);
}

@Test
public void testSerialize() throws Exception {
doSerializeTestImpl(conf);
}

@Test
public void testSetConnectionRoutersPolicyConfiguration() throws Throwable {
doSetConnectionRoutersPolicyConfigurationTestImpl((ConfigurationImpl) conf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,44 @@
import org.junit.Assert;
import org.junit.Test;

public class FileConfigurationDbEncryptedPassTest extends ConfigurationImplTest {

public class FileConfigurationDbEncryptedPassTest extends AbstractConfigurationTestBase {

protected String getConfigurationName() {
return "ConfigurationTest-db-encrypted-pass-config.xml";
}

@Override
@Test
public void testDefaults() {
// empty
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
}

@Test
public void testJdbcPasswordWithCustomCodec() {
Assert.assertTrue(MySensitiveStringCodec.decoded);
}

@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
@Test
public void testSetGetAttributes() throws Exception {
doSetGetAttributesTestImpl(conf);
}

@Test
public void testGetSetInterceptors() {
doGetSetInterceptorsTestImpl(conf);
}

@Test
public void testSerialize() throws Exception {
doSerializeTestImpl(conf);
}

@Test
public void testSetConnectionRoutersPolicyConfiguration() throws Throwable {
doSetConnectionRoutersPolicyConfigurationTestImpl((ConfigurationImpl) conf);
}

public static class MySensitiveStringCodec implements SensitiveDataCodec<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@
import java.util.Map;
import java.util.Set;

public class FileConfigurationSecurityPluginTest extends ConfigurationImplTest {

public class FileConfigurationSecurityPluginTest extends AbstractConfigurationTestBase {

protected String getConfigurationName() {
return "ConfigurationTest-security-plugin-config.xml";
}

@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
}

@Test
public void testDefaults() {
List<SecuritySettingPlugin> securitySettingPlugins = conf.getSecuritySettingPlugins();
Expand All @@ -45,15 +52,27 @@ public void testDefaults() {
Assert.assertEquals("hello", MyPlugin.options.get("setting2"));
}

@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
@Test
public void testSetGetAttributes() throws Exception {
doSetGetAttributesTestImpl(conf);
}

@Test
public void testGetSetInterceptors() {
doGetSetInterceptorsTestImpl(conf);
}

@Test
public void testSerialize() throws Exception {
doSerializeTestImpl(conf);
}

@Test
public void testSetConnectionRoutersPolicyConfiguration() throws Throwable {
doSetConnectionRoutersPolicyConfigurationTestImpl((ConfigurationImpl) conf);
}

// Referenced by the configuration file
public static class MyPlugin implements SecuritySettingPlugin {

private static Map<String, String> options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class FileConfigurationTest extends ConfigurationImplTest {
public class FileConfigurationTest extends AbstractConfigurationTestBase {

@BeforeClass
public static void setupProperties() {
Expand Down Expand Up @@ -116,8 +116,18 @@ protected String getConfigurationName() {
}

@Override
protected Configuration createConfiguration() throws Exception {
// This may be set for the entire testsuite, but on this test we need this out
System.clearProperty("brokerconfig.maxDiskUsage");
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
}

@Test
public void testDefaults() {
public void testFileConfiguration() {
// Check they match the values from the test file
Assert.assertEquals("SomeNameForUseOnTheApplicationServer", conf.getName());
Assert.assertEquals(false, conf.isPersistenceEnabled());
Expand Down Expand Up @@ -927,15 +937,24 @@ public void testMetricsConflict() throws Exception {
assertEquals("value3", metricPluginOptions.get("key3"));
}

@Override
protected Configuration createConfiguration() throws Exception {
// This may be set for the entire testsuite, but on this test we need this out
System.clearProperty("brokerconfig.maxDiskUsage");
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName());
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
return fc;
@Test
public void testSetGetAttributes() throws Exception {
doSetGetAttributesTestImpl(conf);
}

@Test
public void testGetSetInterceptors() {
doGetSetInterceptorsTestImpl(conf);
}

@Test
public void testSerialize() throws Exception {
doSerializeTestImpl(conf);
}

@Test
public void testSetConnectionRoutersPolicyConfiguration() throws Throwable {
doSetConnectionRoutersPolicyConfigurationTestImpl(new FileConfiguration());
}

private Configuration createConfiguration(String filename) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

public class FileXIncludeConfigurationTest extends FileConfigurationTest {

@Override
protected String getConfigurationName() {
return "ConfigurationTest-xinclude-config.xml";
}

public FileXIncludeConfigurationTest(boolean xxeEnabled) {
super(xxeEnabled);
Assume.assumeTrue(xxeEnabled);
Expand All @@ -44,9 +49,4 @@ public static void clearProperties() {
System.clearProperty("trueProp");
System.clearProperty("ninetyTwoProp");
}

@Override
protected String getConfigurationName() {
return "ConfigurationTest-xinclude-config.xml";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest {

@Override
protected String getConfigurationName() {
return "ConfigurationTest-xinclude-schema-config.xml";
}

public FileXIncludeSchemaConfigurationTest(boolean xxeEnabled) {
super(xxeEnabled);
Assume.assumeTrue(xxeEnabled);
Expand All @@ -47,10 +53,11 @@ public static void clearProperties() {
}

@Override
@Test
public void testSerialize() throws Exception {
// ConfigurationImplTest#testSerialize() assumes the one plugin it registers is the only one in the configuration.
// super#testSerialize() assumes the one plugin it registers is the only one in the configuration.

// Check the expected 2 from the include file are present
// Check the expected 2 plugins from the include file are present
assertEquals("included broker plugins are not present", 2, conf.getBrokerPlugins().size());

// Clear the list
Expand All @@ -61,9 +68,4 @@ public void testSerialize() throws Exception {
// Allow the test to proceed
super.testSerialize();
}

@Override
protected String getConfigurationName() {
return "ConfigurationTest-xinclude-schema-config.xml";
}
}

0 comments on commit 98e1389

Please sign in to comment.