PAX EXAM 4 osgi declarative services are not injected and activator not started

132 views
Skip to first unread message

iJava

unread,
May 1, 2016, 1:56:12 PM5/1/16
to OPS4J
I followed this tutorial https://gurke300.gitbooks.io/osgi-with-spring-4-and-hibernate-4/content/project_template_for_running_osgi_integration_tests/index.html
And BundleContext was successfully injected.

Here https://ops4j1.jira.com/wiki/display/PAXEXAM4/Getting+Started+with+CDI+Tests they say that it is necessary to add propery file to root of class loader. I run pax cdi from netbeans ide + maven. So I put it pax.exam.system = cdi in src/test/resources/abc.properties and added the following plugin:

         <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>src/test/resources/abc.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

But anyway I have two problems when I use pax-exam:

1)My osgi declarative services are not injected in test. But I know that they work, because when I deploy this bundle in felix+weld+paxcdi these services work and are injected in service consumer.
 Besides I see in pax-exam logs that my bundle is not scanned for beans.
2) My bundle activator is not executed when I use maven+pax exam.

Please, help me to solve these 2 problems.

Harald Wellmann

unread,
May 2, 2016, 4:38:03 AM5/2/16
to OPS4J Mailing Lists
The Pax Exam configuration file must be called exam.properties. Other names won't work. This may be the root cause for your other problems.

Regards,
Harald

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pavel Kastornyy

unread,
May 2, 2016, 4:45:40 AM5/2/16
to op...@googlegroups.com
Hi, Harald

Thank you for your help. I changed the name of the file, results are the
same. And this is the output I have now:

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.temp.TempIT
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
[org.ops4j.pax.swissbox.extender.BundleWatcher] : Creating bundle
watcher with scanner
[org.ops4j.pax.swissbox.extender.BundleManifestScanner@7145dd13]...
[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle
[org.apache.felix.framework]
[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle
[org.ops4j.pax.exam]
[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle
[org.ops4j.pax.exam.inject]
[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle
[org.ops4j.pax.exam.extender.service]
[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle
[osgi.cmpn]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Enabling SLF4J API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Enabling Jakarta Commons Logging API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Enabling Log4J API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Enabling Avalon Logger API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Enabling JULI Logger API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.logging.pax-logging-api]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.base]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.swissbox.core]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.swissbox.extender]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.swissbox.framework]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.swissbox.lifecycle]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.swissbox.tracker]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.apache.geronimo.specs.geronimo-atinject_1.0_spec]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.tipi.junit]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.tipi.hamcrest.core]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Scanning bundle [org.ops4j.pax.exam.invoker.junit]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.exam.invoker.junit]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.tipi.hamcrest.core]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.tipi.junit]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.apache.geronimo.specs.geronimo-atinject_1.0_spec]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.swissbox.tracker]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.swissbox.lifecycle]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.swissbox.framework]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.swissbox.extender]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.swissbox.core]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.base]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Disabling SLF4J API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Disabling Jakarta Commons Logging API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Disabling Log4J API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Disabling Avalon Logger API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator]
: Disabling JULI Logger API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.logging.pax-logging-api]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [osgi.cmpn]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.exam]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.apache.felix.framework]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.exam.inject]
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher]
: Releasing bundle [org.ops4j.pax.exam.extender.service]
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.57 sec
<<< FAILURE! - in com.temp.TempIT
shouldHaveInjectedTheBundleContextOfThisTestBundle(com.temp.TempIT) Time
elapsed: 0.009 sec <<< ERROR!
org.ops4j.spi.NoServiceProviderException:
org.ops4j.pax.exam.util.InjectorFactory: no service provider found in
META-INF/services on classpath
at
org.ops4j.spi.ServiceProviderFinder.loadUniqueServiceProvider(ServiceProviderFinder.java:96)
at
org.ops4j.pax.exam.spi.reactors.ReactorManager.findInjector(ReactorManager.java:467)
at
org.ops4j.pax.exam.spi.reactors.ReactorManager.inject(ReactorManager.java:457)
at
org.ops4j.pax.exam.junit.impl.InjectingRunner.createTest(InjectingRunner.java:100)
at
org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.ops4j.pax.exam.junit.impl.InjectingRunner.run(InjectingRunner.java:77)
at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:93)
at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)


Results :

Tests in error:
TempIT.shouldHaveInjectedTheBundleContextOfThisTestBundle »
NoServiceProvider ...

iJava

unread,
May 2, 2016, 8:04:57 AM5/2/16
to OPS4J
Please, help me. The problem still is not solved.

Harald Wellmann

unread,
May 2, 2016, 11:27:53 AM5/2/16
to OPS4J Mailing Lists
I believe you're confused about the meaning of pax.exam.system.

pax.exam.system = cdi is for testing applications running in a stand-alone CDI container like Weld SE. This is not related to OSGi at all.

If you're trying to work with Pax CDI in OSGi, you should use pax.exam.system = test (or just leave it undefined, this is the default).

If all you want is a test environment for an OSGi application, then you're totally on the wrong track with CDI. Pax CDI or Pax Exam's CDI mode is irrelevant for OSGi tests. Pax Exam has its own light-weight injector to inject BundleContext and service dependencies from the OSGi service registry.

Usually, Pax Exam's own integration tests [1] are a good basis for getting started. Besides, there are Maven archetypes [2] for quick project setup.

[1] https://github.com/ops4j/org.ops4j.pax.exam2/tree/exam-reactor-4.9.1/itest/osgi/src/it/regression-multi
[2] https://github.com/ops4j/org.ops4j.pax.exam2/tree/exam-reactor-4.9.1/maven/archetypes


Regards,
Harald

2016-05-02 14:04 GMT+02:00 iJava <pavelka...@gmail.com>:
Please, help me. The problem still is not solved.

--

Pavel Kastornyy

unread,
May 2, 2016, 11:41:03 AM5/2/16
to op...@googlegroups.com
Thank you very much. I will study the links you provided.

If you have a little free time, could you answer another my question
which I asked about ERROR: Bundle org.ops4j.pax.cdi.extender [19]
EventDispatcher: Error during dispatch.
(org.jboss.weld.exceptions.IllegalStateException: WELD-000117: Required
service org.jboss.weld.resources.spi.ScheduledExecutorServiceFactory has
not been specified).

I asked https://groups.google.com/forum/#!topic/ops4j/GC3xkvCdXAY

I try to use last version of felix, last version of weld and last
version of pax cdi (CR1) and get this error. And I have no idea how to
solve this problem. Maybe I should install some more bundles. But what?
Reply all
Reply to author
Forward
0 new messages