[AMQ-6546] Big refactoring and cleanup of karaf itests

This commit is contained in:
Christian Schneider 2016-12-19 09:28:03 +01:00
parent 56917c07ec
commit 4dd3aa420e
12 changed files with 211 additions and 361 deletions

View File

@ -16,6 +16,27 @@
*/ */
package org.apache.activemq.karaf.itest; package org.apache.activemq.karaf.itest;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.security.PrivilegedAction;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.security.auth.Subject; import javax.security.auth.Subject;
import org.apache.karaf.features.FeaturesService; import org.apache.karaf.features.FeaturesService;
@ -25,11 +46,12 @@ import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory; import org.apache.karaf.shell.api.console.SessionFactory;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.TestProbeBuilder;
import org.ops4j.pax.exam.ProbeBuilder; import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; import org.ops4j.pax.exam.TestProbeBuilder;
import org.ops4j.pax.exam.karaf.options.LogLevelOption; import org.ops4j.pax.exam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.options.UrlReference; import org.ops4j.pax.exam.options.UrlReference;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
@ -37,49 +59,21 @@ import org.osgi.framework.Constants;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import static org.ops4j.pax.exam.CoreOptions.*;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*;
public abstract class AbstractFeatureTest { public abstract class AbstractFeatureTest {
private static final String KARAF_MAJOR_VERSION = "4.0.0";
public static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureTest.class); public static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureTest.class);
public static final long ASSERTION_TIMEOUT = 30000L; public static final long ASSERTION_TIMEOUT = 30000L;
public static final long COMMAND_TIMEOUT = 30000L; public static final long COMMAND_TIMEOUT = 30000L;
public static final String USER = "karaf"; public static final String USER = "karaf";
public static final String PASSWORD = "karaf"; public static final String PASSWORD = "karaf";
public static final String RESOURCE_BASE = "src/test/resources/org/apache/activemq/karaf/itest/";
static String basedir;
static {
try {
File location = new File(AbstractFeatureTest.class.getProtectionDomain().getCodeSource().getLocation().getFile());
basedir = new File(location, "../..").getCanonicalPath();
System.err.println("basedir=" + basedir);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Inject @Inject
BundleContext bundleContext; BundleContext bundleContext;
@Inject @Inject
FeaturesService featuresService; FeaturesService featuresService;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -101,7 +95,7 @@ public abstract class AbstractFeatureTest {
ExecutorService executor = Executors.newCachedThreadPool(); ExecutorService executor = Executors.newCachedThreadPool();
protected String executeCommand(final String command, final Long timeout, final Boolean silent) { private String executeCommand(final String command, final Long timeout, final Boolean silent) {
String response; String response;
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(byteArrayOutputStream); final PrintStream printStream = new PrintStream(byteArrayOutputStream);
@ -151,19 +145,17 @@ public abstract class AbstractFeatureTest {
return executeCommand(command, COMMAND_TIMEOUT, false); return executeCommand(command, COMMAND_TIMEOUT, false);
} }
/** /**
* Installs a feature and asserts that feature is properly installed. * Installs a feature and asserts that feature is properly installed.
* @param feature *
* @throws Exception * @param feature
*/ * @throws Exception
public void installAndAssertFeature(final String feature) throws Throwable { */
executeCommand("feature:list -i"); public void installAndAssertFeature(final String feature) throws Throwable {
executeCommand("feature:install " + feature); featuresService.installFeature(feature);
assertFeatureInstalled(feature); }
}
public void assertFeatureInstalled(final String feature) throws Throwable { public void assertFeatureInstalled(final String feature) throws Throwable {
executeCommand("feature:list -i");
withinReason(new Callable<Boolean>() { withinReason(new Callable<Boolean>() {
@Override @Override
public Boolean call() throws Exception { public Boolean call() throws Exception {
@ -172,95 +164,49 @@ public abstract class AbstractFeatureTest {
} }
}); });
} }
public boolean verifyBundleInstalled(final String bundleName) throws Exception { public Bundle getBundle(String symName) {
boolean found = false;
for (Bundle bundle: bundleContext.getBundles()) { for (Bundle bundle: bundleContext.getBundles()) {
LOG.debug("Checking: " + bundle.getSymbolicName()); if (bundle.getSymbolicName().contains(symName)) {
if (bundle.getSymbolicName().contains(bundleName)) { return bundle;
found = true;
break;
} }
} }
return found; throw new RuntimeException("Bundle " + symName + " not found");
} }
public static String karafVersion() { public static Option configureBrokerStart(String xmlConfig) {
return System.getProperty("karafVersion", "unknown-need-env-var"); return composite(
replaceConfigurationFile("etc/activemq.xml", new File(RESOURCE_BASE + xmlConfig + ".xml")),
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg",
new File(RESOURCE_BASE + "org.apache.activemq.server-default.cfg"))
);
} }
public static UrlReference getActiveMQKarafFeatureUrl() { public static Option configureBrokerStart() {
String type = "xml/features"; return configureBrokerStart("activemq");
UrlReference urlReference = mavenBundle().groupId("org.apache.activemq").
artifactId("activemq-karaf").versionAsInProject().type(type);
System.err.println("FeatureURL: " + urlReference.getURL());
return urlReference;
} }
// for use from a probe public static Option configure(String... features) {
public String getCamelFeatureUrl() { MavenUrlReference karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf")
return getCamelFeatureUrl(System.getProperty("camel.version", "unknown")); .type("tar.gz").versionAsInProject();
UrlReference camelUrl = maven().groupId("org.apache.camel.karaf")
.artifactId("apache-camel").type("xml").classifier("features").versionAsInProject();
UrlReference activeMQUrl = maven().groupId("org.apache.activemq").
artifactId("activemq-karaf").versionAsInProject().type("xml").classifier("features").versionAsInProject();
return composite(
karafDistributionConfiguration().frameworkUrl(karafUrl).karafVersion(KARAF_MAJOR_VERSION)
.name("Apache Karaf").unpackDirectory(new File("target/paxexam/unpack/")),
keepRuntimeFolder(), //
logLevel(LogLevelOption.LogLevel.WARN), //
editConfigurationFilePut("etc/config.properties", "karaf.startlevel.bundle", "50"),
// debugConfiguration("5005", true),
features(activeMQUrl, features), //
features(camelUrl)
);
} }
public static String getCamelFeatureUrl(String ver) { protected static String camelVersion() {
return "mvn:org.apache.camel.karaf/apache-camel/" return MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel");
+ ver
+ "/xml/features";
}
public static UrlReference getKarafFeatureUrl() {
LOG.info("*** The karaf version is " + karafVersion() + " ***");
String type = "xml/features";
return mavenBundle().groupId("org.apache.karaf.assemblies.features").
artifactId("standard").version(karafVersion()).type(type);
}
public static Option[] configureBrokerStart(Option[] existingOptions, String xmlConfig) {
existingOptions = append(
replaceConfigurationFile("etc/activemq.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/" + xmlConfig + ".xml")),
existingOptions);
return append(
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg")),
existingOptions);
}
public static Option[] configureBrokerStart(Option[] existingOptions) {
final String xmlConfig = "activemq";
return configureBrokerStart(existingOptions, xmlConfig);
}
public static Option[] append(Option toAdd, Option[] existingOptions) {
ArrayList<Option> newOptions = new ArrayList<Option>();
newOptions.addAll(Arrays.asList(existingOptions));
newOptions.add(toAdd);
return newOptions.toArray(new Option[]{});
}
public static Option[] configure(String ...features) {
ArrayList<String> f = new ArrayList<String>();
f.addAll(Arrays.asList(features));
Option[] options =
new Option[]{
karafDistributionConfiguration().frameworkUrl(
maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz").versionAsInProject())
.karafVersion(karafVersion()).name("Apache Karaf")
.unpackDirectory(new File("target/paxexam/unpack/")),
KarafDistributionOption.keepRuntimeFolder(),
logLevel(LogLevelOption.LogLevel.WARN),
editConfigurationFilePut("etc/config.properties", "karaf.startlevel.bundle", "50"),
//debugConfiguration("5005", true),
features(getActiveMQKarafFeatureUrl(), f.toArray(new String[f.size()]))};
if (f.contains("activemq-camel")) {
options = append(features(maven().groupId("org.apache.camel.karaf").artifactId("apache-camel")
.versionAsInProject()
.type("xml/features")), options);
}
return options;
} }
protected boolean withinReason(Callable<Boolean> callable) throws Throwable { protected boolean withinReason(Callable<Boolean> callable) throws Throwable {
@ -278,4 +224,21 @@ public abstract class AbstractFeatureTest {
} }
} }
} }
protected void withinReason(Runnable runable) throws Exception {
long max = System.currentTimeMillis() + ASSERTION_TIMEOUT;
while (true) {
try {
runable.run();
return;
} catch (Throwable t) {
if (System.currentTimeMillis() < max) {
TimeUnit.SECONDS.sleep(1);
continue;
} else {
throw t;
}
}
}
}
} }

