Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

KARAF-1916 Some more speedup and adding some better feedback on error…

…s to the tests

git-svn-id: https://svn.apache.org/repos/asf/karaf/trunk@1397463 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit b1397c02f9e4cc01321ea2dc8e2b5f599aba3f11 1 parent e6390ca
@cschneider cschneider authored
View
63 itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
@@ -16,31 +16,19 @@
*/
package org.apache.karaf.itests;
-import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration;
-import static org.ops4j.pax.exam.CoreOptions.maven;
-
-import javax.inject.Inject;
-
import junit.framework.Assert;
-import org.apache.karaf.features.BootFinished;
-import org.apache.karaf.features.FeaturesService;
-import org.apache.karaf.tooling.exam.options.KarafDistributionOption;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.TestProbeBuilder;
-import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.ops4j.pax.exam.junit.ProbeBuilder;
-import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
+import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
-public class ConditionalFeaturesTest {
-
+@ExamReactorStrategy(EagerSingleStagedReactorFactory.class)
+public class ConditionalFeaturesTest extends KarafTestSupport {
+ /*
@Inject
private FeaturesService featuresService;
@@ -50,12 +38,14 @@
@Inject
BootFinished bootFinished;
+
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*,org.apache.felix.service.*;status=provisional");
return probe;
}
+
@Configuration
public Option[] config() {
@@ -65,40 +55,51 @@ public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
KarafDistributionOption.editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", KarafTestSupport.HTTP_PORT)
};
}
+ */
@Test
public void testScr() throws Exception {
//Remove management and install scr
- featuresService.uninstallFeature("management");
- featuresService.installFeature("scr");
- Assert.assertFalse(isBundleInstalled("org.apache.karaf.scr.management"));
+ featureService.uninstallFeature("management");
+ featureService.installFeature("scr");
+ assertBundleNotInstalled("org.apache.karaf.scr.management");
//Add management back
- featuresService.installFeature("management");
- Assert.assertTrue(isBundleInstalled("org.apache.karaf.scr.management"));
+ featureService.installFeature("management");
+ assertBundleInstalled("org.apache.karaf.scr.management");
}
@Test
public void testWebconsole() throws Exception {
- featuresService.installFeature("webconsole");
+ try {
+ featureService.uninstallFeature("eventadmin");
+ } catch (Exception e) {
+ }
+ featureService.installFeature("webconsole");
- Assert.assertTrue(isBundleInstalled("org.apache.karaf.webconsole.features"));
- Assert.assertTrue(isBundleInstalled("org.apache.karaf.webconsole.instance"));
- Assert.assertTrue(isBundleInstalled("org.apache.karaf.webconsole.gogo"));
- Assert.assertTrue(isBundleInstalled("org.apache.karaf.webconsole.http"));
+ assertBundleInstalled("org.apache.karaf.webconsole.features");
+ assertBundleInstalled("org.apache.karaf.webconsole.instance");
+ assertBundleInstalled("org.apache.karaf.webconsole.gogo");
+ assertBundleInstalled("org.apache.karaf.webconsole.http");
- Assert.assertFalse(isBundleInstalled("org.apache.felix.webconsole.plugins.event"));
+ assertBundleNotInstalled("org.apache.felix.webconsole.plugins.event");
//Add eventadmin
try {
- featuresService.installFeature("eventadmin");
+ featureService.installFeature("eventadmin");
} catch (Exception ex) {
//ignore as the eventadmin activator might throw an error.
}
- Assert.assertTrue(isBundleInstalled("org.apache.felix.webconsole.plugins.event"));
+ assertBundleInstalled("org.apache.felix.webconsole.plugins.event");
}
-
+ private void assertBundleInstalled(String name) {
+ Assert.assertTrue("Bundle " + name + " should be installed", isBundleInstalled(name));
+ }
+
+ private void assertBundleNotInstalled(String name) {
+ Assert.assertFalse("Bundle " + name + " should not be installed", isBundleInstalled(name));
+ }
private boolean isBundleInstalled(String symbolicName) {
for (Bundle bundle : bundleContext.getBundles()) {
View
14 itests/src/test/java/org/apache/karaf/itests/DiagnosticTest.java
@@ -13,27 +13,23 @@
*/
package org.apache.karaf.itests;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-
-import static org.junit.Assert.assertTrue;
-
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(EagerSingleStagedReactorFactory.class)
public class DiagnosticTest extends KarafTestSupport {
@Test
public void dumpCreateCommand() throws Exception {
- String dumpCreateOutput = executeCommand("dev:dump-create");
- System.out.println(dumpCreateOutput);
- assertTrue(dumpCreateOutput.contains("Diagnostic dump created."));
+ assertContains("Diagnostic dump created.", executeCommand("dev:dump-create"));
}
@Test
View
12 itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
@@ -33,9 +33,7 @@
@Test
public void bootFeatures() throws Exception {
- String featureListOutput = executeCommand("feature:list -i");
- System.out.println(featureListOutput);
- assertTrue(featureListOutput.contains("standard"));
+ assertContains("standard", executeCommand("feature:list -i"));
}
@Test
@@ -95,13 +93,9 @@ public void installUninstallViaMBean() throws Exception {
@Test
public void repoAddRemoveCommand() throws Exception {
System.out.println(executeCommand("feature:repo-add mvn:org.apache.karaf.cellar/apache-karaf-cellar/2.2.4/xml/features"));
- String repoListOutput = executeCommand("feature:repo-list");
- System.out.println(repoListOutput);
- assertTrue(repoListOutput.contains("apache-karaf-cellar"));
+ assertContains("apache-karaf-cellar", executeCommand("feature:repo-list"));
System.out.println(executeCommand("feature:repo-remove mvn:org.apache.karaf.cellar/apache-karaf-cellar/2.2.4/xml/features"));
- repoListOutput = executeCommand("feature:repo-list");
- System.out.println(repoListOutput);
- assertFalse(repoListOutput.contains("apache-karaf-cellar"));
+ assertContainsNot("apache-karaf-cellar", executeCommand("feature:repo-list"));
}
@Test
View
7 itests/src/test/java/org/apache/karaf/itests/HttpTest.java
@@ -21,7 +21,6 @@
import javax.management.remote.JMXConnector;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
@@ -40,14 +39,10 @@ public void installHttpFeature() {
@Test
public void list() throws Exception {
- String listOutput = executeCommand("http:list");
- System.out.println(listOutput);
- assertTrue(listOutput.contains("/system/console"));
+ assertContains("/system/console", executeCommand("http:list"));
}
- @Ignore
@Test
- // TODO remove ignore flag when the HttpMBean is fixed
public void listViaMBean() throws Exception {
JMXConnector connector = null;
try {
View
46 itests/src/test/java/org/apache/karaf/itests/InstanceTest.java
@@ -13,7 +13,6 @@
*/
package org.apache.karaf.itests;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import javax.management.MBeanServerConnection;
@@ -21,26 +20,23 @@
import javax.management.openmbean.TabularData;
import javax.management.remote.JMXConnector;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
@RunWith(JUnit4TestRunner.class)
-@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
+@ExamReactorStrategy(EagerSingleStagedReactorFactory.class)
public class InstanceTest extends KarafTestSupport {
@Test
public void createDestroyCommand() throws Exception {
- System.out.println(executeCommand("instance:create itest"));
- String instanceListOutput = executeCommand("instance:list");
- System.out.println(instanceListOutput);
- assertTrue(instanceListOutput.contains("itest"));
- System.out.println(executeCommand("instance:destroy itest"));
- instanceListOutput = executeCommand("instance:list");
- System.out.println(instanceListOutput);
- assertFalse(instanceListOutput.contains("itest"));
+ System.out.println(executeCommand("instance:create itest1"));
+ assertContains("itest1" ,executeCommand("instance:list"));
+ System.out.println(executeCommand("instance:destroy itest1"));
+ assertContainsNot("itest1" ,executeCommand("instance:list"));
}
@Test
@@ -50,25 +46,27 @@ public void createDestroyViaMBean() throws Exception {
connector = this.getJMXConnector();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
- connection.invoke(name, "createInstance", new Object[]{ "itest", 0, 0, 0, null, null, null, null },
+ int oldNum = getInstancesNum(connection, name);
+ connection.invoke(name, "createInstance", new Object[]{ "itest2", 0, 0, 0, null, null, null, null },
new String[]{ "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String" });
- TabularData instances = (TabularData) connection.getAttribute(name, "Instances");
- assertTrue(instances.size() == 2);
- connection.invoke(name, "destroyInstance", new Object[]{ "itest" }, new String[]{ "java.lang.String" });
- instances = (TabularData) connection.getAttribute(name, "Instances");
- assertTrue(instances.size() == 1);
+ Assert.assertEquals(oldNum + 1, getInstancesNum(connection, name));
+ connection.invoke(name, "destroyInstance", new Object[]{ "itest2" }, new String[]{ "java.lang.String" });
+ Assert.assertEquals(oldNum, getInstancesNum(connection, name));
} finally {
if (connector != null)
connector.close();
}
}
+ private int getInstancesNum(MBeanServerConnection connection, ObjectName name) throws Exception {
+ TabularData instances = (TabularData) connection.getAttribute(name, "Instances");
+ return instances.size();
+ }
+
@Test
public void cloneCommand() throws Exception {
- System.out.println(executeCommand("instance:clone root itest"));
- String instanceListOutput = executeCommand("instance:list");
- System.out.println(instanceListOutput);
- assertTrue(instanceListOutput.contains("itest"));
+ System.out.println(executeCommand("instance:clone root itest3"));
+ assertContains("itest3", executeCommand("instance:list"));
}
@Test
@@ -78,10 +76,10 @@ public void cloneViaMBean() throws Exception {
connector = this.getJMXConnector();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
- connection.invoke(name, "cloneInstance", new Object[]{ "root", "itest", 0, 0, 0, null, null },
+ int oldNum = getInstancesNum(connection, name);
+ connection.invoke(name, "cloneInstance", new Object[]{ "root", "itest4", 0, 0, 0, null, null },
new String[]{ "java.lang.String", "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String" });
- TabularData instances = (TabularData) connection.getAttribute(name, "Instances");
- assertTrue(instances.size() == 2);
+ Assert.assertEquals(oldNum + 1, getInstancesNum(connection, name));
} finally {
if (connector != null)
connector.close();
View
7 itests/src/test/java/org/apache/karaf/itests/JaasTest.java
@@ -13,8 +13,6 @@
*/
package org.apache.karaf.itests;
-import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
@@ -28,9 +26,8 @@
@Test
public void realmListCommand() throws Exception {
String listRealmsOutput = executeCommand("jaas:realm-list");
- System.out.println(listRealmsOutput);
- assertTrue(listRealmsOutput.contains("PropertiesLoginModule"));
- assertTrue(listRealmsOutput.contains("PublickeyLoginModule"));
+ assertContains("PropertiesLoginModule", listRealmsOutput);
+ assertContains("PublickeyLoginModule", listRealmsOutput);
}
}
View
8 itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
@@ -17,6 +17,7 @@
import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.keepRuntimeFolder;
import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.logLevel;
+import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import java.io.ByteArrayOutputStream;
@@ -263,4 +264,11 @@ public void assertFeaturesInstalled(String ... expectedFeatures) {
Assert.assertTrue(msg, installedFeatures.containsAll(expectedFeaturesSet));
}
+ public void assertContains(String expectedPart, String actual) {
+ assertTrue("Should contain '" + expectedPart + "' but was : " + actual, actual.contains(expectedPart));
+ }
+
+ public void assertContainsNot(String expectedPart, String actual) {
+ Assert.assertFalse("Should not contain '" + expectedPart + "' but was : " + actual, actual.contains(expectedPart));
+ }
}
View
28 itests/src/test/java/org/apache/karaf/itests/LogTest.java
@@ -25,26 +25,25 @@
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RunWith(JUnit4TestRunner.class)
-@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
+@ExamReactorStrategy(EagerSingleStagedReactorFactory.class)
public class LogTest extends KarafTestSupport {
private static final Logger LOGGER = LoggerFactory.getLogger(LogTest.class);
@Test
public void setDebugAndDisplay() throws Exception {
- System.out.println(executeCommand("log:set DEBUG"));
+ assertSetLevel("DEBUG");
LOGGER.debug("Making sure there is DEBUG level output");
- String displayOutput = executeCommand("log:display -n 200");
- System.out.println(displayOutput);
- assertTrue(displayOutput.contains("DEBUG"));
+ assertContains("DEBUG", executeCommand("log:display -n 200"));
}
@Test
public void setDebugViaMBean() throws Exception {
+ assertSetLevel("INFO");
JMXConnector connector = null;
try {
connector = this.getJMXConnector();
@@ -62,15 +61,16 @@ public void setDebugViaMBean() throws Exception {
@Test
public void setGetDebugAndClear() throws Exception {
- System.out.println(executeCommand("log:set DEBUG"));
- String getOutput = executeCommand("log:get");
- System.out.println(getOutput);
- assertTrue(getOutput.contains("DEBUG"));
- System.out.println(executeCommand("log:set INFO"));
+ assertSetLevel("DEBUG");
+ assertSetLevel("INFO");
System.out.println(executeCommand("log:clear"));
- String displayOutput = executeCommand("log:display");
- System.out.println(displayOutput.trim());
- assertTrue(displayOutput.trim().isEmpty());
+ String displayOutput = executeCommand("log:display").trim();
+ assertTrue("Should be empty but was: " + displayOutput, displayOutput.trim().isEmpty());
+ }
+
+ public void assertSetLevel(String level) {
+ System.out.println(executeCommand("log:set " + level));
+ assertContains(level, executeCommand("log:get"));
}
}
View
18 itests/src/test/java/org/apache/karaf/itests/SystemTest.java
@@ -14,7 +14,6 @@
package org.apache.karaf.itests;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
@@ -30,6 +29,8 @@
@ExamReactorStrategy(EagerSingleStagedReactorFactory.class)
public class SystemTest extends KarafTestSupport {
+ private static final String KARAF_VERSION = "3";
+
@Test
public void nameCommand() throws Exception {
String nameOutput = executeCommand("system:name");
@@ -54,9 +55,7 @@ public void nameViaMBean() throws Exception {
@Test
public void versionCommand() throws Exception {
- String versionOutput = executeCommand("system:version");
- System.out.println(versionOutput);
- assertTrue(versionOutput.contains("3"));
+ assertContains(KARAF_VERSION, executeCommand("system:version"));
}
@Test
@@ -66,8 +65,7 @@ public void versionViaMBean() throws Exception {
connector = this.getJMXConnector();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
- String version = (String) connection.getAttribute(name, "Version");
- assertTrue(version.contains("3"));
+ assertContains(KARAF_VERSION, (String) connection.getAttribute(name, "Version"));
} finally {
if (connector != null)
connector.close();
@@ -76,9 +74,7 @@ public void versionViaMBean() throws Exception {
@Test
public void frameworkCommand() throws Exception {
- String frameworkOutput = executeCommand("system:framework");
- System.out.println(frameworkOutput);
- assertTrue(frameworkOutput.contains("felix"));
+ assertContains("felix", executeCommand("system:framework"));
}
@Test
@@ -98,9 +94,7 @@ public void frameworkViaMBean() throws Exception {
@Test
public void startLevelCommand() throws Exception {
- String startLevelOutput = executeCommand("system:start-level");
- System.out.println(startLevelOutput);
- assertTrue(startLevelOutput.contains("100"));
+ assertContains("100", executeCommand("system:start-level"));
}
@Test

0 comments on commit b1397c0

Please sign in to comment.
Something went wrong with that request. Please try again.