Search in sources :

Example 36 with Documentation

use of org.wso2.carbon.apimgt.api.model.Documentation in project ballerina by ballerina-lang.

the class DocumentationTest method testInlineCode.

@Test(description = "Test doc inline code.")
public void testInlineCode() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/doc_inline.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangVariable connector = (BLangVariable) packageNode.getGlobalVariables().get(0);
    List<BLangDocumentation> docNodes = connector.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.getAttributes().size(), 0);
    Assert.assertEquals(dNode.documentationText, "\n" + "  Example of a string template:\n" + "    ``string s = string `hello {{name}}`;``\n" + "\n" + "  Example for an xml literal:\n" + "    ``xml x = xml `<{{tagName}}>hello</{{tagName}}>`;``\n");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Test(org.testng.annotations.Test)

Example 37 with Documentation

use of org.wso2.carbon.apimgt.api.model.Documentation in project ballerina by ballerina-lang.

the class DocumentationTest method testDocStruct.

@Test(description = "Test doc struct.")
public void testDocStruct() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/struct.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for Test struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field a` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " struct `field b` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " struct `field c` documentation");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 38 with Documentation

use of org.wso2.carbon.apimgt.api.model.Documentation in project ballerina by ballerina-lang.

the class DocumentationTest method testNestedInline.

@Test(description = "Test doc nested inline.")
public void testNestedInline() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/nested_inline.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangVariable constant = (BLangVariable) packageNode.getGlobalVariables().get(0);
    List<BLangDocumentation> docNodes = constant.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.getAttributes().size(), 0);
    Assert.assertEquals(dNode.documentationText, "\n" + "  Example of a string template:\n" + "  ``` This starts ends triple backtick  ``string s = string `hello {{name}}`;`` " + "ends triple backtick```\n" + "\n" + "  Example for an xml literal:\n" + "    ``xml x = xml `<{{tagName}}>hello</{{tagName}}>`;``\n");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Test(org.testng.annotations.Test)

Example 39 with Documentation

use of org.wso2.carbon.apimgt.api.model.Documentation in project ballerina by ballerina-lang.

the class DocumentationTest method testDocService.

@Test(description = "Test doc service.", enabled = false)
public void testDocService() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/service.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangService service = (BLangService) packageNode.getServices().get(0);
    List<BLangDocumentation> docNodes = service.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
    dNode = service.getResources().get(0).docAttachments.get(0);
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.documentationText, "Check orderPizza resource. ");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
    dNode = service.getResources().get(1).docAttachments.get(0);
    Assert.assertEquals(dNode.documentationText, "Check status resource. ");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
}
Also used : BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 40 with Documentation

use of org.wso2.carbon.apimgt.api.model.Documentation in project carbon-apimgt by wso2.

the class AbstractAPIManager method getAllDocumentation.

public List<Documentation> getAllDocumentation(Identifier id) throws APIManagementException {
    List<Documentation> documentationList = new ArrayList<Documentation>();
    String docArtifactKeyType = StringUtils.EMPTY;
    docArtifactKeyType = APIConstants.DOCUMENTATION_KEY;
    String apiOrAPIProductDocPath;
    APIRevision apiRevision = apiMgtDAO.checkAPIUUIDIsARevisionUUID(id.getUUID());
    if (apiRevision != null && apiRevision.getApiUUID() != null) {
        apiOrAPIProductDocPath = APIUtil.getAPIOrAPIProductRevisionDocPath(apiRevision.getApiUUID(), apiRevision.getId());
    } else {
        apiOrAPIProductDocPath = APIUtil.getAPIOrAPIProductDocPath(id);
    }
    String pathToContent = apiOrAPIProductDocPath + APIConstants.INLINE_DOCUMENT_CONTENT_DIR;
    String pathToDocFile = apiOrAPIProductDocPath + APIConstants.DOCUMENT_FILE_DIR;
    try {
        if (registry.resourceExists(apiOrAPIProductDocPath)) {
            Resource resource = registry.get(apiOrAPIProductDocPath);
            if (resource instanceof org.wso2.carbon.registry.core.Collection) {
                List<String> docPaths = getDocPaths((org.wso2.carbon.registry.core.Collection) resource, apiOrAPIProductDocPath);
                for (String docPath : docPaths) {
                    if (!(docPath.equalsIgnoreCase(pathToContent) || docPath.equalsIgnoreCase(pathToDocFile))) {
                        Resource docResource = registry.get(docPath);
                        GenericArtifactManager artifactManager = getAPIGenericArtifactManager(registry, docArtifactKeyType);
                        GenericArtifact docArtifact = artifactManager.getGenericArtifact(docResource.getUUID());
                        Documentation doc = APIUtil.getDocumentation(docArtifact);
                        Date contentLastModifiedDate;
                        Date docLastModifiedDate = docResource.getLastModified();
                        if (Documentation.DocumentSourceType.INLINE.equals(doc.getSourceType()) || Documentation.DocumentSourceType.MARKDOWN.equals(doc.getSourceType())) {
                            String contentPath = StringUtils.EMPTY;
                            if (id instanceof APIIdentifier) {
                                contentPath = APIUtil.getAPIDocContentPath((APIIdentifier) id, doc.getName());
                            } else if (id instanceof APIProductIdentifier) {
                                contentPath = APIUtil.getProductDocContentPath((APIProductIdentifier) id, doc.getName());
                            }
                            contentLastModifiedDate = registry.get(contentPath).getLastModified();
                            doc.setLastUpdated((contentLastModifiedDate.after(docLastModifiedDate) ? contentLastModifiedDate : docLastModifiedDate));
                        } else {
                            doc.setLastUpdated(docLastModifiedDate);
                        }
                        documentationList.add(doc);
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Failed to get documentations for api/product " + id.getName();
        throw new APIManagementException(msg, e);
    }
    return documentationList;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) ArrayList(java.util.ArrayList) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Date(java.util.Date) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Collection(org.wso2.carbon.registry.core.Collection) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

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