use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddUpdateAPIFromWSDLArchive.
@Test(description = "Test adding an API from WSDL archive")
public void testAddUpdateAPIFromWSDLArchive() throws APIManagementException, LifecycleException, IOException {
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(SampleTestObjectCreator.getMockEndpointMap());
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APILifecycleManager apiLifecycleManager = getDefaultMockedAPILifecycleManager();
PolicyDAO policyDAO = getDefaultMockedPolicyDAO();
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO, labelDao);
String endpointId = apiBuilder.getEndpoint().get("production").getId();
Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
apiPublisher.addAPIFromWSDLArchive(apiBuilder, SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream(), true);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDLArchive(Mockito.eq(apiBuilder.getId()), Mockito.anyObject(), Mockito.eq(USER));
apiPublisher.updateAPIWSDLArchive(apiBuilder.getId(), SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream());
Mockito.verify(apiDAO, Mockito.times(2)).addOrUpdateWSDLArchive(Mockito.eq(apiBuilder.getId()), Mockito.anyObject(), Mockito.eq(USER));
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddUpdateAPIFromWSDLFile.
@Test(description = "Test adding an API from WSDL file")
public void testAddUpdateAPIFromWSDLFile() throws APIManagementException, LifecycleException, IOException {
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(SampleTestObjectCreator.getMockEndpointMap());
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APILifecycleManager apiLifecycleManager = getDefaultMockedAPILifecycleManager();
PolicyDAO policyDAO = getDefaultMockedPolicyDAO();
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO, labelDao);
String endpointId = apiBuilder.getEndpoint().get("production").getId();
Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
apiPublisher.addAPIFromWSDLFile(apiBuilder, SampleTestObjectCreator.createDefaultWSDL11ContentInputStream(), true);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDL(apiBuilder.getId(), IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ContentInputStream()), USER);
Mockito.verify(apiLifecycleManager, Mockito.times(1)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
apiPublisher.updateAPIWSDL(apiBuilder.getId(), SampleTestObjectCreator.createAlternativeWSDL11ContentInputStream());
Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDL(apiBuilder.getId(), IOUtils.toByteArray(SampleTestObjectCreator.createAlternativeWSDL11ContentInputStream()), USER);
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultAPI.
public static API.APIBuilder createDefaultAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
transport.add(HTTPS);
Set<String> tags = new HashSet<>();
tags.add(TAG_CLIMATE);
Set<Policy> policies = new HashSet<>();
policies.add(goldSubscriptionPolicy);
policies.add(silverSubscriptionPolicy);
policies.add(bronzeSubscriptionPolicy);
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner(NAME_BUSINESS_OWNER_1);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_1);
businessInformation.setTechnicalOwner(NAME_TECHNICAL_OWNER_1);
businessInformation.setTechnicalOwnerEmail(EMAIL_TECHNICAL_OWNER_1);
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Set<String> visibleRoles = new HashSet<>();
visibleRoles.add("testRple");
List<String> labels = new ArrayList<>();
labels.add("testLabel");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList(APIMgtConstants.FunctionsConstants.GET, APIMgtConstants.FunctionsConstants.POST, APIMgtConstants.FunctionsConstants.DELETE));
corsConfiguration.setAllowHeaders(Arrays.asList(ALLOWED_HEADER_AUTHORIZATION, ALLOWED_HEADER_CUSTOM));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Arrays.asList("*"));
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put("TestEndpoint", createMockEndpoint());
API.APIBuilder apiBuilder = new API.APIBuilder(ADMIN, "WeatherAPI", API_VERSION).id(UUID.randomUUID().toString()).context("weather").description("Get Weather Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).lifecycleInstanceId(UUID.randomUUID().toString()).endpoint(Collections.emptyMap()).wsdlUri("http://localhost:9443/echo?wsdl").isResponseCachingEnabled(false).cacheTimeout(60).isDefaultVersion(false).apiPolicy(unlimitedApiPolicy).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.PUBLIC).visibleRoles(visibleRoles).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy(ADMIN).updatedBy(ADMIN).lastUpdatedTime(LocalDateTime.now()).apiPermission(permissionJson).uriTemplates(getMockUriTemplates()).apiDefinition(apiDefinition).workflowStatus(WORKFLOW_STATUS).labels(labels).endpoint(endpointMap);
Map map = new HashMap();
map.put(DEVELOPER_ROLE_ID, 6);
map.put(ADMIN_ROLE_ID, 15);
apiBuilder.permissionMap(map);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class APIImportExportTestCase method createApi.
private static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
Set<String> transport = new HashSet<>();
transport.add("http");
Set<Policy> policies = new HashSet<>();
policies.add(new SubscriptionPolicy("Silver"));
policies.add(new SubscriptionPolicy("Bronze"));
Set<String> tags = new HashSet<>();
tags.add("food");
tags.add("beverage");
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner("John Doe");
businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
businessInformation.setTechnicalOwner("Jane Doe");
businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition(api1Definition).wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
apiBuilder.uriTemplates(Collections.emptyMap());
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisImportDefinitionPostWSDLFile.
@Test
public void testApisImportDefinitionPostWSDLFile() throws Exception {
printTestMethodName();
File file = new File(getClass().getClassLoader().getResource(WSDL_FILE_LOCATION).getFile());
FileInputStream fis = new FileInputStream(file);
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName(WSDL_FILE);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
String apiId = UUID.randomUUID().toString();
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(apiId);
API api = apiBuilder.build();
APIDTO apiDto = MappingUtil.toAPIDto(api);
ObjectMapper objectMapper = new ObjectMapper();
String additionalProperties = objectMapper.writeValueAsString(apiDto);
Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
Mockito.doReturn(apiId).when(apiPublisher).addAPIFromWSDLFile(Mockito.argThat(getAPIBuilderMatcher(apiBuilder)), Mockito.eq(fis), Mockito.eq(false));
Response response = apisApiService.apisImportDefinitionPost(WSDL, fis, fileInfo, null, additionalProperties, null, null, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 201);
assertTrue(response.getEntity().toString().contains(apiId));
}
Aggregations