|
|
|
@ -25,6 +25,7 @@ import org.thingsboard.server.service.cf.ctx.state.propagation.PropagationArgume |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
@ -59,10 +60,10 @@ public class PropagationArgumentEntryTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
void testGetValueReturnsPropagationIds() { |
|
|
|
assertThat(entry.getValue()).isInstanceOf(List.class); |
|
|
|
assertThat(entry.getValue()).isInstanceOf(Set.class); |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<AssetId> value = (List<AssetId>) entry.getValue(); |
|
|
|
assertThat(value).containsExactly(ENTITY_1_ID, ENTITY_2_ID); |
|
|
|
Set<AssetId> value = (Set<AssetId>) entry.getValue(); |
|
|
|
assertThat(value).containsExactlyInAnyOrder(ENTITY_1_ID, ENTITY_2_ID); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -87,7 +88,7 @@ public class PropagationArgumentEntryTest { |
|
|
|
boolean changed = entry.updateEntry(updated); |
|
|
|
|
|
|
|
assertThat(changed).isTrue(); |
|
|
|
assertThat(entry.getPropagationEntityIds()).containsExactlyElementsOf(newIds); |
|
|
|
assertThat(entry.getEntityIds()).containsExactlyElementsOf(newIds); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -97,59 +98,79 @@ public class PropagationArgumentEntryTest { |
|
|
|
boolean changed = entry.updateEntry(updatedEmpty); |
|
|
|
|
|
|
|
assertThat(changed).isTrue(); |
|
|
|
assertThat(entry.getPropagationEntityIds()).isEmpty(); |
|
|
|
assertThat(entry.getEntityIds()).isEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
void testToTbelCfArgWithValues() { |
|
|
|
TbelCfArg arg = entry.toTbelCfArg(); |
|
|
|
assertThat(arg).isInstanceOf(TbelCfPropagationArg.class); |
|
|
|
void testUpdateEntryWhenAdded() { |
|
|
|
var added = new PropagationArgumentEntry(); |
|
|
|
added.setAdded(ENTITY_3_ID); |
|
|
|
|
|
|
|
TbelCfPropagationArg tbelCfPropagationArg = (TbelCfPropagationArg) arg; |
|
|
|
assertThat(tbelCfPropagationArg.getValue()).isInstanceOf(List.class); |
|
|
|
assertThat((List<EntityId>) tbelCfPropagationArg.getValue()).containsExactly(ENTITY_1_ID, ENTITY_2_ID); |
|
|
|
} |
|
|
|
boolean changed = entry.updateEntry(added); |
|
|
|
|
|
|
|
assertThat(changed).isTrue(); |
|
|
|
assertThat(entry.getEntityIds()).containsExactlyInAnyOrder(ENTITY_1_ID, ENTITY_2_ID, ENTITY_3_ID); |
|
|
|
assertThat(entry.getAdded()).isEqualTo(ENTITY_3_ID); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
void testToTbelCfArgWithEmptyValues() { |
|
|
|
var empty = new PropagationArgumentEntry(List.of()); |
|
|
|
TbelCfArg emptyArg = empty.toTbelCfArg(); |
|
|
|
assertThat(emptyArg).isInstanceOf(TbelCfPropagationArg.class); |
|
|
|
void testUpdateEntryWhenAddedExistingEntity() { |
|
|
|
var added = new PropagationArgumentEntry(); |
|
|
|
added.setAdded(ENTITY_2_ID); |
|
|
|
|
|
|
|
TbelCfPropagationArg tbelCfPropagationArg = (TbelCfPropagationArg) emptyArg; |
|
|
|
assertThat(tbelCfPropagationArg.getValue()).isInstanceOf(List.class); |
|
|
|
assertThat((List<EntityId>) tbelCfPropagationArg.getValue()).isEmpty(); |
|
|
|
boolean changed = entry.updateEntry(added); |
|
|
|
|
|
|
|
assertThat(changed).isFalse(); |
|
|
|
assertThat(entry.getEntityIds()).containsExactlyInAnyOrder(ENTITY_1_ID, ENTITY_2_ID); |
|
|
|
assertThat(entry.getAdded()).isNull(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testAddNewPropagationEntityIdToEmptyArgument() { |
|
|
|
PropagationArgumentEntry empty = new PropagationArgumentEntry(List.of()); |
|
|
|
assertThat(empty.addPropagationEntityId(ENTITY_1_ID)).isTrue(); |
|
|
|
assertThat(empty.getPropagationEntityIds()).containsExactly(ENTITY_1_ID); |
|
|
|
void testUpdateEntryWhenRemoved() { |
|
|
|
var removed = new PropagationArgumentEntry(); |
|
|
|
removed.setRemoved(ENTITY_2_ID); |
|
|
|
|
|
|
|
boolean changed = entry.updateEntry(removed); |
|
|
|
|
|
|
|
assertThat(changed).isTrue(); |
|
|
|
assertThat(entry.getEntityIds()).containsExactlyInAnyOrder(ENTITY_1_ID); |
|
|
|
assertThat(entry.getRemoved()).isNull(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testAddNewPropagationEntityIdThatAlreadyExists() { |
|
|
|
PropagationArgumentEntry hasEntity = new PropagationArgumentEntry(List.of(ENTITY_1_ID)); |
|
|
|
assertThat(hasEntity.addPropagationEntityId(ENTITY_1_ID)).isFalse(); |
|
|
|
assertThat(hasEntity.getPropagationEntityIds()).containsExactly(ENTITY_1_ID); |
|
|
|
void testUpdateEntryWhenRemovedNonExistingEntity() { |
|
|
|
var removed = new PropagationArgumentEntry(); |
|
|
|
removed.setRemoved(ENTITY_3_ID); |
|
|
|
|
|
|
|
boolean changed = entry.updateEntry(removed); |
|
|
|
|
|
|
|
assertThat(changed).isFalse(); |
|
|
|
assertThat(entry.getEntityIds()).containsExactlyInAnyOrder(ENTITY_1_ID, ENTITY_2_ID); |
|
|
|
assertThat(entry.getRemoved()).isNull(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testAddNewPropagationEntityId() { |
|
|
|
PropagationArgumentEntry hasEntity = new PropagationArgumentEntry(List.of(ENTITY_1_ID, ENTITY_2_ID)); |
|
|
|
assertThat(hasEntity.addPropagationEntityId(ENTITY_3_ID)).isTrue(); |
|
|
|
assertThat(hasEntity.getPropagationEntityIds()).contains(ENTITY_1_ID, ENTITY_2_ID, ENTITY_3_ID); |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
void testToTbelCfArgWithValues() { |
|
|
|
TbelCfArg arg = entry.toTbelCfArg(); |
|
|
|
assertThat(arg).isInstanceOf(TbelCfPropagationArg.class); |
|
|
|
|
|
|
|
TbelCfPropagationArg tbelCfPropagationArg = (TbelCfPropagationArg) arg; |
|
|
|
assertThat(tbelCfPropagationArg.getValue()).isInstanceOf(Set.class); |
|
|
|
assertThat((Set<EntityId>) tbelCfPropagationArg.getValue()).containsExactlyInAnyOrder(ENTITY_1_ID, ENTITY_2_ID); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
void testRemovePropagationEntityId() { |
|
|
|
PropagationArgumentEntry hasEntity = new PropagationArgumentEntry(List.of(ENTITY_1_ID)); |
|
|
|
hasEntity.removePropagationEntityId(ENTITY_1_ID); |
|
|
|
assertThat(hasEntity.isEmpty()).isTrue(); |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
void testToTbelCfArgWithEmptyValues() { |
|
|
|
var empty = new PropagationArgumentEntry(List.of()); |
|
|
|
TbelCfArg emptyArg = empty.toTbelCfArg(); |
|
|
|
assertThat(emptyArg).isInstanceOf(TbelCfPropagationArg.class); |
|
|
|
|
|
|
|
TbelCfPropagationArg tbelCfPropagationArg = (TbelCfPropagationArg) emptyArg; |
|
|
|
assertThat(tbelCfPropagationArg.getValue()).isInstanceOf(Set.class); |
|
|
|
assertThat((Set<EntityId>) tbelCfPropagationArg.getValue()).isEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|