use of org.eclipse.leshan.client.californium.impl.CaliforniumLwM2mRequestSender in project leshan by eclipse.
the class RegistrationTest method register_with_additional_attributes.
@Test
public void register_with_additional_attributes() throws InterruptedException {
// Check registration
helper.assertClientNotRegisterered();
// HACK to be able to send a Registration request with additional attributes
LeshanClient lclient = helper.client;
lclient.getCoapServer().start();
Endpoint secureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getSecuredAddress());
Endpoint nonSecureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getUnsecuredAddress());
CaliforniumLwM2mRequestSender sender = new CaliforniumLwM2mRequestSender(secureEndpoint, nonSecureEndpoint);
// Create Request with additional attributes
Map<String, String> additionalAttributes = new HashMap<>();
additionalAttributes.put("key1", "value1");
additionalAttributes.put("imei", "2136872368");
Link[] objectLinks = Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes());
RegisterRequest registerRequest = new RegisterRequest(helper.getCurrentEndpoint(), null, null, null, null, objectLinks, additionalAttributes);
// Send request
RegisterResponse resp = sender.send(helper.server.getUnsecuredAddress(), false, registerRequest, 5000l);
helper.waitForRegistration(1);
// Check we are registered with the expected attributes
helper.assertClientRegisterered();
assertNotNull(helper.last_registration);
assertEquals(additionalAttributes, helper.last_registration.getAdditionalRegistrationAttributes());
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes()), helper.getCurrentRegistration().getObjectLinks());
sender.send(helper.server.getUnsecuredAddress(), false, new DeregisterRequest(resp.getRegistrationID()), 5000l);
lclient.getCoapServer().stop();
}
Aggregations