use of org.wso2.carbon.apimgt.persistence.dto.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");
}
use of org.wso2.carbon.apimgt.persistence.dto.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");
}
use of org.wso2.carbon.apimgt.persistence.dto.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");
}
use of org.wso2.carbon.apimgt.persistence.dto.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.");
}
use of org.wso2.carbon.apimgt.persistence.dto.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;
}
Aggregations