tests: relation query - added test cases with many edges between two nodes, horizontal ring (loop) on the same level, loop Tenant-Asset-Device-Tenant. This commit will fail 4 hierarchy tests. Reformat code
This commit is contained in:
parent
7f3d63512e
commit
a5d446914c
@ -19,6 +19,7 @@ import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@ -82,6 +83,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
|
||||
@ -159,7 +161,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
public void testCountHierarchicalEntitiesByQuery() throws InterruptedException {
|
||||
List<Asset> assets = new ArrayList<>();
|
||||
List<Device> devices = new ArrayList<>();
|
||||
createTestHierarchy(assets, devices, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
||||
createTestHierarchy(tenantId, assets, devices, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
||||
|
||||
RelationsQueryFilter filter = new RelationsQueryFilter();
|
||||
filter.setRootEntity(tenantId);
|
||||
@ -308,7 +310,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
List<Device> devices = new ArrayList<>();
|
||||
List<Long> temperatures = new ArrayList<>();
|
||||
List<Long> highTemperatures = new ArrayList<>();
|
||||
createTestHierarchy(assets, devices, new ArrayList<>(), new ArrayList<>(), temperatures, highTemperatures);
|
||||
createTestHierarchy(tenantId, assets, devices, new ArrayList<>(), new ArrayList<>(), temperatures, highTemperatures);
|
||||
|
||||
List<ListenableFuture<List<Void>>> attributeFutures = new ArrayList<>();
|
||||
for (int i = 0; i < devices.size(); i++) {
|
||||
@ -380,7 +382,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
List<Device> devices = new ArrayList<>();
|
||||
List<Long> temperatures = new ArrayList<>();
|
||||
List<Long> highTemperatures = new ArrayList<>();
|
||||
createTestHierarchy(assets, devices, new ArrayList<>(), new ArrayList<>(), temperatures, highTemperatures);
|
||||
createTestHierarchy(tenantId, assets, devices, new ArrayList<>(), new ArrayList<>(), temperatures, highTemperatures);
|
||||
|
||||
List<ListenableFuture<List<Void>>> attributeFutures = new ArrayList<>();
|
||||
for (int i = 0; i < devices.size(); i++) {
|
||||
@ -453,7 +455,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
List<Device> devices = new ArrayList<>();
|
||||
List<Long> consumptions = new ArrayList<>();
|
||||
List<Long> highConsumptions = new ArrayList<>();
|
||||
createTestHierarchy(assets, devices, consumptions, highConsumptions, new ArrayList<>(), new ArrayList<>());
|
||||
createTestHierarchy(tenantId, assets, devices, consumptions, highConsumptions, new ArrayList<>(), new ArrayList<>());
|
||||
|
||||
List<ListenableFuture<List<Void>>> attributeFutures = new ArrayList<>();
|
||||
for (int i = 0; i < assets.size(); i++) {
|
||||
@ -518,7 +520,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
deviceService.deleteDevicesByTenantId(tenantId);
|
||||
}
|
||||
|
||||
private void createTestHierarchy(List<Asset> assets, List<Device> devices, List<Long> consumptions, List<Long> highConsumptions, List<Long> temperatures, List<Long> highTemperatures) throws InterruptedException {
|
||||
private void createTestHierarchy(TenantId tenantId, List<Asset> assets, List<Device> devices, List<Long> consumptions, List<Long> highConsumptions, List<Long> temperatures, List<Long> highTemperatures) throws InterruptedException {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Asset asset = new Asset();
|
||||
asset.setTenantId(tenantId);
|
||||
@ -563,8 +565,40 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createManyCustomRelationsBetweenTwoNodes(tenantId, "UseCase", assets, devices);
|
||||
createHorizontalRingRelations(tenantId, "Ring(Loop)-Ast", assets);
|
||||
createLoopRelations(tenantId, "Loop-Tnt-Ast-Dev", tenantId, assets.get(0).getId(), devices.get(0).getId());
|
||||
createLoopRelations(tenantId, "Loop-Tnt-Ast", tenantId, assets.get(1).getId());
|
||||
createLoopRelations(tenantId, "Loop-Ast-Tnt-Ast", assets.get(2).getId(), tenantId, assets.get(3).getId());
|
||||
}
|
||||
|
||||
void createLoopRelations(TenantId tenantId, String type, EntityId... ids) {
|
||||
assertThat("ids lenght", ids.length, Matchers.greaterThanOrEqualTo(1));
|
||||
//chain all from the head to the tail
|
||||
for (int i = 1; i < ids.length; i++) {
|
||||
relationService.saveRelation(tenantId, new EntityRelation(ids[i - 1], ids[i], type, RelationTypeGroup.COMMON));
|
||||
}
|
||||
//chain tail -> head
|
||||
relationService.saveRelation(tenantId, new EntityRelation(ids[ids.length - 1], ids[0], type, RelationTypeGroup.COMMON));
|
||||
}
|
||||
|
||||
void createHorizontalRingRelations(TenantId tenantId, String type, List<Asset> assets) {
|
||||
createLoopRelations(tenantId, type, assets.stream().map(Asset::getId).toArray(EntityId[]::new));
|
||||
}
|
||||
|
||||
void createManyCustomRelationsBetweenTwoNodes(TenantId tenantId, String type, List<Asset> assets, List<Device> devices) {
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
final String typeI = type + i;
|
||||
createOneToManyRelations(tenantId, typeI, tenantId, assets.stream().map(Asset::getId).collect(Collectors.toList()));
|
||||
assets.forEach(asset ->
|
||||
createOneToManyRelations(tenantId, typeI, asset.getId(), devices.stream().map(Device::getId).collect(Collectors.toList())));
|
||||
}
|
||||
}
|
||||
|
||||
void createOneToManyRelations(TenantId tenantId, String type, EntityId from, List<EntityId> toIds) {
|
||||
toIds.forEach(toId -> relationService.saveRelation(tenantId, new EntityRelation(from, toId, type, RelationTypeGroup.COMMON)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleFindEntityDataByQuery() throws InterruptedException {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user