use of org.eclipse.leshan.core.model.ObjectModel in project leshan by eclipse.
the class LinkFormatHelperTest method encode_objectModel_to_linkObject_without_root_path.
@Test
public void encode_objectModel_to_linkObject_without_root_path() {
ObjectModel locationModel = getObjectModel(6);
Link[] links = LinkFormatHelper.getObjectDescription(locationModel, null);
String strLinks = Link.serialize(links);
assertEquals("</6>, </6/0/0>, </6/0/1>, </6/0/2>, </6/0/3>, </6/0/4>, </6/0/5>, </6/0/6>", strLinks);
}
use of org.eclipse.leshan.core.model.ObjectModel in project leshan by eclipse.
the class LinkFormatHelperTest method encode_objectModel_to_linkObject_with_version2_0.
@Test
public void encode_objectModel_to_linkObject_with_version2_0() {
ObjectModel locationModel = getVersionedObjectModel(6, "2.0");
Link[] links = LinkFormatHelper.getObjectDescription(locationModel, "/");
String strLinks = Link.serialize(links);
assertEquals("</6>;ver=\"2.0\", </6/0/0>, </6/0/1>, </6/0/2>, </6/0/3>, </6/0/4>, </6/0/5>, </6/0/6>", strLinks);
}
use of org.eclipse.leshan.core.model.ObjectModel in project leshan by eclipse.
the class IntegrationTestHelper method createObjectModels.
protected List<ObjectModel> createObjectModels() {
// load default object from the spec
List<ObjectModel> objectModels = ObjectLoader.loadDefault();
// define custom model for testing purpose
ResourceModel stringfield = new ResourceModel(STRING_RESOURCE_ID, "stringres", Operations.RW, false, false, Type.STRING, null, null, null);
ResourceModel booleanfield = new ResourceModel(BOOLEAN_RESOURCE_ID, "booleanres", Operations.RW, false, false, Type.BOOLEAN, null, null, null);
ResourceModel integerfield = new ResourceModel(INTEGER_RESOURCE_ID, "integerres", Operations.RW, false, false, Type.INTEGER, null, null, null);
ResourceModel floatfield = new ResourceModel(FLOAT_RESOURCE_ID, "floatres", Operations.RW, false, false, Type.FLOAT, null, null, null);
ResourceModel timefield = new ResourceModel(TIME_RESOURCE_ID, "timeres", Operations.RW, false, false, Type.TIME, null, null, null);
ResourceModel opaquefield = new ResourceModel(OPAQUE_RESOURCE_ID, "opaque", Operations.RW, false, false, Type.OPAQUE, null, null, null);
ResourceModel objlnkfield = new ResourceModel(OBJLNK_MULTI_INSTANCE_RESOURCE_ID, "objlnk", Operations.RW, true, false, Type.OBJLNK, null, null, null);
ResourceModel objlnkSinglefield = new ResourceModel(OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, "objlnk", Operations.RW, false, false, Type.OBJLNK, null, null, null);
objectModels.add(new ObjectModel(TEST_OBJECT_ID, "testobject", null, ObjectModel.DEFAULT_VERSION, false, false, stringfield, booleanfield, integerfield, floatfield, timefield, opaquefield, objlnkfield, objlnkSinglefield));
return objectModels;
}
use of org.eclipse.leshan.core.model.ObjectModel in project leshan by eclipse.
the class LeshanClusterServer method createAndStartServer.
public static void createAndStartServer(String clusterInstanceId, String localAddress, int localPort, String secureLocalAddress, int secureLocalPort, String modelsFolderPath, String redisUrl) throws Exception {
// Create Redis connector.
// TODO: support sentinel pool and make pool configurable
Pool<Jedis> jedis = new JedisPool(new URI(redisUrl));
// Prepare LWM2M server.
LeshanServerBuilder builder = new LeshanServerBuilder();
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
DefaultLwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
builder.setDecoder(decoder);
builder.setCoapConfig(NetworkConfig.getStandard());
List<ObjectModel> models = ObjectLoader.loadDefault();
if (modelsFolderPath != null) {
models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath)));
}
LwM2mModelProvider modelProvider = new StaticModelProvider(models);
builder.setObjectModelProvider(modelProvider);
RedisRegistrationStore registrationStore = new RedisRegistrationStore(jedis);
builder.setRegistrationStore(registrationStore);
// TODO add support of public and private server key
builder.setSecurityStore(new RedisSecurityStore(jedis));
// Create and start LWM2M server
LeshanServer lwServer = builder.build();
// Create Clustering support
RedisTokenHandler tokenHandler = new RedisTokenHandler(jedis, clusterInstanceId);
new RedisRequestResponseHandler(jedis, lwServer, lwServer.getRegistrationService(), tokenHandler, lwServer.getObservationService());
lwServer.getRegistrationService().addListener(tokenHandler);
lwServer.getRegistrationService().addListener(new RedisRegistrationEventPublisher(jedis));
// Start Jetty & Leshan
lwServer.start();
}
use of org.eclipse.leshan.core.model.ObjectModel in project leshan by eclipse.
the class ObjectModelSerDesTest method des_ser_must_be_equals.
@Test
public void des_ser_must_be_equals() throws IOException {
// load file
InputStream inputStream = ObjectModelSerDesTest.class.getResourceAsStream("/model.json");
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String smodel = result.toString("UTF-8");
// deserialize
ObjectModelSerDes serDes = new ObjectModelSerDes();
JsonValue json = Json.parse(smodel);
List<ObjectModel> models = serDes.deserialize(json.asArray());
// serialize
JsonArray arr = serDes.jSerialize(models);
String res = arr.toString(WriterConfig.PRETTY_PRINT);
Assert.assertEquals("value should be equals", smodel, res);
}
Aggregations