use of org.eclipse.californium.core.coap.CoAP.Type in project hono by eclipse.
the class ResourceTestBase method newCoapExchange.
static CoapExchange newCoapExchange(final Buffer payload, final Type requestType, final OptionSet options) {
final Request request = mock(Request.class);
when(request.getType()).thenReturn(requestType);
when(request.isConfirmable()).thenReturn(requestType == Type.CON);
when(request.getOptions()).thenReturn(options);
final Exchange exchange = new Exchange(request, Origin.REMOTE, mock(Executor.class));
final CoapExchange coapExchange = mock(CoapExchange.class);
when(coapExchange.advanced()).thenReturn(exchange);
Optional.ofNullable(payload).ifPresent(b -> when(coapExchange.getRequestPayload()).thenReturn(b.getBytes()));
when(coapExchange.getRequestOptions()).thenReturn(options);
when(coapExchange.getQueryParameter(anyString())).thenAnswer(invocation -> {
final String key = invocation.getArgument(0);
return options.getUriQuery().stream().map(param -> param.split("=", 2)).filter(keyValue -> key.equals(keyValue[0])).findFirst().map(keyValue -> keyValue.length < 2 ? Boolean.TRUE.toString() : keyValue[1]).orElse(null);
});
return coapExchange;
}
use of org.eclipse.californium.core.coap.CoAP.Type in project hono by eclipse.
the class CoapProtocolAdapterMockSupport method newCoapExchange.
static CoapExchange newCoapExchange(final Buffer payload, final Type requestType, final OptionSet options) {
final Request request = mock(Request.class);
when(request.getType()).thenReturn(requestType);
when(request.isConfirmable()).thenReturn(requestType == Type.CON);
when(request.getOptions()).thenReturn(options);
final Exchange exchange = new Exchange(request, Origin.REMOTE, mock(Executor.class));
final CoapExchange coapExchange = mock(CoapExchange.class);
when(coapExchange.advanced()).thenReturn(exchange);
Optional.ofNullable(payload).ifPresent(b -> when(coapExchange.getRequestPayload()).thenReturn(b.getBytes()));
when(coapExchange.getRequestOptions()).thenReturn(options);
when(coapExchange.getQueryParameter(anyString())).thenAnswer(invocation -> {
final String key = invocation.getArgument(0);
return options.getUriQuery().stream().map(param -> param.split("=", 2)).filter(keyValue -> key.equals(keyValue[0])).findFirst().map(keyValue -> keyValue.length < 2 ? Boolean.TRUE.toString() : keyValue[1]).orElse(null);
});
return coapExchange;
}
Aggregations