|
|
@ -18,6 +18,9 @@ package org.thingsboard.server.service.cf.ctx.state; |
|
|
import io.hypersistence.utils.hibernate.type.json.internal.JacksonUtil; |
|
|
import io.hypersistence.utils.hibernate.type.json.internal.JacksonUtil; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
|
|
import org.mockito.Mock; |
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
import org.thingsboard.common.util.geo.PerimeterDefinition; |
|
|
import org.thingsboard.common.util.geo.PerimeterDefinition; |
|
|
import org.thingsboard.server.common.data.id.AssetId; |
|
|
import org.thingsboard.server.common.data.id.AssetId; |
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
@ -33,6 +36,7 @@ import java.util.UUID; |
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
public class GeofencingValueArgumentEntryTest { |
|
|
public class GeofencingValueArgumentEntryTest { |
|
|
|
|
|
|
|
|
private final AssetId ZONE_1_ID = new AssetId(UUID.fromString("c0e3031c-7df1-45e4-9590-cfd621a4d714")); |
|
|
private final AssetId ZONE_1_ID = new AssetId(UUID.fromString("c0e3031c-7df1-45e4-9590-cfd621a4d714")); |
|
|
@ -46,6 +50,9 @@ public class GeofencingValueArgumentEntryTest { |
|
|
|
|
|
|
|
|
private GeofencingArgumentEntry entry; |
|
|
private GeofencingArgumentEntry entry; |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
private CalculatedFieldCtx ctx; |
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setUp() { |
|
|
void setUp() { |
|
|
entry = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, allowedZoneAttributeKvEntry, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
entry = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, allowedZoneAttributeKvEntry, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
@ -58,14 +65,14 @@ public class GeofencingValueArgumentEntryTest { |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void testUpdateEntryWhenSingleEntryPassed() { |
|
|
void testUpdateEntryWhenSingleEntryPassed() { |
|
|
assertThatThrownBy(() -> entry.updateEntry(new SingleValueArgumentEntry())) |
|
|
assertThatThrownBy(() -> entry.updateEntry(new SingleValueArgumentEntry(), ctx)) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
.hasMessage("Unsupported argument entry type for geofencing argument entry: SINGLE_VALUE"); |
|
|
.hasMessage("Unsupported argument entry type for geofencing argument entry: SINGLE_VALUE"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void testUpdateEntryWhenRollingEntryPassed() { |
|
|
void testUpdateEntryWhenRollingEntryPassed() { |
|
|
assertThatThrownBy(() -> entry.updateEntry(new TsRollingArgumentEntry(5, 30000L))) |
|
|
assertThatThrownBy(() -> entry.updateEntry(new TsRollingArgumentEntry(5, 30000L), ctx)) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
.hasMessage("Unsupported argument entry type for geofencing argument entry: TS_ROLLING"); |
|
|
.hasMessage("Unsupported argument entry type for geofencing argument entry: TS_ROLLING"); |
|
|
} |
|
|
} |
|
|
@ -74,7 +81,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
void testUpdateEntryWithTheSameTs() { |
|
|
void testUpdateEntryWithTheSameTs() { |
|
|
BaseAttributeKvEntry differentValueSameTs = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 363L, 156L); |
|
|
BaseAttributeKvEntry differentValueSameTs = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 363L, 156L); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueSameTs, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueSameTs, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
assertThat(entry.updateEntry(updated)).isFalse(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isFalse(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -83,7 +90,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
BaseAttributeKvEntry differentValueNewVersionIsNull = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, null); |
|
|
BaseAttributeKvEntry differentValueNewVersionIsNull = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, null); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueNewVersionIsNull, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueNewVersionIsNull, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
|
|
|
|
|
|
assertThat(entry.updateEntry(updated)).isTrue(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isTrue(); |
|
|
assertThat(entry.getValue()).isInstanceOf(Map.class); |
|
|
assertThat(entry.getValue()).isInstanceOf(Map.class); |
|
|
|
|
|
|
|
|
Map<EntityId, GeofencingZoneState> value = (Map<EntityId, GeofencingZoneState>) entry.getValue(); |
|
|
Map<EntityId, GeofencingZoneState> value = (Map<EntityId, GeofencingZoneState>) entry.getValue(); |
|
|
@ -105,7 +112,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
BaseAttributeKvEntry differentValueNewVersionIsSet = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, 156L); |
|
|
BaseAttributeKvEntry differentValueNewVersionIsSet = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, 156L); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueNewVersionIsSet, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueNewVersionIsSet, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
|
|
|
|
|
|
assertThat(entry.updateEntry(updated)).isTrue(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isTrue(); |
|
|
assertThat(entry.getValue()).isInstanceOf(Map.class); |
|
|
assertThat(entry.getValue()).isInstanceOf(Map.class); |
|
|
|
|
|
|
|
|
Map<EntityId, GeofencingZoneState> value = (Map<EntityId, GeofencingZoneState>) entry.getValue(); |
|
|
Map<EntityId, GeofencingZoneState> value = (Map<EntityId, GeofencingZoneState>) entry.getValue(); |
|
|
@ -126,7 +133,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
BaseAttributeKvEntry differentValueNewVersionIsSet = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, 154L); |
|
|
BaseAttributeKvEntry differentValueNewVersionIsSet = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, 154L); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueNewVersionIsSet, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, differentValueNewVersionIsSet, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
|
|
|
|
|
|
assertThat(entry.updateEntry(updated)).isFalse(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isFalse(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -134,7 +141,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
BaseAttributeKvEntry newTsAndTheSameValue = new BaseAttributeKvEntry(allowedZoneDataEntry, 364L, 156L); |
|
|
BaseAttributeKvEntry newTsAndTheSameValue = new BaseAttributeKvEntry(allowedZoneDataEntry, 364L, 156L); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, newTsAndTheSameValue, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, newTsAndTheSameValue, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
|
|
|
|
|
|
assertThat(entry.updateEntry(updated)).isTrue(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isTrue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -142,7 +149,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
BaseAttributeKvEntry oldTsAndTheSameValue = new BaseAttributeKvEntry(allowedZoneDataEntry, 362L, 156L); |
|
|
BaseAttributeKvEntry oldTsAndTheSameValue = new BaseAttributeKvEntry(allowedZoneDataEntry, 362L, 156L); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, oldTsAndTheSameValue, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, oldTsAndTheSameValue, ZONE_2_ID, restrictedZoneAttributeKvEntry)); |
|
|
|
|
|
|
|
|
assertThat(entry.updateEntry(updated)).isFalse(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isFalse(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@ -150,7 +157,7 @@ public class GeofencingValueArgumentEntryTest { |
|
|
final AssetId NEW_ZONE_ID = new AssetId(UUID.fromString("a3eacf1a-6af3-4e9f-87c4-502bb25c7dc3")); |
|
|
final AssetId NEW_ZONE_ID = new AssetId(UUID.fromString("a3eacf1a-6af3-4e9f-87c4-502bb25c7dc3")); |
|
|
BaseAttributeKvEntry newZone = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, 156L); |
|
|
BaseAttributeKvEntry newZone = new BaseAttributeKvEntry(new JsonDataEntry("zone", "[[50.472001, 30.504001], [50.472001, 30.506001], [50.474001, 30.506001], [50.474001, 30.504001]]"), 364L, 156L); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, allowedZoneAttributeKvEntry, ZONE_2_ID, restrictedZoneAttributeKvEntry, NEW_ZONE_ID, newZone)); |
|
|
var updated = new GeofencingArgumentEntry(Map.of(ZONE_1_ID, allowedZoneAttributeKvEntry, ZONE_2_ID, restrictedZoneAttributeKvEntry, NEW_ZONE_ID, newZone)); |
|
|
assertThat(entry.updateEntry(updated)).isTrue(); |
|
|
assertThat(entry.updateEntry(updated, ctx)).isTrue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
|