@ -15,12 +15,22 @@
* /
* /
package org.thingsboard.server.transport.lwm2m.rpc.sql ;
package org.thingsboard.server.transport.lwm2m.rpc.sql ;
import com.fasterxml.jackson.databind.node.ArrayNode ;
import com.fasterxml.jackson.databind.node.ObjectNode ;
import com.fasterxml.jackson.databind.node.ObjectNode ;
import lombok.extern.slf4j.Slf4j ;
import org.eclipse.leshan.core.ResponseCode ;
import org.eclipse.leshan.core.ResponseCode ;
import org.junit.Test ;
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.common.util.JacksonUtil ;
import org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationObserveTest ;
import org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationObserveTest ;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler ;
import java.util.Objects ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.atomic.AtomicLong ;
import static org.awaitility.Awaitility.await ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.assertTrue ;
@ -29,21 +39,25 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.OBJECT_INST
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.OBJECT_INSTANCE_ID_1 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.OBJECT_INSTANCE_ID_1 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_0 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_0 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_14 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_14 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_15 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_2 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_2 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_3 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_3 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_5 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_5 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_7 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_7 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_9 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_9 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_19_0_0 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_19_0_0 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_19_0_2 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_19_1_0 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_19_1_0 ;
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_14 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_3_9 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_NAME_3_9 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_INSTANCE_ID_0 ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_INSTANCE_ID_0 ;
import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.fromVersionedIdToObjectId ;
import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.fromVersionedIdToObjectId ;
@Slf4j
public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MIntegrationObserveTest {
public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MIntegrationObserveTest {
@SpyBean
DefaultLwM2mUplinkMsgHandler defaultUplinkMsgHandlerTest ;
/ * *
/ * *
* ObserveComposite { "ids" : [ "5/0/7" , "5/0/5" , "5/0/3" , "3/0/9" , "19/1/0/0" ] } - Ok
* ObserveComposite { "ids" : [ "5/0/7" , "5/0/5" , "5/0/3" , "3/0/9" , "19/1/0/0" ] } - Ok
@ -51,13 +65,13 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* /
* /
@Test
@Test
public void testObserveCompositeAnyResources_Result_CONTENT_Value_LwM2mSingleResource_LwM2mResourceInstance ( ) throws Exception {
public void testObserveCompositeAnyResources_Result_CONTENT_Value_LwM2mSingleResource_LwM2mResourceInstance ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
@ -74,30 +88,30 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* /
* /
@Test
@Test
public void testObserveComposite_ObjectInstanceWithOtherObjectResourceInstance_Result_CONTENT_Ok ( ) throws Exception {
public void testObserveComposite_ObjectInstanceWithOtherObjectResourceInstance_Result_CONTENT_Ok ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIdVer5_0 = objectInstanceIdVer_5 ;
String expectedIdVer5_0 = objectInstanceIdVer_5 ;
String expectedIds = "[\"" + expectedIdVer19_1_0 + "\", \"" + expectedIdVer5_0 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer19_1_0 + "\", \"" + expectedIdVer5_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actual = rpcActualResult . get ( "value" ) . asText ( ) ;
String actual = rpcActualResult . get ( "value" ) . asText ( ) ;
assertTrue ( actual . contains ( fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) + "=LwM2mMultipleResource" ) ) ;
assertTrue ( actual . contains ( fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) + "=LwM2mMultipleResource" ) ) ;
assertTrue ( actual . contains ( fromVersionedIdToObjectId ( expectedIdVer5_0 ) + "=LwM2mObjectInstance" ) ) ;
assertTrue ( actual . contains ( fromVersionedIdToObjectId ( expectedIdVer5_0 ) + "=LwM2mObjectInstance" ) ) ;
}
}
/ * *
/ * *
* ObserveComposite { "ids" : [ "5/0/7" , "5/0/2" ] } - Ok
* ObserveComposite { "ids" : [ "5/0/7" , "5/0/2" ] } - Ok
* "5/0/2" - Execute ^ result = = null
* "5/0/2" - Execute result = = null
* @throws Exception
* @throws Exception
* /
* /
@Test
@Test
public void testObserveCompositeAnyResources_Result_CONTENT_Value_LwM2mSingleResource_If_Error_ Null ( ) throws Exception {
public void testObserveReadAll_AfterCompositeObservation_WithResourceNotReadable_Result_CONTENT_ObserveResourceNotReadableIs Null ( ) throws Exception {
// sendCancelObserveAllWithAwait(deviceId);
sendObserveCancelAllWithAwait ( deviceId ) ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_2 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_2 ;
String expectedIdVer5_0_2 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_2 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_2 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_2 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
@ -113,34 +127,102 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* /
* /
@Test
@Test
public void testObserveComposite_Result_BAD_REQUEST_ONE_PATH_CONTAINCE_OTHER ( ) throws Exception {
public void testObserveComposite_Result_BAD_REQUEST_ONE_PATH_CONTAINCE_OTHER ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
String expectedIdVer5_0 = objectInstanceIdVer_5 ;
String expectedIdVer5_0 = objectInstanceIdVer_5 ;
String expectedIdVer5_0_2 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_2 ;
String expectedIdVer5_0_2 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_2 ;
String expectedIds = "[\"" + expectedIdVer5_0 + "\", \"" + expectedIdVer5_0_2 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0 + "\", \"" + expectedIdVer5_0_2 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actual = rpcActualResult . get ( "error" ) . asText ( ) ;
String actual = rpcActualResult . get ( "error" ) . asText ( ) ;
String expected = "Invalid path list : /5/0 and /5/0/2 are overlapped paths" ;
String expected = "Invalid path list : /5/0 and /5/0/2 are overlapped paths" ;
assertTrue ( expected . equals ( actual ) ) ;
assertTrue ( expected . equals ( actual ) ) ;
}
}
/ * *
/ * *
* Previous - > "3/0/9"
* Previous - > "3/0/9" , "19/0/2" , "19/1/0" , "19/0/0" , All only SingleObservation ;
* ObserveComposite { "ids" : [ "5/0/7" , "5/0/5" , "5/0/3" , "3/0/9" ] } - CONTENT
* if at least one of the resource objectIds ( Composite ) in SingleObservation or CompositeObservation is already registered - return BAD REQUEST
* ObserveComposite { "ids" : [ "5/0/7" , "5/0/5" , "5/0/3" , "3/0/9" ] }
* @throws Exception
* @throws Exception
* /
* /
@Test
@Test
public void testObserveCompositeThereAreObservationOneResource_Result_CONTENT_Value_ObservationAddIfAbsent ( ) throws Exception {
public void testObserveComposite_IfLeastOneResourceIsAlreadyRegistered_return_BadRequest ( ) throws Exception {
// Verify after start
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
String expectedIdVer19_0_2 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_0 + "/" + RESOURCE_ID_2 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_0_2 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_19_0_0 ) ) ) ;
// Send Observe composite with "/3/0/9"
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( "is already registered" ) ) ;
// verify after send Observe composite
actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_0_2 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_19_0_0 ) ) ) ;
}
/ * *
* Previous - > [ "5/0/7" , "5/0/5" , "5/0/3" ] , CompositeObservation *
* if the resource SingleObservation is already registered in CompositeObservation - return BAD REQUEST
* SingleObservation { "id" : [ "5/0/7" }
* @throws Exception
* /
@Test
public void testObserveSingle_IfResourceIsAlreadyRegisteredInComposite_return_BadRequest ( ) throws Exception {
// Send Observe Composite
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedId5_0_7 = fromVersionedIdToObjectId ( expectedIdVer5_0_7 ) ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedId5_0_5 = fromVersionedIdToObjectId ( expectedIdVer5_0_5 ) ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedId5_0_3 = fromVersionedIdToObjectId ( expectedIdVer5_0_3 ) ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String expectedResult = "/3/0/9=LwM2mSingleResource [id=9" ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
assertTrue ( rpcActualResult . get ( "value" ) . asText ( ) . contains ( expectedResult ) ) ;
assertTrue ( actualValues . contains ( expectedId5_0_7 ) ) ;
assertTrue ( actualValues . contains ( expectedId5_0_5 ) ) ;
assertTrue ( actualValues . contains ( expectedId5_0_3 ) ) ;
// Send Observe Single
actualResult = sendObserve ( "Observe" , expectedIdVer5_0_7 ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( expectedId5_0_7 ) ) ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( "is already registered" ) ) ;
// verify after send Observe Single
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
String expectedIdVer19_0_2 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_0 + "/" + RESOURCE_ID_2 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_0_2 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_19_0_0 ) ) ) ;
assertTrue ( actualValues . contains ( "CompositeObservation:" ) ) ;
assertTrue ( actualValues . contains ( expectedId5_0_7 ) ) ;
assertTrue ( actualValues . contains ( expectedId5_0_5 ) ) ;
assertTrue ( actualValues . contains ( expectedId5_0_3 ) ) ;
}
}
/ * *
/ * *
@ -149,14 +231,14 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* /
* /
@Test
@Test
public void testObserveCompositeAnyResources_Result_CONTENT_Value_LwM2mSingleResource_LwM2mMultipleResource ( ) throws Exception {
public void testObserveCompositeAnyResources_Result_CONTENT_Value_LwM2mSingleResource_LwM2mMultipleResource ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
@ -173,7 +255,7 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* /
* /
@Test
@Test
public void testObserveCompositeWithKeyName_Result_CONTENT_Value_SingleResources ( ) throws Exception {
public void testObserveCompositeWithKeyName_Result_CONTENT_Value_SingleResources ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
String expectedKey3_0_9 = RESOURCE_ID_NAME_3_9 ;
String expectedKey3_0_9 = RESOURCE_ID_NAME_3_9 ;
String expectedKey3_0_14 = RESOURCE_ID_NAME_3_14 ;
String expectedKey3_0_14 = RESOURCE_ID_NAME_3_14 ;
@ -198,18 +280,16 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* @throws Exception
* @throws Exception
* /
* /
@Test
@Test
public void testObserveCompositeWithKeyNameThereAreObservationOneResource_Result_CONTENT_Value_ObservationAddIfAbsen t ( ) throws Exception {
public void testObserveCompositeWithKeyName_IfLeastOneResourceIsAlreadyRegistered_return_BadReques t ( ) throws Exception {
String expectedKey3_0_9 = RESOURCE_ID_NAME_3_9 ;
String expectedKey3_0_9 = RESOURCE_ID_NAME_3_9 ;
String expectedKey3_0_14 = RESOURCE_ID_NAME_3_14 ;
String expectedKey3_0_14 = RESOURCE_ID_NAME_3_14 ;
String expectedKey19_0_0 = RESOURCE_ID_NAME_19_0_0 ;
String expectedKey19_0_0 = RESOURCE_ID_NAME_19_0_0 ;
String expectedKey19_1_0 = RESOURCE_ID_NAME_19_1_0 ;
String expectedKey19_1_0 = RESOURCE_ID_NAME_19_1_0 ;
String expectedKeys = "[\"" + expectedKey3_0_9 + "\", \"" + expectedKey3_0_14 + "\", \"" + expectedKey19_0_0 + "\", \"" + expectedKey19_1_0 + "\"]" ;
String expectedKeys = "[\"" + expectedKey3_0_9 + "\", \"" + expectedKey3_0_14 + "\", \"" + expectedKey19_0_0 + "\", \"" + expectedKey19_1_0 + "\"]" ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String actualResult = sendCompositeRPCByKeys ( "ObserveComposite" , expectedKeys ) ;
String actualResult = sendCompositeRPCByKeys ( "ObserveComposite" , expectedKeys ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actual = rpcActualResult . get ( "value" ) . asText ( ) ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( "is already registered" ) ) ;
assertTrue ( actual . contains ( fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) + "=LwM2mMultipleResource" ) ) ;
}
}
/ * *
/ * *
@ -218,8 +298,8 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* @throws Exception
* @throws Exception
* /
* /
@Test
@Test
public void testObserveReadAll_AfterCompositeObservation_Result_CONTENT_Value_Singl eObservation_Only ( ) throws Exception {
public void testObserveReadAll_AfterbserveCancelAllAndCompositeObservation_Result_CONTENT_Value_Composit eObservation_Only ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
String expectedKey3_0_9 = RESOURCE_ID_NAME_3_9 ;
String expectedKey3_0_9 = RESOURCE_ID_NAME_3_9 ;
String expectedKey3_0_14 = RESOURCE_ID_NAME_3_14 ;
String expectedKey3_0_14 = RESOURCE_ID_NAME_3_14 ;
@ -232,76 +312,15 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
String expectedIdVer3_0_14 = objectInstanceIdVer_3 + "/" + RESOURCE_ID_14 ;
String expectedIdVer3_0_14 = objectInstanceIdVer_3 + "/" + RESOURCE_ID_14 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ;
assertTrue ( actualValues . contains ( "CompositeObservation:" ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer3_0_14 ) ) ) ;
assertFalse ( actualValues . contains ( "SingleObservation" ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) ) ) ;
assertTrue ( actualValues . contains ( Objects . requireNonNull ( fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_19_0_0 ) ) ) ;
assertTrue ( actualValues . contains ( Objects . requireNonNull ( fromVersionedIdToObjectId ( expectedIdVer3_0_14 ) ) ) ) ;
}
assertTrue ( actualValues . contains ( Objects . requireNonNull ( fromVersionedIdToObjectId ( expectedIdVer19_1_0 ) ) ) ) ;
assertTrue ( actualValues . contains ( Objects . requireNonNull ( fromVersionedIdToObjectId ( idVer_19_0_0 ) ) ) ) ;
/ * *
* ObserveReadAll
* { "result" : "CONTENT" , "value" : "{" result ":" CONTENT "," value ":" [ "SingleObservation:/3/0/9" , "SingleObservation:/3/0/14" , "SingleObservation:/19/1/0/0" , "SingleObservation:/19/0/0" ] " } - Ok
* @throws Exception
* /
@Test
public void testObserveReadAll_Result_CONTENT_Value_SingleObservation_Only ( ) throws Exception {
sendCancelObserveAllWithAwait ( deviceId ) ;
String expectedIdVer3_0_14 = objectInstanceIdVer_3 + "/" + RESOURCE_ID_14 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String actualResult3_0_9 = sendObserve ( "Observe" , idVer_3_0_9 ) ;
ObjectNode rpcActualResult3_0_9 = JacksonUtil . fromString ( actualResult3_0_9 , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult3_0_9 . get ( "result" ) . asText ( ) ) ;
String actualResult3_0_14 = sendObserve ( "Observe" , expectedIdVer3_0_14 ) ;
ObjectNode rpcActualResult3_0_14 = JacksonUtil . fromString ( actualResult3_0_14 , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult3_0_14 . get ( "result" ) . asText ( ) ) ;
String actualResult19_1_0_0 = sendObserve ( "Observe" , expectedIdVer19_1_0_0 ) ;
ObjectNode rpcActualResult19_1_0_0 = JacksonUtil . fromString ( actualResult19_1_0_0 , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult19_1_0_0 . get ( "result" ) . asText ( ) ) ;
String actualResult19_0_0 = sendObserve ( "Observe" , idVer_19_0_0 ) ;
ObjectNode rpcActualResult19_0_0 = JacksonUtil . fromString ( actualResult19_0_0 , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult19_0_0 . get ( "result" ) . asText ( ) ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_3_0_9 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer3_0_14 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer19_1_0_0 ) ) ) ;
assertTrue ( actualValues . contains ( "SingleObservation:" + fromVersionedIdToObjectId ( idVer_19_0_0 ) ) ) ;
}
/ * *
* ObserveReadAll
* { "result" : "CONTENT" , "value" : "[\"CompositeObservation: [/19/1/0\",\"/19/0/0\",\"/3/0/14\",\"/3/0/9]\"]" } - Ok
* @throws Exception
* /
@Test
public void testObserveReadAll_AfterCompositeObservation_WithResourceNotReadable_Result_CONTENT_Value_SingleObservation_Only ( ) throws Exception {
sendCancelObserveAllWithAwait ( deviceId ) ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_2 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_2 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_2 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResult . get ( "value" ) . asText ( ) ;
assertTrue ( actualValues . contains ( fromVersionedIdToObjectId ( expectedIdVer5_0_2 ) + "=null" ) ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
assertFalse ( actualValues . contains ( fromVersionedIdToObjectId ( expectedIdVer5_0_2 ) ) ) ;
}
}
/ * *
/ * *
@ -310,166 +329,179 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
* @throws Exception
* @throws Exception
* /
* /
@Test
@Test
public void testObserveCompositeAnyResources_Result_CONTENT_CancelObserveComposite_This_Result_Content_Count_5 ( ) throws Exception {
public void testObserveCancelAllThenObserveC ompositeAnyResources_Result_CONTENT_CancelObserveComposite_This_Result_Content_Count_1 ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancel AllWithAwait ( deviceId ) ;
// ObserveComposite
// ObserveComposite
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
// ObserveCompositeCancel
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( "5" , rpcActualResult . get ( "value" ) . asText ( ) ) ;
assertEquals ( 0 , ( Object ) getCntObserveAll ( deviceId ) ) ;
}
/ * *
* ObserveComposite { "ids" : [ "/3" , "/5/0/3" , "/19/1/0/0" ] } - Ok
* ObserveCompositeCancel { "ids" : [ "/3" , "/5/0/3" , "/19/1/0/0" ] } - Ok
* @throws Exception
* /
@Test
public void testObserveCompositeOneObjectAnyResources_Result_CONTENT_CancelObserveComposite_This_Result_Content_Count_3 ( ) throws Exception {
sendCancelObserveAllWithAwait ( deviceId ) ;
// ObserveComposite
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIds = "[\"" + idVer_3_0_9 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
// ObserveCompositeCancel
// ObserveCompositeCancel
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( "3 " , rpcActualResult . get ( "value" ) . asText ( ) ) ;
assertEquals ( "1" , rpcActualResult . get ( "value" ) . asText ( ) ) ;
assertEquals ( 0 , ( Object ) getCntObserveAll ( deviceId ) ) ;
assertEquals ( 0 , ( Object ) getCntObserveAll ( deviceId ) ) ;
}
}
/ * *
/ * *
* ObserveComposite { "ids" : [ "/3/0/9" , "/5/0/5" , "/5/0/3" , "/5/0/7" , "/19/1/0/0" ] } - Ok
* ObserveComposite { "ids" : [ "/3/0/9" , "/5/0/5" , "/5/0/3" , "/5/0/7" , "/19/1/0/0" ] } - Ok
* ObserveCompositeCancel { "ids" : [ "/5" , "/19/1/0/0" ] } - Ok
* ObserveCompositeCancel { "ids" : [ "/5" , "/19/1/0/0" ] } - BadRequest
* last Observation
* @throws Exception
* @throws Exception
* /
* /
@Test
@Test
public void testObserveCompositeAnyResources_Result_CONTENT_CancelObserveComposite_OneObjectAnyResource_Result_Content_Count_4 ( ) throws Exception {
public void testObserveCompositeFiveResources_Result_CONTENT_CancelObserveComposite_TwoAnyResource_Result_BadRequest ( ) throws Exception {
sendCancel ObserveAllWithAwait ( deviceId ) ;
sendObserveCancelAllWithAwait ( deviceId ) ;
// ObserveComposite
// ObserveComposite five
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_7 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_7 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_5 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_5 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer3_0_9 = objectInstanceIdVer_3 + "/" + RESOURCE_ID_9 ;
String expectedIdVer3_0_9 = objectInstanceIdVer_3 + "/" + RESOURCE_ID_9 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + expectedIdVer3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String expectedIds = "[\"" + expectedIdVer5_0_7 + "\", \"" + expectedIdVer5_0_5 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + expectedIdVer3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
awaitObserveReadAll ( 5 , deviceId ) ;
awaitObserveReadAll ( 1 , deviceId ) ;
// ObserveCompositeCancel
// ObserveCompositeCancel two
expectedIds = "[\"" + objectInstanceIdVer_5 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
expectedIds = "[\"" + objectInstanceIdVer_5 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( "4" , rpcActualResult . get ( "value" ) . asText ( ) ) ; // CNT = 4 ("/5/0/5", "/5/0/3", "/5/0/7", "/19/1/0/0"9)
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( objectInstanceIdVer_5 ) ) ; // CNT = 4 ("/5/0/5", "/5/0/3", "/5/0/7", "/19/1/0/0"9)
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( expectedIdVer19_1_0_0 ) ) ; // CNT = 4 ("/5/0/5", "/5/0/3", "/5/0/7", "/19/1/0/0"9)
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
assertEquals ( "[\"SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer3_0_9 ) + "\"]" , actualValues ) ;
}
}
/ * *
/ * *
* ObserveComposite { "ids" : [ "/3" , "/5/0/3" , "/19/1/0/0" ] } - Ok
* ObserveComposite { "ids" : [ "/3" , "/5/0/3" , "/19/1/0/0" ] } - Ok
* ObserveCompositeCancel { "ids" : [ "/3/0/9" , "/5/0/3" , "/19/1/0/0" } - > BAD_REQUEST
* ObserveCompositeCancel { "ids" : [ "/19/1/0/0" , "/3/0/9" } - > BAD_REQUEST
* ObserveCompositeCancel { "ids" : [ "/3" } - > CONTENT
* /
* /
@Test
@Test
public void testObserveOneObjectAnyResources_Result_CONTENT_Cancel_OneResourceFromObjectAnyResource_Result_BAD_REQUEST_Cancel_OneObject_Result_CONTENT ( ) throws Exception {
public void testObserveOneObjectAnyResources_Result_CONTENT_Cancel_OneResourceFromObjectAnyResource_Result_BAD_REQUEST_Cancel_OneObject_Result_CONTENT ( ) throws Exception {
sendCancelObserveAllWithAwait ( deviceId ) ;
sendObserveCancelAllWithAwait ( deviceId ) ;
// ObserveComposite
// ObserveComposite
sendCancelObserveAllWithAwait ( deviceId ) ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIds = "[\"" + objectIdVer_3 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String expectedIds = "[\"" + objectIdVer_3 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
// ObserveCompositeCancel
// ObserveCompositeCancel
expecte dIds = "[\"" + expectedIdVer19_1_0_0 + "\", \"" + idVer_3_0_9 + "\"]" ;
String sen dIds = "[\"" + expectedIdVer19_1_0_0 + "\", \"" + idVer_3_0_9 + "\"]" ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expecte dIds) ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , sen dIds) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . BAD_REQUEST . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
String expectedValue = "for observation path [" + fromVersionedIdToObjectId ( objectIdVer_3 ) + "], that includes this observation path [" + fromVersionedIdToObjectId ( idVer_3_0_9 ) ;
String expectedValue = "Could not find active Observe Composite component with paths: [/19_1.1/1/0/0, /3_1.2/0/9]" ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( expectedValue ) ) ;
assertTrue ( rpcActualResult . get ( "error" ) . asText ( ) . contains ( expectedValue ) ) ;
// ObserveCompositeCancel
// "ObserveReadAll"
expectedIds = "[\"" + objectIdVer_3 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( "2" , rpcActualResult . get ( "value" ) . asText ( ) ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
assertEquals ( "[\"SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer5_0_3 ) + "\"]" , actualValues ) ;
assertTrue ( actualValues . contains ( "CompositeObservation:" ) ) ;
}
}
/ * *
* ObserveComposite { "ids" : [ "/3/0/9" , "/3/0/14" , "/5/0/3" , "/3/0/15" , "/19/1/0/0" ] } - Ok
* ObserveCancel { "id" : "/3/0/9" } - > INTERNAL_SERVER_ERROR
* ObserveCompositeCancel { "ids" : [ "/3/0/9" , "/19/1/0/0" , " / 3 ] } - Ok
* last Observation
* @throws Exception
* /
@Test
@Test
public void testObserveCompositeAnyResources_Result_CONTENT_CancelObserveComposite_OneResource_OneObjectAnyResource_Result_Content_Count_4 ( ) throws Exception {
public void testObserveCompositeResource_Update_After_Registration_UpdateRegistration ( ) throws Exception {
sendCancelObserveAllWithAwait ( deviceId ) ;
String id_3_0_9 = fromVersionedIdToObjectId ( idVer_3_0_9 ) ;
// ObserveComposite
String id_19_0_0 = fromVersionedIdToObjectId ( idVer_19_0_0 ) ;
sendCancelObserveAllWithAwait ( deviceId ) ;
String idVer_19_1_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 ;
String expectedIdVer3_0_14 = objectIdVer_3 + "/" + OBJECT_INSTANCE_ID_0 + "/" + RESOURCE_ID_14 ;
String id_19_1_0 = fromVersionedIdToObjectId ( idVer_19_1_0 ) ;
String expectedIdVer3_0_15 = objectIdVer_3 + "/" + OBJECT_INSTANCE_ID_0 + "/" + RESOURCE_ID_15 ;
String idVer_19_0_2 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_0 + "/" + RESOURCE_ID_2 ;
String expectedIdVer5_0_3 = objectInstanceIdVer_5 + "/" + RESOURCE_ID_3 ;
String id_19_0_2 = fromVersionedIdToObjectId ( idVer_19_0_2 ) ;
String expectedIdVer19_1_0_0 = objectIdVer_19 + "/" + OBJECT_INSTANCE_ID_1 + "/" + RESOURCE_ID_0 + "/" + RESOURCE_INSTANCE_ID_0 ;
String expectedIds = "[\"" + idVer_3_0_9 + "\", \"" + expectedIdVer3_0_14 + "\", \"" + expectedIdVer5_0_3 + "\", \"" + expectedIdVer3_0_15 + "\", \"" + expectedIdVer19_1_0_0 + "\"]" ;
// 1 - "ObserveReadAll": at least one update value of all resources we observe - after connection
String actualResult = sendCompositeRPCByIds ( "ObserveComposite" , expectedIds ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
// ObserveCompositeCancel
expectedIds = "[\"" + idVer_3_0_9 + "\", \"" + expectedIdVer19_1_0_0 + "\", \"" + objectIdVer_3 + "\"]" ;
actualResult = sendCompositeRPCByIds ( "ObserveCompositeCancel" , expectedIds ) ;
rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResult . get ( "result" ) . asText ( ) ) ;
assertEquals ( "4" , rpcActualResult . get ( "value" ) . asText ( ) ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
String actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
ObjectNode rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
String actualValues = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
String rpcActualVValuesReadAll = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
assertEquals ( "[\"SingleObservation:" + fromVersionedIdToObjectId ( expectedIdVer5_0_3 ) + "\"]" , actualValues ) ;
ArrayNode rpcactualValues = JacksonUtil . fromString ( rpcActualVValuesReadAll , ArrayNode . class ) ;
assertEquals ( rpcactualValues . size ( ) , 4 ) ;
assertTrue ( actualResultReadAll . contains ( "SingleObservation:" + id_3_0_9 ) ) ;
assertTrue ( actualResultReadAll . contains ( "SingleObservation:" + id_19_1_0 ) ) ;
assertTrue ( actualResultReadAll . contains ( "SingleObservation:" + id_19_0_2 ) ) ;
assertTrue ( actualResultReadAll . contains ( "SingleObservation:" + id_19_0_0 ) ) ;
long initAttrTelemetryAtCount = countUpdateAttrTelemetryAll ( ) ;
long initAttrTelemetryAtCount_3_0_9 = countUpdateAttrTelemetryResource ( idVer_3_0_9 ) ;
long initAttrTelemetryAtCount_19_0_0 = countUpdateAttrTelemetryResource ( idVer_19_0_0 ) ;
long initAttrTelemetryAtCount_19_1_0 = countUpdateAttrTelemetryResource ( idVer_19_1_0 ) ;
long initAttrTelemetryAtCount_19_0_2 = countUpdateAttrTelemetryResource ( idVer_19_0_2 ) ;
updateRegAtLeastOnceAfterAction ( ) ;
updateAttrTelemetryAllAtLeastOnceAfterAction ( initAttrTelemetryAtCount ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_3_0_9 , idVer_3_0_9 ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_19_0_0 , idVer_19_0_0 ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_19_1_0 , idVer_19_1_0 ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_19_0_2 , idVer_19_0_2 ) ;
// 2 - "ObserveReadAll": No update of all resources we are observing - after "ObserveReadCancelAll"
sendObserveCancelAllWithAwait ( deviceId ) ;
updateRegAtLeastOnceAfterAction ( ) ;
actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
rpcActualVValuesReadAll = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
rpcactualValues = JacksonUtil . fromString ( rpcActualVValuesReadAll , ArrayNode . class ) ;
assertEquals ( rpcactualValues . size ( ) , 0 ) ;
// 2.1 - ObserveComposite: observeCancelAll verify"
initAttrTelemetryAtCount = countUpdateAttrTelemetryAll ( ) ;
initAttrTelemetryAtCount_3_0_9 = countUpdateAttrTelemetryResource ( idVer_3_0_9 ) ;
initAttrTelemetryAtCount_19_0_0 = countUpdateAttrTelemetryResource ( idVer_19_0_0 ) ;
initAttrTelemetryAtCount_19_1_0 = countUpdateAttrTelemetryResource ( idVer_19_1_0 ) ;
initAttrTelemetryAtCount_19_0_2 = countUpdateAttrTelemetryResource ( idVer_19_0_2 ) ;
updateRegAtLeastOnceAfterAction ( ) ;
assertEquals ( countUpdateAttrTelemetryAll ( ) , initAttrTelemetryAtCount ) ;
assertEquals ( countUpdateAttrTelemetryResource ( idVer_3_0_9 ) , initAttrTelemetryAtCount_3_0_9 ) ;
assertEquals ( countUpdateAttrTelemetryResource ( idVer_19_0_0 ) , initAttrTelemetryAtCount_19_0_0 ) ;
assertEquals ( countUpdateAttrTelemetryResource ( idVer_19_1_0 ) , initAttrTelemetryAtCount_19_1_0 ) ;
assertEquals ( countUpdateAttrTelemetryResource ( idVer_19_0_2 ) , initAttrTelemetryAtCount_19_0_2 ) ;
// 3 - ObserveComposite: at least one update value of all resources we observe - after ObserveComposite"
String expectedKeys = "[\"" + RESOURCE_ID_NAME_3_9 + "\", \"" + RESOURCE_ID_NAME_19_0_0 + "\", \"" + RESOURCE_ID_NAME_19_0_2 + "\", \"" + RESOURCE_ID_NAME_19_1_0 + "\"]" ;
String actualResult = sendCompositeRPCByKeys ( "ObserveComposite" , expectedKeys ) ;
assertTrue ( actualResult . contains ( id_3_0_9 + "=LwM2mSingleResource" ) ) ;
assertTrue ( actualResult . contains ( id_19_0_0 + "=LwM2mMultipleResource" ) ) ;
assertTrue ( actualResult . contains ( id_19_1_0 + "=LwM2mMultipleResource" ) ) ;
assertTrue ( actualResult . contains ( id_19_0_2 + "=LwM2mSingleResource" ) ) ;
// 3.1 - ObserveComposite: - verify");
actualResultReadAll = sendCompositeRPCByKeys ( "ObserveReadAll" , null ) ;
rpcActualResultReadAll = JacksonUtil . fromString ( actualResultReadAll , ObjectNode . class ) ;
assertEquals ( ResponseCode . CONTENT . getName ( ) , rpcActualResultReadAll . get ( "result" ) . asText ( ) ) ;
rpcActualVValuesReadAll = rpcActualResultReadAll . get ( "value" ) . asText ( ) ;
rpcactualValues = JacksonUtil . fromString ( rpcActualVValuesReadAll , ArrayNode . class ) ;
assertEquals ( rpcactualValues . size ( ) , 1 ) ;
assertFalse ( actualResultReadAll . contains ( "SingleObservation" ) ) ;
assertTrue ( actualResultReadAll . contains ( "CompositeObservation:" ) ) ;
assertTrue ( actualResultReadAll . contains ( id_19_0_2 ) ) ;
assertTrue ( actualResultReadAll . contains ( id_19_1_0 ) ) ;
assertTrue ( actualResultReadAll . contains ( id_19_0_0 ) ) ;
assertTrue ( actualResultReadAll . contains ( id_3_0_9 ) ) ;
initAttrTelemetryAtCount = countUpdateAttrTelemetryAll ( ) ;
initAttrTelemetryAtCount_3_0_9 = countUpdateAttrTelemetryResource ( idVer_3_0_9 ) ;
initAttrTelemetryAtCount_19_0_0 = countUpdateAttrTelemetryResource ( idVer_19_0_0 ) ;
initAttrTelemetryAtCount_19_1_0 = countUpdateAttrTelemetryResource ( idVer_19_1_0 ) ;
initAttrTelemetryAtCount_19_0_2 = countUpdateAttrTelemetryResource ( idVer_19_0_2 ) ;
updateRegAtLeastOnceAfterAction ( ) ;
updateAttrTelemetryAllAtLeastOnceAfterAction ( initAttrTelemetryAtCount ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_3_0_9 , idVer_3_0_9 ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_19_0_0 , idVer_19_0_0 ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_19_1_0 , idVer_19_1_0 ) ;
updateAttrTelemetryResourceAtLeastOnceAfterAction ( initAttrTelemetryAtCount_19_0_2 , idVer_19_0_2 ) ;
}
}
private String sendObserve ( String method , String params ) throws Exception {
private String sendObserve ( String method , String params ) throws Exception {
String sendRpcRequest ;
String sendRpcRequest ;
if ( params = = null ) {
if ( params = = null ) {
sendRpcRequest = "{\"method\": \"" + method + "\"}" ;
sendRpcRequest = "{\"method\": \"" + method + "\"}" ;
}
} else {
else {
sendRpcRequest = "{\"method\": \"" + method + "\", \"params\": {\"id\": \"" + params + "\"}}" ;
sendRpcRequest = "{\"method\": \"" + method + "\", \"params\": {\"id\": \"" + params + "\"}}" ;
}
}
return doPostAsync ( "/api/plugins/rpc/twoway/" + deviceId , sendRpcRequest , String . class , status ( ) . isOk ( ) ) ;
return doPostAsync ( "/api/plugins/rpc/twoway/" + deviceId , sendRpcRequest , String . class , status ( ) . isOk ( ) ) ;
@ -481,7 +513,71 @@ public class RpcLwm2MIntegrationObserveCompositeTest extends AbstractRpcLwM2MInt
}
}
private String sendCompositeRPCByKeys ( String method , String keys ) throws Exception {
private String sendCompositeRPCByKeys ( String method , String keys ) throws Exception {
String setRpcRequest = "{\"method\": \"" + method + "\", \"params\": {\"keys\":" + keys + "}}" ;
String sendRpcRequest = "{\"method\": \"" + method + "\", \"params\": {\"keys\":" + keys + "}}" ;
return doPostAsync ( "/api/plugins/rpc/twoway/" + deviceId , setRpcRequest , String . class , status ( ) . isOk ( ) ) ;
return doPostAsync ( "/api/plugins/rpc/twoway/" + deviceId , sendRpcRequest , String . class , status ( ) . isOk ( ) ) ;
}
private long countUpdateAttrTelemetryAll ( ) {
return Mockito . mockingDetails ( defaultUplinkMsgHandlerTest )
. getInvocations ( ) . stream ( )
. filter ( invocation - > invocation . getMethod ( ) . getName ( ) . equals ( "updateAttrTelemetry" ) )
. count ( ) ;
}
private void updateAttrTelemetryAllAtLeastOnceAfterAction ( long initialInvocationCount ) {
AtomicLong newInvocationCount = new AtomicLong ( initialInvocationCount ) ;
log . warn ( "countUpdateAttrTelemetryAllAtLeastOnceAfterAction: initialInvocationCount [{}]" , initialInvocationCount ) ;
await ( "Update AttrTelemetryAll at-least-once after action" )
. atMost ( 50 , TimeUnit . SECONDS )
. until ( ( ) - > {
newInvocationCount . set ( countUpdateAttrTelemetryAll ( ) ) ;
return newInvocationCount . get ( ) > initialInvocationCount ;
} ) ;
log . warn ( "countUpdateAttrTelemetryAllAtLeastOnceAfterAction: newInvocationCount [{}]" , newInvocationCount . get ( ) ) ;
}
private long countUpdateAttrTelemetryResource ( String idVerRez ) {
return Mockito . mockingDetails ( defaultUplinkMsgHandlerTest )
. getInvocations ( ) . stream ( )
. filter ( invocation - >
invocation . getMethod ( ) . getName ( ) . equals ( "updateAttrTelemetry" ) & &
invocation . getArguments ( ) . length > 1 & &
idVerRez . equals ( invocation . getArguments ( ) [ 1 ] )
)
. count ( ) ;
}
private void updateAttrTelemetryResourceAtLeastOnceAfterAction ( long initialInvocationCount , String idVerRez ) {
AtomicLong newInvocationCount = new AtomicLong ( initialInvocationCount ) ;
log . warn ( "countUpdateAttrTelemetryResourceAtLeastOnceAfterAction: initialInvocationCount [{}]" , initialInvocationCount ) ;
await ( "Update AttrTelemetryResource at-least-once after action" )
. atMost ( 50 , TimeUnit . SECONDS )
. until ( ( ) - > {
newInvocationCount . set ( countUpdateAttrTelemetryResource ( idVerRez ) ) ;
return newInvocationCount . get ( ) > initialInvocationCount ;
} ) ;
log . warn ( "countUpdateAttrTelemetryResourceAtLeastOnceAfterAction: newInvocationCount [{}]" , newInvocationCount . get ( ) ) ;
}
private long countUpdateReg ( ) {
return Mockito . mockingDetails ( defaultUplinkMsgHandlerTest )
. getInvocations ( ) . stream ( )
. filter ( invocation - > invocation . getMethod ( ) . getName ( ) . equals ( "updatedReg" ) )
. count ( ) ;
}
private void updateRegAtLeastOnceAfterAction ( ) {
long initialInvocationCount = countUpdateReg ( ) ;
AtomicLong newInvocationCount = new AtomicLong ( initialInvocationCount ) ;
log . warn ( "updateRegAtLeastOnceAfterAction: initialInvocationCount [{}]" , initialInvocationCount ) ;
await ( "Update Registration at-least-once after action" )
. atMost ( 50 , TimeUnit . SECONDS )
. until ( ( ) - > {
newInvocationCount . set ( countUpdateReg ( ) ) ;
return newInvocationCount . get ( ) > initialInvocationCount ;
} ) ;
log . warn ( "updateRegAtLeastOnceAfterAction: newInvocationCount [{}]" , newInvocationCount . get ( ) ) ;
}
}
}
}