use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class AbstractSecureClientTestCase method testOutbound.
@Test
public void testOutbound() throws Exception {
expectException();
String payload = "test-payload";
MuleEventSpy spy = spyMessage(payload.getBytes());
for (Code call : outboundCalls) {
spy.clear();
Request request = new Request(call);
request.setURI(uri.resolve(getPath(call)));
switch(call) {
case DELETE:
case GET:
request.setUnintendedPayload();
break;
default:
break;
}
request.setPayload("nothing important");
CoapResponse response = client.advanced(request);
assertNotNull("get gave no response", response);
assertTrue("response indicates failure: " + response.getCode() + " msg: " + response.getResponseText(), response.isSuccess());
assertArrayEquals("wrong payload in response", payload.getBytes(), response.getPayload());
assertEquals("wrong number of spied events", 1, spy.getEvents().size());
client.shutdown();
}
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class AbstractSecureClientTestCase method spyMessage.
/**
* Create spy for requests with a message replacement
* @return the spy
*/
private MuleEventSpy spyMessage(byte[] replacement) {
MuleEventSpy spy = new MuleEventSpy("securityTest", null, replacement);
spy.clear();
return spy;
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class InsecureClientTest method testInsecureClientDelete.
@Test()
public void testInsecureClientDelete() throws Exception {
MuleEventSpy spy = spyMessage();
Code call = Code.DELETE;
CoapClient client = getClient(getPath(call));
Request request = new Request(call);
CoapResponse response = client.advanced(request);
assertNull("should not receive a response", response);
assertSpy(spy);
client.shutdown();
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy 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.test.utils.MuleEventSpy 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()));
}
Aggregations