use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class GetValues method execute.
public void execute(Context ctx) {
BMap<String, BValue> map = (BMap<String, BValue>) ctx.getRefArgument(0);
Set<String> keySet = map.keySet();
BRefValueArray bRefValueArray = new BRefValueArray(BTypes.typeAny);
int i = 0;
for (String key : keySet) {
BValue value = map.get(key);
bRefValueArray.add(i, ((BRefType) value));
i++;
}
ctx.setReturnValues(bRefValueArray);
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class StreamLiteralTest method testStreamPublishingAndSubscriptionForMultipleEvents.
@Test(description = "Test receipt of multiple events with correct subscription and publishing")
public void testStreamPublishingAndSubscriptionForMultipleEvents() {
BValue[] returns = BRunUtil.invoke(result, "testStreamPublishingAndSubscriptionForMultipleEvents");
BRefValueArray publishedEmployeeEvents = (BRefValueArray) returns[0];
BRefValueArray receivedEmployeeEvents = (BRefValueArray) returns[1];
Assert.assertNotNull(publishedEmployeeEvents);
Assert.assertNotNull(receivedEmployeeEvents);
Assert.assertEquals(publishedEmployeeEvents.size(), receivedEmployeeEvents.size(), "Number of Employee " + "Events received does not match the number published");
for (int i = 0; i < publishedEmployeeEvents.size(); i++) {
BStruct publishedEmployeeEvent = (BStruct) publishedEmployeeEvents.get(i);
BStruct receivedEmployeeEvent = (BStruct) receivedEmployeeEvents.get(i);
Assert.assertTrue(Objects.equals(publishedEmployeeEvent.getType().getName(), receivedEmployeeEvent.getType().getName()));
Assert.assertEquals(publishedEmployeeEvent.getIntField(0), receivedEmployeeEvent.getIntField(0), "Struct field \"id\" of received event does not match that of published event");
Assert.assertEquals(publishedEmployeeEvent.getStringField(0), receivedEmployeeEvent.getStringField(0), "Struct field \"name\" of received event does not match that of published event");
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class VectorTest method testRemove.
@Test(description = "Test case for testing removal of elements from a vector.")
public void testRemove() {
long[] expectedVals = new long[] { 20, 30, 50, 60, 70, 80, 90 };
long[] removedVals = new long[] { 10, 40, 100 };
long vectorSize = 10;
BValue[] returns = BRunUtil.invoke(compileResult, "testRemove", new BValue[] { new BInteger(vectorSize) });
Assert.assertNotNull(returns);
BStruct vector = (BStruct) returns[0];
BRefValueArray vectorEntries = (BRefValueArray) vector.getRefField(0);
long finalVectorSize = vector.getIntField(0);
Assert.assertEquals(finalVectorSize, expectedVals.length);
for (int i = 0; i < removedVals.length; i++) {
Assert.assertEquals(((BInteger) returns[i + 1]).intValue(), removedVals[i]);
}
for (int i = 0; i < finalVectorSize; i++) {
Assert.assertEquals(vectorEntries.get(i).value(), expectedVals[i]);
}
for (int i = (int) finalVectorSize; i < vectorEntries.size(); i++) {
Assert.assertNull(vectorEntries.get(i));
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class Util method prepareRequestWithMultiparts.
/**
* Prepare carbon request message with multiparts.
*
* @param outboundRequest Represent outbound carbon request
* @param requestStruct Ballerina request struct which contains multipart data
*/
private static void prepareRequestWithMultiparts(HTTPCarbonMessage outboundRequest, BStruct requestStruct) {
BStruct entityStruct = requestStruct.getNativeData(MESSAGE_ENTITY) != null ? (BStruct) requestStruct.getNativeData(MESSAGE_ENTITY) : null;
if (entityStruct != null) {
BRefValueArray bodyParts = entityStruct.getNativeData(BODY_PARTS) != null ? (BRefValueArray) entityStruct.getNativeData(BODY_PARTS) : null;
if (bodyParts != null) {
HttpDataFactory dataFactory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);
setDataFactory(dataFactory);
try {
HttpPostRequestEncoder nettyEncoder = new HttpPostRequestEncoder(dataFactory, outboundRequest.getNettyHttpRequest(), true);
for (int i = 0; i < bodyParts.size(); i++) {
BStruct bodyPart = (BStruct) bodyParts.get(i);
encodeBodyPart(nettyEncoder, outboundRequest.getNettyHttpRequest(), bodyPart);
}
nettyEncoder.finalizeRequest();
requestStruct.addNativeData(MULTIPART_ENCODER, nettyEncoder);
} catch (HttpPostRequestEncoder.ErrorDataEncoderException e) {
log.error("Error occurred while creating netty request encoder for multipart data binding", e.getMessage());
}
}
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class SystemTest method testFormatBooleanTrue.
@Test
public void testFormatBooleanTrue() {
BRefValueArray fArgs = new BRefValueArray();
fArgs.add(0, new BBoolean(true));
BValue[] args = { new BString("%b"), fArgs };
BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
Assert.assertEquals(returns[0].stringValue(), "true");
}
Aggregations