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

maybe you can have a look on this PR:
https://github.com/osgi/osgi-test/pull/247

I think we also need simple examples that are good described ( as your snipped)

On 7/16/21 8:37 AM, Jelle Nelis wrote:

Hi again,

see inline.

On 15/07/2021 20:43, Stefan Bischof wrote:

Hello again,


1. all you want to do could be done with the ServiceAware. This will reflect on all changes of services "dynamic".


OK, thanks for the information.



2. the getCardinality() delivers the initial Cardinality (e.g. set via @InjectService(cardinality = 0)

so this is not correct.

        Assertions.assertEquals(1, this.testServicesAware.getCardinality(),
                "The ServiceAware should reflect the same situation");




Makes sense. I just tested using size() on ServiceAware and that indeed seems to work.


3. At the Moment the List is generated before injected. This list is not "dynamic"

I tried to change this behavior. In this PR: https://github.com/osgi/osgi-test/pull/357
This change will break an other test. So lets see what BJ Hargrave is thinking about.
Could you please explain in a comment of this PR why you think this Feature should be integrated?


I am not saying that this feature should or should not be integrated, if ServiceAware already provides that functionality, there is no real reason for the list to be dynamic. I was just validating my expectations as an end-user and those expectations can be wrong, of course.


I used your snipped in the test of the pr is that okay?



Sure.


4. When you are writing a lot of tests to find out how osgi-tests works. Could you please do an PR  and all these tests into the "examples/osgi-test-example-mvn" project?


I currently have a total of 7 very simple tests testing the different places in which you can inject a bundle context and a service. We are using Gradle as a build system, would it be beneficial/appreciated if I made a PR adding examples of using osgi-test using Gradle?



regards.
Stefan

On 7/15/21 6:17 PM, Jelle Nelis wrote:

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

_______________________________________________
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

_______________________________________________
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