Search in sources :

Example 51 with Endpoint

use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint in project carbon-apimgt by wso2.

the class ExternalResourcesApiServiceImplTestCase method testExternalResourcesServicesGet.

@Test
public void testExternalResourcesServicesGet() throws Exception {
    printTestMethodName();
    ExternalResourcesApiServiceImpl externalResourcesApiService = new ExternalResourcesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint1 = SampleTestObjectCreator.createMockEndpoint();
    Endpoint endpoint2 = SampleTestObjectCreator.createMockEndpoint();
    List<Endpoint> endpointList = new ArrayList<>();
    endpointList.add(endpoint1);
    endpointList.add(endpoint2);
    Mockito.doReturn(endpointList).doThrow(new IllegalArgumentException()).when(apiPublisher).discoverServiceEndpoints();
    Response response = externalResourcesApiService.externalResourcesServicesGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertTrue(response.getEntity().toString().contains(endpoint1.getId()));
    Assert.assertTrue(response.getEntity().toString().contains(endpoint2.getId()));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with Endpoint

use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint 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 53 with Endpoint

use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint 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 54 with Endpoint

use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint 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 55 with Endpoint

use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint 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

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)118 Test (org.testng.annotations.Test)114 HashMap (java.util.HashMap)90 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)77 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)70 Test (org.junit.Test)62 API (org.wso2.carbon.apimgt.core.models.API)58 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)50 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)50 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)46 Map (java.util.Map)44 HashSet (java.util.HashSet)36 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)33 URL (java.net.URL)31 CharonException (org.wso2.charon3.core.exceptions.CharonException)31 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)30 OMElement (org.apache.axiom.om.OMElement)28 Response (javax.ws.rs.core.Response)27 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)27