You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Roy Teeuwen <ro...@teeuwen.be> on 2016/12/20 22:03:00 UTC

Using OSGi Mocks with OSGi DS annotations

Hey all,

I am trying to use the osgi mocks in the following setup:
@Component
@Designate(ocd = ServiceImpl.Config.class)
public class ServiceImpl implements Service {

    @ObjectClassDefinition
    @interface Config {

        String property() default "value";
    }
    
    private Config config;

    @Activate
    public void activate(Config config) {
        this.config = config;
    }
}
Test class:
service = context.registerInjectActivateService(new ServiceImpl(), "property", "some-value");
But I am getting the following exception:

java.lang.RuntimeException: No matching activation method with name 'activate'  found in class some.packagename.ServiceImpl

	at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:157)
	at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:209)
	at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:220)
	at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:160)
	at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:174)

Is this a known issue or am I using it wrong?

Greets,
Roy

Re: Using OSGi Mocks with OSGi DS annotations

Posted by Roy Teeuwen <ro...@teeuwen.be>.
Hey Stefan,

Cool! Nice to know, thanks :) Will definitely do that then

Greets,
Roy
> On 23 Dec 2016, at 11:28, Stefan Seifert <ss...@pro-vision.de> wrote:
> 
> please note you can also mix sling mocks 1.x and osgi mocks 2.x if you are using OSGi R6 in your application but still use an older sling version (e.g. AEM 6.1).
> 
> this talks lists the possible version matrix combinations
> https://adapt.to/2016/en/schedule/unit-testing-with-sling-aem-mocks.html
> 
> sefan
> 
>> -----Original Message-----
>> From: Roy Teeuwen [mailto:roy@teeuwen.be]
>> Sent: Wednesday, December 21, 2016 9:12 AM
>> To: users@sling.apache.org
>> Subject: Re: Using OSGi Mocks with OSGi DS annotations
>> 
>> Hey Robbert,
>> 
>> Aha okey that explains it, I'm still on the 1.x branch for now! I will have
>> to wait until I can do an upgrade to the new sling api, or maybe backport
>> the functionality, thanks!
>> 
>> Greets
>> Roy
>> 
>>> Op 21 dec. 2016 om 08:49 heeft Robert Munteanu <ro...@apache.org> het
>> volgende geschreven:
>>> 
>>> Hi Roy,
>>> 
>>>> On Tue, 2016-12-20 at 23:03 +0100, Roy Teeuwen wrote:
>>>> Hey all,
>>>> 
>>>> I am trying to use the osgi mocks in the following setup:
>>>> @Component
>>>> @Designate(ocd = ServiceImpl.Config.class)
>>>> public class ServiceImpl implements Service {
>>>> 
>>>>    @ObjectClassDefinition
>>>>    @interface Config {
>>>> 
>>>>        String property() default "value";
>>>>    }
>>>> 
>>>>    private Config config;
>>>> 
>>>>    @Activate
>>>>    public void activate(Config config) {
>>>>        this.config = config;
>>>>    }
>>>> }
>>>> Test class:
>>>> service = context.registerInjectActivateService(new ServiceImpl(),
>>>> "property", "some-value");
>>>> But I am getting the following exception:
>>>> 
>>>> java.lang.RuntimeException: No matching activation method with name
>>>> 'activate'  found in class some.packagename.ServiceImpl
>>> 
>>> (snip)
>>> 
>>> Support for annotation classes as configuration was added with
>>> 
>>> https://issues.apache.org/jira/browse/SLING-5327
>>> 
>>> which is part of OSGi Mocks 2.0.0 . What version are you using?
>>> 
>>> Robert
> 
> 


RE: Using OSGi Mocks with OSGi DS annotations

Posted by Stefan Seifert <ss...@pro-vision.de>.
please note you can also mix sling mocks 1.x and osgi mocks 2.x if you are using OSGi R6 in your application but still use an older sling version (e.g. AEM 6.1).

this talks lists the possible version matrix combinations
https://adapt.to/2016/en/schedule/unit-testing-with-sling-aem-mocks.html

sefan

