Search in sources :

Example 1 with Builder

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

Example 2 with Builder

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) Builder(org.eclipse.leshan.server.registration.Registration.Builder) 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) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Test(org.junit.Test)

Aggregations

Builder (org.eclipse.leshan.server.registration.Registration.Builder)2 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 Request (org.eclipse.californium.core.coap.Request)1 Link (org.eclipse.leshan.Link)1 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)1 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)1 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)1 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)1 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)1 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)1 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)1 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)1 Registration (org.eclipse.leshan.server.registration.Registration)1 Test (org.junit.Test)1