use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.
the class OptLocationQueryOutbound1Test method getPropertyValue.
@Override
protected Object getPropertyValue() {
LinkedList<QueryParam> list = new LinkedList<>();
list.add(new QueryParam("first", "1"));
list.add(new QueryParam("second", "2"));
return list;
}
use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.
the class OptLocationQueryOutbound2Test method getPropertyValue.
@Override
protected Object getPropertyValue() {
LinkedList<QueryParam> list = new LinkedList<>();
list.add(new QueryParam("first", "1"));
list.add(new QueryParam("second", "2"));
list.add(new QueryParam("third", null));
return list;
}
use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.
the class QueryTest method testSyncRequest.
/**
* Test Sync request with query parameters.
* @throws Exception should not happen in this test
*/
@Test
public void testSyncRequest() throws Exception {
MuleEventSpy spy = new MuleEventSpy("query-handler");
spy.clear();
LinkedList<QueryParam> params = new LinkedList<>();
params.add(new QueryParam("query1", "one"));
params.add(new QueryParam("query2", "two"));
params.add(new QueryParam("query3", null));
Event result = flowRunner("request-sync").keepStreamsOpen().withPayload("nothing_important").withVariable("code", requestCode.toString()).withVariable("query", params).run();
Message response = result.getMessage();
// assertions...
// assertTrue( "wrong response payload type", response.getPayload().getDataType().isCompatibleWith( DataType.BYTE_ARRAY ) );
assertNotNull("no mule event", response);
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertTrue("request failed", attributes.isSuccess());
assertEquals("wrong request uri", expectedRequestUri(params), attributes.getRequestUri());
CursorStreamProvider responsePayload = (CursorStreamProvider) TypedValue.unwrap(response.getPayload());
assertArrayEquals("wrong response payload", expectedPayload(requestCode, params).getBytes(Defs.COAP_CHARSET), IOUtils.toByteArray(responsePayload.openCursor()));
}
use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.
the class QueryTest method testRequestSyncWithDefaults1.
/**
* Test Sync request with default query parameters.
* @throws Exception should not happen in this test
*/
@Test
public void testRequestSyncWithDefaults1() throws Exception {
MuleEventSpy spy = new MuleEventSpy("query-handler");
spy.clear();
LinkedList<QueryParam> params = new LinkedList<>();
params.add(new QueryParam("query1", "one"));
params.add(new QueryParam("query2", "two"));
params.add(new QueryParam("query3", null));
LinkedList<QueryParam> expectedParams = new LinkedList<>();
expectedParams.add(new QueryParam("test1", "one"));
expectedParams.add(new QueryParam("test2", "two"));
expectedParams.add(new QueryParam("novalue1", null));
expectedParams.add(new QueryParam("query1", "one"));
expectedParams.add(new QueryParam("query2", "two"));
expectedParams.add(new QueryParam("query3", null));
Event result = flowRunner("request-sync-with-defaults").keepStreamsOpen().withPayload("nothing_important").withVariable("code", requestCode.toString()).withVariable("query", params).run();
Message response = result.getMessage();
// assertions...
// assertTrue( "wrong response payload type", response.getPayload().getDataType().isCompatibleWith( DataType.BYTE_ARRAY ) );
assertNotNull("no mule event", response);
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertTrue("request failed", attributes.isSuccess());
assertEquals("wrong request uri", expectedRequestUri(expectedParams), attributes.getRequestUri());
CursorStreamProvider responsePayload = (CursorStreamProvider) TypedValue.unwrap(response.getPayload());
assertArrayEquals("wrong response payload", expectedPayload(requestCode, expectedParams).getBytes(Defs.COAP_CHARSET), IOUtils.toByteArray(responsePayload.openCursor()));
}
use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.
the class QueryTest method testFixedAsyncRequest.
/**
* Test Async request with fixed query parameters.
* @throws Exception should not happen in this test
*/
@Test
public void testFixedAsyncRequest() throws Exception {
MuleEventSpy spy = new MuleEventSpy("query-handler");
spy.clear();
LinkedList<QueryParam> params = new LinkedList<>();
params.add(new QueryParam("query1", "one"));
params.add(new QueryParam("query2", "two"));
params.add(new QueryParam("query3", null));
LinkedList<QueryParam> expectedParams = new LinkedList<>();
expectedParams.add(new QueryParam("test3", "three"));
expectedParams.add(new QueryParam("test4", "four"));
expectedParams.add(new QueryParam("novalue2", null));
Event result = flowRunner("request-async-fixed").withPayload("nothing_important").withVariable("code", requestCode.toString()).withVariable("query", params).run();
Message response = result.getMessage();
assertTrue("wrong response payload", response.getPayload().getDataType().isCompatibleWith(DataType.STRING));
assertEquals("wrong response payload", "nothing_important", (String) response.getPayload().getValue());
// let handler do its asynchronous work
await().atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1;
});
// assertions...
response = (Message) spy.getEvents().get(0).getContent();
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertTrue("error response", attributes.isSuccess());
assertEquals("wrong request uri", expectedRequestUri(expectedParams), attributes.getRequestUri());
assertArrayEquals("wrong response payload", expectedPayload(requestCode, expectedParams).getBytes(Defs.COAP_CHARSET), (byte[]) response.getPayload().getValue());
}
Aggregations