You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2010/10/07 11:18:23 UTC
svn commit: r1005378 - in /sling/whiteboard/fmeschbe/jmx-whiteboard: ./
src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/sling/ src/test/java/org/apache/sling/whiteboard/
src/test/java/org/apache/sling/whit...
Author: fmeschbe
Date: Thu Oct 7 09:18:21 2010
New Revision: 1005378
URL: http://svn.apache.org/viewvc?rev=1005378&view=rev
Log:
ARIES-430 Add intergation tests validating MBean registration support; refer to Aries JMX parent POM (instead of Sling Parent); use Aries way of defining Bundle Manifest
Added:
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java (with props)
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java (with props)
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java (with props)
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java (with props)
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java (with props)
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java (with props)
sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java (with props)
Modified:
sling/whiteboard/fmeschbe/jmx-whiteboard/pom.xml
Modified: sling/whiteboard/fmeschbe/jmx-whiteboard/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/pom.xml?rev=1005378&r1=1005377&r2=1005378&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/pom.xml (original)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/pom.xml Thu Oct 7 09:18:21 2010
@@ -1,30 +1,23 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+>
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>9</version>
- <relativePath>../../parent/pom.xml</relativePath>
+ <groupId>org.apache.aries.jmx</groupId>
+ <artifactId>jmx</artifactId>
+ <version>0.2-incubating</version>
</parent>
<artifactId>org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard</artifactId>
@@ -45,24 +38,76 @@
<url>http://svn.apache.org/viewvc/incubator/sling/fmeschbe/jmx-whiteboard</url>
</scm>
+
+ <!-- A Note on Testing ================= This project contains two kinds
+ of tests: regular unit tests running in the test phase and integration tests
+ based on PAX Exam running in the integration-test phase. Basically the complete
+ project is build using Java 1.3 source and target compatibility (as inherited
+ from the parent pom). The exception are the unit tests in the "integration"
+ packages. These have to be compiled with Java 5 source and target compatibility
+ because the employ annotations and generics. For running the integration
+ tests from the console using Maven nothing special has to be done as the
+ tests run automatically. To run the tests in your IDE, the project has to
+ be built to the "package" phase with the profile "ide" enabled: $ mvn -Pide
+ clean package This creates the scr.jar file in the target folder, which is
+ used by the integration tests when run from the IDE. Alternatively the "project.bundle.file"
+ system property may be set to the bundle JAR in the IDE launcher. -->
<properties>
+ <bundle.build.name>
+ ${basedir}/target
+ </bundle.build.name>
+ <bundle.file.name>
+ ${bundle.build.name}/${project.build.finalName}.jar
+ </bundle.file.name>
+
+ <aries.osgi.activator>
+ org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.Activator
+ </aries.osgi.activator>
+ <aries.osgi.export.pkg>
+ !*
+ </aries.osgi.export.pkg>
+ <aries.osgi.private.pkg>
+ org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard
+ </aries.osgi.private.pkg>
+ <aries.osgi.import.service>
+ javax.management.MBeanServer
+ </aries.osgi.import.service>
</properties>
-
+
<build>
<plugins>
+ <!-- Exclude Integration tests in (default) unit tests and conversely
+ enable integration tests for integration testing only. Helper classes are
+ completely excluded from testing. -->
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>surefire-it</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>project.bundle.file</name>
+ <value>${bundle.file.name}</value>
+ </property>
+ </systemProperties>
+ <excludes>
+ <exclude>**/whiteboard/*</exclude>
+ </excludes>
+ <includes>
+ <include>**/integration/*</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
<configuration>
- <instructions>
- <Bundle-Category>aries</Bundle-Category>
- <Bundle-Activator>org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.Activator</Bundle-Activator>
- <Export-Package>!*</Export-Package>
- <Private-Package>
- org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard
- </Private-Package>
- </instructions>
+ <excludes>
+ <exclude>**/integration/**</exclude>
+ </excludes>
</configuration>
</plugin>
</plugins>
@@ -89,5 +134,89 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
+
+ <!-- Integration Testing with Pax Exam -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>0.6.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <version>0.6.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <version>0.6.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.swissbox</groupId>
+ <artifactId>pax-swissbox-tinybundles</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+
+ <profiles>
+ <!-- copy the package such that IDEs may easily use it without setting
+ the system property -->
+ <profile>
+ <id>ide</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.3</version>
+ <executions>
+ <execution>
+ <id>cm-file-create</id>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <copy
+ file="${project.build.directory}/${project.build.finalName}.jar"
+ tofile="${project.build.directory}/jmx-whiteboard.jar" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <!-- repositories for Pax Exam and BND tool -->
+ <repositories>
+ <repository>
+ <id>ops4j</id>
+ <name>ops4j</name>
+ <url>http://repository.ops4j.org/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>aqute</id>
+ <name>aqute</name>
+ <url>http://www.aqute.biz/repo</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
</project>
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.IntegrationTestBase;
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.TestClass;
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.TestClassMBean;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The <code>MBeanTest</code> tests MBean registration with MBean Servers
+ */
+@RunWith(JUnit4TestRunner.class)
+public class MBeanServerTest extends IntegrationTestBase {
+
+ @Test
+ public void test_MServerBean() throws Exception {
+ final String instanceName = "simple.test.instance";
+ final String objectNameString = "domain:instance=" + instanceName;
+ final ObjectName objectName = new ObjectName(objectNameString);
+ final TestClass testInstance = new TestClass(instanceName);
+
+ // get or create the dynamic MBean Server
+ final MBeanServer server = getOrCreateMBeanServer();
+
+ // MBean server not registered as service, unknown object
+ assertNotRegistered(server, objectName);
+
+ // expect the MBean to be registered with the static server
+ final ServiceRegistration mBeanReg = registerService(
+ TestClassMBean.class.getName(), testInstance, objectNameString);
+
+ // MBean server not registered, expect object to not be known
+ assertNotRegistered(server, objectName);
+
+ // register MBean server, expect MBean registered
+ ServiceRegistration mBeanServerReg = registerMBeanServer(server);
+ assertRegistered(server, objectName);
+
+ // expect MBean to return expected value
+ TestCase.assertEquals(instanceName,
+ server.getAttribute(objectName, "InstanceName"));
+
+ // unregister MBean server, expect MBean to be unregistered
+ mBeanServerReg.unregister();
+ assertNotRegistered(server, objectName);
+
+ // unregister MBean, expect to not be registered any more
+ mBeanReg.unregister();
+ assertNotRegistered(server, objectName);
+ }
+
+}
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanServerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration;
+
+import javax.management.DynamicMBean;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.IntegrationTestBase;
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.TestClass;
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.TestClassMBean;
+import org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper.TestStandardMBean;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The <code>MBeanTest</code> tests MBean registration with MBean Servers
+ */
+@RunWith(JUnit4TestRunner.class)
+public class MBeanTest extends IntegrationTestBase {
+
+ @Test
+ public void test_simple_MBean() throws Exception {
+ final String instanceName = "simple.test.instance";
+ final String objectNameString = "domain:instance=" + instanceName;
+ final ObjectName objectName = new ObjectName(objectNameString);
+ final TestClass testInstance = new TestClass(instanceName);
+
+ final MBeanServer server = getStaticMBeanServer();
+
+ // expect MBean to not be registered yet
+ assertNotRegistered(server, objectName);
+
+ // expect the MBean to be registered with the static server
+ final ServiceRegistration reg = registerService(
+ TestClassMBean.class.getName(), testInstance, objectNameString);
+ assertRegistered(server, objectName);
+
+ // expect MBean to return expected value
+ TestCase.assertEquals(instanceName,
+ server.getAttribute(objectName, "InstanceName"));
+
+ // unregister MBean, expect to not be registered any more
+ reg.unregister();
+ assertNotRegistered(server, objectName);
+ }
+
+ @Test
+ public void test_StandardMBean() throws Exception {
+ final String instanceName = "standard.test.instance";
+ final String objectNameString = "domain:instance=" + instanceName;
+ final ObjectName objectName = new ObjectName(objectNameString);
+ final TestStandardMBean testInstance = new TestStandardMBean(
+ instanceName);
+
+ final MBeanServer server = getStaticMBeanServer();
+
+ // expect MBean to not be registered yet
+ assertNotRegistered(server, objectName);
+
+ // expect the MBean to be registered with the static server
+ final ServiceRegistration reg = registerService(
+ DynamicMBean.class.getName(), testInstance, objectNameString);
+ assertRegistered(server, objectName);
+
+ // expect MBean to return expected value
+ TestCase.assertEquals(instanceName,
+ server.getAttribute(objectName, "InstanceName"));
+
+ // unregister MBean, expect to not be registered any more
+ reg.unregister();
+ assertNotRegistered(server, objectName);
+ }
+}
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/MBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;
+
+import java.io.File;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.junit.After;
+import org.junit.Before;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class IntegrationTestBase {
+
+ // the name of the system property providing the bundle file to be installed
+ // and tested
+ protected static final String BUNDLE_JAR_SYS_PROP = "project.bundle.file";
+
+ // the default bundle jar file name
+ protected static final String BUNDLE_JAR_DEFAULT = "target/jmx-whiteboard.jar";
+
+ // the JVM option to set to enable remote debugging
+ protected static final String DEBUG_VM_OPTION = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303";
+
+ // the actual JVM option set, extensions may implement a static
+ // initializer overwriting this value to have the configuration()
+ // method include it when starting the OSGi framework JVM
+ protected static String paxRunnerVmOption = null;
+
+ private static MBeanServer staticServer;
+
+ private MBeanServer server;
+
+ @Inject
+ protected BundleContext bundleContext;
+
+ private ServiceRegistration staticServerRegistration;
+
+ protected static final String PROP_NAME = "theValue";
+
+ protected static final Dictionary<String, String> theConfig;
+
+ static {
+ theConfig = new Hashtable<String, String>();
+ theConfig.put(PROP_NAME, PROP_NAME);
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ final String bundleFileName = System.getProperty(BUNDLE_JAR_SYS_PROP,
+ BUNDLE_JAR_DEFAULT);
+ final File bundleFile = new File(bundleFileName);
+ if (!bundleFile.canRead()) {
+ throw new IllegalArgumentException("Cannot read from bundle file "
+ + bundleFileName + " specified in the " + BUNDLE_JAR_SYS_PROP
+ + " system property");
+ }
+
+ final Option[] base = options(
+ provision(
+ CoreOptions.bundle(bundleFile.toURI().toString()),
+ mavenBundle("org.ops4j.pax.swissbox",
+ "pax-swissbox-tinybundles", "1.0.0"),
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin",
+ "1.2.8"), mavenBundle("org.slf4j", "slf4j-api", "1.5.2"),
+ mavenBundle("org.slf4j", "slf4j-simple", "1.5.2")),
+ waitForFrameworkStartup());
+ final Option vmOption = (paxRunnerVmOption != null)
+ ? PaxRunnerOptions.vmOption(paxRunnerVmOption)
+ : null;
+ return OptionUtils.combine(base, vmOption);
+ }
+
+ @Before
+ public void setUp() {
+ staticServerRegistration = registerMBeanServer(getStaticMBeanServer());
+ }
+
+ @After
+ public void tearDown() {
+ staticServerRegistration.unregister();
+ }
+
+ protected MBeanServer getStaticMBeanServer() {
+ if (staticServer == null) {
+ staticServer = MBeanServerFactory.createMBeanServer("StaticServerDomain");
+ }
+ return staticServer;
+ }
+
+ protected MBeanServer getMBeanServer() {
+ return server;
+ }
+
+ protected MBeanServer getOrCreateMBeanServer() {
+ if (server == null) {
+ server = MBeanServerFactory.createMBeanServer("DynamicServerDomain");
+ }
+ return server;
+ }
+
+ protected void dropMBeanServer() {
+ if (server != null) {
+ MBeanServerFactory.releaseMBeanServer(server);
+ server = null;
+ }
+ }
+
+ protected ServiceRegistration registerMBeanServer(final MBeanServer server) {
+ return registerService(MBeanServer.class.getName(), server, null);
+ }
+
+ protected ServiceRegistration registerService(final String clazz,
+ final Object service, final String objectName) {
+ Hashtable<String, String> properties;
+ if (objectName != null) {
+ properties = new Hashtable<String, String>();
+ properties.put("jmx.objectname", objectName);
+ } else {
+ properties = null;
+ }
+ return bundleContext.registerService(clazz, service, properties);
+ }
+
+ protected void assertRegistered(final MBeanServer server,
+ final ObjectName objectName) {
+ try {
+ ObjectInstance instance = server.getObjectInstance(objectName);
+ TestCase.assertNotNull(instance);
+ TestCase.assertEquals(objectName, instance.getObjectName());
+ } catch (InstanceNotFoundException nfe) {
+ TestCase.fail("Expected instance of " + objectName
+ + " registered with MBeanServer");
+ }
+ }
+
+ protected void assertNotRegistered(final MBeanServer server,
+ final ObjectName objectName) {
+ try {
+ server.getObjectInstance(objectName);
+ TestCase.fail("Unexpected instance of " + objectName
+ + " registered with MBeanServer");
+ } catch (InstanceNotFoundException nfe) {
+ // expected, ignore
+ }
+ }
+
+}
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/IntegrationTestBase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ops4j.pax.swissbox.tinybundles.core.BuildableBundle;
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundle;
+import org.ops4j.pax.swissbox.tinybundles.core.metadata.RawBuilder;
+
+public class MyTinyBundle implements TinyBundle {
+
+ private Map<String, URL> m_resources = new HashMap<String, URL>();
+
+ @SuppressWarnings("unchecked")
+ public TinyBundle addClass( Class clazz )
+ {
+ String name = clazz.getName().replaceAll( "\\.", "/" ) + ".class";
+ addResource( name, clazz.getResource( "/" + name ) );
+ return this;
+ }
+
+ public TinyBundle addResource( String name, URL url )
+ {
+ m_resources.put( name, url );
+ return this;
+ }
+
+ public BuildableBundle prepare( BuildableBundle builder )
+ {
+ return builder.setResources( m_resources );
+ }
+
+ public BuildableBundle prepare()
+ {
+ return new RawBuilder().setResources( m_resources );
+ }
+
+}
\ No newline at end of file
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/MyTinyBundle.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper;
+
+/**
+ * The <code>TestClass</code> is a simple class which will be registered as a
+ * Simple MBean implementing the {@link TestClassMBean} interface.
+ */
+public class TestClass implements TestClassMBean {
+
+ private final String instanceName;
+
+ public TestClass() {
+ this(null);
+ }
+
+ public TestClass(final String name) {
+ this.instanceName = (name == null) ? getClass().getName() : name;
+ }
+
+ public String getInstanceName() {
+ return instanceName;
+ }
+
+}
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClass.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper;
+
+/**
+ * The <code>TestClassMBean</code> is the simple MBean interface for the
+ * {@link TestClass} class.
+ */
+public interface TestClassMBean {
+
+ String getInstanceName();
+
+}
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestClassMBean.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java?rev=1005378&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java (added)
+++ sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java Thu Oct 7 09:18:21 2010
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.whiteboard.fmeschbe.jmx.whiteboard.integration.helper;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+public class TestStandardMBean extends StandardMBean implements TestClassMBean {
+
+ private final String instanceName;
+
+ protected TestStandardMBean() throws NotCompliantMBeanException {
+ this(null);
+ }
+
+ public TestStandardMBean(final String name)
+ throws NotCompliantMBeanException {
+ super(TestClassMBean.class);
+ this.instanceName = (name == null) ? getClass().getName() : name;
+ }
+
+ public String getInstanceName() {
+ return instanceName;
+ }
+
+}
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/fmeschbe/jmx-whiteboard/src/test/java/org/apache/sling/whiteboard/fmeschbe/jmx/whiteboard/integration/helper/TestStandardMBean.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url