Search in sources :

Example 81 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class HtmlDocTest method testAnnotations.

@Test(description = "Annotation in a package should be shown in the constructs")
public void testAnnotations() throws Exception {
    BLangPackage bLangPackage = createPackage("package x.y; " + "public annotation ParameterInfo;" + "public annotation ReturnInfo;");
    Page page = generatePage(bLangPackage);
    Assert.assertEquals(page.constructs.size(), 2);
    Assert.assertEquals(page.constructs.get(0).name, "ParameterInfo");
    Assert.assertEquals(page.constructs.get(1).name, "ReturnInfo");
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) Page(org.ballerinalang.docgen.model.Page) Test(org.testng.annotations.Test)

Example 82 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class Generator method generatePage.

/**
 * Generate the page when the bal package is passed.
 * @param balPackage The current package that is being viewed.
 * @param packages List of available packages.
 * @return A page model for the current package.
 */
public static Page generatePage(BLangPackage balPackage, List<Link> packages) {
    ArrayList<Documentable> documentables = new ArrayList<>();
    String currentPackageName = (balPackage.symbol).pkgID.name.value;
    // Check for structs in the package
    if (balPackage.getStructs().size() > 0) {
        for (BLangStruct struct : balPackage.getStructs()) {
            if (struct.getFlags().contains(Flag.PUBLIC)) {
                documentables.add(createDocForNode(struct));
            }
        }
    }
    // Check for functions in the package
    if (balPackage.getFunctions().size() > 0) {
        for (BLangFunction function : balPackage.getFunctions()) {
            if (function.getFlags().contains(Flag.PUBLIC)) {
                if (function.getReceiver() != null) {
                    if (documentables.size() > 0) {
                        for (Documentable parentDocumentable : documentables) {
                            TypeNode langType = function.getReceiver().getTypeNode();
                            String typeName = (langType instanceof BLangUserDefinedType ? ((BLangUserDefinedType) langType).typeName.value : langType.toString());
                            if (typeName.equals(parentDocumentable.name)) {
                                parentDocumentable.children.add(createDocForNode(function));
                            }
                        }
                    }
                } else {
                    // If there's no receiver type i.e. no struct binding to the function
                    documentables.add(createDocForNode(function));
                }
            }
        }
    }
    // Check for connectors in the package
    for (BLangConnector connector : balPackage.getConnectors()) {
        if (connector.getFlags().contains(Flag.PUBLIC)) {
            documentables.add(createDocForNode(connector));
        }
    }
    // Check for connectors in the package
    for (EnumNode enumNode : balPackage.getEnums()) {
        if (enumNode.getFlags().contains(Flag.PUBLIC)) {
            documentables.add(createDocForNode(enumNode));
        }
    }
    // Check for annotations
    for (BLangAnnotation annotation : balPackage.getAnnotations()) {
        if (annotation.getFlags().contains(Flag.PUBLIC)) {
            documentables.add(createDocForNode(annotation));
        }
    }
    // Check for global variables
    for (BLangVariable var : balPackage.getGlobalVariables()) {
        if (var.getFlags().contains(Flag.PUBLIC)) {
            documentables.add(createDocForNode(var));
        }
    }
    // Create the links to select which page or package is active
    List<Link> links = new ArrayList<>();
    PackageName packageNameHeading = null;
    for (Link pkgLink : packages) {
        if (pkgLink.caption.value.equals(currentPackageName)) {
            packageNameHeading = (PackageName) pkgLink.caption;
            links.add(new Link(pkgLink.caption, pkgLink.href, true));
        } else {
            links.add(new Link(pkgLink.caption, pkgLink.href, false));
        }
    }
    return new Page(packageNameHeading, documentables, links);
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) PackageName(org.ballerinalang.docgen.model.PackageName) ArrayList(java.util.ArrayList) EnumNode(org.ballerinalang.model.tree.EnumNode) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) Page(org.ballerinalang.docgen.model.Page) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Documentable(org.ballerinalang.docgen.model.Documentable) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) TypeNode(org.ballerinalang.model.tree.types.TypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) Link(org.ballerinalang.docgen.model.Link)

Example 83 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class DocumentationTest method testDocEnum.

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

Example 84 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class DocumentationTest method testMultiple.

@Test(description = "Test doc multiple.")
public void testMultiple() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/multiple.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 Tst struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " annotation `field a` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " annotation `field b` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " annotation `field c` documentation");
    docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for state enum\n");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "foo");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " enum `field foo` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "bar");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " enum `field bar` documentation");
    docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + " Transformer Foo Person -> Employee\n" + " ");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "p");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "e");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
    BLangService service = (BLangService) packageNode.getServices().get(0);
    docNodes = service.docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
/*
        // Commented due to https://github.com/ballerina-lang/ballerina/issues/5586 issue
        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) 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 85 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testBogusProducesAnnotation.

@Test(description = "Test bogus Produces annotation with URL. /echo66/test2 ")
public void testBogusProducesAnnotation() {
    String path = "/echo66/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), ":,;,v567br");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
    Assert.assertEquals(trueResponse, 406, "Not acceptable");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7