Search in sources :

Example 86 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class WorkerInFunctionTest method testWorkerMultipleInteractions.

@Test(description = "Test worker interactions with each other")
public void testWorkerMultipleInteractions() {
    CompileResult result = BCompileUtil.compile("test-src/workers/worker-multiple-interactions.bal");
    BValue[] args = { new BInteger(100) };
    BValue[] returns = BRunUtil.invoke(result, "testMultiInteractions", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertTrue(returns[0] instanceof BInteger);
    final String expected = "1103";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) CompileResult(org.ballerinalang.launcher.util.CompileResult) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 87 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class VMDebuggerUtil method setupProgram.

private static TestDebugger setupProgram(String sourceFilePath, BreakPointDTO[] breakPoints) {
    CompileResult result = BCompileUtil.compile(sourceFilePath);
    TestDebugger debugger = new TestDebugger(result.getProgFile());
    result.getProgFile().setDebugger(debugger);
    debugger.setDebugEnabled();
    String[] args = { "Hello", "World" };
    DebuggerExecutor executor = new DebuggerExecutor(result, args, debugger, new ArrayList<>(Arrays.asList(breakPoints)));
    (new Thread(executor)).start();
    return debugger;
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult)

Example 88 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class BalGenToolTest method testUnaryHelloWorld.

@Test(enabled = false)
public void testUnaryHelloWorld() throws IllegalAccessException, ClassNotFoundException, InstantiationException, IOException {
    Class<?> grpcCmd = Class.forName("org.ballerinalang.protobuf.cmd.GrpcCmd");
    GrpcCmd grpcCmd1 = (GrpcCmd) grpcCmd.newInstance();
    Path sourcePath = Paths.get("protoFiles");
    Path sourceRoot = resourceDir.resolve(sourcePath);
    Path protoPath = Paths.get("protoFiles/helloWorld.proto");
    Path protoRoot = resourceDir.resolve(protoPath);
    grpcCmd1.setBalOutPath(sourceRoot.toString());
    grpcCmd1.setProtoPath(protoRoot.toString());
    grpcCmd1.execute();
    Path sourceFileRoot = resourceDir.resolve(Paths.get("protoFiles/helloWorld.pb.bal"));
    Path destFileRoot = resourceDir.resolve(Paths.get("protoFiles/helloWorld.gen.pb.bal"));
    removePackage(sourceFileRoot.toString(), destFileRoot.toString());
    CompileResult compileResult = BCompileUtil.compile(destFileRoot.toString());
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getStructInfo("helloWorldClient"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getStructInfo("helloWorldBlockingClient"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getStructInfo("helloWorldBlockingStub"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getFunctionInfo("helloWorldBlockingStub.hello"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getFunctionInfo("helloWorldStub.hello"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getFunctionInfo("helloWorldBlockingStub.bye"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getFunctionInfo("helloWorldStub.bye"), "Connector not found.");
    BalFileGenerationUtils.delete(new File(protoExeName));
}
Also used : Path(java.nio.file.Path) GrpcCmd(org.ballerinalang.protobuf.cmd.GrpcCmd) CompileResult(org.ballerinalang.launcher.util.CompileResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 89 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class BalGenToolTest method testClientStreamingHelloWorld.

@Test(enabled = false)
public void testClientStreamingHelloWorld() throws IllegalAccessException, ClassNotFoundException, InstantiationException, IOException {
    Class<?> grpcCmd = Class.forName("org.ballerinalang.protobuf.cmd.GrpcCmd");
    GrpcCmd grpcCmd1 = (GrpcCmd) grpcCmd.newInstance();
    Path sourcePath = Paths.get("protoFiles");
    Path sourceRoot = resourceDir.resolve(sourcePath);
    Path protoPath = Paths.get("protoFiles/helloWorldClientStreaming.proto");
    Path protoRoot = resourceDir.resolve(protoPath);
    grpcCmd1.setBalOutPath(sourceRoot.toString());
    grpcCmd1.setProtoPath(protoRoot.toString());
    grpcCmd1.execute();
    Path sourceFileRoot = resourceDir.resolve(Paths.get("protoFiles/helloWorldClientStreaming.pb.bal"));
    Path destFileRoot = resourceDir.resolve(Paths.get("protoFiles/helloWorldClientStreaming.gen.pb.bal"));
    removePackage(sourceFileRoot.toString(), destFileRoot.toString());
    CompileResult compileResult = BCompileUtil.compile(destFileRoot.toString());
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getStructInfo("helloWorldClientStreamingClient"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getStructInfo("helloWorldClientStreamingStub"), "Connector not found.");
    Assert.assertNotNull(compileResult.getProgFile().getPackageInfo(PACKAGE_NAME).getFunctionInfo("helloWorldClientStreamingStub.LotsOfGreetings"), "Connector not found.");
    BalFileGenerationUtils.delete(new File(protoExeName));
}
Also used : Path(java.nio.file.Path) GrpcCmd(org.ballerinalang.protobuf.cmd.GrpcCmd) CompileResult(org.ballerinalang.launcher.util.CompileResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 90 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class ObjectTest method testObjectWithSimpleInitWithDiffValues.

@Test(description = "Test object with init with different values")
public void testObjectWithSimpleInitWithDiffValues() {
    CompileResult compileResult = BCompileUtil.compile("test-src/object/object-with-init-func.bal");
    BValue[] returns = BRunUtil.invoke(compileResult, "testObjectWithSimpleInitWithDiffValues");
    Assert.assertEquals(returns.length, 4);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    Assert.assertSame(returns[1].getClass(), BString.class);
    Assert.assertSame(returns[2].getClass(), BInteger.class);
    Assert.assertSame(returns[3].getClass(), BString.class);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 37);
    Assert.assertEquals(returns[1].stringValue(), "sample value1");
    Assert.assertEquals(((BInteger) returns[2]).intValue(), 675);
    Assert.assertEquals(returns[3].stringValue(), "adding value in invocation");
}
Also used : BValue(org.ballerinalang.model.values.BValue) CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Aggregations

CompileResult (org.ballerinalang.launcher.util.CompileResult)291 Test (org.testng.annotations.Test)287 BValue (org.ballerinalang.model.values.BValue)60 PackageNode (org.ballerinalang.model.tree.PackageNode)16 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)14 BString (org.ballerinalang.model.values.BString)13 BInteger (org.ballerinalang.model.values.BInteger)12 Path (java.nio.file.Path)5 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 File (java.io.File)4 GrpcCmd (org.ballerinalang.protobuf.cmd.GrpcCmd)4 BStringArray (org.ballerinalang.model.values.BStringArray)3 BLangDeprecatedNode (org.wso2.ballerinalang.compiler.tree.BLangDeprecatedNode)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BFloat (org.ballerinalang.model.values.BFloat)2 BIntArray (org.ballerinalang.model.values.BIntArray)2 BMap (org.ballerinalang.model.values.BMap)2 BeforeTest (org.testng.annotations.BeforeTest)2 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)2