Commit aec646b0 authored by Ryan Berkheimer's avatar Ryan Berkheimer

added successful test conditions for return list field values (and order)

parent 81e5eb8f
Pipeline #5745 failed with stages
in 0 seconds
......@@ -30,6 +30,9 @@
"constructor": {"native-library": "/Users/rberkheimer/projects/asos/ingest/libraries/messageapi/lib/test/native/demoendpointlibrary/libDemoEndpointLibrary.jnilib",
"default-fields": [{"id": "test-integer",
"type": "integer",
"required": false},
{"id": "return-list",
"type": "list(string)",
"required": false}],
"state-container": [{"id": "counter",
"type": "integer",
......
......@@ -82,6 +82,14 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_endpoints_NativeEndpoint_proc
}
}
fflush(stdout);
printf("Creating a string list\n");
struct val_list *return_val_list = createList(message);
addStringEntry(message, return_val_list, "first element of our string!");
addStringEntry(message, return_val_list, "second element of our string!!");
printf("Created a string list.\n");
setFieldListVal(message, getField(message, returnRecord, "return-list"), return_val_list);
printf("Added the string list to the return record. Should have two elements, see above.\n");
fflush(stdout);
struct packet* packet = createPacket(message);
addPacketRecord(message, packet, returnRecord);
printf("Leaving our C test!");
......
......@@ -3,44 +3,48 @@
* @author Ryan Berkheimer
*/
import gov.noaa.messageapi.interfaces.ISession;
import gov.noaa.messageapi.interfaces.IRequest;
import gov.noaa.messageapi.interfaces.IResponse;
import gov.noaa.messageapi.interfaces.IRejection;
import gov.noaa.messageapi.interfaces.IRecord;
import gov.noaa.messageapi.interfaces.IField;
import java.util.List
import gov.noaa.messageapi.sessions.DefaultSession;
import gov.noaa.messageapi.interfaces.ISession
import gov.noaa.messageapi.interfaces.IRequest
import gov.noaa.messageapi.interfaces.IResponse
import gov.noaa.messageapi.interfaces.IRejection
import gov.noaa.messageapi.interfaces.IRecord
import gov.noaa.messageapi.interfaces.IField
import gov.noaa.messageapi.sessions.DefaultSession
class NativeEndpointTests extends spock.lang.Specification {
def "Tests submission of a very simple native task with only one endpoint that calls into C and increments a counter."() {
given: "A session created based on a native counter"
ISession session = new DefaultSession("{}/resources/test/basic-native/manifest.json")
IRequest request = session.createRequest();
IRecord record1 = request.createRecord();
IRecord record2 = request.createRecord();
record1.setField("initial-value", 1000);
record1.setField("string-test", "hi there!");
record1.setField("null-test", "null");
record2.setField("string-test", "cool!");
record2.setField("initial-value", 5000);
record2.setField("null-test", "null");
def 'Session with one endpoint that calls into C, populates a return record, and checks vals.'() {
given: 'A session created based on a native counter'
ISession session = new DefaultSession('{}/resources/test/basic-native/manifest.json')
IRequest request = session.createRequest()
IRecord record1 = request.createRecord()
IRecord record2 = request.createRecord()
record1.setField('initial-value', 1000)
record1.setField('string-test', 'hi there!')
record1.setField('null-test', 'null')
record2.setField('string-test', 'cool!')
record2.setField('initial-value', 5000)
record2.setField('null-test', 'null')
/*for (int i=0; i<500; i++) {
IRecord r = request.createRecord();
r.setField("initial-value", i);
r.setField("string-test", Integer.toString(i));
}*/
when: "We submit the test session with a single endpoint, let it call into C, increment a counter, add it to a new record, and return"
IResponse response = request.submit();
while (!response.isComplete()) {}
then: "We should have no rejections, there should be one return record, and when we grab the 'test-string' field, we should get 1."
when: 'Submit to one endpoint, call into C, increment counter, return/check record'
IResponse response = request.submit()
while (!response.isComplete()) { }
then: 'No rejections, one return record, field values match..'
response.getRejections().size() == 0
//println response.getRejections().size()
response.getRecords().size() == 1
response.getRecords().get(0).getField("test-integer").getValue() == 5
response.getRecords().get(0).getField('test-integer').getValue() == 5
response.getRecords().get(0).getField('return-list').getValue().get(0) == "first element of our string!"
response.getRecords().get(0).getField('return-list').getValue().get(1) == "second element of our string!!"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment