Author: rmannibucau
Date: Sun Dec 25 23:01:58 2011
New Revision: 1224656

URL: http://svn.apache.org/viewvc?rev=1224656&view=rev
Log:
adding an integration test for OSGi

Added:
    openejb/trunk/openejb/osgi/openejb-osgi-tests/
    openejb/trunk/openejb/osgi/openejb-osgi-tests/pom.xml
    openejb/trunk/openejb/osgi/openejb-osgi-tests/src/
    openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/
    openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/
    openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/
    openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/
    
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/
    
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/
    
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/test/
    
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/test/OSGiKarafStartupTest.java
Removed:
    openejb/trunk/openejb/osgi/openejb-core-osgi/src/test/
Modified:
    openejb/trunk/openejb/osgi/pom.xml

Added: openejb/trunk/openejb/osgi/openejb-osgi-tests/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-osgi-tests/pom.xml?rev=1224656&view=auto
==============================================================================
--- openejb/trunk/openejb/osgi/openejb-osgi-tests/pom.xml (added)
+++ openejb/trunk/openejb/osgi/openejb-osgi-tests/pom.xml Sun Dec 25 23:01:58 
2011
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd";>
+  <parent>
+    <artifactId>osgi</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>4.0.0-beta-2-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>openejb-osgi-tests</artifactId>
+  <name>OpenEJB :: OSGi :: Tests</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <version>2.3.0.M1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.karaf.tooling.exam</groupId>
+      <artifactId>org.apache.karaf.tooling.exam.container</artifactId>
+      <version>3.0.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.console</artifactId>
+      <version>${karaf.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apache-karafee</artifactId>
+      <version>${karafee.version}</version>
+      <type>tar.gz</type>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/filtered-resources</directory>
+        <filtering>true</filtering>
+        <includes>
+          <include>**/*</include>
+        </includes>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.servicemix.tooling</groupId>
+        <artifactId>depends-maven-plugin</artifactId>
+        <version>1.2</version>
+        <executions>
+          <execution>
+            <id>generate-depends-file</id>
+            <goals>
+              <goal>generate-depends-file</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: 
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/test/OSGiKarafStartupTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/test/OSGiKarafStartupTest.java?rev=1224656&view=auto
==============================================================================
--- 
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/test/OSGiKarafStartupTest.java
 (added)
+++ 
openejb/trunk/openejb/osgi/openejb-osgi-tests/src/test/java/org/apache/openejb/osgi/test/OSGiKarafStartupTest.java
 Sun Dec 25 23:01:58 2011
@@ -0,0 +1,94 @@
+package org.apache.openejb.osgi.test;
+
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.junit.ProbeBuilder;
+
+import javax.inject.Inject;
+import java.io.ByteArrayOutputStream;
+import java.io.FileReader;
+import java.io.PrintStream;
+import java.util.Properties;
+
+import static 
org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE;
+
+@RunWith(JUnit4TestRunner.class)
+public class OSGiKarafStartupTest {
+    @Inject
+    private CommandProcessor processor;
+
+    @Configuration
+    public Option[] configure() throws Exception {
+        final Properties jreProperties = new Properties();
+        jreProperties.load(new 
FileReader("../apache-karafee/src/main/filtered-resources/etc/jre.properties"));
+        final String[] packages = 
trim(jreProperties.getProperty("jre-1.6").split(","));
+
+        return options(
+                karafDistributionConfiguration()
+                        .frameworkUrl(
+                                
maven().groupId("org.apache.openejb").artifactId("apache-karafee").versionAsInProject().type("tar.gz"))
+                        .name("Apache Karafee")
+                        .karafVersion("2.2.4"),
+                felix()
+
+                // , 
vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
+        );
+    }
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(final TestProbeBuilder probe) {
+        return probe.setHeader(DYNAMICIMPORT_PACKAGE, 
"*,org.apache.felix.service.*;status=provisional");
+    }
+
+    private static String[] trim(String[] split) {
+        final String[] trimmed = new String[split.length];
+        for (int i = 0; i < split.length; i++) {
+            trimmed[i] = split[i].trim();
+        }
+        return trimmed;
+    }
+
+    @Test
+    public void openejbIsStarted() {
+        assertTrue(OpenEJB.isInitialized());
+        
assertNotNull(SystemInstance.get().getComponent(ContainerSystem.class));
+    }
+
+    @Test
+    public void commandsAreInstalled() throws Exception {
+        assertCommand("openejb:list", "Name");
+    }
+
+    private void assertCommand(final String cmd, final String... expected) 
throws Exception {
+        final ByteArrayOutputStream out = new ByteArrayOutputStream();
+        final PrintStream psOut = new PrintStream(out);
+        final ByteArrayOutputStream err = new ByteArrayOutputStream();
+        final PrintStream psErr = new PrintStream(out);
+
+        final CommandSession session = processor.createSession(System.in, 
psOut, psErr);
+        session.execute(cmd);
+        session.getConsole().flush();
+        session.close();
+
+        assertTrue(err.toString().isEmpty());
+        final String sout = out.toString();
+        for (String s : expected) {
+            assertTrue(sout.contains(s));
+        }
+    }
+}

Modified: openejb/trunk/openejb/osgi/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/pom.xml?rev=1224656&r1=1224655&r2=1224656&view=diff
==============================================================================
--- openejb/trunk/openejb/osgi/pom.xml (original)
+++ openejb/trunk/openejb/osgi/pom.xml Sun Dec 25 23:01:58 2011
@@ -19,6 +19,7 @@
     <module>openejb-karaf-commands</module>
     <module>openejb-karaf-rebranding</module>
     <module>apache-karafee</module>
+    <module>openejb-osgi-tests</module>
   </modules>
 
   <properties>


Reply via email to