use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CoapRequestBuilderTest method build_create_request__with_instance_id.
@Test
public void build_create_request__with_instance_id() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
CreateRequest request = new CreateRequest(12, new LwM2mObjectInstance(26, LwM2mSingleResource.newStringResource(0, "value")));
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, 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/12", coapRequest.getURI());
assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
assertNotNull(coapRequest.getPayload());
// assert it is encoded as array of instance TLV
Tlv[] tlvs = TlvDecoder.decode(ByteBuffer.wrap(coapRequest.getPayload()));
assertEquals(TlvType.OBJECT_INSTANCE, tlvs[0].getType());
assertEquals(26, tlvs[0].getIdentifier());
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CoapRequestBuilderTest method build_observe_request.
@Test
public void build_observe_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
ObserveRequest request = new ObserveRequest(12, 0);
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.GET, coapRequest.getCode());
assertEquals(0, coapRequest.getOptions().getObserve().intValue());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals("coap://127.0.0.1:12354/12/0", coapRequest.getURI());
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CoapRequestBuilderTest method build_delete_request.
@Test
public void build_delete_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
DeleteRequest request = new DeleteRequest(12, 0);
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.DELETE, 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/12/0", coapRequest.getURI());
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CoapRequestBuilderTest method build_create_request__without_instance_id.
@Test
public void build_create_request__without_instance_id() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
CreateRequest request = new CreateRequest(12, LwM2mSingleResource.newStringResource(0, "value"));
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, 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/12", coapRequest.getURI());
assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
assertNotNull(coapRequest.getPayload());
// assert it is encoded as array of resources TLV
Tlv[] tlvs = TlvDecoder.decode(ByteBuffer.wrap(coapRequest.getPayload()));
assertEquals(TlvType.RESOURCE_VALUE, tlvs[0].getType());
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class ObservationServiceTest method givenASimpleClient.
public Registration givenASimpleClient(String registrationId) {
InetSocketAddress registrationAddress = InetSocketAddress.createUnresolved("localhost", LwM2m.DEFAULT_COAP_PORT);
Registration.Builder builder;
try {
builder = new Registration.Builder(registrationId, registrationId + "_ep", Identity.unsecure(InetAddress.getLocalHost(), 10000), registrationAddress);
return builder.build();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
Aggregations