[jboss-osgi-commits] JBoss-OSGI SVN: r91490 - in projects/jboss-osgi/trunk/testsuite/example: src/test/java/org/jboss/test/osgi/example and 10 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Jul 21 04:39:46 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-07-21 04:39:45 -0400 (Tue, 21 Jul 2009)
New Revision: 91490

Added:
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/dom/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.bnd
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.xml
Removed:
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/dom/JMXTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/dom/bundle/
Modified:
   projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
   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/simple/SimpleHuskyTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd
Log:
[JBOSGI-97] Provide SAX/DOM parser example

Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2009-07-21 07:13:28 UTC (rev 91489)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2009-07-21 08:39:45 UTC (rev 91490)
@@ -62,6 +62,9 @@
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple.jar" files="${tests.resources.dir}/simple/example-simple.bnd" />
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple-husky.jar" files="${tests.resources.dir}/simple/example-simple-husky.bnd" />
     
+    <!-- xml/parser -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-xml-parser.jar" files="${tests.resources.dir}/xml/parser/example-xml-parser.bnd" />
+    
     <!-- Please add alphabetically -->
 
   </target>

Copied: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/dom (from rev 91483, projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx)

Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/dom/JMXTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/JMXTestCase.java	2009-07-21 04:23:37 UTC (rev 91483)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/dom/JMXTestCase.java	2009-07-21 08:39:45 UTC (rev 91490)
@@ -1,77 +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;
-
-//$Id$
-
-import static org.jboss.test.osgi.example.jmx.bundle.FooMBean.MBEAN_NAME;
-import static org.junit.Assert.assertEquals;
-
-import org.jboss.osgi.jmx.JMXCapability;
-import org.jboss.osgi.jndi.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.OSGiTestHelper;
-import org.jboss.test.osgi.example.jmx.bundle.FooMBean;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * A test that deployes a bundle that registeres an MBean
- * 
- * @author thomas.diesler at jboss.com
- * @since 12-Feb-2009
- */
-public class JMXTestCase
-{
-   private static OSGiRuntime runtime;
-   private static OSGiBundle bundle;
-
-   @BeforeClass
-   public static void setUpClass() throws Exception
-   {
-      runtime = new OSGiTestHelper().getDefaultRuntime();
-      runtime.addCapability(new JNDICapability());
-      runtime.addCapability(new JMXCapability());
-
-      bundle = runtime.installBundle("example-jmx.jar");
-      bundle.start();
-   }
-
-   @AfterClass
-   public static void tearDownClass() throws Exception
-   {
-      if (bundle != null)
-         bundle.uninstall();
-      
-      runtime.shutdown();
-   }
-
-   @Test
-   public void testMBeanAccess() throws Exception
-   {
-      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/http/HttpServiceTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/http/HttpServiceTestCase.java	2009-07-21 07:13:28 UTC (rev 91489)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/http/HttpServiceTestCase.java	2009-07-21 08:39:45 UTC (rev 91490)
@@ -65,9 +65,6 @@
    @AfterClass
    public static void tearDownClass() throws Exception
    {
-      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-07-21 07:13:28 UTC (rev 91489)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/JMXTestCase.java	2009-07-21 08:39:45 UTC (rev 91490)
@@ -62,9 +62,6 @@
    @AfterClass
    public static void tearDownClass() throws Exception
    {
-      if (bundle != null)
-         bundle.uninstall();
-      
       runtime.shutdown();
    }
 

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/simple/SimpleHuskyTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/simple/SimpleHuskyTestCase.java	2009-07-21 07:13:28 UTC (rev 91489)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/simple/SimpleHuskyTestCase.java	2009-07-21 08:39:45 UTC (rev 91490)
@@ -60,6 +60,7 @@
    @Before
    public void setUp() throws BundleException
    {
+      // Only do this if we are not within the OSGi Runtime
       if (context == null)
       {
          // Get the default runtime
@@ -81,10 +82,6 @@
       // Only do this if we are not within the OSGi Runtime
       if (context == null)
       {
-         // Uninstall the bundle
-         if (bundle != null)
-            bundle.uninstall();
-         
          // Shutdown the runtime 
          runtime.shutdown();
       }

Copied: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java (from rev 91483, 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/xml/parser/DOMParserTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java	2009-07-21 08:39:45 UTC (rev 91490)
@@ -0,0 +1,124 @@
+/*
+ * 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.xml.parser;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeNotNull;
+
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.osgi.husky.BridgeFactory;
+import org.jboss.osgi.husky.HuskyCapability;
+import org.jboss.osgi.husky.annotation.ProvideContext;
+import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.jboss.osgi.xml.XMLParserCapability;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * A test that parses XML ducuments
+ * 
+ * @see http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 12-Feb-2009
+ */
+public class DOMParserTestCase
+{
+   @ProvideContext
+   public static BundleContext context;
+   private static OSGiRuntime runtime;
+
+   @Before
+   public void beforeClass() throws Exception
+   {
+      // Only do this if we are not within the OSGi Runtime
+      if (context == null)
+      {
+         runtime = new OSGiTestHelper().getDefaultRuntime();
+         runtime.addCapability(new XMLParserCapability());
+         runtime.addCapability(new HuskyCapability());
+
+         OSGiBundle bundle = runtime.installBundle("example-xml-parser.jar");
+         bundle.start();
+      }
+   }
+
+   @After
+   public void afterClass() throws Exception
+   {
+      // Only do this if we are not within the OSGi Runtime
+      if (context == null)
+         runtime.shutdown();
+   }
+
+   @Test
+   public void testDOMParser() throws Exception
+   {
+      // Tell Husky to run this test method within the OSGi Runtime
+      if (context == null)
+         BridgeFactory.getBridge().run();
+      
+      // Stop here if the context is not injected
+      assumeNotNull(context);
+
+      DocumentBuilder domParser = getDocumentBuilder();
+      URL resURL = context.getBundle().getResource("example-xml-parser.xml");
+      Document dom = domParser.parse(resURL.openStream());
+      assertNotNull("Document not null", dom);
+      
+      Element root = dom.getDocumentElement();
+      assertEquals("root", root.getLocalName());
+      
+      Node child = root.getFirstChild();
+      assertEquals("child", child.getLocalName());
+      assertEquals("content", child.getTextContent());
+   }
+
+   private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException
+   {
+      // This service gets registerd by the jboss-osgi-apache-xerces service
+      ServiceReference sref = context.getServiceReference(DocumentBuilderFactory.class.getName());
+      if (sref == null)
+         throw new IllegalStateException("DocumentBuilderFactory not available");
+      
+      DocumentBuilderFactory factory = (DocumentBuilderFactory)context.getService(sref);
+      factory.setValidating(false);
+      
+      return factory.newDocumentBuilder();
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java	2009-07-21 08:39:45 UTC (rev 91490)
@@ -0,0 +1,134 @@
+/*
+ * 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.xml.parser;
+
+//$Id: JMXTestCase.java 91196 2009-07-14 09:41:15Z thomas.diesler at jboss.com $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeNotNull;
+
+import java.net.URL;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.jboss.osgi.husky.BridgeFactory;
+import org.jboss.osgi.husky.HuskyCapability;
+import org.jboss.osgi.husky.annotation.ProvideContext;
+import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.jboss.osgi.xml.XMLParserCapability;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A test that parses XML ducuments
+ * 
+ * @see http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 12-Feb-2009
+ */
+public class SAXParserTestCase
+{
+   @ProvideContext
+   public static BundleContext context;
+   private static OSGiRuntime runtime;
+
+   @Before
+   public void beforeClass() throws Exception
+   {
+      // Only do this if we are not within the OSGi Runtime
+      if (context == null)
+      {
+         runtime = new OSGiTestHelper().getDefaultRuntime();
+         runtime.addCapability(new XMLParserCapability());
+         runtime.addCapability(new HuskyCapability());
+
+         OSGiBundle bundle = runtime.installBundle("example-xml-parser.jar");
+         bundle.start();
+      }
+   }
+
+   @After
+   public void afterClass() throws Exception
+   {
+      // Only do this if we are not within the OSGi Runtime
+      if (context == null)
+         runtime.shutdown();
+   }
+
+   @Test
+   public void testSAXParser() throws Exception
+   {
+      // Tell Husky to run this test method within the OSGi Runtime
+      if (context == null)
+         BridgeFactory.getBridge().run();
+      
+      // Stop here if the context is not injected
+      assumeNotNull(context);
+
+      SAXParser saxParser = getSAXParser();
+      URL resURL = context.getBundle().getResource("example-xml-parser.xml");
+      
+      SAXHandler saxHandler = new SAXHandler();
+      saxParser.parse(resURL.openStream(), saxHandler);
+      assertEquals("content", saxHandler.getContent());
+   }
+
+   private SAXParser getSAXParser() throws SAXException, ParserConfigurationException
+   {
+      // This service gets registerd by the jboss-osgi-apache-xerces service
+      ServiceReference sref = context.getServiceReference(SAXParserFactory.class.getName());
+      if (sref == null)
+         throw new IllegalStateException("DocumentBuilderFactory not available");
+      
+      SAXParserFactory factory = (SAXParserFactory)context.getService(sref);
+      factory.setValidating(false);
+      
+      SAXParser saxParser = factory.newSAXParser();
+      return saxParser;
+   }
+   
+   static class SAXHandler extends DefaultHandler
+   {
+      private String content;
+
+      @Override
+      public void characters(char[] ch, int start, int length) throws SAXException
+      {
+         content = new String(ch, start, length);
+      }
+
+      public String getContent()
+      {
+         return content;
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd	2009-07-21 07:13:28 UTC (rev 91489)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd	2009-07-21 08:39:45 UTC (rev 91490)
@@ -6,7 +6,7 @@
 
 Private-Package: org.jboss.test.osgi.example.simple.bundle
 
-# Export the package that contains tthe test case
+# Export the package that contains the test case
 Export-Package: org.jboss.test.osgi.example.simple
 
 # Tell Husky that there are test cases in this package

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.bnd	2009-07-21 08:39:45 UTC (rev 91490)
@@ -0,0 +1,10 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-xml-parser.jar src/test/resources/example/xml/parser/example-xml-parser.bnd
+
+Bundle-SymbolicName: example-xml-parser
+
+# Export the package that contains the test case
+Export-Package: org.jboss.test.osgi.example.xml.parser
+Include-Resource: example-xml-parser.xml
+
+# Tell Husky that there are test cases in this package
+Test-Package: org.jboss.test.osgi.example.xml.parser

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.xml	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/parser/example-xml-parser.xml	2009-07-21 08:39:45 UTC (rev 91490)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<root><child>content</child></root>



More information about the jboss-osgi-commits mailing list