use of org.wso2.carbon.apimgt.rest.api.core.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()));
}
use of org.wso2.carbon.apimgt.rest.api.core.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"));
}
use of org.wso2.carbon.apimgt.rest.api.core.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"));
}
use of org.wso2.carbon.apimgt.rest.api.core.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"));
}
use of org.wso2.carbon.apimgt.rest.api.core.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();
}
Aggregations