Permalink
Browse files

adding some bundles, constraints not working

  • Loading branch information...
1 parent 6b2f205 commit ff306686b9cd217356e1c8fe4621c1d82b64e2ca @peterneubauer peterneubauer committed Jun 8, 2011
Showing with 92 additions and 168 deletions.
  1. +75 −68 pom.xml
  2. +17 −100 src/test/java/org/neo4j/examples/osgi/OSGiTest.java
View
143 pom.xml
@@ -2,79 +2,86 @@
<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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.neo4j</groupId>
+ <artifactId>parent-pom</artifactId>
+ <version>21</version>
+ </parent>
+
+ <groupId>org.neo4j.examples</groupId>
+ <artifactId>neo4j-osgi-examples</artifactId>
+ <version>0.1-SNAPSHOT</version>
+
+ <name>Neo4j OSGi examples</name>
+ <properties>
+ <paxexamversion>2.1.0</paxexamversion>
+ </properties>
+ <dependencies>
+ <dependency>
<groupId>org.neo4j</groupId>
- <artifactId>parent-pom</artifactId>
- <version>21</version>
- </parent>
+ <artifactId>neo4j</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+
+ <!-- Pax Exam Dependencies -->
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-player</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-testforge</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
- <groupId>org.neo4j.examples</groupId>
- <artifactId>neo4j-osgi-examples</artifactId>
- <version>0.1-SNAPSHOT</version>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
- <name>Neo4j OSGi examples</name>
- <properties>
- <paxexamversion>2.0.0</paxexamversion>
- </properties>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
- <!-- Pax Exam Dependencies -->
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${paxexamversion}</version>
- <scope>test</scope>
- </dependency>
+ <!-- OSGi R4 frameworks -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>3.2.1</version>
+ <scope>test</scope>
+ </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-paxrunner</artifactId>
- <version>${paxexamversion}</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.sonatype.tycho</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>3.6.2.R36x_v20110210</version>
+ <scope>test</scope>
+ </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-link-mvn</artifactId>
- <version>${paxexamversion}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-testforge</artifactId>
- <version>${paxexamversion}</version>
- <scope>test</scope>
- </dependency>
- <!-- For sane logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.6.1</version>
- <scope>test</scope>
- </dependency>
-
- <!-- OSGi R4 frameworks -->
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>3.2.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.runner</groupId>
- <artifactId>pax-runner-no-jcl</artifactId>
- <version>1.7.1</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
+ <!-- For sane logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.6.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
@@ -19,117 +19,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.LibraryOptions.junitBundles;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.TestAddress;
-import org.ops4j.pax.exam.TestProbeBuilder;
-import org.ops4j.pax.exam.junit.Configuration;
-import org.ops4j.pax.exam.junit.ExamReactorStrategy;
-import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+import org.ops4j.pax.exam.player.Player;
import org.ops4j.pax.exam.testforge.SingleClassProvider;
-import org.osgi.framework.BundleContext;
+import org.ops4j.pax.exam.testforge.WaitForService;
+import org.osgi.service.log.LogService;
import org.slf4j.LoggerFactory;
-/**
- * This is what's probably most known to Pax Exam 1.x users.
- * You can recognize the "Junit Driver" approach by the @RunWith() annotation at class level.
- *
- * This overloads JUnit4s default runner so that Pax Exam is in full control of:
- * - the test roaster
- * - the test invokation
- *
- * So whats the test roaster ?
- * You know methods annotated with @Test annotations from JUnit4 API, right ?
- * This is the standard roaster. Those will appear in your Test Runner when launching this class in your IDE using "Run with JUnit..".
- *
- * But: You learned (in Lesson 1) that with Pax Exam you might have your tests executed more than once in different Test Container instances.
- * (Remember the TestContainerFactory.parse() returning a list of TestContainers ?)
- *
- * So wouldn't it be nice to have that reflected in your JUnit Roaster ?
- * Thats what the @RunWith(JUnit4TestRunner.class) does. Pax Exam re-aranges the JUnit4 Roaster and gives you a single entry for each physical test.
- * In this lesson we are using the NativeTestContainer implementation (see the pom.xml), and additional put two OSGi Frameworks to it: Felix and Equinox.
- * You will see each of the @Test methods below twice. Once for each framework.
- *
- * The @Configuration is a desclarative way of what you did manually in the previous lessons. Now you only return Option[] in any @Configuration-annotated method
- * and you are set.
- * A probe will be generated underneath with every @Test put into it.
- *
- * Important:
- * It might be subtle at first, but it is very important to understand that this test class is also the class that will end up in your probe.
- * Just because you use it to initially kick of the tests (see, you press "Run with JUnit" on this class) it does not mean the tests will run in the same instance of this class.
- * Underneath, the @Tests are invoked on a fresh instance of this class insight the OSGi Container (which might be a totally different JVM).
- * So @Tests should be rather side-effect and stateless and aware of package visibility inside the OSGi container.
- */
-
-@RunWith( JUnit4TestRunner.class )
-
-/**
- * NEW & Optional:
- * You can annotate your class with the @ExamReactorStrategy to overwrite the default strategy:
- * @ExamReactorStrategy( AllConfinedStagedReactorFactory.class )
- * This is the default setting.
- * It resembles the way Exam 1.x worked: a new TestContainer instance for every test in your probe(s).
- * Depending on the TestContainerFactory you use (pom.xml!) this may be slower than every other strategy.
- * But its probably also the most side-effect free solution.
- * Lets do the math how many test containers are launched (one after another):
- * 2 tests x 2 test containers in pom = 4 launches
- *
- *
- * or
- *
- * @ExamReactorStrategy( EagerSingleStagedReactorFactory.class )
- * This is the other extreme to AllConfinedStagedReactorFactory. It uses one TestContainer (for all of your tests).
- * Important: You will still get of cause two test container instances for every physical container (like Felix + Equinox).
- * Its just that the Felix container will be started once, all your tests are running against it, then it will shutdown.
- * So in this specific example, you will have two test container launches (one for Felix and another for Equinox.
- * This does not change when adding more Tests to this TestCase.
- *
- *
- */
-@ExamReactorStrategy( AllConfinedStagedReactorFactory.class )
public class OSGiTest {
- @Configuration()
- public Option[] config()
- {
- return options(
- junitBundles(),
- felix() );
- }
- /**
- * Just like any other Test in previous lessons, they can receive an instance of BundleContext plus optional arguments.
- * Because you have Test Setup (@Configuration method) and Tests (this method) side by side, there is no point passing additional arguments.
- *
- * @param ctx BundleContext injected. Must be first argument, if any.
- */
@Test
- public void withBC( BundleContext ctx )
+ public void lessonTest()
+ throws Exception
{
- assertThat( ctx, is( notNullValue() ) );
- System.out.println( "BundleContext of bundle injected: " + ctx.getBundle().getSymbolicName() );
+ new Player().with(
+ options(
+ mavenBundle().groupId( "org.ops4j.pax.logging" ).artifactId( "pax-logging-service" ).version( "1.6.2" ),
+ mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version( "1.1" ).start(),
+ mavenBundle().groupId( "org.neo4j" ).artifactId( "neo4j-kernel" ).version( "1.3" ).start()
+ )
+ )
+ .test( WaitForService.class, LogService.class.getName(), 5000 )
+ // set skip systembundle=true because equinox is indeed loading LoggerFactory from a different source.
+ .test( SingleClassProvider.class, LoggerFactory.class.getName(), true )
+ .play();
}
-
- @Test
- public void without()
- {
- System.out.println( "------- HERE!" );
- }
-
-
- @Test
- public TestAddress prebuilt( TestProbeBuilder builder )
- {
- return builder.addTest( SingleClassProvider.class, (Object)LoggerFactory.class.getName() );
- }
}

0 comments on commit ff30668

Please sign in to comment.