Yes, this worked for me.

System.setProperty("carbon.home", "");
PrivilegedCarbonContext.startTenantFlow();

Thereafter you can access PrivilegedCarbonContext.getThreadLocalCarbonContext()
as explained by KasunG



Farasath Ahamed
Software Engineer, WSO2 Inc.; http://wso2.com
Mobile: +94777603866
Blog: blog.farazath.com
Twitter: @farazath619 <https://twitter.com/farazath619>
<http://wso2.com/signature>




On Tue, Oct 10, 2017 at 10:56 AM, KasunG Gajasinghe <kas...@wso2.com> wrote:

>
> Please note that you need to set the carbon.home system property before
> initializing privilegedcarboncontext.
>
> System.setProperty("carbon.home", <target/carbon-home folder>);
>
> On Thu, Oct 5, 2017 at 12:18 AM, KasunG Gajasinghe <kas...@wso2.com>
> wrote:
>
>>
>> CarbonContext is a thread-local variable. That means the carbon context
>> can be accessible from anywhere within a given thread. So, you may not need
>> to mock it!
>>
>> Since the test class and the testing class runs in the same thread, we
>> can try to populate the CarbonContext in the @Test method before actual
>> testing class invocations.
>>
>> Please see the following code example:
>>
>> @Test
>> public void testSetClaimValue() throws Exception{
>> try {
>>     PrivilegedCarbonContext.startTenantFlow();
>>     PrivilegedCarbonContext.getThreadLocalCarbonContext().setTen
>> antDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
>>     PrivilegedCarbonContext.getThreadLocalCarbonContext().setTen
>> antId(MultitenantConstants.SUPER_TENANT_ID);
>>
>> //actual test code and assertions
>>
>> } finally {
>>     PrivilegedCarbonContext.endTenantFlow();
>> }
>>
>> }
>>
>> We of course need to test this out. But I think this is ideal if this
>> works.
>>
>>
>>
>> On Wed, Oct 4, 2017 at 10:42 PM, Dharshana Warusavitharana <
>> dharsha...@wso2.com> wrote:
>>
>>> Hi Sivaramya,
>>>
>>> You dont have to mock the whole carbon context here. You can send a mock
>>> payload when the particular method is called.
>>>
>>> Are you using powerMock + mockito if so do as the document sample in [1].
>>>
>>> [1]. https://github.com/searls/mockito-testng-example/blob/m
>>> aster/presentation/Mockito.pdf
>>>
>>> Thank you,
>>> Dharshana.
>>>
>>>
>>>
>>> On Wed, Oct 4, 2017 at 9:55 PM, Malaka Silva <mal...@wso2.com> wrote:
>>>
>>>> +Dharshana
>>>>
>>>> On Wed, Oct 4, 2017 at 8:26 PM, Sivaramya Sivanathan <
>>>> sivara...@wso2.com> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> Currently I am working on the unit testing for the esb-connector-jms
>>>>> extension. For that I need to mock the CarbonContext for the method
>>>>> CarbonContext.getThreadLocalCarbonContext().getTenantId(). But, I'm
>>>>> unable mock the CarbonContext.
>>>>> Can any one suggest me how can we mock the CarbonContext?
>>>>>
>>>>> Thanks,
>>>>> Sivaramya Sivanathan
>>>>> Associate Software Engineer | WSO2
>>>>> Tel: 0770874960 <077%20087%204960>
>>>>> WSO2 Inc : http://wso2.org
>>>>> <http://www.google.com/url?q=http%3A%2F%2Fwso2.org&sa=D&sntz=1&usg=AFQjCNE_eTDfyl2ibPcq0hcXvRDNVuQmMg>
>>>>> LinkedIn | www.linkedin.com/in/sivaramya
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Best Regards,
>>>>
>>>> Malaka Silva
>>>> Associate Director / Architect
>>>> M: +94 777 219 791 <077%20721%209791>
>>>> Tel : 94 11 214 5345
>>>> Fax :94 11 2145300 <011%202%20145300>
>>>> Skype : malaka.sampath.silva
>>>> LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
>>>> Blog : http://mrmalakasilva.blogspot.com/
>>>>
>>>> WSO2, Inc.
>>>> lean . enterprise . middleware
>>>> https://wso2.com/signature
>>>> http://www.wso2.com/about/team/malaka-silva/
>>>> <http://wso2.com/about/team/malaka-silva/>
>>>> https://store.wso2.com/store/
>>>>
>>>> Don't make Trees rare, we should keep them with care
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Dharshana Warusavitharana
>>> Associate Technical Lead
>>> WSO2 Inc. http://wso2.com
>>> email : dharsha...@wso2.com <dharsha...@wso2.com>
>>> Tel  : +94 11 214 5345
>>> Fax :+94 11 2145300 <011%202%20145300>
>>> cell : +94770342233 <077%20034%202233>
>>> blog : http://dharshanaw.blogspot.com
>>>
>>> lean . enterprise . middleware
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> Dev@wso2.org
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>>
>> *Kasun Gajasinghe*Associate Technical Lead, WSO2 Inc.
>> email: kasung AT spamfree wso2.com
>> linked-in: http://lk.linkedin.com/in/gajasinghe
>> blog: http://kasunbg.org
>> phone: +1 650-745-4499 <+1%20650-745-4499>, 77 678 0813
>>
>>
>
>
>
> --
>
> *Kasun Gajasinghe*Associate Technical Lead, WSO2 Inc.
> email: kasung AT spamfree wso2.com
> linked-in: http://lk.linkedin.com/in/gajasinghe
> blog: http://kasunbg.org
> phone: +1 650-745-4499 <(650)%20745-4499>, 77 678 0813
>
>
> _______________________________________________
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to