Search in sources :

Example 86 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testIsAPIContextExists.

@Test
public void testIsAPIContextExists() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    testAddGetEndpoint();
    API api = SampleTestObjectCreator.createUniqueAPI().build();
    apiDAO.addAPI(api);
    Assert.assertTrue(apiDAO.isAPIContextExists(api.getContext()));
}
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) Test(org.testng.annotations.Test)

Example 87 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testDeleteDocumentation.

@Test(description = "Delete documentation for an API")
public void testDeleteDocumentation() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    testAddGetEndpoint();
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    apiDAO.addAPI(api);
    // adding documentation
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
    String docId = documentInfo.getId();
    apiDAO.addDocumentInfo(api.getId(), documentInfo);
    // delete documentation
    apiDAO.deleteDocument(docId);
    DocumentInfo documentInfoFromDB = apiDAO.getDocumentInfo(docId);
    Assert.assertNull(documentInfoFromDB);
}
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)

Example 88 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testAddDuplicateProviderNameVersionAPI.

@Test
public void testAddDuplicateProviderNameVersionAPI() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API api = SampleTestObjectCreator.createUniqueAPI().build();
    apiDAO.addAPI(api);
    API.APIBuilder duplicateAPIBuilder = SampleTestObjectCreator.createUniqueAPI();
    duplicateAPIBuilder.provider(api.getProvider());
    duplicateAPIBuilder.name(api.getName());
    duplicateAPIBuilder.version(api.getVersion());
    duplicateAPIBuilder.labels(api.getLabels());
    API duplicateAPI = duplicateAPIBuilder.build();
    try {
        apiDAO.addAPI(duplicateAPI);
        Assert.fail("Exception not thrown for adding duplicate API");
    } catch (APIMgtDAOException e) {
    // Just catch the exception so that we can continue execution
    }
    API apiFromDB = apiDAO.getAPI(api.getId());
    try {
        apiDAO.getAPI(duplicateAPI.getId());
    } catch (APIMgtDAOException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.API_NOT_FOUND);
    }
    Assert.assertEquals(apiDAO.getAPIs(new HashSet<String>(), api.getProvider()).size(), 1);
    Assert.assertEquals(apiFromDB, api, TestUtil.printDiff(apiFromDB, api));
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) 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 89 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testGetAPIsByStatusAndLabel.

