use of org.wso2.carbon.context.CarbonContext in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeLifeCycleStatusOfAPIProduct.
@Test
public void testChangeLifeCycleStatusOfAPIProduct() throws APIManagementException, FaultGatewaysException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
String provider = "admin";
PrivilegedCarbonContext carbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext);
PowerMockito.doNothing().when(carbonContext).setUsername(Mockito.anyString());
PowerMockito.doNothing().when(carbonContext).setTenantDomain(Mockito.anyString(), Mockito.anyBoolean());
APIProduct product = createMockAPIProduct(provider);
Mockito.when(apimgtDAO.getAPIProductId(product.getId())).thenReturn(1);
WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
Mockito.when(workflowDTO.getStatus()).thenReturn(WorkflowStatus.CREATED);
Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(workflowDTO);
APIStateChangeResponse response = apiProvider.changeLifeCycleStatus("carbon.super", new ApiTypeWrapper(product), "Publish", null);
Assert.assertNotNull(response);
}
use of org.wso2.carbon.context.CarbonContext 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