Search in sources :

Example 61 with APIDefinition

use of org.wso2.carbon.apimgt.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 62 with APIDefinition

use of org.wso2.carbon.apimgt.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 63 with APIDefinition

use of org.wso2.carbon.apimgt.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 64 with APIDefinition

use of org.wso2.carbon.apimgt.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)

Example 65 with APIDefinition

use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testDocumentAdd.

@Test
public void testDocumentAdd() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultFileDocumentationInfo();
    Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
    apiDAO.addDocumentInfo(api.getId(), documentInfo);
    apiDAO.addDocumentFileContent(documentInfo.getId(), IOUtils.toInputStream(SampleTestObjectCreator.createDefaultInlineDocumentationContent()), "inline1.txt", documentInfo.getCreatedBy());
    Assert.assertTrue(apiDAO.isDocumentExist(api.getId(), documentInfo));
    List<DocumentInfo> documentInfoList = apiDAO.getDocumentsInfoList(api.getId());
    Assert.assertEquals(documentInfoList.get(0), documentInfo);
    apiDAO.deleteDocument(documentInfo.getId());
    Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 HashMap (java.util.HashMap)30 APIDefinition (org.wso2.carbon.apimgt.api.APIDefinition)30 API (org.wso2.carbon.apimgt.core.models.API)30 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)25 ArrayList (java.util.ArrayList)23 API (org.wso2.carbon.apimgt.api.model.API)20 Map (java.util.Map)19 IOException (java.io.IOException)18 Test (org.testng.annotations.Test)18 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)16 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)15 Scope (org.wso2.carbon.apimgt.api.model.Scope)15 HashSet (java.util.HashSet)13 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)12 SwaggerData (org.wso2.carbon.apimgt.api.model.SwaggerData)12 BusinessInformation (org.wso2.carbon.apimgt.core.models.BusinessInformation)12 CorsConfiguration (org.wso2.carbon.apimgt.core.models.CorsConfiguration)12