Search in sources :

Example 1 with EndPointDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.

the class TestMappingUtilTestCase method testEndpointToEndpointDTOMappingAndViceVersa.

@Test(description = "Endpoint to Endpoint DTO mapping and vice versa")
void testEndpointToEndpointDTOMappingAndViceVersa() throws IOException {
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    assertEquals(endpoint.getId(), endPointDTO.getId());
    assertEquals(endpoint.getName(), endPointDTO.getName());
    assertEquals(endpoint.getType(), endPointDTO.getType());
    assertEquals(endpoint.getMaxTps(), endPointDTO.getMaxTps());
    assertTrue(endpoint.getSecurity().contains(endPointDTO.getEndpointSecurity().getEnabled().toString()));
    Endpoint mappedEndpoint = MappingUtil.toEndpoint(endPointDTO);
    assertEquals(mappedEndpoint.getId(), endPointDTO.getId());
    assertEquals(mappedEndpoint.getName(), endPointDTO.getName());
    assertEquals(mappedEndpoint.getType(), endPointDTO.getType());
    assertEquals(mappedEndpoint.getMaxTps(), endPointDTO.getMaxTps());
    assertTrue(mappedEndpoint.getSecurity().contains(endPointDTO.getEndpointSecurity().getEnabled().toString()));
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) EndPointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO) Test(org.testng.annotations.Test)

Example 2 with EndPointDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO 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 3 with EndPointDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPutException.

@Test
public void testEndpointsEndpointIdPutException() 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();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.ENDPOINT_ALREADY_EXISTS)).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdPut(endpointId, endPointDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 409);
    assertTrue(response.getEntity().toString().contains("Endpoint already exists"));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) 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 4 with EndPointDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPutNotExist.

@Test
public void testEndpointsEndpointIdPutNotExist() 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();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    String endpointId = endpoint.getId();
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdPut(endpointId, endPointDTO, 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) EndPointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with EndPointDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.

the class MappingUtil method toEndpoint.

/**
 * Convert EndPointDTO to Endpoint
 *
 * @param endPointDTO Contains data of a endpoint
 * @return Endpoint model instance containing endpoint data
 */
public static Endpoint toEndpoint(EndPointDTO endPointDTO) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    Endpoint.Builder endPointBuilder = new Endpoint.Builder();
    endPointBuilder.endpointConfig(endPointDTO.getEndpointConfig());
    endPointBuilder.name(endPointDTO.getName());
    if (!StringUtils.isEmpty(endPointDTO.getId())) {
        endPointBuilder.id(endPointDTO.getId());
    } else {
        endPointBuilder.id(UUID.randomUUID().toString());
    }
    if (endPointDTO.getMaxTps() != null) {
        endPointBuilder.maxTps(endPointDTO.getMaxTps());
    }
    endPointBuilder.security(mapper.writeValueAsString(endPointDTO.getEndpointSecurity()));
    endPointBuilder.type(endPointDTO.getType());
    endPointBuilder.applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT);
    return endPointBuilder.build();
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)11 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)7 EndPointDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO)7 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 ArrayList (java.util.ArrayList)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 Test (org.testng.annotations.Test)2 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)2 EndPointDTO (org.wso2.carbon.apimgt.rest.api.core.dto.EndPointDTO)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1 API (org.wso2.carbon.apimgt.core.models.API)1 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)1