Fwd: [2.x] Sling mock

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: [2.x] Sling mock

nino martinez wael
Somethings wrong with my test,

@Rule
public final OsgiContext context = new OsgiContextBuilder().build();

@Test
public void test() throws CiscoAPIException, FailedSecurityException {
    context.registerInjectActivateService(BusinessServiceImpl.class);
    BusinessService service = context.getService(BusinessService.class);
    Assert.assertEquals("got more campaigns than
expected",0,service.getAllCampaigns().size());


}


Above are failing at
"context.registerInjectActivateService(BusinessServiceImpl.class);"

With this message:

org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
metadata found for class java.lang.Class

        at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServiceUtil.java:381)
        at org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:148)
        at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:153)
        at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141)
        at dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTestBusinessService.java:22)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)


When debugging the test the actual fail are :
class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin

Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
what am I doing wrong?


--
Best regards / Med venlig hilsen
Nino Martinez
Reply | Threaded
Open this post in threaded view
|

Re: [2.x] Sling mock

nino martinez wael
What a horrible mail, I sent (apprerently yesterday was not my day)..
Wheres the content without quotes:

Somethings wrong with my test,

@Rule
public final OsgiContext context = new OsgiContextBuilder().build();

@Test
public void test() throws CiscoAPIException, FailedSecurityException {
    context.registerInjectActivateService(BusinessServiceImpl.class);
    BusinessService service = context.getService(BusinessService.class);
    Assert.assertEquals("got more campaigns than
expected",0,service.getAllCampaigns().size());


}


Above are failing at
"context.registerInjectActivateService(BusinessServiceImpl.class);"

With this message:

org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
metadata found for class java.lang.Class

        at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServiceUtil.java:381)
        at org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:148)
        at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:153)
        at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141)
        at dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTestBusinessService.java:22)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)


When debugging the test the actual fail are :
class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin

Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
what am I doing wrong?

On Thu, Oct 26, 2017 at 4:25 PM, nino martinez wael <
[hidden email]> wrote:

>
>
> Somethings wrong with my test,
>
> @Rule
> public final OsgiContext context = new OsgiContextBuilder().build();
>
> @Test
> public void test() throws CiscoAPIException, FailedSecurityException {
>     context.registerInjectActivateService(BusinessServiceImpl.class);
>     BusinessService service = context.getService(BusinessService.class);
>     Assert.assertEquals("got more campaigns than expected",0,service.getAllCampaigns().size());
>
>
> }
>
>
> Above are failing at "context.registerInjectActivateService(BusinessServiceImpl.class);"
>
> With this message:
>
> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found for class java.lang.Class
>
> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServiceUtil.java:381)
> at org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:148)
> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:153)
> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141)
> at dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTestBusinessService.java:22)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>
>
> When debugging the test the actual fail are :
> class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin
>
> Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
> what am I doing wrong?
>
>
> --
> Best regards / Med venlig hilsen
> Nino Martinez
>
>
>


--
Best regards / Med venlig hilsen
Nino Martinez
Reply | Threaded
Open this post in threaded view
|

Re: [2.x] Sling mock

nino martinez wael
Captains log,

When I changed from calling

context.registerInjectActivateService(BusinessServiceImpl.class);


TO doing this instead, everything works:

BusinessServiceImpl businessService= new BusinessServiceImpl();
MockOsgi.injectServices(businessService,context.bundleContext());
MockOsgi.activate(businessService,context.bundleContext());


On Fri, Oct 27, 2017 at 6:41 AM, nino martinez wael <
[hidden email]> wrote:

> What a horrible mail, I sent (apprerently yesterday was not my day)..
> Wheres the content without quotes:
>
> Somethings wrong with my test,
>
> @Rule
> public final OsgiContext context = new OsgiContextBuilder().build();
>
> @Test
> public void test() throws CiscoAPIException, FailedSecurityException {
>     context.registerInjectActivateService(BusinessServiceImpl.class);
>     BusinessService service = context.getService(BusinessService.class);
>     Assert.assertEquals("got more campaigns than expected",0,service.getAllCampaigns().size());
>
>
> }
>
>
> Above are failing at "context.registerInjectActivateService(BusinessServiceImpl.class);"
>
> With this message:
>
> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found for class java.lang.Class
>
> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServiceUtil.java:381)
> at org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:148)
> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:153)
> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141)
> at dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTestBusinessService.java:22)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>
>
> When debugging the test the actual fail are :
> class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin
>
> Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
> what am I doing wrong?
>
> On Thu, Oct 26, 2017 at 4:25 PM, nino martinez wael <
> [hidden email]> wrote:
>
>>
>>
>> Somethings wrong with my test,
>>
>> @Rule
>> public final OsgiContext context = new OsgiContextBuilder().build();
>>
>> @Test
>> public void test() throws CiscoAPIException, FailedSecurityException {
>>     context.registerInjectActivateService(BusinessServiceImpl.class);
>>     BusinessService service = context.getService(BusinessService.class);
>>     Assert.assertEquals("got more campaigns than expected",0,service.getAllCampaigns().size());
>>
>>
>> }
>>
>>
>> Above are failing at "context.registerInjectActivateService(BusinessServiceImpl.class);"
>>
>> With this message:
>>
>> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found for class java.lang.Class
>>
>> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServiceUtil.java:381)
>> at org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:148)
>> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:153)
>> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141)
>> at dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTestBusinessService.java:22)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:498)
>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>>
>>
>> When debugging the test the actual fail are :
>> class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin
>>
>> Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
>> what am I doing wrong?
>>
>>
>> --
>> Best regards / Med venlig hilsen
>> Nino Martinez
>>
>>
>>
>
>
> --
> Best regards / Med venlig hilsen
> Nino Martinez
>



