Repository: eclipse/leshan
Pull request #386 (2017-09-18 07:08:04)

Set basename.
Fix JUnit basename related.

Signed-off-by: Rokwoon Kim <k862390@gmail.com>


Patch:
diff --git a/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/json/LwM2mNodeJsonEncoder.java b/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/json/LwM2mNodeJsonEncoder.java
index b6ee5246..bc225a0c 100644
--- a/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/json/LwM2mNodeJsonEncoder.java
+++ b/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/json/LwM2mNodeJsonEncoder.java
@@ -57,6 +57,7 @@ public class LwM2mNodeJsonEncoder {
         internalEncoder.converter = converter;
         node.accept(internalEncoder);
         JsonRootObject jsonObject = new JsonRootObject(internalEncoder.resourceList);
+        jsonObject.setBaseName(path.toString());
         return LwM2mJson.toJsonLwM2m(jsonObject).getBytes();
     }
 
@@ -79,7 +80,7 @@ public class LwM2mNodeJsonEncoder {
             entries.addAll(internalEncoder.resourceList);
         }
         JsonRootObject jsonObject = new JsonRootObject(entries);
-
+        jsonObject.setBaseName(path.toString());
         return LwM2mJson.toJsonLwM2m(jsonObject).getBytes();
     }
 


Test patch:
diff --git a/leshan-core/src/test/java/org/eclipse/leshan/core/node/codec/LwM2mNodeEncoderTest.java b/leshan-core/src/test/java/org/eclipse/leshan/core/node/codec/LwM2mNodeEncoderTest.java
index 41ade33a..74c734a9 100644
--- a/leshan-core/src/test/java/org/eclipse/leshan/core/node/codec/LwM2mNodeEncoderTest.java
+++ b/leshan-core/src/test/java/org/eclipse/leshan/core/node/codec/LwM2mNodeEncoderTest.java
@@ -175,7 +175,7 @@ public class LwM2mNodeEncoderTest {
         byte[] encoded = encoder.encode(oInstance, ContentFormat.JSON, new LwM2mPath("/3/0"), model);
 
         StringBuilder b = new StringBuilder();
-        b.append("{\"e\":[");
+        b.append("{\"bn\":\"/3/0\",\"e\":[");
         b.append("{\"n\":\"0\",\"sv\":\"Open Mobile Alliance\"},");
         b.append("{\"n\":\"1\",\"sv\":\"Lightweight M2M Client\"},");
         b.append("{\"n\":\"2\",\"sv\":\"345000123\"},");
@@ -207,7 +207,7 @@ public class LwM2mNodeEncoderTest {
         byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024, 0, 1), model);
 
         StringBuilder b = new StringBuilder();
-        b.append("{\"e\":[");
+        b.append("{\"bn\":\"/1024/0/1\",\"e\":[");
         b.append("{\"n\":\"\",\"v\":22.9,\"t\":500},");
         b.append("{\"n\":\"\",\"v\":22.4,\"t\":510},");
         b.append("{\"n\":\"\",\"v\":24.1,\"t\":520}]}");
@@ -232,7 +232,7 @@ public class LwM2mNodeEncoderTest {
         byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024, 0), model);
 
         StringBuilder b = new StringBuilder();
-        b.append("{\"e\":[");
+        b.append("{\"bn\":\"/1024/0\",\"e\":[");
         b.append("{\"n\":\"1\",\"v\":22.9,\"t\":110},");
         b.append("{\"n\":\"0\",\"sv\":\"a string\",\"t\":120},");
         b.append("{\"n\":\"1\",\"v\":22.4,\"t\":120},");
@@ -264,7 +264,7 @@ public class LwM2mNodeEncoderTest {
         byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024), model);
 
         StringBuilder b = new StringBuilder();
-        b.append("{\"e\":[");
+        b.append("{\"bn\":\"/1024\",\"e\":[");
         b.append("{\"n\":\"0/1\",\"v\":22.9,\"t\":210},");
         b.append("{\"n\":\"0/0\",\"sv\":\"a string\",\"t\":220},");
         b.append("{\"n\":\"0/1\",\"v\":22.4,\"t\":220},");