use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGetException.
@Test
public void testEndpointsEndpointIdGetException() 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.doThrow(new APIManagementException("Error occurred", ExceptionCodes.APPLICATION_INACTIVE)).when(apiPublisher).getEndpoint(endpointId);
Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Application is not active"));
}
use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint 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.governance.api.endpoints.dataobjects.Endpoint 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.governance.api.endpoints.dataobjects.Endpoint in project carbon-apimgt by wso2.
the class MappingUtil method toAPI.
/**
* This method converts the API model object from the DTO object.
*
* @param apidto APIDTO object with API data
* @return APIBuilder object
*/
public static API.APIBuilder toAPI(APIDTO apidto) throws JsonProcessingException {
BusinessInformation businessInformation = new BusinessInformation();
API_businessInformationDTO apiBusinessInformationDTO = apidto.getBusinessInformation();
if (apiBusinessInformationDTO != null) {
businessInformation.setBusinessOwner(apiBusinessInformationDTO.getBusinessOwner());
businessInformation.setBusinessOwnerEmail(apiBusinessInformationDTO.getBusinessOwnerEmail());
businessInformation.setTechnicalOwner(apiBusinessInformationDTO.getTechnicalOwner());
businessInformation.setTechnicalOwnerEmail(apiBusinessInformationDTO.getTechnicalOwnerEmail());
}
API_corsConfigurationDTO apiCorsConfigurationDTO = apidto.getCorsConfiguration();
CorsConfiguration corsConfiguration = new CorsConfiguration();
if (apiCorsConfigurationDTO != null) {
corsConfiguration.setAllowCredentials(apiCorsConfigurationDTO.getAccessControlAllowCredentials());
corsConfiguration.setAllowHeaders(apiCorsConfigurationDTO.getAccessControlAllowHeaders());
corsConfiguration.setAllowMethods(apiCorsConfigurationDTO.getAccessControlAllowMethods());
corsConfiguration.setAllowOrigins(apiCorsConfigurationDTO.getAccessControlAllowOrigins());
corsConfiguration.setEnabled(apiCorsConfigurationDTO.getCorsConfigurationEnabled());
}
List<API_operationsDTO> operationList = apidto.getOperations();
Map<String, UriTemplate> uriTemplateList = new HashMap<>();
for (API_operationsDTO operationsDTO : operationList) {
UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder();
uriTemplateBuilder.uriTemplate(operationsDTO.getUritemplate());
uriTemplateBuilder.authType(operationsDTO.getAuthType());
uriTemplateBuilder.httpVerb(operationsDTO.getHttpVerb());
uriTemplateBuilder.policy(new APIPolicy(operationsDTO.getPolicy()));
uriTemplateBuilder.scopes(operationsDTO.getScopes());
if (operationsDTO.getEndpoint() != null && !operationsDTO.getEndpoint().isEmpty()) {
uriTemplateBuilder.endpoint(fromEndpointListToMap(operationsDTO.getEndpoint()));
}
if (operationsDTO.getId() != null) {
uriTemplateBuilder.templateId(operationsDTO.getId());
} else {
uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(operationsDTO.getUritemplate(), operationsDTO.getHttpVerb()));
}
uriTemplateList.put(uriTemplateBuilder.getTemplateId(), uriTemplateBuilder.build());
}
Set<Policy> subscriptionPolicies = new HashSet<>();
apidto.getPolicies().forEach(v -> subscriptionPolicies.add(new SubscriptionPolicy(v)));
API.APIBuilder apiBuilder = new API.APIBuilder(apidto.getProvider(), apidto.getName(), apidto.getVersion()).id(apidto.getId()).context(apidto.getContext()).description(apidto.getDescription()).lifeCycleStatus(apidto.getLifeCycleStatus()).endpoint(fromEndpointListToMap(apidto.getEndpoint())).visibleRoles(new HashSet<>(apidto.getVisibleRoles())).policies(subscriptionPolicies).apiPermission(apidto.getPermission()).tags(new HashSet<>(apidto.getTags())).labels(new ArrayList<>(apidto.getLabels())).transport(new HashSet<>(apidto.getTransport())).isResponseCachingEnabled(Boolean.valueOf(apidto.getResponseCaching())).businessInformation(businessInformation).uriTemplates(uriTemplateList).corsConfiguration(corsConfiguration).wsdlUri(apidto.getWsdlUri()).scopes(apidto.getScopes()).securityScheme(mapSecuritySchemeListToInt(apidto.getSecurityScheme()));
if (apidto.getIsDefaultVersion() != null) {
apiBuilder.isDefaultVersion(apidto.getIsDefaultVersion());
}
if (apidto.getVisibility() != null) {
apiBuilder.visibility(API.Visibility.valueOf(apidto.getVisibility().toString()));
}
if (apidto.getCacheTimeout() != null) {
apiBuilder.cacheTimeout(apidto.getCacheTimeout());
}
if (apidto.getApiPolicy() != null) {
Policy policy = new APIPolicy(apidto.getApiPolicy());
apiBuilder.apiPolicy(policy);
}
if (apidto.getHasOwnGateway() != null) {
apiBuilder.hasOwnGateway(apidto.getHasOwnGateway());
}
if (apidto.getThreatProtectionPolicies() != null) {
API_threatProtectionPoliciesDTO threatProtectionPoliciesDTO = apidto.getThreatProtectionPolicies();
List<API_threatProtectionPolicies_listDTO> threatProtectionPolicies_listDTO = threatProtectionPoliciesDTO.getList();
Set<String> policyIdSet = new HashSet<>();
for (API_threatProtectionPolicies_listDTO listDTO : threatProtectionPolicies_listDTO) {
policyIdSet.add(listDTO.getPolicyId());
}
apiBuilder.threatProtectionPolicies(policyIdSet);
}
return apiBuilder;
}
use of org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint 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