--
Best regards / Med venlig hilsen
Nino Martinez
Reply | Threaded
Open this post in threaded view
|

RE: [2.x] Sling mock

Stefan Seifert
please try to add a special "manifest" goal to the maven-bundle-plugin in your pom as described here [1]

stefan

[1] http://felix.apache.org/documentation/faqs/apache-felix-bundle-plugin-faq.html#use-scr-metadata-generated-by-bnd-in-unit-tests


>-----Original Message-----
>From: nino martinez wael [mailto:[hidden email]]
>Sent: Wednesday, November 1, 2017 9:17 AM
>To: [hidden email]
>Subject: Re: [2.x] Sling mock
>
>Captains log,
>
>When I changed from calling
>
>context.registerInjectActivateService(BusinessServiceImpl.class);
>
>
>TO doing this instead, everything works:
>
>BusinessServiceImpl businessService= new BusinessServiceImpl();
>MockOsgi.injectServices(businessService,context.bundleContext());
>MockOsgi.activate(businessService,context.bundleContext());
>
>
>On Fri, Oct 27, 2017 at 6:41 AM, nino martinez wael <
>[hidden email]> wrote:
>
>> What a horrible mail, I sent (apprerently yesterday was not my day)..
>> Wheres the content without quotes:
>>
>> Somethings wrong with my test,
>>
>> @Rule
>> public final OsgiContext context = new OsgiContextBuilder().build();
>>
>> @Test
>> public void test() throws CiscoAPIException, FailedSecurityException {
>>     context.registerInjectActivateService(BusinessServiceImpl.class);
>>     BusinessService service = context.getService(BusinessService.class);
>>     Assert.assertEquals("got more campaigns than
>expected",0,service.getAllCampaigns().size());
>>
>>
>> }
>>
>>
>> Above are failing at
>"context.registerInjectActivateService(BusinessServiceImpl.class);"
>>
>> With this message:
>>
>> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
>metadata found for class java.lang.Class
>>
>> at
>org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServi
>ceUtil.java:381)
>> at
>org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:14
>8)
>> at
>org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectAc
>tivateService(OsgiContextImpl.java:153)
>> at
>org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectAc
>tivateService(OsgiContextImpl.java:141)
>> at
>dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTest
>BusinessService.java:22)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:6
>2)
>> at
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:498)
>> at
>org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod
>.java:47)
>> at
>org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.
>java:12)
>> at
>org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.j
>ava:44)
>> at
>org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja
>va:17)
>>
>>
>> When debugging the test the actual fail are :
>> class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin
>>
>> Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
>> what am I doing wrong?
>>
>> On Thu, Oct 26, 2017 at 4:25 PM, nino martinez wael <
>> [hidden email]> wrote:
>>
>>>
>>>
>>> Somethings wrong with my test,
>>>
>>> @Rule
>>> public final OsgiContext context = new OsgiContextBuilder().build();
>>>
>>> @Test
>>> public void test() throws CiscoAPIException, FailedSecurityException {
>>>     context.registerInjectActivateService(BusinessServiceImpl.class);
>>>     BusinessService service = context.getService(BusinessService.class);
>>>     Assert.assertEquals("got more campaigns than
>expected",0,service.getAllCampaigns().size());
>>>
>>>
>>> }
>>>
>>>
>>> Above are failing at
>"context.registerInjectActivateService(BusinessServiceImpl.class);"
>>>
>>> With this message:
>>>
>>> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
>metadata found for class java.lang.Class
>>>
>>> at
>org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServices(OsgiServi
>ceUtil.java:381)
>>> at
>org.apache.sling.testing.mock.osgi.MockOsgi.injectServices(MockOsgi.java:14
>8)
>>> at
>org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectAc
>tivateService(OsgiContextImpl.java:153)
>>> at
>org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectAc
>tivateService(OsgiContextImpl.java:141)
>>> at
>dk.netdesign.dialer.backend.SlingMockTestBusinessService.test(SlingMockTest
>BusinessService.java:22)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:6
>2)
>>> at
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:43)
>>> at java.lang.reflect.Method.invoke(Method.java:498)
>>> at
>org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod
>.java:47)
>>> at
>org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.
>java:12)
>>> at
>org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.j
>ava:44)
>>> at
>org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja
>va:17)
>>>
>>>
>>> When debugging the test the actual fail are :
>>> class org.apache.sling.testing.mock.osgi.MockConfigurationAdmin
>>>
>>> Which comes from OsgiContextImpl.setUp().. Seems I am missing something,
>>> what am I doing wrong?
>>>
>>>
>>> --
>>> Best regards / Med venlig hilsen
>>> Nino Martinez
>>>
>>>
>>>
>>
>>
>> --
>> Best regards / Med venlig hilsen
>> Nino Martinez
>>
>
>
>
>--
>Best regards / Med venlig hilsen
>Nino Martinez