View File

@ -71,11 +71,10 @@ public abstract class AbstractJmsFeatureTest extends AbstractFeatureTest {
connection.close(); connection.close();
} }
protected Connection getConnection() throws Throwable { protected Connection getConnection() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(AbstractFeatureTest.USER, AbstractFeatureTest.PASSWORD); Connection connection = factory.createConnection(AbstractFeatureTest.USER, AbstractFeatureTest.PASSWORD);
connection.start(); connection.start();
return connection; return connection;
} }
} }

View File

@ -16,10 +16,6 @@
*/ */
package org.apache.activemq.karaf.itest; package org.apache.activemq.karaf.itest;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.Callable;
import javax.jms.Connection; import javax.jms.Connection;
import org.apache.qpid.jms.JmsConnectionFactory; import org.apache.qpid.jms.JmsConnectionFactory;
@ -29,41 +25,41 @@ import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class ActiveMQAMQPBrokerFeatureTest extends ActiveMQBrokerFeatureTest { public class ActiveMQAMQPBrokerFeatureTest extends ActiveMQBrokerFeatureTest {
private static final Integer AMQP_PORT = 61636; private static final Integer AMQP_PORT = 61636;
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
Option[] configure = configure("activemq", "activemq-amqp-client"); return new Option[] //
{
Option[] configuredOptions = configureBrokerStart(configure); configure("activemq", "activemq-amqp-client"), //
configureBrokerStart()
return configuredOptions; };
} }
@Override @Override
protected Connection getConnection() throws Throwable { protected Connection getConnection() throws Exception {
withinReason(new Callable<Boolean>() { withinReason(new Runnable() {
@Override public void run() {
public Boolean call() throws Exception { getBundle("org.apache.qpid.jms.client");
assertTrue("qpid jms client bundle installed", verifyBundleInstalled("org.apache.qpid.jms.client"));
return true;
} }
}); });
String amqpURI = "amqp://localhost:" + AMQP_PORT; String amqpURI = "amqp://localhost:" + AMQP_PORT;
JmsConnectionFactory factory = new JmsConnectionFactory(amqpURI); JmsConnectionFactory factory = new JmsConnectionFactory(amqpURI);
factory.setUsername(AbstractFeatureTest.USER); factory.setUsername(AbstractFeatureTest.USER);
factory.setPassword(AbstractFeatureTest.PASSWORD); factory.setPassword(AbstractFeatureTest.PASSWORD);
Connection connection = factory.createConnection(); Connection connection = factory.createConnection();
connection.start(); connection.start();
return connection; return connection;
} }
@Override @Override
@Ignore @Ignore
@Test(timeout = 5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)

