use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class APIMappingUtilTestCase 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("").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.core.api.APIDefinition in project carbon-apimgt by wso2.
the class APIStoreImpl method addCompositeApiFromDefinition.
/**
* {@inheritDoc}
*/
@Override
public String addCompositeApiFromDefinition(InputStream apiDefinition) throws APIManagementException {
try {
String apiDefinitionString = IOUtils.toString(apiDefinition);
CompositeAPI.Builder apiBuilder = apiDefinitionFromSwagger20.generateCompositeApiFromSwaggerResource(getUsername(), apiDefinitionString);
apiBuilder.apiDefinition(apiDefinitionString);
addCompositeApi(apiBuilder);
return apiBuilder.getId();
} catch (IOException e) {
throw new APIManagementException("Couldn't Generate ApiDefinition from file", ExceptionCodes.API_DEFINITION_MALFORMED);
}
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testSingleWSDLForAPI.
@Test
public void testSingleWSDLForAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
// there can't be any WSDLs added at first
boolean isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
boolean isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// add a WSDL
byte[] wsdlContentBytes = SampleTestObjectCreator.createDefaultWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether they are same
String receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// now there should be a single WSDL for API exists but no WSDL archives
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertTrue(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// update the WSDL file
wsdlContentBytes = SampleTestObjectCreator.createAlternativeWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether updated successfully
receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// update with a WSDL archive
InputStream wsdl11ArchiveInputStream = SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream();
byte[] wsdlArchiveBytesDefault = IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
apiDAO.addOrUpdateWSDLArchive(api.getId(), wsdl11ArchiveInputStream, ADMIN);
// retrieves and check whether successfully updated
InputStream wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
byte[] streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(wsdlArchiveBytesDefault.length, streamFromDBBytes.length);
// removes and validate
apiDAO.removeWSDLArchiveOfAPI(api.getId());
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateGetDedicatedGatewayWhenLabelsAreEmpty.
@Test
public void testUpdateGetDedicatedGatewayWhenLabelsAreEmpty() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
dedicatedGateway.setUpdatedBy(api.getCreatedBy());
dedicatedGateway.setApiId(api.getId());
List<String> labels = new ArrayList<>();
apiDAO.updateDedicatedGateway(dedicatedGateway, labels);
DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testWSDLArchiveForAPI.
@Test
public void testWSDLArchiveForAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
// there can't be any WSDLs added at first
boolean isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
boolean isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// add a WSDL
InputStream wsdl11ArchiveInputStream = SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream();
byte[] wsdlArchiveBytesDefault = IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
apiDAO.addOrUpdateWSDLArchive(api.getId(), wsdl11ArchiveInputStream, ADMIN);
// retrieves and check whether they are same
InputStream wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
byte[] streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(wsdlArchiveBytesDefault.length, streamFromDBBytes.length);
// now there should be a single WSDL for API exists but no WSDL archives
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertTrue(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertTrue(isWSDLArchiveExists);
// update the WSDL archive
InputStream alternativeWSDL11ArchiveInputStream = SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream();
apiDAO.addOrUpdateWSDLArchive(api.getId(), alternativeWSDL11ArchiveInputStream, ADMIN);
// retrieves and check whether updated successfully
byte[] wsdlArchiveBytesAlternative = IOUtils.toByteArray(SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream());
wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(streamFromDBBytes.length, wsdlArchiveBytesAlternative.length);
// update the WSDL with a file
byte[] wsdlContentBytes = SampleTestObjectCreator.createAlternativeWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether updated successfully
String receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// removes and validate
apiDAO.removeWSDL(api.getId());
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
}
Aggregations