|
|
|
@ -16,19 +16,34 @@ |
|
|
|
package org.thingsboard.server.transport.lwm2m.rpc.sql; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.eclipse.leshan.core.ResponseCode; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mNode; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mPath; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mResource; |
|
|
|
import org.eclipse.leshan.core.node.TimestampedLwM2mNodes; |
|
|
|
import org.eclipse.leshan.server.registration.Registration; |
|
|
|
import org.junit.Test; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationTest; |
|
|
|
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler; |
|
|
|
|
|
|
|
import java.time.Instant; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static org.eclipse.leshan.core.LwM2mId.SERVER; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.mockito.Mockito.doAnswer; |
|
|
|
import static org.mockito.Mockito.timeout; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.BINARY_APP_DATA_CONTAINER; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.OBJECT_INSTANCE_ID_0; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.OBJECT_INSTANCE_ID_1; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.OBJECT_INSTANCE_ID_12; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_0; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_1; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_11; |
|
|
|
@ -41,9 +56,13 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_3_14; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_3_9; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class RpcLwm2mIntegrationReadTest extends AbstractRpcLwM2MIntegrationTest { |
|
|
|
|
|
|
|
@SpyBean |
|
|
|
DefaultLwM2mUplinkMsgHandler defaultUplinkMsgHandlerTest; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Read {"id":"/3"} |
|
|
|
* Read {"id":"/6"}... |
|
|
|
@ -57,7 +76,7 @@ public class RpcLwm2mIntegrationReadTest extends AbstractRpcLwM2MIntegrationTest |
|
|
|
String expectedObjectId = pathIdVerToObjectId((String) expected); |
|
|
|
LwM2mPath expectedPath = new LwM2mPath(expectedObjectId); |
|
|
|
ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); |
|
|
|
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); |
|
|
|
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); |
|
|
|
String expectedObjectInstances = "LwM2mObject [id=" + expectedPath.getObjectId() + ", instances={0=LwM2mObjectInstance [id=0, resources="; |
|
|
|
if (expectedPath.getObjectId() == 1) { |
|
|
|
expectedObjectInstances = "LwM2mObject [id=1, instances={1="; |
|
|
|
@ -211,6 +230,60 @@ public class RpcLwm2mIntegrationReadTest extends AbstractRpcLwM2MIntegrationTest |
|
|
|
assertTrue(actualValues.contains(expected19_1_0)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* /3303/0/5700 |
|
|
|
* Read {"id":"/3303/0/5700"} |
|
|
|
* Trigger a Send operation from the client with multiple values for the same resource as a payload |
|
|
|
* acked "[{"bn":"/3303/12/5700","bt":1724".. 116 bytes] |
|
|
|
* 2 values for the resource /3303/12/5700 should be stored with timestamps1 = Instance.now(), timestamps2 = Instance.now() |
|
|
|
* |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testReadSingleResource_sendFromClient_CollectedValue() throws Exception { |
|
|
|
TimestampedLwM2mNodes[] tsNodesHolder = new TimestampedLwM2mNodes[1]; |
|
|
|
doAnswer(inv -> { |
|
|
|
tsNodesHolder[0] = inv.getArgument(1); |
|
|
|
return null; |
|
|
|
}).when(defaultUplinkMsgHandlerTest).onUpdateValueWithSendRequest( |
|
|
|
Mockito.any(Registration.class), |
|
|
|
Mockito.any(TimestampedLwM2mNodes.class) |
|
|
|
); |
|
|
|
int resourceId = 5700; |
|
|
|
String expectedIdVer = objectIdVer_3303 + "/" + OBJECT_INSTANCE_ID_12 + "/" + resourceId; |
|
|
|
String actualResult = sendRPCById(expectedIdVer); |
|
|
|
verify(defaultUplinkMsgHandlerTest, timeout(10000).times(1)) |
|
|
|
.onUpdateValueWithSendRequest(Mockito.any(Registration.class), Mockito.any(TimestampedLwM2mNodes.class)); |
|
|
|
|
|
|
|
ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); |
|
|
|
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); |
|
|
|
String expected = "LwM2mSingleResource [id=" + resourceId + ", value="; |
|
|
|
String actual = rpcActualResult.get("value").asText(); |
|
|
|
assertTrue(actual.contains(expected)); |
|
|
|
int indStart = actual.indexOf(expected) + expected.length(); |
|
|
|
int indEnd = actual.indexOf(",", indStart); |
|
|
|
String valStr = actual.substring(indStart, indEnd); |
|
|
|
double dd = Double.parseDouble(valStr); |
|
|
|
long combined = Double.doubleToRawLongBits(dd); |
|
|
|
int t0 = (int) (combined >> 32); |
|
|
|
int t1 = (int) combined; |
|
|
|
double[] expectedValues ={(double)t0/100, (double)t1/100}; |
|
|
|
int ind = 0; |
|
|
|
LwM2mPath expectedPath = new LwM2mPath("/3303/12/5700"); |
|
|
|
for (Instant ts : tsNodesHolder[0].getTimestamps()) { |
|
|
|
Map<LwM2mPath, LwM2mNode> nodesAt = tsNodesHolder[0].getNodesAt(ts); |
|
|
|
for (var instant : nodesAt.entrySet()) { |
|
|
|
LwM2mPath actualPath = instant.getKey(); |
|
|
|
LwM2mNode node = instant.getValue(); |
|
|
|
LwM2mResource lwM2mResource = (LwM2mResource) node; |
|
|
|
assertEquals(expectedPath, actualPath); |
|
|
|
assertEquals(expectedValues[ind], lwM2mResource.getValue()); |
|
|
|
ind++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* ReadComposite {"keys":["batteryLevel", "UtfOffset", "dataDescription"]} |
|
|
|
*/ |
|
|
|
|