Search in sources :

Example 11 with EndPointDTO

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

the class EndpointsApiServiceImplTestCase method testEndpointsPostException.

@Test
public void testEndpointsPostException() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.mockStatic(MappingUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    PowerMockito.when(MappingUtil.toEndpoint(endPointDTO)).thenReturn(endpoint);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.ENDPOINT_ALREADY_EXISTS)).when(apiPublisher).addEndpoint(endpoint);
    Response response = endpointsApiService.endpointsPost(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 12 with EndPointDTO

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

the class EndpointsApiServiceImplTestCase method testEndpointsPost.

@Test
public void testEndpointsPost() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.mockStatic(MappingUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpointBuilder().build();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    String endpointId = UUID.randomUUID().toString();
    PowerMockito.when(MappingUtil.toEndpoint(endPointDTO)).thenReturn(endpoint);
    Mockito.doReturn(endpointId).doThrow(new IllegalArgumentException()).when(apiPublisher).addEndpoint(endpoint);
    Mockito.doReturn(endpoint).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsPost(endPointDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 201);
}
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 13 with EndPointDTO

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

the class MappingUtil method fromEndpointToList.

private static List<API_endpointDTO> fromEndpointToList(Map<String, Endpoint> endpoint) throws IOException {
    List<API_endpointDTO> endpointDTOs = new ArrayList<>();
    if (endpoint != null) {
        for (Map.Entry<String, Endpoint> entry : endpoint.entrySet()) {
            API_endpointDTO endpointDTO = new API_endpointDTO();
            if (APIMgtConstants.API_SPECIFIC_ENDPOINT.equals(entry.getValue().getApplicableLevel())) {
                endpointDTO.setInline(toEndPointDTO(entry.getValue()));
            } else {
                endpointDTO.setKey(entry.getValue().getId());
            }
            endpointDTO.setType(entry.getKey());
            endpointDTOs.add(endpointDTO);
        }
    }
    return endpointDTOs;
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) API_endpointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_endpointDTO)

Example 14 with EndPointDTO

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

the class MappingUtil method toEndPointDTO.

/**
 * Convert Endpoint to EndPointDTO
 *
 * @param endpoint endpoint model instance
 * @return EndPointDTO instance containing endpoint data
 */
public static EndPointDTO toEndPointDTO(Endpoint endpoint) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    EndPointDTO endPointDTO = new EndPointDTO();
    endPointDTO.setId(endpoint.getId());
    endPointDTO.setName(endpoint.getName());
    endPointDTO.setEndpointConfig(endpoint.getEndpointConfig());
    EndPoint_endpointSecurityDTO endpointSecurityDTO = mapper.readValue(endpoint.getSecurity(), EndPoint_endpointSecurityDTO.class);
    if (endpointSecurityDTO.getEnabled()) {
        endpointSecurityDTO.setPassword("");
    }
    endPointDTO.setEndpointSecurity(endpointSecurityDTO);
    endPointDTO.setMaxTps(endpoint.getMaxTps());
    endPointDTO.setType(endpoint.getType());
    return endPointDTO;
}
Also used : EndPoint_endpointSecurityDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPoint_endpointSecurityDTO) EndPointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO) 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