ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.67k stars 751 forks source link

CodeGenerator throws BallerinaException when compiling tests #9901

Closed Seralahthan closed 6 years ago

Seralahthan commented 6 years ago

Description: Getting a ballerina build failure with

Compiling tests soap_consumer_client_test.bal error:./soap_consumer_client_test.bal:10:64: mismatched input '\n '. expecting XMLLiteralEnd ballerina: Oh no, something really went wrong. Bad. Sad.

ballerina-internal.log files have the following ballerina exception thrown by the compiler.

ERROR {org.ballerinalang.launcher.Main} - error : compilation failed org.ballerinalang.util.exceptions.BallerinaException: error : compilation failed at org.ballerinalang.testerina.core.BTestRunner.lambda$compileAndBuildSuites$7(BTestRunner.java:175) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) at org.ballerinalang.testerina.core.BTestRunner.compileAndBuildSuites(BTestRunner.java:155) at org.ballerinalang.testerina.core.BTestRunner.runTest(BTestRunner.java:97) at org.ballerinalang.testerina.core.BTestRunner.runTest(BTestRunner.java:82) at org.ballerinalang.testerina.core.BTestRunner.runTest(BTestRunner.java:71) at org.ballerinalang.testerina.core.TestCmd.execute(TestCmd.java:160) at java.util.Optional.ifPresent(Optional.java:159) at org.ballerinalang.launcher.Main.main(Main.java:66)

Steps to reproduce: Run the following lines using 0.980.1

`import ballerina/io;
 import ballerina/test;
 import soap_consumer_client;
 import wso2/soap;

 @test:Config
 function testSoapConsumerClient() {
    io:println("Starting the test for Soap Consumer Client...");

xml soapResp1 = xml `<?xml version="1.0" encoding="UTF-8"?>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
    <ns:return xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:GetQuoteResponse">
        <ax21:change>3.8023739781944386</ax21:change>
        <ax21:earnings>-9.58706726808414</ax21:earnings>
        <ax21:high>90.1204744818775</ax21:high>
        <ax21:last>87.00770771274415</ax21:last>
        <ax21:lastTradeTimestamp>Wed Jan 10 10:17:04 IST 2018</ax21:lastTradeTimestamp>
        <ax21:low>89.96298980939689</ax21:low>
        <ax21:marketCap>5.349140522956562E7</ax21:marketCap>
        <ax21:name>WSO2 Company</ax21:name>
        <ax21:open>-85.85962074870565</ax21:open>
        <ax21:peRatio>-19.963567651822213</ax21:peRatio>
        <ax21:percentageChange>3.867313309537189</ax21:percentageChange>
        <ax21:prevClose>98.32081535306169</ax21:prevClose>
        <ax21:symbol>WSO2</ax21:symbol>
        <ax21:volume>16449</ax21:volume>
    </ns:return>
</ns:getQuoteResponse>`;

var resp1 = soap_consumer_client:unsecureSoapConsumerClient();
io:println("Running the test for Unsecure Soap Consumer Client");
match resp1 {
    soap:SoapResponse soapResponse => {
        test:assertEquals(soapResp1, resp1);
    }
    soap:SoapError soapError => {
        test:assertFail(msg = "Failed to retrieve data from the Soap end point");
    }
}

}`

Affected Versions: Running the code on Ballerina-0.980.1. VS Code Plugin 0.980.1.vsix

OS, DB, other environment details and versions: Ubuntu:16.04

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

VijithaEkanayake-zz commented 6 years ago

Hi @Seralahthan,

XML Literal (xml some content) only allows parsing a single xml item (a single element, text, comment or a processing instruction). However, in soapResp1 contains two items within the literal. That's why it fails.

The solution is to define them separately and concat them as below.

xml docType = xml `<?xml version="1.0" encoding="UTF-8"?>` ;

xml soapPayload = xml `<ns:getQuoteResponse xmlns:ns="http://services.samples">
    <ns:return xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:GetQuoteResponse">
        <ax21:change>3.8023739781944386</ax21:change>
        <ax21:earnings>-9.58706726808414</ax21:earnings>
        <ax21:high>90.1204744818775</ax21:high>
        <ax21:last>87.00770771274415</ax21:last>
        <ax21:lastTradeTimestamp>Wed Jan 10 10:17:04 IST 2018</ax21:lastTradeTimestamp>
        <ax21:low>89.96298980939689</ax21:low>
        <ax21:marketCap>5.349140522956562E7</ax21:marketCap>
        <ax21:name>WSO2 Company</ax21:name>
        <ax21:open>-85.85962074870565</ax21:open>
        <ax21:peRatio>-19.963567651822213</ax21:peRatio>
        <ax21:percentageChange>3.867313309537189</ax21:percentageChange>
        <ax21:prevClose>98.32081535306169</ax21:prevClose>
        <ax21:symbol>WSO2</ax21:symbol>
        <ax21:volume>16449</ax21:volume>
    </ns:return>
</ns:getQuoteResponse>`;

xml finalXml = docType + soapPayload;
VijithaEkanayake-zz commented 6 years ago

Solution shared, hence closing the issue.