View File

@ -39,7 +39,7 @@ public class ActiveMQBrokerBlueprintTest extends AbstractJmsFeatureTest {
{ {
composite(super.configure("activemq", "activemq-blueprint")), composite(super.configure("activemq", "activemq-blueprint")),
replaceConfigurationFile("deploy/activemq-blueprint.xml", replaceConfigurationFile("deploy/activemq-blueprint.xml",
new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/activemq-blueprint.xml")) new File("src/test/resources/org/apache/activemq/karaf/itest/activemq-blueprint.xml"))
}; };
} }

View File

@ -16,12 +16,6 @@
*/ */
package org.apache.activemq.karaf.itest; package org.apache.activemq.karaf.itest;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.Callable;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
@ -43,29 +37,11 @@ public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
return configureBrokerStart(configure("activemq")); return new Option[] //
} {
configure("activemq"), //
protected final File file = new File("../../../classes/META-INF/maven/dependencies.properties"); configureBrokerStart()
};
public final String getArtifactVersion(final String groupId, final String artifactId) {
final Properties dependencies = new Properties();
try (FileInputStream fis = new FileInputStream(file)){
dependencies.load(fis);
final String version = dependencies
.getProperty(groupId + "/" + artifactId + "/version");
if (version == null) {
throw new RuntimeException(
"Could not resolve version. Do you have a dependency for " + groupId + "/"
+ artifactId + " in your maven project?");
}
return version;
}
catch (IOException e) {
throw new RuntimeException("Could not resolve version for groupId:" + groupId
+ " artifactId:" + artifactId
+ " by reading the dependency information generated by maven.", e);
}
} }
protected String installWrappedBundle(WrappedUrlProvisionOption option) { protected String installWrappedBundle(WrappedUrlProvisionOption option) {
@ -75,20 +51,10 @@ public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
@Test(timeout=5 * 60 * 1000) @Test(timeout=5 * 60 * 1000)
public void test() throws Throwable { public void test() throws Throwable {
withinReason(new Callable<Boolean>() { withinReason(new Runnable() {
@Override public void run() {
public Boolean call() throws Exception {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim()); assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker")); assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true;
} }
}); });
@ -96,13 +62,11 @@ public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
final String nameAndPayload = String.valueOf(System.currentTimeMillis()); final String nameAndPayload = String.valueOf(System.currentTimeMillis());
produceMessage(nameAndPayload); produceMessage(nameAndPayload);
executeCommand("activemq:bstat", COMMAND_TIMEOUT, false).trim(); executeCommand("activemq:bstat").trim();
withinReason(new Callable<Boolean>(){ withinReason(new Runnable() {
@Override public void run() {
public Boolean call() throws Exception {
assertEquals("JMS_BODY_FIELD:JMSText = " + nameAndPayload, executeCommand("activemq:browse --amqurl tcp://localhost:61616 --user karaf --password karaf -Vbody " + nameAndPayload).trim()); assertEquals("JMS_BODY_FIELD:JMSText = " + nameAndPayload, executeCommand("activemq:browse --amqurl tcp://localhost:61616 --user karaf --password karaf -Vbody " + nameAndPayload).trim());
return true;
} }
}); });

View File

@ -17,74 +17,44 @@
package org.apache.activemq.karaf.itest; package org.apache.activemq.karaf.itest;
import java.io.File; import java.io.File;
import java.util.concurrent.Callable;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.junit.PaxExam;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
public class ActiveMQBrokerNdCamelFeatureTest extends AbstractJmsFeatureTest { public class ActiveMQBrokerNdCamelFeatureTest extends AbstractJmsFeatureTest {
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
return append( return new Option[] //
editConfigurationFilePut("etc/system.properties", "camel.version", MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")), {
configure("activemq", "activemq-camel")); composite(configure("activemq", "activemq-camel")),
editConfigurationFilePut("etc/system.properties", "camel.version", camelVersion()),
replaceConfigurationFile("etc/activemq.xml", new File(RESOURCE_BASE + "activemq-nd-camel.xml")),
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new File(RESOURCE_BASE + "org.apache.activemq.server-default.cfg"))
};
} }
@Test(timeout = 2 * 60 * 1000) @Test(timeout = 2 * 60 * 1000)
public void test() throws Throwable { public void test() throws Throwable {
System.err.println(executeCommand("feature:list").trim()); System.err.println(executeCommand("feature:list -i").trim());
assertFeatureInstalled("activemq"); assertFeatureInstalled("activemq");
assertTrue("activemq-camel bundle installed", verifyBundleInstalled("org.apache.activemq.activemq-camel")); withinReason(new Runnable() {
public void run() {
withinReason(new Callable<Boolean>() { getBundle("org.apache.activemq.activemq-camel");
@Override
public Boolean call() throws Exception {
assertTrue("activemq-camel bundle installed", verifyBundleInstalled("org.apache.activemq.activemq-camel"));
return true;
}
});
// start broker with embedded camel route
String karafDir = System.getProperty("karaf.base");
File target = new File(karafDir + "/etc/activemq.xml");
copyFile(new File(basedir + "/../../../src/test/resources/org/apache/activemq/karaf/itest/activemq-nd-camel.xml"), target);
target = new File(karafDir + "/etc/org.apache.activemq.server-default.cfg");
copyFile(new File(basedir + "/../../../src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg"), target);
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim()); assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker")); assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue("we have camel consumers", executeCommand("activemq:dstat").trim().contains("camel_in")); assertTrue("we have camel consumers", executeCommand("activemq:dstat").trim().contains("camel_in"));
return true;
} }
}); });