>-----Original Message-----
>From: Roy Teeuwen [mailto:roy@teeuwen.be]
>Sent: Wednesday, December 21, 2016 9:12 AM
>To: users@sling.apache.org
>Subject: Re: Using OSGi Mocks with OSGi DS annotations
>
>Hey Robbert,
>
>Aha okey that explains it, I'm still on the 1.x branch for now! I will have
>to wait until I can do an upgrade to the new sling api, or maybe backport
>the functionality, thanks!
>
>Greets
>Roy
>
>> Op 21 dec. 2016 om 08:49 heeft Robert Munteanu <ro...@apache.org> het
>volgende geschreven:
>>
>> Hi Roy,
>>
>>> On Tue, 2016-12-20 at 23:03 +0100, Roy Teeuwen wrote:
>>> Hey all,
>>>
>>> I am trying to use the osgi mocks in the following setup:
>>> @Component
>>> @Designate(ocd = ServiceImpl.Config.class)
>>> public class ServiceImpl implements Service {
>>>
>>>     @ObjectClassDefinition
>>>     @interface Config {
>>>
>>>         String property() default "value";
>>>     }
>>>
>>>     private Config config;
>>>
>>>     @Activate
>>>     public void activate(Config config) {
>>>         this.config = config;
>>>     }
>>> }
>>> Test class:
>>> service = context.registerInjectActivateService(new ServiceImpl(),
>>> "property", "some-value");
>>> But I am getting the following exception:
>>>
>>> java.lang.RuntimeException: No matching activation method with name
>>> 'activate'  found in class some.packagename.ServiceImpl
>>
>> (snip)
>>
>> Support for annotation classes as configuration was added with
>>
>>  https://issues.apache.org/jira/browse/SLING-5327
>>
>> which is part of OSGi Mocks 2.0.0 . What version are you using?
>>
>> Robert



Re: Using OSGi Mocks with OSGi DS annotations

Posted by Roy Teeuwen <ro...@teeuwen.be>.
Hey Robbert,

Aha okey that explains it, I'm still on the 1.x branch for now! I will have to wait until I can do an upgrade to the new sling api, or maybe backport the functionality, thanks!

Greets
Roy

> Op 21 dec. 2016 om 08:49 heeft Robert Munteanu <ro...@apache.org> het volgende geschreven:
> 
> Hi Roy,
> 
>> On Tue, 2016-12-20 at 23:03 +0100, Roy Teeuwen wrote:
>> Hey all,
>> 
>> I am trying to use the osgi mocks in the following setup:
>> @Component
>> @Designate(ocd = ServiceImpl.Config.class)
>> public class ServiceImpl implements Service {
>> 
>>     @ObjectClassDefinition
>>     @interface Config {
>> 
>>         String property() default "value";
>>     }
>>     
>>     private Config config;
>> 
>>     @Activate
>>     public void activate(Config config) {
>>         this.config = config;
>>     }
>> }
>> Test class:
>> service = context.registerInjectActivateService(new ServiceImpl(),
>> "property", "some-value");
>> But I am getting the following exception:
>> 
>> java.lang.RuntimeException: No matching activation method with name
>> 'activate'  found in class some.packagename.ServiceImpl
> 
> (snip)
> 
> Support for annotation classes as configuration was added with
> 
>  https://issues.apache.org/jira/browse/SLING-5327
> 
> which is part of OSGi Mocks 2.0.0 . What version are you using?
> 
> Robert

Re: Using OSGi Mocks with OSGi DS annotations

Posted by Robert Munteanu <ro...@apache.org>.
Hi Roy,

On Tue, 2016-12-20 at 23:03 +0100, Roy Teeuwen wrote:
> Hey all,
> 
> I am trying to use the osgi mocks in the following setup:
> @Component
> @Designate(ocd = ServiceImpl.Config.class)
> public class ServiceImpl implements Service {
> 
> ����@ObjectClassDefinition
> ����@interface Config {
> 
> ��������String property() default "value";
> ����}
> ����
> ����private Config config;
> 
> ����@Activate
> ����public void activate(Config config) {
> ��������this.config = config;
> ����}
> }
> Test class:
> service = context.registerInjectActivateService(new ServiceImpl(),
> "property", "some-value");
> But I am getting the following exception:
> 
> java.lang.RuntimeException: No matching activation method with name
> 'activate'��found in class some.packagename.ServiceImpl

(snip)

Support for annotation classes as configuration was added with

  https://issues.apache.org/jira/browse/SLING-5327

which is part of OSGi Mocks 2.0.0 . What version are you using?

Robert