private CorrelationContext getNonSecureCorrelationContext() { MapBasedCorrelationContext ctx = new MapBasedCorrelationContext(); ctx.put("someKey", "someValue"); return ctx; } }
@Before public void setUp() throws Exception { context = new MapBasedCorrelationContext(); receivedRequests = new ArrayList<Request>(); connector = new SimpleConnector(); endpoint = new CoapEndpoint(connector, CONFIG); sentLatch = new CountDownLatch(1); MessageDeliverer deliverer = new MessageDeliverer() { @Override public void deliverResponse(Exchange exchange, Response response) { } @Override public void deliverRequest(Exchange exchange) { receivedRequests.add(exchange.getRequest()); latch.countDown(); } }; endpoint.setMessageDeliverer(deliverer); endpoint.start(); }
@Test public void testReceiveResponseAcceptsResponseWithoutCorrelationInformation() { // GIVEN a request sent without any additional correlation information // using a matcher set to lax matching UdpMatcher matcher = newMatcher(false); Exchange exchange = sendRequest(matcher, null); // WHEN a response arrives with arbitrary additional correlation information Exchange matchedExchange = matcher.receiveResponse( responseFor(exchange.getCurrentRequest()), new MapBasedCorrelationContext()); // THEN assert that the response is successfully matched against the request assertThat(matchedExchange, is(exchange)); }
@Test public void testReceiveResponseRejectsResponseWithArbitraryCorrelationInformation() { // GIVEN a request sent with some additional correlation information // using a matcher set to lax matching UdpMatcher matcher = newMatcher(false); MapBasedCorrelationContext ctx = new MapBasedCorrelationContext(); ctx.put("key", "value"); Exchange exchange = sendRequest(matcher, ctx); // WHEN a response arrives without any correlation information Exchange matchedExchange = matcher.receiveResponse(responseFor(exchange.getCurrentRequest()), null); // THEN assert that the response is not matched assertThat(matchedExchange, is(nullValue())); }