Search in sources :

Example 96 with API

use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testGetDocumentInfoList.

@Test(description = "Getting document info list for an API")
public void testGetDocumentInfoList() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    testAddGetEndpoint();
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    apiDAO.addAPI(api);
    DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo();
    apiDAO.addDocumentInfo(api.getId(), documentInfo1);
    DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo();
    apiDAO.addDocumentInfo(api.getId(), documentInfo2);
    List<DocumentInfo> documentInfoList = new ArrayList<>();
    documentInfoList.add(documentInfo1);
    documentInfoList.add(documentInfo2);
    List<DocumentInfo> documentInfoListFromDB = apiDAO.getDocumentsInfoList(api.getId());
    Assert.assertTrue(documentInfoListFromDB.containsAll(documentInfoList));
    Assert.assertTrue(documentInfoList.size() == documentInfoListFromDB.size());
}
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) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 97 with API

use of org.wso2.carbon.apimgt.keymgt.model.entity.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 98 with API

use of org.wso2.carbon.apimgt.keymgt.model.entity.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 99 with API

use of org.wso2.carbon.apimgt.keymgt.model.entity.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 100 with API

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

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)582 ArrayList (java.util.ArrayList)374 API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)350 HashMap (java.util.HashMap)318 Test (org.junit.Test)316 API (org.wso2.carbon.apimgt.api.model.API)307 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)255 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)234 SQLException (java.sql.SQLException)190 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)186 IOException (java.io.IOException)181 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 PreparedStatement (java.sql.PreparedStatement)169 Connection (java.sql.Connection)158 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)149 JSONObject (org.json.simple.JSONObject)142 Resource (org.wso2.carbon.registry.core.Resource)139