|
|
@ -22,6 +22,7 @@ import org.thingsboard.server.common.data.cf.CalculatedFieldType; |
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
|
|
import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
|
|
|
|
|
import org.thingsboard.server.common.data.relation.RelationPathLevel; |
|
|
|
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
@ -42,6 +43,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenConfigurationDisallowArgumentsWithReferencedEntity() { |
|
|
void validateShouldThrowWhenConfigurationDisallowArgumentsWithReferencedEntity() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
Argument argumentWithRefEntityIdSet = new Argument(); |
|
|
Argument argumentWithRefEntityIdSet = new Argument(); |
|
|
argumentWithRefEntityIdSet.setRefEntityId(new DeviceId(UUID.fromString("bda14084-f40e-4acc-9b85-9d1dd209bb64"))); |
|
|
argumentWithRefEntityIdSet.setRefEntityId(new DeviceId(UUID.fromString("bda14084-f40e-4acc-9b85-9d1dd209bb64"))); |
|
|
cfg.setArguments(Map.of("argumentWithRefEntityIdSet", argumentWithRefEntityIdSet)); |
|
|
cfg.setArguments(Map.of("argumentWithRefEntityIdSet", argumentWithRefEntityIdSet)); |
|
|
@ -53,6 +55,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenConfigurationDisallowArgumentsWithDynamicReferenceConfiguration() { |
|
|
void validateShouldThrowWhenConfigurationDisallowArgumentsWithDynamicReferenceConfiguration() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
Argument argumentWithDynamicRefEntitySource = new Argument(); |
|
|
Argument argumentWithDynamicRefEntitySource = new Argument(); |
|
|
argumentWithDynamicRefEntitySource.setRefDynamicSourceConfiguration(new CurrentOwnerDynamicSourceConfiguration()); |
|
|
argumentWithDynamicRefEntitySource.setRefDynamicSourceConfiguration(new CurrentOwnerDynamicSourceConfiguration()); |
|
|
cfg.setArguments(Map.of("argumentWithDynamicRefEntitySource", argumentWithDynamicRefEntitySource)); |
|
|
cfg.setArguments(Map.of("argumentWithDynamicRefEntitySource", argumentWithDynamicRefEntitySource)); |
|
|
@ -64,6 +67,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenConfigurationHasNoArgumentsWithCurrentEntitySource() { |
|
|
void validateShouldThrowWhenConfigurationHasNoArgumentsWithCurrentEntitySource() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
Argument argumentWithRefEntityIdSet = new Argument(); |
|
|
Argument argumentWithRefEntityIdSet = new Argument(); |
|
|
argumentWithRefEntityIdSet.setRefEntityId(new DeviceId(UUID.fromString("3703e895-3f9b-4b75-a715-b68f1ad51944"))); |
|
|
argumentWithRefEntityIdSet.setRefEntityId(new DeviceId(UUID.fromString("3703e895-3f9b-4b75-a715-b68f1ad51944"))); |
|
|
cfg.setArguments(Map.of("argumentWithRefEntityIdSet", argumentWithRefEntityIdSet)); |
|
|
cfg.setArguments(Map.of("argumentWithRefEntityIdSet", argumentWithRefEntityIdSet)); |
|
|
@ -77,6 +81,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenUsedReservedPropagationArgumentName() { |
|
|
void validateShouldThrowWhenUsedReservedPropagationArgumentName() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
cfg.setArguments(Map.of(PROPAGATION_CONFIG_ARGUMENT, new Argument())); |
|
|
cfg.setArguments(Map.of(PROPAGATION_CONFIG_ARGUMENT, new Argument())); |
|
|
assertThatThrownBy(cfg::validate) |
|
|
assertThatThrownBy(cfg::validate) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
@ -86,6 +91,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenUsedReservedCtxArgumentName() { |
|
|
void validateShouldThrowWhenUsedReservedCtxArgumentName() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
cfg.setArguments(Map.of("ctx", new Argument())); |
|
|
cfg.setArguments(Map.of("ctx", new Argument())); |
|
|
assertThatThrownBy(cfg::validate) |
|
|
assertThatThrownBy(cfg::validate) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
@ -95,6 +101,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenReferencedEntityKeyIsNotSet() { |
|
|
void validateShouldThrowWhenReferencedEntityKeyIsNotSet() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
Argument argument = new Argument(); |
|
|
Argument argument = new Argument(); |
|
|
cfg.setArguments(Map.of("someArgumentName", argument)); |
|
|
cfg.setArguments(Map.of("someArgumentName", argument)); |
|
|
assertThatThrownBy(cfg::validate) |
|
|
assertThatThrownBy(cfg::validate) |
|
|
@ -105,6 +112,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenReferencedEntityKeyTypeIsTsRolling() { |
|
|
void validateShouldThrowWhenReferencedEntityKeyTypeIsTsRolling() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
ReferencedEntityKey referencedEntityKey = new ReferencedEntityKey("someKey", ArgumentType.TS_ROLLING, null); |
|
|
ReferencedEntityKey referencedEntityKey = new ReferencedEntityKey("someKey", ArgumentType.TS_ROLLING, null); |
|
|
Argument argument = new Argument(); |
|
|
Argument argument = new Argument(); |
|
|
argument.setRefEntityKey(referencedEntityKey); |
|
|
argument.setRefEntityKey(referencedEntityKey); |
|
|
@ -118,6 +126,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateShouldThrowWhenExpressionIsNotSet() { |
|
|
void validateShouldThrowWhenExpressionIsNotSet() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
|
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
cfg.setArguments(Map.of("someArgumentName", new Argument())); |
|
|
cfg.setArguments(Map.of("someArgumentName", new Argument())); |
|
|
cfg.setApplyExpressionToResolvedArguments(true); |
|
|
cfg.setApplyExpressionToResolvedArguments(true); |
|
|
assertThatThrownBy(cfg::validate) |
|
|
assertThatThrownBy(cfg::validate) |
|
|
@ -128,8 +137,7 @@ public class PropagationCalculatedFieldConfigurationTest { |
|
|
@Test |
|
|
@Test |
|
|
void validateToPropagationArgumentMethodCallReturnCorrectArgument() { |
|
|
void validateToPropagationArgumentMethodCallReturnCorrectArgument() { |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
var cfg = new PropagationCalculatedFieldConfiguration(); |
|
|
cfg.setDirection(EntitySearchDirection.TO); |
|
|
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE)); |
|
|
cfg.setRelationType(EntityRelation.CONTAINS_TYPE); |
|
|
|
|
|
|
|
|
|
|
|
Argument propagationArgument = cfg.toPropagationArgument(); |
|
|
Argument propagationArgument = cfg.toPropagationArgument(); |
|
|
assertThat(propagationArgument).isNotNull(); |
|
|
assertThat(propagationArgument).isNotNull(); |
|
|
|