|
|
|
@ -26,24 +26,31 @@ import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.JsonDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.StringDataEntry; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.CalculatedFieldStateProto; |
|
|
|
import org.thingsboard.server.service.cf.ctx.CalculatedFieldEntityCtxId; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.ArgumentEntry; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.CalculatedFieldCtx; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.CalculatedFieldState; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.SingleValueArgumentEntry; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.geofencing.GeofencingArgumentEntry; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.geofencing.GeofencingCalculatedFieldState; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.geofencing.GeofencingZoneState; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.propagation.PropagationArgumentEntry; |
|
|
|
import org.thingsboard.server.service.cf.ctx.state.propagation.PropagationCalculatedFieldState; |
|
|
|
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.mockito.BDDMockito.given; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.thingsboard.server.common.data.cf.configuration.PropagationCalculatedFieldConfiguration.PROPAGATION_CONFIG_ARGUMENT; |
|
|
|
import static org.thingsboard.server.utils.CalculatedFieldUtils.toProto; |
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
class CalculatedFieldUtilsTest { |
|
|
|
|
|
|
|
@ -105,4 +112,41 @@ class CalculatedFieldUtilsTest { |
|
|
|
assertThat(fromProtoGeoArgument.getZoneStates().get(z2).getLastPresence()).isNull(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void toProtoAndFromProto_shouldCreatePropagationStateWithoutPropagationArgument() { |
|
|
|
// given
|
|
|
|
CalculatedFieldEntityCtxId stateId = mock(CalculatedFieldEntityCtxId.class); |
|
|
|
given(stateId.tenantId()).willReturn(TENANT_ID); |
|
|
|
given(stateId.cfId()).willReturn(CF_ID); |
|
|
|
given(stateId.entityId()).willReturn(DEVICE_ID); |
|
|
|
|
|
|
|
AssetId propagationAssetId = new AssetId(UUID.fromString("17bbf99c-3b87-4d21-b07d-da7409bb2bb7")); |
|
|
|
PropagationArgumentEntry propagationArgumentEntry = new PropagationArgumentEntry(List.of(propagationAssetId)); |
|
|
|
|
|
|
|
long lastUpdateTs = System.currentTimeMillis(); |
|
|
|
SingleValueArgumentEntry singleValueArgumentEntry = new SingleValueArgumentEntry(new BaseAttributeKvEntry(new StringDataEntry("state", "active"), lastUpdateTs, 1L)); |
|
|
|
|
|
|
|
CalculatedFieldCtx cfCtxMock = mock(CalculatedFieldCtx.class); |
|
|
|
|
|
|
|
CalculatedFieldState state = new PropagationCalculatedFieldState(DEVICE_ID); |
|
|
|
state.update(Map.of(PROPAGATION_CONFIG_ARGUMENT, propagationArgumentEntry, "state", singleValueArgumentEntry), cfCtxMock); |
|
|
|
|
|
|
|
// when
|
|
|
|
CalculatedFieldStateProto proto = toProto(stateId, state); |
|
|
|
|
|
|
|
// then
|
|
|
|
CalculatedFieldState restored = CalculatedFieldUtils.fromProto(stateId, proto); |
|
|
|
|
|
|
|
// Propagation argument is not persisted -> should be absent after restore
|
|
|
|
assertThat(restored).isNotNull(); |
|
|
|
assertThat(restored).isInstanceOf(PropagationCalculatedFieldState.class); |
|
|
|
|
|
|
|
PropagationCalculatedFieldState propagationState = (PropagationCalculatedFieldState) restored; |
|
|
|
|
|
|
|
assertThat(propagationState.getEntityId()).isEqualTo(DEVICE_ID); |
|
|
|
assertThat(propagationState.getArguments()).isNotNull(); |
|
|
|
assertThat(propagationState.getArguments().get(PROPAGATION_CONFIG_ARGUMENT)).isNull(); |
|
|
|
assertThat(propagationState.getArguments().get("state")).isNotNull().isEqualTo(singleValueArgumentEntry); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|