use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy 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());
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class QueryTest method testRequestAsyncFixedWithDefaults.
/**
* Test Async request with fixed and default query parameters.
* @throws Exception should not happen in this test
*/
@Test
public void testRequestAsyncFixedWithDefaults() 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("test3", "three"));
expectedParams.add(new QueryParam("test4", "four"));
expectedParams.add(new QueryParam("novalue2", null));
Event result = flowRunner("request-async-fixed-with-defaults").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());
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class VirtualHostTestCase method testDefaultVirtualHostOverrideRequest.
/**
* Test inbound property
* @throws Exception should not happen in this test
*/
@Test
public void testDefaultVirtualHostOverrideRequest() throws Exception {
MuleEventSpy spy = new MuleEventSpy("6768");
spy.clear();
Event result = flowRunner("do_request_to_virtual_host_override").withPayload("nothing_important").withVariable("code", requestCode.name()).withVariable("host", host).withVariable("port", port).withVariable("endpointHost", endpointHost).withVariable("endpointPort", endpointPort).withVariable("path", path).run();
Message response = result.getMessage();
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertEquals("wrong response code", expectedResponseCode.name(), attributes.getResponseCode());
MuleEventSpy.Event event = spy.getEvents().get(0);
assertEquals("wrong options class", OptionSet.class, event.getContent().getClass());
OptionSet options = (OptionSet) event.getContent();
assertEquals("wrong uri host", host, options.getUriHost());
assertEquals("wrong uri port", port, options.getUriPort());
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class VirtualHostTestCase method testDefaultVirtualHostRequest.
/**
* Test inbound property
* @throws Exception should not happen in this test
*/
@Test
public void testDefaultVirtualHostRequest() throws Exception {
MuleEventSpy spy = new MuleEventSpy("6767");
spy.clear();
Event result = flowRunner("do_request_to_virtual_host").withPayload("nothing_important").withVariable("code", requestCode.name()).withVariable("host", host).withVariable("port", port).withVariable("endpointHost", endpointHost).withVariable("endpointPort", endpointPort).withVariable("path", path).run();
Message response = result.getMessage();
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertEquals("wrong response code", expectedResponseCode.name(), attributes.getResponseCode());
MuleEventSpy.Event event = spy.getEvents().get(0);
assertEquals("wrong options class", OptionSet.class, event.getContent().getClass());
OptionSet options = (OptionSet) event.getContent();
assertEquals("wrong uri host", host, options.getUriHost());
assertEquals("wrong uri port", port, options.getUriPort());
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class MulticastIPv4Test method testMulticast.
@Test(timeout = 20000L)
public void testMulticast() throws Exception {
MultiCoapHandler handler = new MultiCoapHandler();
// spyRequestMessage();
MuleEventSpy spy = new MuleEventSpy(spyId);
spy.clear();
// spyActivated.set( false );
client.useLateNegotiation();
Request request = new Request(requestCode, Type.NON);
if (unintendedPayload)
request.setUnintendedPayload();
request.setPayload(Data.getContent(contentSize));
client.advanced(handler, request);
while (handler.waitOn(15000)) ;
validateInboundResponse(handler.getResponse(), spy);
}
Aggregations