@Test
public void testGetAPIsByStatusAndLabel() throws Exception {
    // Define statuses used in test
    final String publishedStatus = "PUBLISHED";
    final String createdStatus = "CREATED";
    // Define labels used in test
    final String publicLabel = "public";
    final String privateLabel = "private";
    // Add labels
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label label1 = SampleTestObjectCreator.createLabel(publicLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
    Label label2 = SampleTestObjectCreator.createLabel(privateLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
    List<Label> labelList = new ArrayList<>();
    labelList.add(label1);
    labelList.add(label2);
    LabelDAOImpl.addLabel(label1);
    LabelDAOImpl.addLabel(label2);
    String publicLabelId = labelDAO.getLabelIdByNameAndType(publicLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
    String privateLabelId = labelDAO.getLabelIdByNameAndType(privateLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    // Define number of APIs to be created for a given status
    final int numberOfPublishedWithLabelPublicPrivate = 1;
    final int numberOfPublishedWithLabelPrivate = 2;
    final int numberOfCreatedWithLabelPublic = 3;
    // Add APIs with Status = PUBLISHED having labels "public" and "private"
    List<API> publishedAPIsPublicPrivateSummary = new ArrayList<>();
    List<String> labelsPublicPrivate = new ArrayList<>(Arrays.asList(publicLabelId, privateLabelId));
    testAddGetEndpoint();
    for (int i = 0; i < numberOfPublishedWithLabelPublicPrivate; ++i) {
        API api = SampleTestObjectCreator.createUniqueAPI().lifeCycleStatus(publishedStatus).labels(labelsPublicPrivate).build();
        publishedAPIsPublicPrivateSummary.add(SampleTestObjectCreator.getSummaryFromAPI(api));
        apiDAO.addAPI(api);
    }
    // Add APIs with Status = PUBLISHED having label "private"
    List<API> publishedAPIsPrivateSummary = new ArrayList<>();
    List<String> labelsPrivate = new ArrayList<>(Collections.singletonList(privateLabelId));
    for (int i = 0; i < numberOfPublishedWithLabelPrivate; ++i) {
        API api = SampleTestObjectCreator.createUniqueAPI().lifeCycleStatus(publishedStatus).labels(labelsPrivate).build();
        publishedAPIsPrivateSummary.add(SampleTestObjectCreator.getSummaryFromAPI(api));
        apiDAO.addAPI(api);
    }
    // Add APIs with Status = CREATED having labels "public"
    List<API> createdAPIsPublicSummary = new ArrayList<>();
    List<String> labelsPublic = new ArrayList<>(Collections.singletonList(publicLabelId));
    for (int i = 0; i < numberOfCreatedWithLabelPublic; ++i) {
        API api = SampleTestObjectCreator.createUniqueAPI().lifeCycleStatus(createdStatus).labels(labelsPublic).build();
        createdAPIsPublicSummary.add(SampleTestObjectCreator.getSummaryFromAPI(api));
        apiDAO.addAPI(api);
    }
    // verifying APIs with Status = PUBLISHED having labels "public" or "private"
    List<API> publishedPublicPrivateApiListFromDB = apiDAO.getAPIsByStatus(Arrays.asList(publicLabel, privateLabel), publishedStatus);
    List<API> publishedApisWithPublicOrPrivateLabels = new ArrayList<>();
    publishedApisWithPublicOrPrivateLabels.addAll(publishedAPIsPrivateSummary);
    publishedApisWithPublicOrPrivateLabels.addAll(publishedAPIsPublicPrivateSummary);
    Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(publishedPublicPrivateApiListFromDB, publishedApisWithPublicOrPrivateLabels, new APIComparator()));
    List<API> publishedApisWithPrivateLabels = new ArrayList<>();
    publishedApisWithPrivateLabels.addAll(publishedAPIsPrivateSummary);
    publishedApisWithPrivateLabels.addAll(publishedAPIsPublicPrivateSummary);
    // verifying APIs with Status = PUBLISHED having label "private"
    List<API> publishedPrivateApiListFromDB = apiDAO.getAPIsByStatus(Collections.singletonList(privateLabel), publishedStatus);
    Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(publishedPrivateApiListFromDB, publishedApisWithPrivateLabels, new APIComparator()));
    // verifying APIs with Status = CREATED having label "public"
    List<API> createdPublicApiListFromDB = apiDAO.getAPIsByStatus(Collections.singletonList(publicLabel), createdStatus);
    Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(createdPublicApiListFromDB, createdAPIsPublicSummary, new APIComparator()));
    // verifying APIs with Status = CREATED having label "private"
    List<API> createdPrivateApiListFromDB = apiDAO.getAPIsByStatus(Collections.singletonList(privateLabel), createdStatus);
    Assert.assertTrue(createdPrivateApiListFromDB.isEmpty());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) APIComparator(org.wso2.carbon.apimgt.core.util.APIComparator) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Example 90 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testUpdateAPIWithLabels.

@Test
public void testUpdateAPIWithLabels() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    LabelDAOImpl.addLabel(label1);
    LabelDAOImpl.addLabel(label2);
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    List<String> labelIds = new ArrayList<>();
    labelIds.add(label1.getId());
    API.APIBuilder builder1 = SampleTestObjectCreator.createDefaultAPI();
    API api = builder1.labels(labelIds).build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    API apiFromDBWithOneLabel = apiDAO.getAPI(api.getId());
    Assert.assertEquals(apiFromDBWithOneLabel.getLabels().size(), builder1.getLabels().size());
    labelIds.add(label2.getId());
    API substituteAPI = new API.APIBuilder(api).labels(labelIds).build();
    apiDAO.updateAPI(api.getId(), substituteAPI);
    API apiFromDB = apiDAO.getAPI(api.getId());
    API expectedAPI = SampleTestObjectCreator.copyAPIIgnoringNonEditableFields(api, substituteAPI);
    Assert.assertNotNull(apiFromDB);
    Assert.assertEquals(apiFromDB.getLabels().size(), expectedAPI.getLabels().size());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)320 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)132 HashMap (java.util.HashMap)129 ArrayList (java.util.ArrayList)112 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)106 Test (org.junit.Test)83 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)83 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)82 SQLException (java.sql.SQLException)75 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)70 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)61 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)60 Connection (java.sql.Connection)58 Response (javax.ws.rs.core.Response)58