use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class HtmlDocTest method testStructDefaultValues.
@Test(description = "Tests whether default values are collected.")
public void testStructDefaultValues() {
BLangPackage bLangPackage = createPackage("package x.y; " + "public struct Person {" + " string id;" + " string address = \"20,Palm Grove\";" + "}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 1);
Assert.assertTrue(page.constructs.get(0) instanceof StructDoc, "Documentable of type StructDoc expected.");
StructDoc personStructDoc = (StructDoc) page.constructs.get(0);
Assert.assertEquals(personStructDoc.fields.size(), 2, "2 fields are expected.");
Assert.assertEquals(personStructDoc.fields.get(0).name, "id", "Field \"id\" expected.");
Assert.assertEquals(personStructDoc.fields.get(1).name, "address", "Field \"address\" expected.");
Assert.assertEquals(personStructDoc.fields.get(1).defaultValue, "20,Palm Grove", "Unexpected address value found.");
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class HtmlDocTest method testConnectorPropertiesExtracted.
@Test(description = "Connector properties should be available via construct", enabled = false)
public void testConnectorPropertiesExtracted() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"Http client connector for outbound HTTP requests\"}\n" + "@Param { value:\"serviceUri: Url of the service\" }\n" + "@Param { value:\"n: connector options\" }" + "connector HttpClient (string serviceUri, int n) {" + "@Description { value:\"The POST action implementation of the HTTP ConnectorDoc\"}\n" + "@Param { value:\"path: Resource path \" }\n" + "@Param { value:\"req: An HTTP Request struct\" }\n" + "@Return { value:\"The response message\" }\n" + "@Return { value:\"Error occured during HTTP client invocation\" }\n" + "action post(string path, string req) (string, int) { return \"value within filter\"; }}");
ConnectorDoc connectorDoc = Generator.createDocForNode(bLangPackage.getConnectors().get(0));
Assert.assertEquals(connectorDoc.name, "HttpClient", "Connector name should be extracted");
Assert.assertEquals(connectorDoc.description, "Http client connector for outbound HTTP requests", "Description of the connector should be extracted");
Assert.assertEquals(connectorDoc.parameters.get(0).name, "serviceUri", "Parameter name should be extracted");
Assert.assertEquals(connectorDoc.parameters.get(0).dataType, "string", "Parameter type should be extracted");
Assert.assertEquals(connectorDoc.parameters.get(0).description, "Url of the service", "Description of the parameter type should be extracted");
// For actions inside the connector
ActionDoc actionDoc = (ActionDoc) connectorDoc.children.get(0);
Assert.assertEquals(actionDoc.name, "post", "Action name should be extracted");
Assert.assertEquals(actionDoc.description, "The POST action implementation of the HTTP ConnectorDoc", "Description of the action should be extracted");
Assert.assertEquals(actionDoc.parameters.get(0).name, "path", "Parameter name should be extracted");
Assert.assertEquals(actionDoc.parameters.get(0).dataType, "string", "Parameter type should be extracted");
Assert.assertEquals(actionDoc.parameters.get(0).description, "Resource path", "Description of the " + "parameter should be extracted");
Assert.assertEquals(actionDoc.returnParams.get(1).dataType, "int", "Return parameter type should be extracted");
Assert.assertEquals(actionDoc.returnParams.get(1).description, "Error occured during HTTP client invocation", "Description of the return parameter should be extracted");
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class HtmlDocTest method testPrimitiveConstructsWithFunctions.
@Test(description = "Testing primitive constructs.")
public void testPrimitiveConstructsWithFunctions() {
BLangPackage bLangPackage = createPackage("package ballerina.builtin;" + "public native function <blob b> data (string encoding) returns" + "(string);" + "public native function <blob b> sample () returns (string);");
List<Link> packages = new ArrayList<>();
packages.add(new Link(new PackageName((bLangPackage.symbol).pkgID.name.value, ""), "", false));
packages.add(new Link(new StaticCaption(BallerinaDocConstants.PRIMITIVE_TYPES_PAGE_NAME), BallerinaDocConstants.PRIMITIVE_TYPES_PAGE_HREF, false));
Page primitivesPage = Generator.generatePageForPrimitives(bLangPackage, packages);
Assert.assertEquals(primitivesPage.constructs.size(), 1);
Assert.assertEquals(primitivesPage.constructs.get(0).children.size(), 2);
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class HtmlDocTest method testFunctionsPropertiesExtracted.
@Test(description = "Function properties should be available via construct")
public void testFunctionsPropertiesExtracted() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"This function would say hello\"}" + "@Param { value:\"message: The message sent\" }" + "@Return { value:\"int representation of the message\" }" + "public function sayHello(string message) returns (int){}");
FunctionDoc functionDoc = Generator.createDocForNode(bLangPackage.getFunctions().get(0));
Assert.assertEquals(functionDoc.name, "sayHello", "Function name should be extracted");
Assert.assertEquals(functionDoc.description, "This function would say hello", "Description of the " + "function should be extracted");
Assert.assertEquals(functionDoc.parameters.get(0).name, "message", "Parameter name should be extracted");
Assert.assertEquals(functionDoc.parameters.get(0).dataType, "string", "Parameter type should be extracted");
Assert.assertEquals(functionDoc.parameters.get(0).description, "The message sent", "Description of the " + "parameter should be extracted");
Assert.assertEquals(functionDoc.returnParams.get(0).dataType, "int", "Return parameter type " + "should be extracted");
Assert.assertEquals(functionDoc.returnParams.get(0).description, "int representation of the message", "Description of the return parameter should be extracted");
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class WorkspaceUtils method getBallerinaFileForContent.
public static BLangPackage getBallerinaFileForContent(String fileName, String source) {
CompilerContext context = prepareCompilerContext(fileName, source);
CompilerOptions options = CompilerOptions.getInstance(context);
options.put(CompilerOptionName.COMPILER_PHASE, CompilerPhase.DEFINE.toString());
options.put(CompilerOptionName.PRESERVE_WHITESPACE, Boolean.TRUE.toString());
return getBallerinaPackage(fileName, context);
}
Aggregations