Search in sources :

Example 6 with BXMLItem

use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.

the class JSONTest method testToXMLJsonWithStringValue.

@Test(description = "Convert a json object with string value only")
public void testToXMLJsonWithStringValue() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLStringValue");
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(((OMText) returnElement).getText(), "value");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) Test(org.testng.annotations.Test)

Example 7 with BXMLItem

use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.

the class BMapValueTest method testBMapToString.

@Test(description = "Testing convert map values to string")
public void testBMapToString() {
    BMap<String, BRefType> map = new BMap<>();
    map.put(new String("key1"), new BInteger(1));
    map.put(new String("key2"), new BString("foo"));
    map.put(new String("key3"), new BXMLItem("<bar>hello</bar>"));
    Assert.assertEquals(map.stringValue(), "{\"key1\":1, \"key2\":\"foo\", \"key3\":<bar>hello</bar>}");
}
Also used : BRefType(org.ballerinalang.model.values.BRefType) BXMLItem(org.ballerinalang.model.values.BXMLItem) BMap(org.ballerinalang.model.values.BMap) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 8 with BXMLItem

use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.

the class StringTest method testXmlValueOf.

@Test
public void testXmlValueOf() {
    BValue[] args = { new BXMLItem("<test>name</test>") };
    BValue[] returns = BRunUtil.invoke(result, "xmlValueOf", args);
    Assert.assertTrue(returns[0] instanceof BString);
    final String expected = "<test>name</test>";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 9 with BXMLItem

use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.

the class StringTest method testXmlValueOfNegative.

// TODO test this
@Test(expectedExceptions = { BLangRuntimeException.class })
public void testXmlValueOfNegative() {
    BValue[] args = { new BXMLItem("<test>name<test>") };
    BRunUtil.invoke(result, "xmlValueOf", args);
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 10 with BXMLItem

use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.

the class XMLNativeFunctionTest method testToJsonWithMultipleAttributesNamespaces.

@Test
public void testToJsonWithMultipleAttributesNamespaces() {
    String xmlStr = "<ns0:bookStore status=\"online\" xmlns:ns0=\"http://sample0.com/test\" " + "xmlns:ns1=\"http://sample1.com/test\"><ns0:storeName>foo</ns0:storeName>" + "<ns3:postalCode xmlns:ns3=\"http://sample3.com/test\">94</ns3:postalCode>" + "<ns0:isOpen>true</ns0:isOpen><ns2:address xmlns:ns2=\"http://sample2.com/test\">" + "<ns2:street>foo</ns2:street><ns2:city>111</ns2:city><ns2:country>true</ns2:country>" + "</ns2:address><ns4:codes xmlns:ns4=\"http://sample4.com/test\"><ns4:item>4</ns4:item><ns4:item>8" + "</ns4:item><ns4:item>9</ns4:item></ns4:codes></ns0:bookStore>";
    BValue[] args = { new BXMLItem(xmlStr) };
    BValue[] returns = BRunUtil.invoke(result, "testToJSON", args);
    Assert.assertTrue(returns[0] instanceof BJSON);
    Assert.assertEquals(returns[0].stringValue(), "{\"ns0:bookStore\":{\"@xmlns:ns0\":\"http://sample0.com/test\"," + "\"@xmlns:ns1\":\"http://sample1.com/test\",\"@status\":\"online\",\"ns0:storeName\":\"foo\"," + "\"ns0:isOpen\":\"true\",\"ns3:postalCode\":{\"@xmlns:ns3\":\"http://sample3.com/test\"," + "\"#text\":\"94\"},\"ns2:address\":{\"@xmlns:ns2\":\"http://sample2.com/test\"," + "\"ns2:street\":\"foo\",\"ns2:city\":\"111\",\"ns2:country\":\"true\"}," + "\"ns4:codes\":{\"@xmlns:ns4\":\"http://sample4.com/test\",\"ns4:item\":[\"4\",\"8\",\"9\"]}}}");
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

BXMLItem (org.ballerinalang.model.values.BXMLItem)56 Test (org.testng.annotations.Test)46 BValue (org.ballerinalang.model.values.BValue)42 BJSON (org.ballerinalang.model.values.BJSON)36 BString (org.ballerinalang.model.values.BString)26 OMNode (org.apache.axiom.om.OMNode)18 BXML (org.ballerinalang.model.values.BXML)17 BStruct (org.ballerinalang.model.values.BStruct)6 OMElement (org.apache.axiom.om.OMElement)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)5 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)4 ArrayList (java.util.ArrayList)3 OMText (org.apache.axiom.om.OMText)3 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)3 OMDocument (org.apache.axiom.om.OMDocument)2 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)2 BFloatArray (org.ballerinalang.model.values.BFloatArray)2 BIntArray (org.ballerinalang.model.values.BIntArray)2 BStringArray (org.ballerinalang.model.values.BStringArray)2 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)2