Search in sources :

Example 6 with Documentation

use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testRemoveDocumentationInfo.

@Test(description = "Remove Documentation Info")
public void testRemoveDocumentationInfo() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    apiPublisher.removeDocumentation(DOC_ID);
    Mockito.verify(apiDAO, Mockito.times(1)).deleteDocument(DOC_ID);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 7 with Documentation

use of org.wso2.carbon.apimgt.persistence.dto.Documentation 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)

Example 8 with Documentation

use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUploadDocumentationFile.

@Test(description = "Upload Documentation File")
public void testUploadDocumentationFile() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    apiPublisher.uploadDocumentationFile(DOC_ID, null, "text/plain");
    Mockito.verify(apiDAO, Mockito.times(1)).addDocumentFileContent(DOC_ID, null, "text/plain", USER);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 9 with Documentation

use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateDocumentationInfoJsonParseException.

@Test(description = "Parse exception when updating documentation info", expectedExceptions = APIManagementException.class)
public void testUpdateDocumentationInfoJsonParseException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    DocumentInfo documentInfo = new DocumentInfo.Builder().fileName("sample_doc.pdf").name("howto_guide").id("").permission("data").build();
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    apiPublisher.updateDocumentation(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)

Example 10 with Documentation

use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.

the class APIImportExportTestCase method testApiExport.

