use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class InMemoryRegistrationStoreTest method update_registration_to_extend_time_to_live.
@Test
public void update_registration_to_extend_time_to_live() {
givenASimpleRegistration(0L);
store.addRegistration(registration);
Assert.assertFalse(registration.isAlive());
RegistrationUpdate update = new RegistrationUpdate(registrationId, Identity.unsecure(address, port), lifetime, null, null, null, null);
UpdatedRegistration updatedRegistration = store.updateRegistration(update);
Assert.assertTrue(updatedRegistration.getUpdatedRegistration().isAlive());
Registration reg = store.getRegistrationByEndpoint(ep);
Assert.assertTrue(reg.isAlive());
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class RedisSecureIntegrationTestHelper method createServer.
@Override
public void createServer() {
LeshanServerBuilder builder = new LeshanServerBuilder();
StaticModelProvider modelProvider = new StaticModelProvider(createObjectModels());
builder.setObjectModelProvider(modelProvider);
DefaultLwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
builder.setDecoder(decoder);
builder.setLocalAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
builder.setLocalSecureAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
// Create redis store
String redisURI = System.getenv("REDIS_URI");
if (redisURI == null)
redisURI = "";
Pool<Jedis> jedis = new JedisPool(redisURI);
builder.setRegistrationStore(new RedisRegistrationStore(jedis));
builder.setSecurityStore(new RedisSecurityStore(jedis));
// Build server !
server = builder.build();
// monitor client registration
resetLatch();
server.getRegistrationService().addListener(new RegistrationListener() {
@Override
public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) {
if (updatedRegistration.getEndpoint().equals(getCurrentEndpoint())) {
updateLatch.countDown();
}
}
@Override
public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
if (registration.getEndpoint().equals(getCurrentEndpoint())) {
deregisterLatch.countDown();
}
}
@Override
public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObsersations) {
if (registration.getEndpoint().equals(getCurrentEndpoint())) {
last_registration = registration;
registerLatch.countDown();
}
}
});
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CoapRequestBuilderTest method build_write_request.
@Test
public void build_write_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
WriteRequest request = new WriteRequest(Mode.UPDATE, 3, 0, LwM2mSingleResource.newStringResource(4, "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(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());
assertEquals("value", TlvDecoder.decodeString(tlvs[0].getValue()));
assertEquals("coap://127.0.0.1:12354/3/0", coapRequest.getURI());
}
use of org.eclipse.leshan.server.registration.Registration 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());
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CoapRequestBuilderTest method build_read_request_with_root_path.
@Test
public void build_read_request_with_root_path() throws Exception {
Registration reg = newRegistration("/");
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
ReadRequest request = new ReadRequest(3);
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals("coap://127.0.0.1:12354/3", coapRequest.getURI());
}
Aggregations