Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [osgi-users] Registering service with injected bundle context using osgi-test

Hi Stefan,

Thanks for the answer. Currently, I don't have a real problem (yet). I was tinkering around to see what the possibilities were and writing tests that I envisioned could help our code base in the end. The test I wrote that I thought should work, but does not, is:


    @Test
    public void servicesWithMultipleCardinalityCanAlsoBeInjected() {
        Assertions.assertEquals(0, this.testServices.size(), "Initially no test service should be found");
        Assertions.assertEquals(0, this.testServicesAware.getCardinality(),
                "The ServiceAware should reflect the same situation");
        // register service through bundle context
        final ServiceRegistration<TestServiceWithMultipleCardinality> reg = this.context.registerService(
                TestServiceWithMultipleCardinality.class, new TestServiceWithMultipleCardinalityImpl(), null);
        Assertions.assertEquals(1, this.testServices.size(), "After registration, there should be 1 service"); // Test fails here
        Assertions.assertEquals(1, this.testServicesAware.getCardinality(),
                "The ServiceAware should reflect the same situation");
        reg.unregister();
        Assertions.assertEquals(0, this.testServices.size(), "After unregister, no test service should be found");
        Assertions.assertEquals(0, this.testServicesAware.getCardinality(),
                "The ServiceAware should reflect the same situation");
    }

If this is supposed to succeed, I can look into creating a repo that shows the problem, of course. The test fails with the assertion after the registration of the service with the bundle context. The difference I see with the tests you refer to, is that the service is registered within the test itself. Should this be possible?

Kind regards,

Jelle
On 15/07/2021 17:52, Stefan Bischof wrote:

Hello Jelle,


maybe you can paste the code or link an repo to have a look on your Problem.

I understood that you mean something like in this test.

https://github.com/osgi/osgi-test/blob/main/org.osgi.test.junit5/src/test/java/org/osgi/test/junit5/test/service/ServiceListTest.java


 the ServiceAware.getServices() should also work.


https://github.com/osgi/osgi-test/blob/main/org.osgi.test.junit5/src/test/java/org/osgi/test/junit5/test/service/MultiCardinalityServiceTest.java


regards

Stefan
On 7/15/21 5:14 PM, Jelle Nelis wrote:

Hi all,

I have been trying out osgi-test the last couple of days by writing several very simple tests that use the functionality provided by BundleContextExtension and ServiceExtension.
Firstly, thanks for the very simple-to-use integration testing possibilities.
I wrote a test using both BundleContextExtension and ServiceExtension. I was expecting that if I would have an injected List<S> with S a certain type of service, and I would register a service using the BundleContext in the test, the List<S> would reflect the newly registered service. A ServiceAware<S> also does not seem to reflect the new situation.

Are my expectations wrong?

Kind regards,

Jelle


_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users

_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users

Back to the top