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);
}
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);
}
Aggregations