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());
}
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()));
}
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);
}
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));
}
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());
}
Aggregations