use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetDocumentContent.
@Test(description = "Getting document content for an API")
public void testGetDocumentContent() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo1);
List<DocumentInfo> documentInfoList = new ArrayList<>();
documentInfoList.add(documentInfo1);
List<DocumentInfo> documentInfoListFromDB = apiDAO.getDocumentsInfoList(api.getId());
Assert.assertTrue(documentInfoListFromDB.containsAll(documentInfoList));
DocumentInfo documentInfo = SampleTestObjectCreator.createFileDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo);
byte[] contentBytes = SampleTestObjectCreator.createDefaultFileDocumentationContent();
apiDAO.addDocumentFileContent(documentInfo.getId(), new ByteArrayInputStream(contentBytes), "application/pdf", ADMIN);
byte[] retrievedContentFromDB = IOUtils.toByteArray(apiDAO.getDocumentFileContent(documentInfo.getId()));
Assert.assertEquals(contentBytes.length, retrievedContentFromDB.length);
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddAPIWithoutAddingLabels.
@Test
public void testAddAPIWithoutAddingLabels() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
List<String> labelIds = new ArrayList<>();
labelIds.add(label1.getId());
labelIds.add(label2.getId());
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDB = apiDAO.getAPI(api.getId());
Assert.assertNotNull(apiFromDB);
Assert.assertEquals(apiFromDB.getLabels().size(), 2);
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testDeleteComment.
@Test
public void testDeleteComment() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
apiDAO.addComment(comment, api.getId());
apiDAO.deleteComment(comment.getUuid(), api.getId());
Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
Assert.assertNull(commentFromDB);
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetDocumentInfo.
@Test(description = "Getting document info for an API")
public void testGetDocumentInfo() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
apiDAO.addDocumentInfo(api.getId(), documentInfo);
DocumentInfo documentInfoFromDB = apiDAO.getDocumentInfo(documentInfo.getId());
Assert.assertEquals(documentInfo, documentInfoFromDB);
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testFingerprintAfterUpdatingSwaggerDefinition.
@Test
public void testFingerprintAfterUpdatingSwaggerDefinition() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
String fingerprintBeforeUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfSwaggerDefinition(api.getId()));
Assert.assertNotNull(fingerprintBeforeUpdate);
Thread.sleep(1);
String swagger = SampleTestObjectCreator.createAlternativeSwaggerDefinition();
apiDAO.updateApiDefinition(api.getId(), swagger, ADMIN);
String fingerprintAfterUpdate = ETagUtils.generateETag(apiDAO.getLastUpdatedTimeOfSwaggerDefinition(api.getId()));
Assert.assertNotNull(fingerprintAfterUpdate);
Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
Aggregations