Search in sources :

Example 31 with APIDefinition

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;
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashSet(java.util.HashSet)

Example 32 with APIDefinition

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) IOException(java.io.IOException)

Example 33 with APIDefinition

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 34 with APIDefinition

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());
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Example 35 with APIDefinition

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)30 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)25 Test (org.testng.annotations.Test)18 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 HashMap (java.util.HashMap)16 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 HashSet (java.util.HashSet)12 BusinessInformation (org.wso2.carbon.apimgt.core.models.BusinessInformation)12 CorsConfiguration (org.wso2.carbon.apimgt.core.models.CorsConfiguration)12 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)12 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)11 Map (java.util.Map)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)7 ArrayList (java.util.ArrayList)5 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)5 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)5 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)5 HashedMap (org.apache.commons.collections.map.HashedMap)4