use of org.eclipse.leshan.server.registration.Registration.Builder in project leshan by eclipse.
the class CoapRequestBuilderTest method newRegistration.
private Registration newRegistration(String rootpath) throws UnknownHostException {
Builder b = new Registration.Builder("regid", "endpoint", Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354), new InetSocketAddress(0));
if (rootpath != null) {
Map<String, String> attr = new HashMap<>();
attr.put("rt", "oma.lwm2m");
b.objectLinks(new Link[] { new Link(rootpath, attr) });
}
return b.build();
}
use of org.eclipse.leshan.server.registration.Registration.Builder in project leshan by eclipse.
the class CoapRequestBuilderTest method build_write_attribute_request.
@Test
public void build_write_attribute_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
WriteAttributesRequest request = new WriteAttributesRequest(3, 0, 14, new ObserveSpec.Builder().minPeriod(10).maxPeriod(100).build());
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.PUT, coapRequest.getCode());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals("coap://127.0.0.1:12354/3/0/14?pmin=10&pmax=100", coapRequest.getURI());
}
Aggregations