Search in sources :

Example 11 with Registration

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());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) Registration(org.eclipse.leshan.server.registration.Registration) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 12 with Registration

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) Test(org.junit.Test)

Example 13 with Registration

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) Test(org.junit.Test)

Example 14 with Registration

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Example 15 with Registration

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) Registration(org.eclipse.leshan.server.registration.Registration)

Aggregations

Registration (org.eclipse.leshan.server.registration.Registration)44 Test (org.junit.Test)19 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)15 Request (org.eclipse.californium.core.coap.Request)14 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)13 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)13 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)13 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)13 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)13 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)13 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)12 Observation (org.eclipse.leshan.core.observation.Observation)10 UpdatedRegistration (org.eclipse.leshan.server.registration.UpdatedRegistration)10 InetSocketAddress (java.net.InetSocketAddress)7 Jedis (redis.clients.jedis.Jedis)6 RegistrationUpdate (org.eclipse.leshan.server.registration.RegistrationUpdate)5 Deregistration (org.eclipse.leshan.server.registration.Deregistration)4 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)3 LwM2mResponse (org.eclipse.leshan.core.response.LwM2mResponse)3 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)3