Search in sources :

Example 16 with APIManagerFactory

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);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with APIManagerFactory

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);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with APIManagerFactory

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());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with APIManagerFactory

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());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with APIManagerFactory

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());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)27 Response (javax.ws.rs.core.Response)23 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)17 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)6 ArrayList (java.util.ArrayList)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 API (org.wso2.carbon.apimgt.core.models.API)5 Request (org.wso2.msf4j.Request)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)3 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)3 APIManagerFactory (org.wso2.carbon.apimgt.impl.APIManagerFactory)3 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)2 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)2 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1