View File

@ -16,74 +16,54 @@
*/ */
package org.apache.activemq.karaf.itest; package org.apache.activemq.karaf.itest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import java.io.File; import java.io.File;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
//@RunWith(PaxExam.class) //@RunWith(PaxExam.class)
@Ignore @Ignore
public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeatureTest { public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeatureTest {
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
Option[] baseOptions = configure("activemq"); return new Option[] //
// copy camel.xml into a temporary directory in karaf, so we later can hot-deploy it {
baseOptions = append(replaceConfigurationFile("data/tmp/camel.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/camel.xml")), baseOptions); configure("activemq"),
baseOptions = append(editConfigurationFilePut("etc/system.properties", "camel.version", MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")), baseOptions); // copy camel.xml into a temporary directory in karaf, so we later can hot-deploy it
return configureBrokerStart(baseOptions); replaceConfigurationFile("data/tmp/camel.xml", new File(RESOURCE_BASE + "camel.xml")),
editConfigurationFilePut("etc/system.properties", "camel.version", camelVersion())
};
} }
@Ignore("camel.xml from auto deploy directory does not seem to get picked up, no idea why atm") @Ignore("camel.xml from auto deploy directory does not seem to get picked up, no idea why atm")
@Test(timeout = 2 * 60 * 1000) @Test(timeout = 2 * 60 * 1000)
public void test() throws Throwable { public void test() throws Throwable {
assertFeatureInstalled("activemq"); assertFeatureInstalled("activemq");
executeCommand("feature:repo-add " + getCamelFeatureUrl());
installAndAssertFeature("camel"); installAndAssertFeature("camel");
installAndAssertFeature("activemq-camel"); installAndAssertFeature("activemq-camel");
withinReason(new Callable<Boolean>() { withinReason(new Runnable() {
@Override public void run() {
public Boolean call() throws Exception {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim()); assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker")); assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true; getBundle("org.apache.activemq.activemq-camel");
} }
}); });
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertTrue("activemq-camel bundle installed", verifyBundleInstalled("org.apache.activemq.activemq-camel"));
return true;
}
});
assertFeatureInstalled("activemq-camel");
System.err.println(executeCommand("activemq:bstat").trim()); System.err.println(executeCommand("activemq:bstat").trim());
// hot deploy the camel.xml file by copying it to the deploy directory // hot deploy the camel.xml file by copying it to the deploy directory
System.err.println("Karaf is running in dir: " + System.getProperty("karaf.base"));
String karafDir = System.getProperty("karaf.base"); String karafDir = System.getProperty("karaf.base");
System.err.println("Karaf is running in dir: " + karafDir);
System.err.println("Hot deploying Camel application"); System.err.println("Hot deploying Camel application");
copyFile(new File(karafDir + "/data/tmp/camel.xml"), new File(karafDir + "/deploy/camel.xml")); copyFile(new File(karafDir + "/data/tmp/camel.xml"), new File(karafDir + "/deploy/camel.xml"));