private void testApiExport(String exportDir) throws Exception {
    String api1Id = UUID.randomUUID().toString();
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api1 = createApi("provider1", api1Id, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    String api1Doc1Id = UUID.randomUUID().toString();
    DocumentInfo api1Doc1Info = createAPIDoc(api1Doc1Id, "api1doc1", "", "API 1 DOC 1", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.INLINE, "", DocumentInfo.Visibility.PRIVATE);
    String api1Doc2Id = UUID.randomUUID().toString();
    DocumentInfo api1Doc2Info = createAPIDoc(api1Doc2Id, "api1doc2.pdf", "api1doc2.pdf", "API 1 DOC 2", DocumentInfo.DocType.PUBLIC_FORUM, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.API_LEVEL);
    String api1Doc3Id = UUID.randomUUID().toString();
    DocumentInfo api1Doc3Info = createAPIDoc(api1Doc3Id, "api1doc3", "", "API 1 DOC 3", DocumentInfo.DocType.OTHER, "other type", DocumentInfo.SourceType.OTHER, "", DocumentInfo.Visibility.API_LEVEL);
    Set<DocumentInfo> api1DocumentInfo = new HashSet<>();
    api1DocumentInfo.add(api1Doc1Info);
    api1DocumentInfo.add(api1Doc2Info);
    api1DocumentInfo.add(api1Doc3Info);
    // contents for documents
    DocumentContent api1Doc1Content = createDocContent(api1Doc1Info, "Sample inline content for API1 DOC 1", null);
    DocumentContent api1Doc2Content = createDocContent(api1Doc2Info, "", api1Doc2Stream);
    DocumentContent api1Doc3Content = createDocContent(api1Doc3Info, "", null);
    Set<DocumentContent> api1DocContent = new HashSet<>();
    api1DocContent.add(api1Doc1Content);
    api1DocContent.add(api1Doc2Content);
    api1DocContent.add(api1Doc3Content);
    APIDetails api1Details = new APIDetails(api1, api1Definition);
    api1Details.setGatewayConfiguration(api1GatewayConfig);
    api1Details.addDocumentInformation(api1DocumentInfo);
    api1Details.addDocumentContents(api1DocContent);
    api1Details.setThumbnailStream(getClass().getClassLoader().getResourceAsStream("api1_thumbnail.png"));
    Endpoint api1SandboxEndpoint = createEndpoint(api1SandBoxEndpointId.getId(), "api1SandBoxEndpoint", "SANDBOX", "{'type':'http','url':'http://localhost:8280'}", "{'enabled':'true','type':'basic','properties':{'username':'admin','password':'admin'}}", 10l);
    Endpoint api1ProdEndpoint = createEndpoint(api1ProdEndpointId.getId(), "api1ProdEndpoint", "PRODUCTION", "{'type':'http','url':'http://localhost:8280'}", "{'enabled':'true','type':'basic','properties':{'username':'admin','password':'admin'}}", 10l);
    api1Details.addEndpoint(api1SandboxEndpoint);
    api1Details.addEndpoint(api1ProdEndpoint);
    String api2Id = UUID.randomUUID().toString();
    Endpoint api2SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api2ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api2 = createApi("provider2", api2Id, "testapi2", "3.0.0", "Test API 2 - version 3.0.0", createEndpointTypeToIdMap(api2SandBoxEndpointId, api2ProdEndpointId)).build();
    List<API> apis = new ArrayList<>();
    apis.add(api1);
    apis.add(api2);
    String api2Doc1Id = UUID.randomUUID().toString();
    DocumentInfo api2Doc1Info = createAPIDoc(api2Doc1Id, "api2doc1", "", "API 2 DOC 1", DocumentInfo.DocType.API_MESSAGE_FORMAT, "other type", DocumentInfo.SourceType.INLINE, "", DocumentInfo.Visibility.API_LEVEL);
    String api2Doc2Id = UUID.randomUUID().toString();
    DocumentInfo api2Doc2Info = createAPIDoc(api2Doc2Id, "api2doc2", "", "API 2 DOC 2", DocumentInfo.DocType.PUBLIC_FORUM, "other type", DocumentInfo.SourceType.URL, "http://api2.org/documentation/1", DocumentInfo.Visibility.PRIVATE);
    Set<DocumentInfo> api2DocumentInfo = new HashSet<>();
    api2DocumentInfo.add(api2Doc1Info);
    api2DocumentInfo.add(api2Doc2Info);
    DocumentContent api2Doc1Content = createDocContent(api2Doc1Info, "Sample inline content for API2 DOC 1", null);
    DocumentContent api2Doc2Content = createDocContent(api2Doc2Info, "", null);
    Set<DocumentContent> api2DocContent = new HashSet<>();
    api2DocContent.add(api2Doc1Content);
    api2DocContent.add(api2Doc2Content);
    APIDetails api2Details = new APIDetails(api2, api2Definition);
    api2Details.setGatewayConfiguration(api2GatewayConfig);
    api2Details.addDocumentInformation(api2DocumentInfo);
    api2Details.addDocumentContents(api2DocContent);
    api2Details.setThumbnailStream(getClass().getClassLoader().getResourceAsStream("api2_thumbnail.jpg"));
    Endpoint api2SandboxEndpoint = createEndpoint(api2SandBoxEndpointId.getId(), "api2SandBoxEndpoint", "SANDBOX", "{'type':'http','url':'http://localhost:8280'}", "{'enabled':'true','type':'basic','properties':{'username':'admin','password':'admin'}}", 20l);
    Endpoint api2ProdEndpoint = createEndpoint(api2ProdEndpointId.getId(), "api2ProdEndpoint", "PRODUCTION", "{'type':'http','url':'http://localhost:8280'}", "{'enabled':'true','type':'basic','properties':{'username':'admin','password':'admin'}}", 20l);
    api2Details.addEndpoint(api2SandboxEndpoint);
    api2Details.addEndpoint(api2ProdEndpoint);
    Set<APIDetails> apiDetailsSet = new HashSet<>();
    apiDetailsSet.add(api1Details);
    apiDetailsSet.add(api2Details);
    // mock the method calls for retrieving APIs
    Mockito.when(apiPublisher.getAPIbyUUID(api1Id)).thenReturn(api1);
    Mockito.when(apiPublisher.getAPIbyUUID(api2Id)).thenReturn(api2);
    // export
    FileBasedApiImportExportManager importExportManager = new FileBasedApiImportExportManager(apiPublisher, exportDir);
    String exportedApiDirName = "exported-apis";
    String exportedApiDirPath = importExportManager.exportAPIs(apiDetailsSet, exportedApiDirName);
    String exportedApiArchiveFilePath = importExportManager.createArchiveFromExportedApiArtifacts(exportedApiDirPath, exportDir, exportedApiDirName);
    // check if two APIs are written to the file system
    String unzipPath = importExportRootDirectory + File.separator + "unzipped-export-archive";
    APIFileUtils.extractArchive(exportedApiArchiveFilePath, unzipPath);
    Assert.assertEquals(APIFileUtils.getDirectoryList(unzipPath).size() == 2, true, "Exported API count is not equal to 2");
    Mockito.when(apiPublisher.isAPIExists(api2Id)).thenReturn(true);
}
Also used : APIDetails(org.wso2.carbon.apimgt.core.models.APIDetails) ArrayList(java.util.ArrayList) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) DocumentContent(org.wso2.carbon.apimgt.core.models.DocumentContent) API(org.wso2.carbon.apimgt.core.models.API) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) HashSet(java.util.HashSet)

Aggregations

Documentation (org.wso2.carbon.apimgt.api.model.Documentation)56 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 Test (org.testng.annotations.Test)38 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)34 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)33 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)32 ArrayList (java.util.ArrayList)29 Resource (org.wso2.carbon.registry.core.Resource)27 HashMap (java.util.HashMap)26 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)26 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)24 API (org.wso2.carbon.apimgt.api.model.API)23 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)23 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)22 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)18 Registry (org.wso2.carbon.registry.core.Registry)18 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 DocumentationPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)17