use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTestCase method applicationsGetExceptionTestCase.
@Test
public void applicationsGetExceptionTestCase() throws Exception {
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
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_INACTIVE);
Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
Response response = blacklistApiService.blacklistGet(null, getRequest());
Assert.assertEquals(response.getStatus(), 400);
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method endpointsEndpointIdGatewayConfigGetExceptionTest.
@Test
public void endpointsEndpointIdGatewayConfigGetExceptionTest() throws Exception {
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
String message = "Error while retrieving gateway configuration.";
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.ENDPOINT_CONFIG_NOT_FOUND);
Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
String endpointId = UUID.randomUUID().toString();
Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
Assert.assertEquals(response.getStatus(), 404);
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisApiIdSdksLanguageGet.
@Test
public void apisApiIdSdksLanguageGet() throws APIManagementException, ApiStoreSdkGenerationException, NotFoundException {
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
PowerMockito.mockStatic(RestApiUtil.class);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStoreCorrect);
Response response = apisApiService.apisApiIdSdksLanguageGet(apiId, correctLanguage, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisApiIdSdksLanguageGetIncorrectApiId.
@Test
public void apisApiIdSdksLanguageGetIncorrectApiId() throws APIManagementException, ApiStoreSdkGenerationException, NotFoundException {
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
PowerMockito.mockStatic(RestApiUtil.class);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStoreCorrect);
Response response = apisApiService.apisApiIdSdksLanguageGet(apiId + "Error-Part", correctLanguage, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisApiIdSdksLanguageGetIncorrectSwagger.
@Test
public void apisApiIdSdksLanguageGetIncorrectSwagger() throws APIManagementException, ApiStoreSdkGenerationException, NotFoundException {
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
PowerMockito.mockStatic(RestApiUtil.class);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStoreIncorrect);
Response response = apisApiService.apisApiIdSdksLanguageGet(apiId, correctLanguage, request);
Assert.assertEquals(500, response.getStatus());
}
Aggregations