use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class AbstractOutboundPropertyTestcase method mockMessage.
/**
* Mock that sets the outbound property in the Mule flow
* @param propertyName name of the outbound property to set
* @param propertyValue value to set on the property
*/
private MuleEventSpy mockMessage(String propertyName, Object propertyValue) {
MuleEventSpy spy = new MuleEventSpy(propertyName, propertyName, propertyValue);
spy.clear();
return spy;
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class AsyncMulticastTest method testAsyncRequest.
/**
* Test Async request
* @throws Exception should not happen in this test
*/
@Test
public void testAsyncRequest() throws Exception {
MuleEventSpy spy = new MuleEventSpy("async-handler");
spy.clear();
Event result = flowRunner(flowName).withPayload("nothing_important").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
if (expectedResponseCode == null) {
Instant start = Instant.now();
await().atMost(20, TimeUnit.SECONDS).until(() -> {
return Instant.now().isAfter(start.plusSeconds(15L));
});
assertEquals("should not receive response on multicast", 0, spy.getEvents().size());
} else {
await().atMost(15, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1;
});
response = (Message) spy.getEvents().get(0).getContent();
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertEquals("wrong request code", expectedRequestCode.name(), attributes.getRequestCode());
assertEquals("wrong request uri", expectedRequestUri, attributes.getRequestUri());
assertEquals("wrong response code", expectedResponseCode, attributes.getResponseCode());
assertArrayEquals("wrong response payload", expectedPayload, (byte[]) response.getPayload().getValue());
}
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class ObserveTest method testObserveReregistration1.
/**
* Test observe re-registration after max_age
* @throws Exception should not happen in this test
*/
@Test(timeout = 100000L)
public void testObserveReregistration1() throws Exception {
@SuppressWarnings("unused") Event result;
MuleEventSpy spy = new MuleEventSpy("maxage1_nonotify");
spy.clear();
// let asynchronous work happen
pauze();
// check clean start
assertEquals("unexpected observation on start test", 0, spy.getEvents().size());
result = flowRunner("start_maxage1_nonotify").withPayload("nothing_important").run();
// five notifications expected, period= max_age + notificationReregistrationBackoff per notification, plus margin
pauze(5000 + 500 + 100);
result = flowRunner("stop_maxage1_nonotify").withPayload("nothing_important").run();
// GET observe=0 response + notification= 1 + 5
await("number of notifications received 1").atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1 + 5 + 1;
});
// wait some more
pauze(5000 + 500 + 100);
// stop result is also handled -> 1+5+1 times
await("number of notifications received 2").atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1 + 5 + 1;
});
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class ObserveTest method testObserveReregistration4.
/**
* Test observe re-registration after max_age
* @throws Exception should not happen in this test
*/
@Test(timeout = 100000L)
public void testObserveReregistration4() throws Exception {
@SuppressWarnings("unused") Event result;
MuleEventSpy spy = new MuleEventSpy("maxage4_nonotify");
spy.clear();
// let asynchronous work happen
pauze();
// check clean start
assertEquals("unexpected observation on start test", 0, spy.getEvents().size());
result = flowRunner("start_maxage4_nonotify").withPayload("nothing_important").run();
// five notifications expected, period= max_age + notificationReregistrationBackoff per notification, plus margin
pauze(5 * (4 * 1000 + 100) + 500);
result = flowRunner("stop_maxage4_nonotify").withPayload("nothing_important").run();
// GET observe=0 response + notification= 1 + 5
await("number of notifications received 1").atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1 + 5 + 1;
});
// five notifications expected, period= max_age + notificationReregistrationBackoff per notification, plus margin
pauze(5 * (4 * 1000 + 100) + 500);
// GET observe=0 response + notification= 1 + 5
await("number of notifications received 2").atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1 + 5 + 1;
});
}
use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.
the class ObserveTest method testObserveNotifications.
// TODO warn when not existing observe is stopped
/**
* Test observe notifications at max_age
* @throws Exception should not happen in this test
*/
@Test(timeout = 100000L)
public void testObserveNotifications() throws Exception {
@SuppressWarnings("unused") Event result;
MuleEventSpy spy = new MuleEventSpy("maxage1");
spy.clear();
// let asynchronous work happen
pauze();
assertEquals("unexpected observation on start test", 0, spy.getEvents().size());
result = flowRunner("start_maxage1").withPayload("nothing_important").run();
pauze(5500);
result = flowRunner("stop_maxage1").withPayload("nothing_important").run();
// GET observe=0 response + notifications= 1+5+1
await("number of notifications received").atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1 + 5 + 1;
});
pauze(5500);
// GET observe=0 response + notifications= 1+5
// stop result is also handled -> 1+5+1 times
await("number of notifications received").atMost(10, TimeUnit.SECONDS).until(() -> {
return spy.getEvents().size() == 1 + 5 + 1;
});
}
Aggregations