Search in sources :

Example 81 with APIPublisher

use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisPost.

@Test
public void testApisPost() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    API api = apiBuilder.id(apiId).build();
    APIDTO apidto = MappingUtil.toAPIDto(api);
    Mockito.doReturn(apiId).doThrow(new IllegalArgumentException()).when(apiPublisher).addAPI(apiBuilder);
    Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
    Response response = apisApiService.apisPost(apidto, getRequest());
    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity().toString().contains(api.getId()));
    assertTrue(response.getEntity().toString().contains(api.getName()));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 82 with APIPublisher

use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGet.

@Test
public void testEndpointsEndpointIdGet() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    String endpointId = endpoint.getId();
    Mockito.doReturn(endpoint).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains(endpointId));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 83 with APIPublisher

use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPut.

@Test
public void testEndpointsEndpointIdPut() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpointOld = SampleTestObjectCreator.createMockEndpoint();
    String endpointOldId = endpointOld.getId();
    Endpoint.Builder endpointUpdateBuilder = SampleTestObjectCreator.createMockEndpointBuilder();
    endpointUpdateBuilder.name("newNameEndpoint").id(endpointOldId);
    Endpoint newEndpoint = endpointUpdateBuilder.build();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(newEndpoint);
    Mockito.doReturn(endpointOld).doReturn(newEndpoint).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointOldId);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateEndpoint(newEndpoint);
    Response response = endpointsApiService.endpointsEndpointIdPut(endpointOldId, endPointDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("newNameEndpoint"));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) EndPointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 84 with APIPublisher

use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsGetException.

@Test
public void testEndpointsGetException() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.ENDPOINT_ADD_FAILED)).when(apiPublisher).getAllEndpoints();
    Response response = endpointsApiService.endpointsGet(null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Endpoint adding failed"));
}
Also used : Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 85 with APIPublisher

use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGetNotExist.

@Test
public void testEndpointsEndpointIdGetNotExist() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    String endpointId = endpoint.getId();
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Endpoint Not Found"));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)199 Test (org.testng.annotations.Test)185 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)168 Response (javax.ws.rs.core.Response)144 Test (org.junit.Test)144 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)144 API (org.wso2.carbon.apimgt.core.models.API)124 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)120 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)99 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)99 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)93 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 HashMap (java.util.HashMap)61 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)61 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)53 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)52 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)45 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)44 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)41 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)39