View File

@ -39,9 +39,12 @@ public class ActiveMQBrokerNdWebConsoleFeatureTest extends ActiveMQBrokerFeature
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
return append(CoreOptions.mavenBundle("commons-codec", "commons-codec").versionAsInProject(), return new Option[] //
append(CoreOptions.mavenBundle("commons-httpclient", "commons-httpclient").versionAsInProject(), {
configure("activemq-broker"))); CoreOptions.mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
CoreOptions.mavenBundle("commons-httpclient", "commons-httpclient").versionAsInProject(),
configure("activemq-broker")
};
} }
@Override @Override

View File

@ -16,50 +16,43 @@
*/ */
package org.apache.activemq.karaf.itest; package org.apache.activemq.karaf.itest;
import java.io.File;
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.junit.PaxExam;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import java.io.File;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
public class ActiveMQBrokerRuntimeConfigTest extends AbstractJmsFeatureTest { public class ActiveMQBrokerRuntimeConfigTest extends AbstractJmsFeatureTest {
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
return append(editConfigurationFilePut("etc/org.apache.activemq.server-default.cfg", "config.check", "false"), return new Option[] //
configureBrokerStart( {
append(replaceConfigurationFile("data/tmp/modified-config.xml", configure("activemq"),
new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/activemq-runtime-config-mod.xml")), editConfigurationFilePut("etc/org.apache.activemq.server-default.cfg", "config.check", "false"),
configure("activemq")), "activemq-runtime-config")); replaceConfigurationFile("data/tmp/modified-config.xml",
new File(RESOURCE_BASE + "activemq-runtime-config-mod.xml")),
configureBrokerStart("activemq-runtime-config")
};
} }
@Test(timeout = 2 * 60 * 1000) @Test(timeout = 2 * 60 * 1000)
public void test() throws Throwable { public void test() throws Throwable {
withinReason(new Callable<Boolean>() { withinReason(new Runnable() {
@Override public void run() {
public Boolean call() throws Exception {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim()); assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue("3MB limit", executeCommand("activemq:query").trim().contains("MemoryLimit = 3145728")); assertTrue("3MB limit", executeCommand("activemq:query").trim().contains("MemoryLimit = 3145728"));
return true;
} }
}); });
@ -73,11 +66,9 @@ public class ActiveMQBrokerRuntimeConfigTest extends AbstractJmsFeatureTest {
copyFile(new File(karafDir + "/data/tmp/modified-config.xml"), target); copyFile(new File(karafDir + "/data/tmp/modified-config.xml"), target);
System.err.println("new mod at: " + new Date(target.lastModified())); System.err.println("new mod at: " + new Date(target.lastModified()));
withinReason(new Callable<Boolean>() { withinReason(new Runnable() {
@Override public void run() {
public Boolean call() throws Exception {
assertTrue("4MB limit", executeCommand("activemq:query").trim().contains("MemoryLimit = 4194304")); assertTrue("4MB limit", executeCommand("activemq:query").trim().contains("MemoryLimit = 4194304"));
return true;
} }
}); });

View File

@ -19,8 +19,8 @@ package org.apache.activemq.karaf.itest;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.junit.PaxExam;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
@ -28,7 +28,10 @@ public class ActiveMQClientBundleTest extends AbstractFeatureTest {
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
return configure("activemq-client"); return new Option[] //
{
configure("activemq-client")
};
} }
@Test(timeout = 2 * 60 * 1000) @Test(timeout = 2 * 60 * 1000)

View File

@ -22,103 +22,84 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class ObrFeatureTest extends AbstractFeatureTest { public class ObrFeatureTest extends AbstractFeatureTest {
@Configuration @Configuration
public static Option[] configure() { public static Option[] configure() {
Option[] options = append( return new Option[] //
editConfigurationFilePut("etc/system.properties", "camel.version", MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")), {
configure("obr")); configure("obr"),
// can't see where these deps die in a paxexam container - vanilla distro unpack can install war feature ok editConfigurationFilePut("etc/system.properties", "camel.version", camelVersion()),
options = append(CoreOptions.mavenBundle("org.apache.xbean", "xbean-bundleutils").versionAsInProject(), options); };
options = append(CoreOptions.mavenBundle("org.apache.xbean", "xbean-asm-util").versionAsInProject(), options);
return append(CoreOptions.mavenBundle("org.apache.xbean", "xbean-finder").versionAsInProject(), options);
} }
@Test(timeout = 5 * 60 * 1000)
@Test(timeout=5 * 60 * 1000)
public void testWar() throws Throwable {
installAndAssertFeature("war");
}
@Test(timeout=5 * 60 * 1000)
public void testClient() throws Throwable { public void testClient() throws Throwable {
installAndAssertFeature("activemq-client"); installAndAssertFeature("activemq-client");
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testActiveMQ() throws Throwable { public void testActiveMQ() throws Throwable {
installAndAssertFeature("activemq"); installAndAssertFeature("activemq");
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testBroker() throws Throwable { public void testBroker() throws Throwable {
installAndAssertFeature("activemq-broker"); installAndAssertFeature("activemq-broker");
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testCamel() throws Throwable { public void testCamel() throws Throwable {
executeCommand("feature:repo-add " + getCamelFeatureUrl());
installAndAssertFeature("activemq-camel"); installAndAssertFeature("activemq-camel");
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring31() throws Throwable { public void testClientWithSpring31() throws Throwable {
executeCommand("feature:install spring/3.1.4.RELEASE"); testWithSpringVersion("3.1.4.RELEASE");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring32() throws Throwable { public void testClientWithSpring32() throws Throwable {
executeCommand("feature:install spring/3.2.14.RELEASE_1"); testWithSpringVersion("3.2.14.RELEASE_1");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring40() throws Throwable { public void testClientWithSpring40() throws Throwable {
executeCommand("feature:install spring/4.0.7.RELEASE_3"); testWithSpringVersion("4.0.7.RELEASE_3");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring41() throws Throwable { public void testClientWithSpring41() throws Throwable {
executeCommand("feature:install spring/4.1.7.RELEASE_2"); testWithSpringVersion("4.1.7.RELEASE_2");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
} }
@Test(timeout=5 * 60 * 1000) @Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring42() throws Throwable { public void testClientWithSpring42() throws Throwable {
executeCommand("feature:install spring/4.2.2.RELEASE_1"); testWithSpringVersion("4.2.2.RELEASE_1");
}
private void testWithSpringVersion(String version) throws Exception, Throwable {
featuresService.installFeature("spring", version);
installAndAssertFeature("activemq-client"); installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2); verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
} }
public boolean verifyBundleInstalledAndRegisteredServices(final String bundleName, final int numberOfServices) throws Exception { private void verifyBundleInstalledAndRegisteredServices(final String bundleName,
boolean found = false; final int numberOfServices)
for (final Bundle bundle : bundleContext.getBundles()) { throws Exception {
LOG.debug("Checking: " + bundle.getSymbolicName()); Bundle bundle = getBundle(bundleName);
if (bundle.getSymbolicName().contains(bundleName)) { Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
Assert.assertEquals(Bundle.ACTIVE, bundle.getState()); // Assert that the bundle has registered some services via blueprint
// Assert that the bundle has registered some services via blueprint Assert.assertNotNull(bundle.getRegisteredServices());
Assert.assertNotNull(bundle.getRegisteredServices()); // Assert that the bundle has registered the correct number of services
// Assert that the bundle has registered the correct number of services Assert.assertEquals(numberOfServices, bundle.getRegisteredServices().length);
Assert.assertEquals(numberOfServices, bundle.getRegisteredServices().length);
found = true;
break;
}
}
return found;
} }
} }

View File

@ -135,7 +135,7 @@
<jaxb-basics-version>0.6.4</jaxb-basics-version> <jaxb-basics-version>0.6.4</jaxb-basics-version>
<stompjms-version>1.19</stompjms-version> <stompjms-version>1.19</stompjms-version>
<pax-exam-version>4.6.0</pax-exam-version> <pax-exam-version>4.9.1</pax-exam-version>
<paxexam-karaf-container-version>1.0.0</paxexam-karaf-container-version> <paxexam-karaf-container-version>1.0.0</paxexam-karaf-container-version>
<pax-runner-version>1.8.6</pax-runner-version> <pax-runner-version>1.8.6</pax-runner-version>
<pax-url-version>2.4.3</pax-url-version> <pax-url-version>2.4.3</pax-url-version>