Search in sources :

Example 21 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.

the class RestApiCommonUtilTest method testGetLoggedInUserProvider.

@Test
public void testGetLoggedInUserProvider() throws Exception {
    System.setProperty(CARBON_HOME, "");
    String providerName = "admin";
    PowerMockito.mockStatic(APIManagerFactory.class);
    APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
    when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
    APIProvider testApiProvider = Mockito.mock(APIProvider.class);
    when(apiManagerFactory.getAPIProvider(providerName)).thenReturn(testApiProvider);
    PowerMockito.mockStatic(RestApiCommonUtil.class);
    when(RestApiCommonUtil.getLoggedInUsername()).thenReturn(providerName);
    when(RestApiCommonUtil.getLoggedInUserProvider()).thenCallRealMethod();
    APIProvider loggedInUserProvider = RestApiCommonUtil.getLoggedInUserProvider();
    Assert.assertEquals(testApiProvider, loggedInUserProvider);
}
Also used : APIManagerFactory(org.wso2.carbon.apimgt.impl.APIManagerFactory) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.

the class RestApiUtilTest method testGetLoggedInUsername.

@Test
public void testGetLoggedInUsername() {
    System.setProperty(CARBON_HOME, "");
    String defaultUsername = "default@user.com";
    mockStatic(CarbonContext.class);
    CarbonContext carbonContext = Mockito.mock(CarbonContext.class);
    Mockito.when(CarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext);
    Mockito.when(carbonContext.getUsername()).thenReturn(defaultUsername);
    String loggedInUsername = RestApiCommonUtil.getLoggedInUsername();
    Assert.assertEquals(defaultUsername, loggedInUsername);
}
Also used : CarbonContext(org.wso2.carbon.context.CarbonContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)13 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)5 Before (org.junit.Before)4 API (org.wso2.carbon.apimgt.api.model.API)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)4 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)4 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)4 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)4 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)4 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)4 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)4 Registry (org.wso2.carbon.registry.core.Registry)4 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)4 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)4 TreeMap (java.util.TreeMap)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Tier (org.wso2.carbon.apimgt.api.model.Tier)3