Author: thomas.diesler(a)jboss.com
Date: 2009-06-02 12:10:01 -0400 (Tue, 02 Jun 2009)
New Revision: 89677
Added:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooServiceActivator.java
Removed:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/JMXTestService.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/ServiceActivator.java
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/http/HttpServiceTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/JMXTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooMBean.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/JNDITestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/example-jmx.bnd
Log:
Simplify example tests
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/http/HttpServiceTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/http/HttpServiceTestCase.java 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/http/HttpServiceTestCase.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -33,7 +33,6 @@
import org.jboss.osgi.spi.capability.HttpCapability;
import org.jboss.osgi.spi.testing.OSGiBundle;
import org.jboss.osgi.spi.testing.OSGiRuntime;
-import org.jboss.osgi.spi.testing.OSGiTest;
import org.jboss.osgi.spi.testing.OSGiTestHelper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -45,10 +44,10 @@
* @author thomas.diesler(a)jboss.com
* @since 23-Jan-2009
*/
-public class HttpServiceTestCase extends OSGiTest
+public class HttpServiceTestCase
{
private static OSGiRuntime runtime;
- private static OSGiBundle testBundle;
+ private static OSGiBundle bundle;
@BeforeClass
public static void setUpClass() throws Exception
@@ -59,14 +58,16 @@
Thread.sleep(5000);
- testBundle = runtime.installBundle("example-http.jar");
- testBundle.start();
+ bundle = runtime.installBundle("example-http.jar");
+ bundle.start();
}
@AfterClass
public static void tearDownClass() throws Exception
{
- testBundle.uninstall();
+ if (bundle != null)
+ bundle.uninstall();
+
runtime.shutdown();
}
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/JMXTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/JMXTestCase.java 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/JMXTestCase.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -23,16 +23,14 @@
//$Id$
+import static org.jboss.test.osgi.example.jmx.bundle.FooMBean.MBEAN_NAME;
import static org.junit.Assert.assertEquals;
-import javax.management.ObjectName;
-
import org.jboss.osgi.spi.capability.JMXCapability;
import org.jboss.osgi.spi.capability.JNDICapability;
import org.jboss.osgi.spi.management.MBeanProxy;
import org.jboss.osgi.spi.testing.OSGiBundle;
import org.jboss.osgi.spi.testing.OSGiRuntime;
-import org.jboss.osgi.spi.testing.OSGiTest;
import org.jboss.osgi.spi.testing.OSGiTestHelper;
import org.jboss.test.osgi.example.jmx.bundle.FooMBean;
import org.junit.AfterClass;
@@ -45,7 +43,7 @@
* @author thomas.diesler(a)jboss.com
* @since 12-Feb-2009
*/
-public class JMXTestCase extends OSGiTest
+public class JMXTestCase
{
private static OSGiRuntime runtime;
private static OSGiBundle bundle;
@@ -64,15 +62,16 @@
@AfterClass
public static void tearDownClass() throws Exception
{
- bundle.uninstall();
+ if (bundle != null)
+ bundle.uninstall();
+
runtime.shutdown();
}
@Test
public void testMBeanAccess() throws Exception
{
- ObjectName oname = new
ObjectName("jboss.osgi:service=mbean-test-service");
- FooMBean foo = (FooMBean)MBeanProxy.get(FooMBean.class, oname,
runtime.getMBeanServer());
+ FooMBean foo = (FooMBean)MBeanProxy.get(FooMBean.class, MBEAN_NAME,
runtime.getMBeanServer());
assertEquals("hello", foo.echo("hello"));
}
}
\ No newline at end of file
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooMBean.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooMBean.java 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooMBean.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -21,9 +21,15 @@
*/
package org.jboss.test.osgi.example.jmx.bundle;
+import javax.management.ObjectName;
+
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+
//$Id$
public interface FooMBean
{
- String echo(String msg);
+ ObjectName MBEAN_NAME =
ObjectNameFactory.create("jboss.osgi:service=mbean-test-service");
+
+ String echo(String msg);
}
Copied:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooServiceActivator.java
(from rev 89672,
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/ServiceActivator.java)
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooServiceActivator.java
(rev 0)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/FooServiceActivator.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.jmx.bundle;
+
+//$Id$
+
+import static org.jboss.test.osgi.example.jmx.bundle.FooMBean.MBEAN_NAME;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * A Service Activator
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 24-Apr-2009
+ */
+public class FooServiceActivator implements BundleActivator
+{
+ public void start(BundleContext context)
+ {
+ ServiceTracker tracker = new ServiceTracker(context, MBeanServer.class.getName(),
null)
+ {
+ public Object addingService(ServiceReference reference)
+ {
+ MBeanServer mbeanServer = (MBeanServer)super.addingService(reference);
+ registerMBean(mbeanServer);
+ return mbeanServer;
+ }
+
+ @Override
+ public void removedService(ServiceReference reference, Object service)
+ {
+ unregisterMBean((MBeanServer)service);
+ super.removedService(reference, service);
+ }
+ };
+ tracker.open();
+ }
+
+ public void stop(BundleContext context)
+ {
+ ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+ if (sref != null)
+ {
+ MBeanServer mbeanServer = (MBeanServer)context.getService(sref);
+ unregisterMBean(mbeanServer);
+ }
+ }
+
+ private void registerMBean(MBeanServer mbeanServer)
+ {
+ try
+ {
+ mbeanServer.registerMBean(new Foo(), MBEAN_NAME);
+ }
+ catch (JMException ex)
+ {
+ throw new IllegalStateException(ex);
+ }
+ }
+
+ private void unregisterMBean(MBeanServer mbeanServer)
+ {
+ try
+ {
+ if (mbeanServer.isRegistered(MBEAN_NAME))
+ mbeanServer.unregisterMBean(MBEAN_NAME);
+ }
+ catch (JMException ex)
+ {
+ throw new IllegalStateException(ex);
+ }
+ }
+}
\ No newline at end of file
Deleted:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/JMXTestService.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/JMXTestService.java 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/JMXTestService.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -1,85 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.osgi.example.jmx.bundle;
-
-//$Id$
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.jboss.osgi.spi.management.ObjectNameFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * A service that registers an MBean
- *
- * @author thomas.diesler(a)jboss.com
- * @since 24-Apr-2009
- */
-public class JMXTestService
-{
- private ServiceTracker tracker;
- private ObjectName objectName =
ObjectNameFactory.create("jboss.osgi:service=mbean-test-service");
-
- public JMXTestService(BundleContext context)
- {
- tracker = new ServiceTracker(context, MBeanServer.class.getName(), null);
- tracker.open();
-
- MBeanServer mbeanServer = getMBeanServer();
- if (mbeanServer == null)
- throw new IllegalStateException("No MBeanServer");
- }
-
- public void start()
- {
- try
- {
- MBeanServer mbeanServer = getMBeanServer();
- mbeanServer.registerMBean(new Foo(), objectName);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException(ex);
- }
- }
-
- public void stop()
- {
- try
- {
- MBeanServer mbeanServer = getMBeanServer();
- mbeanServer.isRegistered(objectName);
- mbeanServer.unregisterMBean(objectName);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException(ex);
- }
- }
-
- private MBeanServer getMBeanServer()
- {
- return (MBeanServer)tracker.getService();
- }
-}
Deleted:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/ServiceActivator.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/ServiceActivator.java 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/ServiceActivator.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.osgi.example.jmx.bundle;
-
-//$Id$
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * A Service Activator
- *
- * @author thomas.diesler(a)jboss.com
- * @since 24-Apr-2009
- */
-public class ServiceActivator implements BundleActivator
-{
- private JMXTestService service;
-
- public void start(BundleContext context)
- {
- service = new JMXTestService(context);
- service.start();
-
- context.registerService(JMXTestService.class.getName(), service, null);
- }
-
- public void stop(BundleContext context)
- {
- if (service != null)
- {
- service.stop();
- service = null;
- }
- }
-}
\ No newline at end of file
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/JNDITestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/JNDITestCase.java 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/JNDITestCase.java 2009-06-02
16:10:01 UTC (rev 89677)
@@ -32,7 +32,6 @@
import org.jboss.osgi.spi.capability.JNDICapability;
import org.jboss.osgi.spi.testing.OSGiBundle;
import org.jboss.osgi.spi.testing.OSGiRuntime;
-import org.jboss.osgi.spi.testing.OSGiTest;
import org.jboss.osgi.spi.testing.OSGiTestHelper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -45,7 +44,7 @@
* @author thomas.diesler(a)jboss.com
* @since 05-May-2009
*/
-public class JNDITestCase extends OSGiTest
+public class JNDITestCase
{
private static OSGiRuntime runtime;
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/example-jmx.bnd
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/example-jmx.bnd 2009-06-02
16:03:12 UTC (rev 89676)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/example-jmx.bnd 2009-06-02
16:10:01 UTC (rev 89677)
@@ -1,5 +1,5 @@
# bnd build -classpath target/test-classes -output target/test-libs/example-jmx.jar
src/test/resources/jmx/example-jmx.bnd
Bundle-SymbolicName: example-jmx
-Bundle-Activator: org.jboss.test.osgi.example.jmx.bundle.ServiceActivator
+Bundle-Activator: org.jboss.test.osgi.example.jmx.bundle.FooServiceActivator
Export-Package: org.jboss.test.osgi.example.jmx.bundle