You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2014/05/26 17:17:53 UTC
svn commit: r1597603 [2/2] - in /aries/trunk/jmx:
jmx-core/src/main/java/org/apache/aries/jmx/
jmx-core/src/main/java/org/apache/aries/jmx/agent/
jmx-core/src/main/java/org/apache/aries/jmx/cm/
jmx-core/src/main/java/org/apache/aries/jmx/codec/ jmx-ite...
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java Mon May 26 15:17:52 2014
@@ -16,19 +16,12 @@
*/
package org.apache.aries.jmx.framework;
-import static org.apache.aries.itest.ExtraOptions.mavenBundle;
-import static org.apache.aries.itest.ExtraOptions.paxLogging;
-import static org.apache.aries.itest.ExtraOptions.testOptions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+import static org.ops4j.pax.exam.CoreOptions.options;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -47,16 +40,18 @@ import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
+import junit.framework.Assert;
+
import org.apache.aries.jmx.AbstractIntegrationTest;
import org.apache.aries.jmx.codec.PropertyData;
import org.apache.aries.jmx.test.bundlea.api.InterfaceA;
import org.apache.aries.jmx.test.bundleb.api.InterfaceB;
+import org.junit.Before;
import org.junit.Test;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
-import org.ops4j.pax.exam.junit.Configuration;
+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.Constants;
import org.osgi.framework.ServiceReference;
@@ -71,65 +66,29 @@ import org.osgi.service.cm.ManagedServic
*
* @version $Rev$ $Date$
*/
+@ExamReactorStrategy(PerMethod.class)
public class ServiceStateMBeanTest extends AbstractIntegrationTest {
+
+ private ObjectName objectName;
+ private ServiceStateMBean mbean;
@Configuration
- public static Option[] configuration() {
- return testOptions(
- // new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
- // new TimeoutOption( 0 ),
-
- PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
- CoreOptions.equinox().version("3.8.0.V20120529-1548"),
- paxLogging("INFO"),
-
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
- mavenBundle("org.osgi", "org.osgi.compendium"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.api"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.whiteboard"),
- mavenBundle("org.apache.aries", "org.apache.aries.util"),
-
- new Customizer() {
- public InputStream customizeTestProbe(InputStream testProbe) throws Exception {
- return modifyBundle(testProbe)
- .removeHeader(Constants.DYNAMICIMPORT_PACKAGE)
- .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea,org.apache.aries.jmx.test.bundleb")
- .build(withBnd());
- }
- },
- provision(newBundle()
- .add(org.apache.aries.jmx.test.bundlea.Activator.class)
- .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
- .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
- .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
- .set(Constants.BUNDLE_VERSION, "2.0.0")
- .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api;version=2.0.0")
- .set(Constants.IMPORT_PACKAGE,
- "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional" +
- ",org.osgi.service.cm")
- .set(Constants.BUNDLE_ACTIVATOR,
- org.apache.aries.jmx.test.bundlea.Activator.class.getName())
- .build(withBnd())),
- provision(newBundle()
- .add(org.apache.aries.jmx.test.bundleb.Activator.class)
- .add(org.apache.aries.jmx.test.bundleb.api.InterfaceB.class)
- .add(org.apache.aries.jmx.test.bundleb.api.MSF.class)
- .add(org.apache.aries.jmx.test.bundleb.impl.B.class)
- .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.aries.jmx.test.bundleb")
- .set(Constants.BUNDLE_VERSION, "1.0.0")
- .set(Constants.EXPORT_PACKAGE,"org.apache.aries.jmx.test.bundleb.api;version=1.1.0")
- .set(Constants.IMPORT_PACKAGE,"org.osgi.framework;version=1.5.0,org.osgi.util.tracker" +
- ",org.osgi.service.cm")
- .set(Constants.BUNDLE_ACTIVATOR,
- org.apache.aries.jmx.test.bundleb.Activator.class.getName())
- .build(withBnd()))
- );
- }
-
- @Override
- public void doSetUp() throws Exception {
- waitForMBean(new ObjectName(ServiceStateMBean.OBJECTNAME));
+ public Option[] configuration() {
+ return options(
+ // new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
+ // new TimeoutOption( 0 ),
+ jmxRuntime(),
+ bundlea(),
+ bundleb()
+ );
+ }
+
+ @Before
+ public void doSetUp() {
+ waitForMBean(ServiceStateMBean.OBJECTNAME);
+ objectName = waitForMBean(ServiceStateMBean.OBJECTNAME);
+ mbean = getMBean(objectName, ServiceStateMBean.class);
+ assertNotNull(mbean);
}
@Test
@@ -144,35 +103,28 @@ public class ServiceStateMBeanTest exten
@Test
public void testMBeanInterface() throws Exception {
- ObjectName objectName = waitForMBean(new ObjectName(ServiceStateMBean.OBJECTNAME));
-
- ServiceStateMBean mbean = getMBean(objectName, ServiceStateMBean.class);
- assertNotNull(mbean);
-
//get bundles
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- assertNotNull(a);
-
- Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
- assertNotNull(b);
+ Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
+ assertBundleStarted(a);
+ Bundle b = getBundleByName("org.apache.aries.jmx.test.bundleb");
+ assertBundleStarted(b);
// get services
- ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
+ ServiceReference<?> refA = bundleContext.getServiceReference(InterfaceA.class.getName());
assertNotNull(refA);
long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
assertTrue(serviceAId > -1);
- ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
+ ServiceReference<?> refB = bundleContext.getServiceReference(InterfaceB.class.getName());
assertNotNull(refB);
long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
assertTrue(serviceBId > -1);
- ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+ ServiceReference<?>[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
assertNotNull(refs);
assertEquals(1, refs.length);
- ServiceReference msf = refs[0];
+ ServiceReference<?> msf = refs[0];
// getBundleIdentifier
@@ -245,11 +197,13 @@ public class ServiceStateMBeanTest exten
assertEquals(4, attributeChanges.size());
}
- @Test
- public void testAttributeChangeNotifications() throws Exception {
- ObjectName objectName = waitForMBean(new ObjectName(ServiceStateMBean.OBJECTNAME));
- ServiceStateMBean mbean = getMBean(objectName, ServiceStateMBean.class);
+ private void assertBundleStarted(Bundle bundle) {
+ Assert.assertEquals("Bundle " + bundle.getSymbolicName() + " should be started but is in state " + bundle.getState(),
+ Bundle.ACTIVE, bundle.getState());
+ }
+ @Test
+ public void testAttributeChangeNotifications() throws Exception {
final List<AttributeChangeNotification> attributeChanges = new ArrayList<AttributeChangeNotification>();
mbeanServer.addNotificationListener(objectName, new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
@@ -275,7 +229,7 @@ public class ServiceStateMBeanTest exten
waitForListToReachSize(attributeChanges, 1);
AttributeChangeNotification ac = attributeChanges.get(0);
assertEquals("ServiceIds", ac.getAttributeName());
- assertEquals(1, ac.getSequenceNumber());
+ long seq1 = ac.getSequenceNumber();
assertTrue(Arrays.equals(idsWithout, (long []) ac.getOldValue()));
assertTrue(Arrays.equals(idsWith, (long []) ac.getNewValue()));
@@ -293,15 +247,13 @@ public class ServiceStateMBeanTest exten
waitForListToReachSize(attributeChanges, 2);
AttributeChangeNotification ac2 = attributeChanges.get(1);
assertEquals("ServiceIds", ac2.getAttributeName());
- assertEquals(2, ac2.getSequenceNumber());
+ assertEquals(seq1 +1, ac2.getSequenceNumber());
assertTrue(Arrays.equals(idsWith, (long []) ac2.getOldValue()));
assertTrue(Arrays.equals(idsWithout, (long []) ac2.getNewValue()));
}
@Test
public void testGetServiceIds() throws Exception {
- ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
-
ServiceReference<?>[] allSvsRefs = bundleContext.getAllServiceReferences(null, null);
long[] expectedServiceIds = new long[allSvsRefs.length];
for (int i=0; i < allSvsRefs.length; i++) {
@@ -315,9 +267,10 @@ public class ServiceStateMBeanTest exten
@Test
public void testGetServiceAndGetProperty() throws Exception {
- ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
-
+
ServiceReference<InterfaceA> sref = bundleContext.getServiceReference(InterfaceA.class);
+ // Get service to increase service references
+ context().getService(sref);
Long serviceID = (Long) sref.getProperty(Constants.SERVICE_ID);
CompositeData svcData = mbean.getService(serviceID);
@@ -346,13 +299,12 @@ public class ServiceStateMBeanTest exten
assertTrue(ocData.get("Value").equals(form1) ||
ocData.get("Value").equals(form2));
assertEquals("Array of String", ocData.get("Type"));
+ context().ungetService(sref);
}
@Test
@SuppressWarnings("unchecked")
public void testServicePropertiesInListServices() throws Exception {
- ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
-
ServiceReference<?>[] refs = bundleContext.getAllServiceReferences(InterfaceA.class.getName(), null);
assertEquals("Precondition", 1, refs.length);
ServiceReference<?> ref = refs[0];
@@ -391,8 +343,6 @@ public class ServiceStateMBeanTest exten
@Test
public void testListServices() throws Exception {
- ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
-
String filter = "(" + Constants.SERVICE_PID + "=*)";
ServiceReference<?>[] refs = bundleContext.getAllServiceReferences(null, filter);
TabularData svcData = mbean.listServices(null, filter);
@@ -406,10 +356,9 @@ public class ServiceStateMBeanTest exten
assertEquals(expectedSvc, actualSvc);
}
- @Test
+ @SuppressWarnings("unchecked")
+ @Test
public void testListServicesSelectiveItems() throws Exception {
- ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
-
String filter = "(|(service.pid=org.apache.aries.jmx.test.ServiceB)(service.pid=jmx.test.B.factory))";
ServiceReference<?>[] refs = bundleContext.getAllServiceReferences(null, filter);
TabularData svcData = mbean.listServices(null, filter, ServiceStateMBean.BUNDLE_IDENTIFIER);
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanWhiteboardTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanWhiteboardTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanWhiteboardTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanWhiteboardTest.java Mon May 26 15:17:52 2014
@@ -18,29 +18,13 @@
*/
package org.apache.aries.jmx.framework;
-import org.apache.aries.itest.ExtraOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
-public class ServiceStateMBeanWhiteboardTest extends ServiceStateMBeanTest
-{
- @Configuration
- public static Option[] configuration() {
- Option[] options = ServiceStateMBeanTest.configuration();
-
- for (int i = 0; i < options.length; i++)
- {
- if (options[i] instanceof MavenArtifactProvisionOption) {
- MavenArtifactProvisionOption po = (MavenArtifactProvisionOption) options[i];
- String url = po.getURL();
- if (url.contains("mvn:org.apache.aries.jmx/org.apache.aries.jmx/")) {
- options[i] = ExtraOptions.mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.core.whiteboard");
- }
- }
- }
-
- return options;
- }
+public class ServiceStateMBeanWhiteboardTest extends ServiceStateMBeanTest {
+
+ @Override
+ protected MavenArtifactProvisionOption jmxBundle() {
+ return jmxWhiteBoardBundle();
+ }
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java Mon May 26 15:17:52 2014
@@ -16,13 +16,7 @@
*/
package org.apache.aries.jmx.framework.wiring;
-import static org.apache.aries.itest.ExtraOptions.mavenBundle;
-import static org.apache.aries.itest.ExtraOptions.paxLogging;
-import static org.apache.aries.itest.ExtraOptions.testOptions;
import static org.junit.Assert.assertEquals;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
import java.util.ArrayList;
import java.util.Arrays;
@@ -41,11 +35,11 @@ import javax.management.openmbean.Tabula
import org.apache.aries.jmx.AbstractIntegrationTest;
import org.apache.aries.jmx.codec.PropertyData;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
-import org.ops4j.pax.exam.junit.Configuration;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.wiring.BundleCapability;
@@ -57,66 +51,27 @@ import org.osgi.framework.wiring.BundleW
import org.osgi.jmx.framework.wiring.BundleWiringStateMBean;
public class BundleWiringStateMBeanTest extends AbstractIntegrationTest {
- @Configuration
- public static Option[] configuration() {
- return testOptions(
+ private BundleWiringStateMBean brsMBean;
+ private Bundle bundleA;
+
+ @Configuration
+ public Option[] configuration() {
+ return CoreOptions.options(
// new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
// new TimeoutOption( 0 ),
- PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
- CoreOptions.equinox().version("3.8.0.V20120529-1548"),
- paxLogging("INFO"),
-
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
- mavenBundle("org.osgi", "org.osgi.compendium"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.api"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.whiteboard"),
- mavenBundle("org.apache.aries", "org.apache.aries.util"),
- provision(newBundle()
- .add(org.apache.aries.jmx.test.bundlea.Activator.class)
- .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
- .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
- .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
- .set(Constants.BUNDLE_VERSION, "2.0.0")
- .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api;version=2.0.0")
- .set(Constants.IMPORT_PACKAGE,
- "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional" +
- ",org.osgi.service.cm")
- .set(Constants.BUNDLE_ACTIVATOR,
- org.apache.aries.jmx.test.bundlea.Activator.class.getName())
- .build(withBnd())),
- provision(newBundle()
- .add(org.apache.aries.jmx.test.bundleb.Activator.class)
- .add(org.apache.aries.jmx.test.bundleb.api.InterfaceB.class)
- .add(org.apache.aries.jmx.test.bundleb.api.MSF.class)
- .add(org.apache.aries.jmx.test.bundleb.impl.B.class)
- .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.aries.jmx.test.bundleb")
- .set(Constants.BUNDLE_VERSION, "1.0.0")
- .set(Constants.EXPORT_PACKAGE,"org.apache.aries.jmx.test.bundleb.api;version=1.1.0")
- .set(Constants.IMPORT_PACKAGE,"org.osgi.framework;version=1.5.0,org.osgi.util.tracker," +
- "org.osgi.service.cm,org.apache.aries.jmx.test.fragmentc")
- .set(Constants.BUNDLE_ACTIVATOR,
- org.apache.aries.jmx.test.bundleb.Activator.class.getName())
- .build(withBnd())),
- provision(newBundle()
- .add(org.apache.aries.jmx.test.fragmentc.C.class)
- .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.fragc")
- .set(Constants.FRAGMENT_HOST, "org.apache.aries.jmx.test.bundlea")
- .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.fragmentc")
- .build(withBnd())),
- provision(newBundle()
- .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundled")
- .set(Constants.BUNDLE_VERSION, "3.0.0")
- .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea;bundle-version=2.0.0")
- .build(withBnd()))
+ jmxRuntime(),
+ bundlea(),
+ bundleb(),
+ fragmentc(),
+ bundled()
);
-
}
- @Override
+ @Before
public void doSetUp() throws Exception {
- waitForMBean(new ObjectName(BundleWiringStateMBean.OBJECTNAME));
+ brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
+ bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
}
@Test
@@ -131,9 +86,7 @@ public class BundleWiringStateMBeanTest
@Test
public void testGetCurrentRevisionDeclaredRequirements() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
+ Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
BundleRevision br = a.adapt(BundleRevision.class);
List<BundleRequirement> requirements = br.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
@@ -147,13 +100,10 @@ public class BundleWiringStateMBeanTest
@Test
public void testGetCurrentRevisionDeclaredCapabilities() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- BundleRevision br = a.adapt(BundleRevision.class);
+ BundleRevision br = bundleA.adapt(BundleRevision.class);
List<BundleCapability> capabilities = br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
- CompositeData[] jmxCapabilities = brsMBean.getCurrentRevisionDeclaredCapabilities(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
+ CompositeData[] jmxCapabilities = brsMBean.getCurrentRevisionDeclaredCapabilities(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
@@ -163,14 +113,11 @@ public class BundleWiringStateMBeanTest
@Test
public void testGetRevisionsDeclaredRequirements() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- BundleRevisions revisions = a.adapt(BundleRevisions.class);
+ BundleRevisions revisions = bundleA.adapt(BundleRevisions.class);
Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
- TabularData jmxRequirementsTable = brsMBean.getRevisionsDeclaredRequirements(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
+ TabularData jmxRequirementsTable = brsMBean.getRevisionsDeclaredRequirements(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxRequirementsTable.size());
List<BundleRequirement> requirements = revisions.getRevisions().iterator().next().getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
@@ -184,14 +131,11 @@ public class BundleWiringStateMBeanTest
@Test
public void testGetRevisionsDeclaredCapabilities() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- BundleRevisions revisions = a.adapt(BundleRevisions.class);
+ BundleRevisions revisions = bundleA.adapt(BundleRevisions.class);
Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
- TabularData jmxCapabilitiesTable = brsMBean.getRevisionsDeclaredCapabilities(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
+ TabularData jmxCapabilitiesTable = brsMBean.getRevisionsDeclaredCapabilities(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxCapabilitiesTable.size());
List<BundleCapability> capabilities = revisions.getRevisions().iterator().next().getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
@@ -205,31 +149,25 @@ public class BundleWiringStateMBeanTest
@Test
public void testGetCurrentWiring() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- CompositeData jmxWiring = brsMBean.getCurrentWiring(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
+ CompositeData jmxWiring = brsMBean.getCurrentWiring(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(BundleWiringStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
- Assert.assertEquals(a.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
+ Assert.assertEquals(bundleA.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
- BundleWiring bw = a.adapt(BundleWiring.class);
+ BundleWiring bw = bundleA.adapt(BundleWiring.class);
assertBundleWiring(bw, jmxWiring);
}
@Test
public void testRevisionsWiring() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- TabularData jmxWiringTable = brsMBean.getRevisionsWiring(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
+ TabularData jmxWiringTable = brsMBean.getRevisionsWiring(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxWiringTable.size());
CompositeData jmxWiring = (CompositeData) jmxWiringTable.values().iterator().next();
Assert.assertEquals(BundleWiringStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
- Assert.assertEquals(a.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
+ Assert.assertEquals(bundleA.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
- BundleWiring bw = a.adapt(BundleWiring.class);
+ BundleWiring bw = bundleA.adapt(BundleWiring.class);
assertBundleWiring(bw, jmxWiring);
}
@@ -313,13 +251,10 @@ public class BundleWiringStateMBeanTest
@Test
public void testCurrentWiringClosure() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
+ TabularData jmxWiringClosure = brsMBean.getCurrentWiringClosure(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- TabularData jmxWiringClosure = brsMBean.getCurrentWiringClosure(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
-
- CompositeData jmxWiringA = jmxWiringClosure.get(new Object [] {a.getBundleId(), 0});
- assertBundleWiring(a.adapt(BundleWiring.class), jmxWiringA);
+ CompositeData jmxWiringA = jmxWiringClosure.get(new Object [] {bundleA.getBundleId(), 0});
+ assertBundleWiring(bundleA.adapt(BundleWiring.class), jmxWiringA);
Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
int bRevID = findRevisionID(jmxWiringA, b);
@@ -339,13 +274,10 @@ public class BundleWiringStateMBeanTest
@Test
public void testRevisionsWiringClosure() throws Exception {
- BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
-
- Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
- TabularData jmxWiringClosure = brsMBean.getRevisionsWiringClosure(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
+ TabularData jmxWiringClosure = brsMBean.getRevisionsWiringClosure(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
- CompositeData jmxWiringA = jmxWiringClosure.get(new Object [] {a.getBundleId(), 0});
- assertBundleWiring(a.adapt(BundleWiring.class), jmxWiringA);
+ CompositeData jmxWiringA = jmxWiringClosure.get(new Object [] {bundleA.getBundleId(), 0});
+ assertBundleWiring(bundleA.adapt(BundleWiring.class), jmxWiringA);
Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
int bRevID = findRevisionID(jmxWiringA, b);
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java Mon May 26 15:17:52 2014
@@ -16,28 +16,17 @@
*/
package org.apache.aries.jmx.permissionadmin;
-import static org.apache.aries.itest.ExtraOptions.mavenBundle;
-import static org.apache.aries.itest.ExtraOptions.paxLogging;
-import static org.apache.aries.itest.ExtraOptions.testOptions;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+import static org.ops4j.pax.exam.CoreOptions.options;
import java.io.IOException;
-import javax.management.ObjectName;
-
import org.apache.aries.jmx.AbstractIntegrationTest;
import org.junit.Test;
-import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
-import org.ops4j.pax.exam.junit.Configuration;
import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
import org.osgi.jmx.service.permissionadmin.PermissionAdminMBean;
import org.osgi.service.permissionadmin.PermissionAdmin;
import org.osgi.service.permissionadmin.PermissionInfo;
@@ -50,41 +39,20 @@ import org.osgi.service.permissionadmin.
public class PermissionAdminMBeanTest extends AbstractIntegrationTest {
@Configuration
- public static Option[] configuration() {
- return testOptions(
- PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
- CoreOptions.equinox().version("3.8.0.V20120529-1548"),
- paxLogging("INFO"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.api"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.whiteboard"),
- mavenBundle("org.apache.aries", "org.apache.aries.util"),
- provision(newBundle()
- .add(org.apache.aries.jmx.test.bundlea.Activator.class)
- .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
- .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
- .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
- .set(Constants.BUNDLE_VERSION, "2.0.0")
- .set(Constants.IMPORT_PACKAGE,
- "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional")
- .set(Constants.BUNDLE_ACTIVATOR,
- org.apache.aries.jmx.test.bundlea.Activator.class.getName())
- .build(withBnd()))
+ public Option[] configuration() {
+ return options(
+ jmxRuntime(),
+ bundlea()
/* For debugging, uncomment the next two lines */
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7778"),
// waitForFrameworkStartup()
);
}
- @Override
- public void doSetUp() throws Exception {
- waitForMBean(new ObjectName(PermissionAdminMBean.OBJECTNAME));
- }
-
@Test
public void testMBeanInterface() throws IOException {
PermissionAdminMBean mBean = getMBean(PermissionAdminMBean.OBJECTNAME, PermissionAdminMBean.class);
- PermissionAdmin permAdminService = getService(PermissionAdmin.class);
+ PermissionAdmin permAdminService = context().getService(PermissionAdmin.class);
assertNotNull(permAdminService);
String[] serviceLocation = permAdminService.getLocations();
@@ -132,14 +100,4 @@ public class PermissionAdminMBeanTest ex
return encoded;
}
- private <S> S getService(Class<S> serviceInterface){
- ServiceReference ref = bundleContext.getServiceReference(serviceInterface.getName());
- if(ref != null){
- Object service = bundleContext.getService(ref);
- if(service != null){
- return (S)service;
- }
- }
- return null;
- }
}
\ No newline at end of file
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanWhiteboardTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanWhiteboardTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanWhiteboardTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanWhiteboardTest.java Mon May 26 15:17:52 2014
@@ -18,29 +18,13 @@
*/
package org.apache.aries.jmx.permissionadmin;
-import org.apache.aries.itest.ExtraOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
-public class PermissionAdminMBeanWhiteboardTest extends PermissionAdminMBeanTest
-{
- @Configuration
- public static Option[] configuration() {
- Option[] options = PermissionAdminMBeanTest.configuration();
-
- for (int i = 0; i < options.length; i++)
- {
- if (options[i] instanceof MavenArtifactProvisionOption) {
- MavenArtifactProvisionOption po = (MavenArtifactProvisionOption) options[i];
- String url = po.getURL();
- if (url.contains("mvn:org.apache.aries.jmx/org.apache.aries.jmx/")) {
- options[i] = ExtraOptions.mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.core.whiteboard");
- }
- }
- }
-
- return options;
- }
+public class PermissionAdminMBeanWhiteboardTest extends PermissionAdminMBeanTest {
+
+ @Override
+ protected MavenArtifactProvisionOption jmxBundle() {
+ return jmxWhiteBoardBundle();
+ }
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanTest.java Mon May 26 15:17:52 2014
@@ -21,32 +21,31 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.options;
import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_AGENT_CONFIG;
import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_REFERENCE;
-import static org.apache.aries.itest.ExtraOptions.*;
-
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Dictionary;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
-import javax.management.ObjectName;
+import javax.inject.Inject;
import javax.management.openmbean.TabularData;
import org.apache.aries.jmx.AbstractIntegrationTest;
import org.apache.aries.jmx.codec.PropertyData;
import org.junit.Ignore;
import org.junit.Test;
-import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
import org.osgi.jmx.JmxConstants;
import org.osgi.jmx.service.provisioning.ProvisioningServiceMBean;
import org.osgi.service.provisioning.ProvisioningService;
-import org.osgi.util.tracker.ServiceTracker;
/**
*
@@ -54,69 +53,34 @@ import org.osgi.util.tracker.ServiceTrac
* @version $Rev$ $Date$
*/
public class ProvisioningServiceMBeanTest extends AbstractIntegrationTest {
-
+ @Inject
+ ProvisioningService ps;
@Configuration
- public static Option[] configuration() {
- return testOptions(
- CoreOptions.equinox(),
- paxLogging("INFO"),
- mavenBundle("org.osgi", "org.osgi.compendium"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.whiteboard"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
- mavenBundle("org.apache.aries", "org.apache.aries.util"));
- }
-
- @Override
- public void doSetUp() throws Exception {
- waitForMBean(new ObjectName(ProvisioningServiceMBean.OBJECTNAME));
+ public Option[] configuration() {
+ return options(
+ jmxRuntime()
+ );
}
@Ignore("For now.. Cannot find public repo for org.eclipse.equinox.ip")
@Test
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({ "unchecked"})
public void testMBeanInterface() throws Exception {
-
ProvisioningServiceMBean mbean = getMBean(ProvisioningServiceMBean.OBJECTNAME, ProvisioningServiceMBean.class);
- assertNotNull(mbean);
-
- ServiceTracker tracker = new ServiceTracker(bundleContext, ProvisioningService.class.getName(), null);
- tracker.open();
- ProvisioningService ps = (ProvisioningService) tracker.getService();
- assertNotNull(ps);
-
Dictionary<String, Object> info;
// add information URL (create temp zip file)
-
- File provZip = File.createTempFile("Prov-jmx-itests", ".zip");
- Manifest man = new Manifest();
- man.getMainAttributes().putValue("Manifest-Version", "1.0");
- man.getMainAttributes().putValue("Content-Type", "application/zip");
- JarOutputStream jout = new JarOutputStream(new FileOutputStream(provZip), man);
- ZipEntry entry = new ZipEntry(PROVISIONING_AGENT_CONFIG);
- jout.putNextEntry( entry );
- jout.write(new byte[] { 10, 20, 30 });
- jout.closeEntry();
- jout.flush();
- jout.close();
-
- provZip.deleteOnExit();
-
- mbean.addInformationFromZip(provZip.toURL().toExternalForm());
+ File provZip = createProvAgentConfigZip();
+ mbean.addInformationFromZip(provZip.toURI().toURL().toExternalForm());
//check the info has been added
-
info = ps.getInformation();
assertNotNull(info);
assertTrue(info.size() >= 1);
- byte[] config = (byte[]) info.get(PROVISIONING_AGENT_CONFIG);
- assertNotNull(config);
- assertArrayEquals(new byte[] { 10, 20, 30 }, config);
-
+ assertProvAgentConfigCorrect(info);
// test list information
-
TabularData data = mbean.listInformation();
assertNotNull(data);
assertEquals(JmxConstants.PROPERTIES_TYPE, data.getTabularType());
@@ -124,42 +88,54 @@ public class ProvisioningServiceMBeanTes
PropertyData<byte[]> configEntry = PropertyData.from(data.get(new Object[] {PROVISIONING_AGENT_CONFIG }));
assertNotNull(configEntry);
assertArrayEquals(new byte[] { 10, 20, 30 }, configEntry.getValue());
-
// test add information
-
PropertyData<String> reference = PropertyData.newInstance(PROVISIONING_REFERENCE, "rsh://0.0.0.0/provX");
data.put(reference.toCompositeData());
-
mbean.addInformation(data);
-
info = ps.getInformation();
assertNotNull(info);
assertTrue(info.size() >= 2);
- config = (byte[]) info.get(PROVISIONING_AGENT_CONFIG);
- assertNotNull(config);
- assertArrayEquals(new byte[] { 10, 20, 30 }, config);
+ assertProvAgentConfigCorrect(info);
String ref = (String) info.get(PROVISIONING_REFERENCE);
assertNotNull(ref);
assertEquals("rsh://0.0.0.0/provX", ref);
-
// test set information
-
data.clear();
PropertyData<String> newRef = PropertyData.newInstance(PROVISIONING_REFERENCE, "rsh://0.0.0.0/newProvRef");
data.put(newRef.toCompositeData());
-
mbean.setInformation(data);
info = ps.getInformation();
assertNotNull(info);
assertTrue(info.size() >= 1);
assertNull(info.get(PROVISIONING_AGENT_CONFIG));
-
ref = (String) info.get(PROVISIONING_REFERENCE);
assertNotNull(ref);
assertEquals("rsh://0.0.0.0/newProvRef", ref);
-
}
+
+ private void assertProvAgentConfigCorrect(Dictionary<String, Object> info) {
+ byte[] config = (byte[]) info.get(PROVISIONING_AGENT_CONFIG);
+ assertNotNull(config);
+ assertArrayEquals(new byte[] { 10, 20, 30 }, config);
+ }
+
+ private File createProvAgentConfigZip() throws IOException, FileNotFoundException {
+ File provZip = File.createTempFile("Prov-jmx-itests", ".zip");
+ Manifest man = new Manifest();
+ man.getMainAttributes().putValue("Manifest-Version", "1.0");
+ man.getMainAttributes().putValue("Content-Type", "application/zip");
+ JarOutputStream jout = new JarOutputStream(new FileOutputStream(provZip), man);
+ ZipEntry entry = new ZipEntry(PROVISIONING_AGENT_CONFIG);
+ jout.putNextEntry( entry );
+ jout.write(new byte[] { 10, 20, 30 });
+ jout.closeEntry();
+ jout.flush();
+ jout.close();
+
+ provZip.deleteOnExit();
+ return provZip;
+ }
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanWhiteboardTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanWhiteboardTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanWhiteboardTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanWhiteboardTest.java Mon May 26 15:17:52 2014
@@ -18,28 +18,12 @@
*/
package org.apache.aries.jmx.provisioning;
-import org.apache.aries.itest.ExtraOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
-public class ProvisioningServiceMBeanWhiteboardTest extends ProvisioningServiceMBeanTest
-{
- @Configuration
- public static Option[] configuration() {
- Option[] options = ProvisioningServiceMBeanTest.configuration();
-
- for (int i = 0; i < options.length; i++)
- {
- if (options[i] instanceof MavenArtifactProvisionOption) {
- MavenArtifactProvisionOption po = (MavenArtifactProvisionOption) options[i];
- String url = po.getURL();
- if (url.contains("mvn:org.apache.aries.jmx/org.apache.aries.jmx/")) {
- options[i] = ExtraOptions.mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.core.whiteboard");
- }
- }
- }
-
- return options;
- }
+public class ProvisioningServiceMBeanWhiteboardTest extends ProvisioningServiceMBeanTest {
+
+ @Override
+ protected MavenArtifactProvisionOption jmxBundle() {
+ return jmxWhiteBoardBundle();
+ }
}
\ No newline at end of file
Added: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/MbeanServerActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/MbeanServerActivator.java?rev=1597603&view=auto
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/MbeanServerActivator.java (added)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/MbeanServerActivator.java Mon May 26 15:17:52 2014
@@ -0,0 +1,19 @@
+package org.apache.aries.jmx.test;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class MbeanServerActivator implements BundleActivator {
+
+ public void start(BundleContext context) throws Exception {
+ MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();
+ context.registerService(MBeanServer.class, mBeanServer, null);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ }
+
+}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java Mon May 26 15:17:52 2014
@@ -18,14 +18,13 @@
*/
package org.apache.aries.jmx.test.blueprint;
-import static org.apache.aries.itest.ExtraOptions.mavenBundle;
-import static org.apache.aries.itest.ExtraOptions.paxLogging;
-import static org.apache.aries.itest.ExtraOptions.testOptions;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import java.util.Arrays;
+import javax.inject.Inject;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.openmbean.TabularData;
@@ -45,10 +44,12 @@ import org.apache.aries.jmx.test.bluepri
import org.apache.aries.jmx.test.blueprint.framework.RegistrationListenerValidator;
import org.apache.aries.jmx.test.blueprint.framework.ServiceValidator;
import org.apache.aries.jmx.test.blueprint.framework.ValueValidator;
+import org.junit.Before;
import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.util.Filter;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
@@ -56,78 +57,65 @@ import org.osgi.framework.ServiceReferen
import org.osgi.service.blueprint.container.BlueprintContainer;
public class BlueprintMBeanTest extends AbstractIntegrationTest {
+ @Inject
+ @Filter("(osgi.blueprint.container.symbolicname=org.apache.aries.blueprint)")
+ BlueprintContainer blueprintExtender;
+
+ @Inject
+ @Filter("(osgi.blueprint.container.symbolicname=org.apache.aries.blueprint.sample)")
+ BlueprintContainer blueprintSample;
+
+ private Bundle extender;
+ private Bundle sample;
@Configuration
- public static Option[] configuration() {
- return testOptions(
- CoreOptions.equinox(),
- paxLogging("INFO"),
-
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
- mavenBundle("org.apache.aries", "org.apache.aries.util"),
- mavenBundle("org.ow2.asm", "asm-all"),
- mavenBundle("org.apache.aries.proxy", "org.apache.aries.proxy"),
- mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
- mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.jexl.evaluator"),
- mavenBundle("org.apache.commons", "commons-jexl"),
- mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample"),
- mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.blueprint"),
- mavenBundle("org.osgi", "org.osgi.compendium")
+ public Option[] configuration() {
+ return CoreOptions.options(
+ jmxRuntime(),
+ blueprint(),
+ mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.blueprint").versionAsInProject(),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").versionAsInProject()
);
}
- @Override
- public void doSetUp() throws Exception {
- waitForMBean(new ObjectName(BlueprintStateMBean.OBJECTNAME));
- waitForMBean(new ObjectName(BlueprintMetadataMBean.OBJECTNAME));
-
- // Wait enough time for osgi framework and blueprint bundles to be set up
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Waiting for bundles to be set up");
- context().getService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=org.apache.aries.blueprint)");
- context().getService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=org.apache.aries.blueprint.sample)");
- }
+ protected Option blueprint() {
+ return composite(
+ mavenBundle("org.ow2.asm", "asm-all").versionAsInProject(),
+ mavenBundle("org.apache.aries.proxy", "org.apache.aries.proxy").versionAsInProject(),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint").versionAsInProject(),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.jexl.evaluator").versionAsInProject(),
+ mavenBundle("org.apache.commons", "commons-jexl").versionAsInProject()
+ );
+ }
+
+ @Before
+ public void setup() {
+ extender = getBundleByName("org.apache.aries.blueprint");
+ sample = getBundleByName("org.apache.aries.blueprint.sample");
+ }
@Test
- public void BlueprintSample() throws Exception {
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Start Test Blueprint Sample");
-
- //////////////////////////////
- //Test BlueprintStateMBean
- //////////////////////////////
-
- //find the Blueprint Sample bundle id and the blueprint extender bundle id
- long sampleBundleId = -1;
- long extenderBundleId = -1; // the blueprint extender bundle "org.apache.geronimo.blueprint.geronimo-blueprint" is also a blueprint bundle.
- for (Bundle bundle : bundleContext.getBundles()){
- if (bundle.getSymbolicName().equals("org.apache.aries.blueprint.sample")) sampleBundleId = bundle.getBundleId();
- if (bundle.getSymbolicName().equals("org.apache.aries.blueprint")) extenderBundleId = bundle.getBundleId();
- }
- if (-1==sampleBundleId) fail("Blueprint Sample Bundle is not found!");
- if (-1==extenderBundleId) fail("Blueprint Extender Bundle is not found!");
-
- //retrieve the proxy object
- BlueprintStateMBean stateProxy = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(BlueprintStateMBean.OBJECTNAME), BlueprintStateMBean.class, false);
+ public void testBlueprintStateMBean() throws Exception {
+ BlueprintStateMBean stateProxy = getMBean(BlueprintStateMBean.OBJECTNAME, BlueprintStateMBean.class);
// test getBlueprintBundleIds
long[] bpBundleIds = stateProxy.getBlueprintBundleIds();
assertEquals("The blueprint bundle ids are: " + Arrays.toString(bpBundleIds), 3, bpBundleIds.length);
// test getLastEvent
- BlueprintEventValidator sampleValidator = new BlueprintEventValidator(sampleBundleId, extenderBundleId, 2);
- sampleValidator.validate(stateProxy.getLastEvent(sampleBundleId));
+ BlueprintEventValidator sampleValidator = new BlueprintEventValidator(sample.getBundleId(), extender.getBundleId(), 2);
+ sampleValidator.validate(stateProxy.getLastEvent(sample.getBundleId()));
// test getLastEvents
TabularData lastEvents = stateProxy.getLastEvents();
assertEquals(BlueprintStateMBean.OSGI_BLUEPRINT_EVENTS_TYPE,lastEvents.getTabularType());
- sampleValidator.validate(lastEvents.get(new Long[]{sampleBundleId}));
-
- //////////////////////////////
- //Test BlueprintMetadataMBean
- //////////////////////////////
-
+ sampleValidator.validate(lastEvents.get(new Long[]{sample.getBundleId()}));
+ }
+
+ @Test
+ public void testBlueprintMetaDataMBean() throws Exception {
//find the Blueprint Sample bundle's container service id
- Bundle sampleBundle = bundleContext.getBundle(sampleBundleId);
String filter = "(&(osgi.blueprint.container.symbolicname=" // no similar one in interfaces
- + sampleBundle.getSymbolicName() + ")(osgi.blueprint.container.version=" + sampleBundle.getVersion() + "))";
- ServiceReference[] serviceReferences = null;
+ + sample.getSymbolicName() + ")(osgi.blueprint.container.version=" + sample.getVersion() + "))";
+ ServiceReference<?>[] serviceReferences = null;
try {
serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(), filter);
} catch (InvalidSyntaxException e) {
@@ -143,39 +131,31 @@ public class BlueprintMBeanTest extends
assertEquals(3, bpContainerServiceIds.length);
// test getBlueprintContainerServiceId
- assertEquals(sampleBlueprintContainerServiceId, metadataProxy.getBlueprintContainerServiceId(sampleBundleId));
+ assertEquals(sampleBlueprintContainerServiceId, metadataProxy.getBlueprintContainerServiceId(sample.getBundleId()));
// test getComponentMetadata
// bean: foo
BeanValidator bv_foo = new BeanValidator("org.apache.aries.blueprint.sample.Foo", "init", "destroy");
- BeanPropertyValidator bpv_a = new BeanPropertyValidator("a");
- bpv_a.setObjectValueValidator(new ValueValidator("5"));
-
- BeanPropertyValidator bpv_b = new BeanPropertyValidator("b");
- bpv_b.setObjectValueValidator(new ValueValidator("-1"));
-
+ BeanPropertyValidator bpv_a = property("a", "5");
+ BeanPropertyValidator bpv_b = property("b", "-1");
BeanPropertyValidator bpv_bar = new BeanPropertyValidator("bar");
bpv_bar.setObjectValueValidator(new RefValidator("bar"));
-
- BeanPropertyValidator bpv_currency = new BeanPropertyValidator("currency");
- bpv_currency.setObjectValueValidator(new ValueValidator("PLN"));
-
- BeanPropertyValidator bpv_date = new BeanPropertyValidator("date");
- bpv_date.setObjectValueValidator(new ValueValidator("2009.04.17"));
+ BeanPropertyValidator bpv_currency = property("currency", "PLN");
+ BeanPropertyValidator bpv_date = property("date", "2009.04.17");
bv_foo.addPropertyValidators(bpv_a, bpv_b, bpv_bar, bpv_currency, bpv_date);
bv_foo.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "foo"));
// bean: bar
- BeanPropertyValidator bpv_value = new BeanPropertyValidator("value");
- bpv_value.setObjectValueValidator(new ValueValidator("Hello FooBar"));
-
+ BeanPropertyValidator bpv_value = property("value", "Hello FooBar");
BeanPropertyValidator bpv_context = new BeanPropertyValidator("context");
bpv_context.setObjectValueValidator(new RefValidator("blueprintBundleContext"));
CollectionValidator cv = new CollectionValidator("java.util.List");
- cv.addCollectionValueValidators(new ValueValidator("a list element"), new ValueValidator("5", "java.lang.Integer"));
+ cv.addCollectionValueValidators(
+ new ValueValidator("a list element"),
+ new ValueValidator("5", "java.lang.Integer"));
BeanPropertyValidator bpv_list = new BeanPropertyValidator("list");
bpv_list.setObjectValueValidator(cv);
@@ -242,4 +222,10 @@ public class BlueprintMBeanTest extends
bv_circularReference.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "circularReference"));
}
+ private BeanPropertyValidator property(String name, String expectedValue) {
+ BeanPropertyValidator val = new BeanPropertyValidator(name);
+ val.setObjectValueValidator(new ValueValidator(expectedValue));
+ return val;
+ }
+
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/Activator.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/Activator.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/Activator.java Mon May 26 15:17:52 2014
@@ -25,7 +25,6 @@ import org.apache.aries.jmx.test.bundleb
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ManagedService;
import org.osgi.util.tracker.ServiceTracker;
@@ -36,7 +35,6 @@ import org.osgi.util.tracker.ServiceTrac
*/
public class Activator implements BundleActivator {
- ServiceRegistration registration;
ServiceTracker tracker;
/* (non-Javadoc)
@@ -49,7 +47,8 @@ public class Activator implements Bundle
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, "org.apache.aries.jmx.test.ServiceA");
- registration = context.registerService(new String[] { InterfaceA.class.getName(), ManagedService.class.getName() }, new A(tracker), props);
+ String[] interfaces = new String[] { InterfaceA.class.getName(), ManagedService.class.getName() };
+ context.registerService(interfaces, new A(tracker), props);
}
@@ -57,7 +56,6 @@ public class Activator implements Bundle
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- registration.unregister();
tracker.close();
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/api/InterfaceA.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/api/InterfaceA.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/api/InterfaceA.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/api/InterfaceA.java Mon May 26 15:17:52 2014
@@ -25,11 +25,11 @@ import org.osgi.service.cm.ManagedServic
*
* @version $Rev$ $Date$
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings("rawtypes")
public interface InterfaceA extends ManagedService {
boolean invoke();
- Dictionary getConfig();
+ Dictionary getConfig();
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/impl/A.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/impl/A.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/impl/A.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundlea/impl/A.java Mon May 26 15:17:52 2014
@@ -28,7 +28,7 @@ import org.osgi.util.tracker.ServiceTrac
*
* @version $Rev$ $Date$
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings("rawtypes")
public class A implements InterfaceA {
private ServiceTracker tracker;
@@ -52,7 +52,7 @@ public class A implements InterfaceA {
}
- public void updated(Dictionary dictionary) throws ConfigurationException {
+ public void updated(Dictionary dictionary) throws ConfigurationException {
this.props = dictionary;
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/Activator.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/Activator.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/Activator.java Mon May 26 15:17:52 2014
@@ -25,7 +25,6 @@ import org.apache.aries.jmx.test.bundleb
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ManagedServiceFactory;
/**
@@ -35,27 +34,22 @@ import org.osgi.service.cm.ManagedServic
*/
public class Activator implements BundleActivator {
- ServiceRegistration plainRegistration;
- ServiceRegistration msfRegistration;
-
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, "org.apache.aries.jmx.test.ServiceB");
- plainRegistration = context.registerService(InterfaceB.class.getName(), new B(), props);
+ context.registerService(InterfaceB.class.getName(), new B(), props);
Dictionary<String, Object> fprops = new Hashtable<String, Object>();
fprops.put(Constants.SERVICE_PID, "jmx.test.B.factory");
- msfRegistration = context.registerService(ManagedServiceFactory.class.getName(), new MSF(), fprops);
+ context.registerService(ManagedServiceFactory.class.getName(), new MSF(), fprops);
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- plainRegistration.unregister();
- msfRegistration.unregister();
}
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/InterfaceB.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/InterfaceB.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/InterfaceB.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/InterfaceB.java Mon May 26 15:17:52 2014
@@ -23,13 +23,13 @@ import java.util.Dictionary;
*
* @version $Rev$ $Date$
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings("rawtypes")
public interface InterfaceB {
boolean invoke();
void configure(Dictionary<String, Object> props);
- Dictionary getConfig();
+ Dictionary getConfig();
}
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/MSF.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/MSF.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/MSF.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/api/MSF.java Mon May 26 15:17:52 2014
@@ -29,7 +29,7 @@ import org.osgi.service.cm.ManagedServic
*
* @version $Rev$ $Date$
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings({"unchecked", "rawtypes"})
public class MSF implements ManagedServiceFactory {
Map<String, InterfaceB> configured = new HashMap<String, InterfaceB>();
@@ -42,7 +42,8 @@ public class MSF implements ManagedServi
return "jmx.test.B.factory";
}
- public void updated(String pid, Dictionary dictionary) throws ConfigurationException {
+
+ public void updated(String pid, Dictionary dictionary) throws ConfigurationException {
if (configured.containsKey(pid)) {
configured.get(pid).configure(dictionary);
} else {
Modified: aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/impl/B.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/impl/B.java?rev=1597603&r1=1597602&r2=1597603&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/impl/B.java (original)
+++ aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/bundleb/impl/B.java Mon May 26 15:17:52 2014
@@ -25,7 +25,7 @@ import org.apache.aries.jmx.test.bundleb
*
* @version $Rev$ $Date$
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings("rawtypes")
public class B implements InterfaceB {
private Dictionary<String, Object> conf;