use of com.icthh.xm.ms.entity.domain.spec.LocationSpec in project xm-ms-entity by xm-online.
the class XmEntityGeneratorServiceIntTest method generateXmEntityWithLocations.
@Test
@SneakyThrows
public void generateXmEntityWithLocations() {
XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity(ENTITY_TYPE_WITH_TAGS_AND_LOCATIONS_KEY);
log.info(new ObjectMapper().writeValueAsString(generatedEntity));
Set<Location> locations = generatedEntity.getLocations();
assertFalse("No locations generated", isEmpty(locations));
TypeSpec specType = xmEntitySpecService.findTypeByKey("TYPE1.SUBTYPE1");
List<LocationSpec> locationSpecs = specType.getLocations();
Set<String> locationSpecKeys = locationSpecs.stream().map(LocationSpec::getKey).collect(toSet());
Set<String> locationKeys = locations.stream().map(Location::getTypeKey).collect(toSet());
assertTrue("Tag type not from locations specification", locationSpecKeys.containsAll(locationKeys));
for (val location : locations) {
assertFalse("Name of location is empty", isBlank(location.getName()));
assertFalse("Coordinates and address is empty", isBlank(location.getAddressLine1()) && (location.getLatitude() == null || location.getLongitude() == null));
}
}
use of com.icthh.xm.ms.entity.domain.spec.LocationSpec in project xm-ms-entity by xm-online.
the class XmEntityGeneratorService method generateLocations.
private Set<Location> generateLocations(LocationSpec locationSpec) {
Set<Location> result = new HashSet<>();
List<Location> originalLocationStubs = getLocationStubs();
val locationStubs = originalLocationStubs.stream().filter(l -> RandomUtils.nextBoolean()).collect(toList());
if (isEmpty(locationStubs)) {
int randomLocationPosition = RandomUtils.nextInt(0, originalLocationStubs.size() - 1);
Location randomLocationStub = originalLocationStubs.get(randomLocationPosition);
locationStubs.add(randomLocationStub);
}
int locationsLimit = min(locationSpec.getMax(), locationStubs.size());
int countLocations = RandomUtils.nextInt(1, locationsLimit);
IntStream.range(0, countLocations).forEachOrdered(i -> {
Location locationStub = locationStubs.get(i);
updateLocationStubToLocation(locationSpec, locationStub);
result.add(locationStub);
});
return result;
}
Aggregations