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"));
}
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);
}
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;
}
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;
}
Aggregations