use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method applicationsGetTestCase.
@Test
public void applicationsGetTestCase() throws Exception {
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
List<Application> applicationList = new ArrayList<>();
Application applicationOne = SampleTestObjectCreator.createRandomApplication();
Application applicationTwo = SampleTestObjectCreator.createRandomApplication();
Application applicationThree = SampleTestObjectCreator.createRandomApplication();
applicationList.add(applicationOne);
applicationList.add(applicationTwo);
applicationList.add(applicationThree);
Mockito.when(adminService.getAllApplications()).thenReturn(applicationList);
Response response = applicationsApiService.applicationsGet(null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
Assert.assertEquals(((ApplicationListDTO) response.getEntity()).getList().size(), 3);
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTestCase method blacklistGetTestCase.
@Test
public void blacklistGetTestCase() throws Exception {
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
BlockConditions blockConditionOne = SampleTestObjectCreator.createUniqueBlockConditions("IP_RANGE");
BlockConditions blockConditionTwo = SampleTestObjectCreator.createUniqueBlockConditions("IP");
BlockConditions blockConditionThree = SampleTestObjectCreator.createUniqueBlockConditions("IP_RANGE");
List<BlockConditions> blockConditions = new ArrayList<>();
blockConditions.add(blockConditionOne);
blockConditions.add(blockConditionTwo);
blockConditions.add(blockConditionThree);
Mockito.when(adminService.getBlockConditions()).thenReturn(blockConditions);
Response response = blacklistApiService.blacklistGet(null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
Assert.assertEquals(((BlockingConditionListDTO) response.getEntity()).getList().size(), 3);
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApiNullApi.
@Test(expected = APIManagementException.class)
public void testGenerateSdkForApiNullApi() throws APIManagementException, ApiStoreSdkGenerationException {
String apiId = UUID.randomUUID().toString();
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(null);
ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisApiIdGatewayConfigGetWhenGatewayConfigNullTestCase.
@Test
public void apisApiIdGatewayConfigGetWhenGatewayConfigNullTestCase() throws Exception {
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
String apiID = UUID.randomUUID().toString();
String gatewayConfig = null;
Mockito.when(adminService.getAPIGatewayServiceConfig(apiID)).thenReturn(gatewayConfig);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
Response response = apisApiService.apisApiIdGatewayConfigGet(apiID, null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method applicationsGetExceptionTestCase.
@Test
public void applicationsGetExceptionTestCase() throws Exception {
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
String message = "Error while retrieving applications.";
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.APPLICATION_NOT_FOUND);
Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
Response response = applicationsApiService.applicationsGet(null, getRequest());
Assert.assertEquals(response.getStatus(), 404);
}
Aggregations