Search in sources :

Example 6 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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 7 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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);
}
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 8 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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 9 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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 10 with DocumentInfo

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

the class APIPublisherImplTestCase method testAddDocumentationInfoDocAlreadyExists.

@Test(description = "Document already exists error when adding Documentation Info", expectedExceptions = APIManagementException.class)
public void testAddDocumentationInfoDocAlreadyExists() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    Mockito.when(apiDAO.isDocumentExist(API_ID, documentInfo)).thenReturn(true);
    apiPublisher.addDocumentationInfo(API_ID, documentInfo);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Aggregations

DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)71 Test (org.testng.annotations.Test)28 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)28 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)22 Response (javax.ws.rs.core.Response)21 Test (org.junit.Test)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)20 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)18 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)18 API (org.wso2.carbon.apimgt.core.models.API)17 DocumentContent (org.wso2.carbon.apimgt.core.models.DocumentContent)16 HashMap (java.util.HashMap)14 DocumentDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO)12 ArrayList (java.util.ArrayList)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)9 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)9 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)8 APIDetails (org.wso2.carbon.apimgt.core.models.APIDetails)7