use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class BallerinaConnectorDocGenTest method testConnectorWithMultipleAction.
@Test(description = "Test single action in a connector file", enabled = false)
public void testConnectorWithMultipleAction() {
try {
Map<String, BLangPackage> docsMap = BallerinaDocGenerator.generatePackageDocsFromBallerina(sourceRoot, "balWith2Actions.bal");
Assert.assertNotNull(docsMap);
Assert.assertEquals(docsMap.size(), 1);
BallerinaDocGenTestUtils.printDocMap(docsMap);
BLangPackage balPackage = docsMap.get(".");
List<BLangConnector> connectors = balPackage.getConnectors();
Assert.assertEquals(connectors.size(), 1);
BLangConnector connector = connectors.iterator().next();
Assert.assertEquals(connector.getParameters().size(), 4);
for (BLangAction action : connector.getActions()) {
Assert.assertEquals(action.getParameters().size(), 1);
Assert.assertEquals(action.getReturnParameters().size(), 1);
}
} catch (IOException e) {
Assert.fail();
} finally {
BallerinaDocGenTestUtils.cleanUp();
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class DocumentationTest method testDocConnectorFunction.
@Test(description = "Test doc connector/function.", enabled = false)
public void testDocConnectorFunction() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/connector_function.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
BLangConnector connector = (BLangConnector) packageNode.getConnectors().get(0);
List<BLangDocumentation> docNodes = connector.docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.documentationText, "Test Connector\n");
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "url");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " url for endpoint\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "path");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " path for endpoint\n");
dNode = connector.getActions().get(0).docAttachments.get(0);
Assert.assertEquals(dNode.getAttributes().size(), 1);
Assert.assertEquals(dNode.documentationText, "Test Connector action testAction ");
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "s");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not");
dNode = connector.getActions().get(1).docAttachments.get(0);
Assert.assertEquals(dNode.documentationText, "Test Connector action testSend ");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "ep");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "s");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " which represent successful or not");
docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "file");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " file path ``C:\\users\\OddThinking\\Documents\\My Source\\Widget\\foo.src``\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "accessMode");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " read or write mode\n");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "successful");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " boolean `true` or `false`\n");
docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for File struct\n");
Assert.assertEquals(dNode.getAttributes().size(), 1);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "path");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field path` documentation\n");
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class DocumentationTest method testDeprecated.
@Test(description = "Test doc deprecated.", enabled = false)
public void testDeprecated() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/deprecated.bal");
Assert.assertEquals(compileResult.getWarnCount(), 0);
PackageNode packageNode = compileResult.getAST();
List<BLangDeprecatedNode> dNodes = ((BLangFunction) packageNode.getFunctions().get(0)).deprecatedAttachments;
BLangDeprecatedNode dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This function is deprecated use `openFile(string accessMode){}` instead.\n");
dNodes = ((BLangStruct) packageNode.getStructs().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Struct is deprecated use `File2` instead.\n");
dNodes = ((BLangEnum) packageNode.getEnums().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Enum is deprecated use `Enum2` instead.\n");
dNodes = ((BLangEnum) packageNode.getEnums().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Enum is deprecated use `Enum2` instead.\n");
dNodes = ((BLangVariable) packageNode.getGlobalVariables().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "use ```const string testConst = " + "\"TestConstantDocumentation\";``` instead");
dNodes = ((BLangConnector) packageNode.getConnectors().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Connector is deprecated use `Connector(string url2){}` instead.\n");
dNodes = ((BLangConnector) packageNode.getConnectors().get(0)).getActions().get(0).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This action is deprecated use `Connector.test(string url2){}` instead.\n" + " ");
dNodes = ((BLangService) packageNode.getServices().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Service is deprecated use `PizzaHutService{}` instead.\n");
dNodes = ((BLangService) packageNode.getServices().get(0)).getResources().get(0).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "This Resource is deprecated use `PizzaHutService.orderFromPizza()` instead.");
}
use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.
the class ParserUtils method extractConnector.
/**
* Extract connectors from ballerina lang.
*
* @param packages packages to send
* @param connector connector
*/
private static void extractConnector(Map<String, ModelPackage> packages, String packagePath, BLangConnector connector) {
String fileName = connector.getPosition().getSource().getCompilationUnitName();
if (packages.containsKey(packagePath)) {
ModelPackage modelPackage = packages.get(packagePath);
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters, connector.getParameters());
List<AnnotationAttachment> annotations = new ArrayList<>();
addAnnotations(annotations, connector.getAnnotationAttachments());
List<Action> actions = new ArrayList<>();
addActions(actions, connector.getActions());
modelPackage.addConnectorsItem(createNewConnector(connector.getName().getValue(), annotations, actions, parameters, null, fileName));
} else {
ModelPackage modelPackage = new ModelPackage();
modelPackage.setName(packagePath);
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters, connector.getParameters());
List<AnnotationAttachment> annotations = new ArrayList<>();
addAnnotations(annotations, connector.getAnnotationAttachments());
List<Action> actions = new ArrayList<>();
addActions(actions, connector.getActions());
modelPackage.addConnectorsItem(createNewConnector(connector.getName().getValue(), annotations, actions, parameters, null, fileName));
packages.put(packagePath, modelPackage);
}
}
Aggregations