use of com.icthh.xm.ms.entity.domain.XmEntity 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.XmEntity in project xm-ms-entity by xm-online.
the class XmEntityGeneratorServiceIntTest method generateXmEntityWithTagsTest.
@Test
@SneakyThrows
public void generateXmEntityWithTagsTest() {
XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity(ENTITY_TYPE_WITH_TAGS_AND_LOCATIONS_KEY);
log.info(new ObjectMapper().writeValueAsString(generatedEntity));
Set<Tag> tags = generatedEntity.getTags();
assertFalse("No tags generated", isEmpty(tags));
TypeSpec specType = xmEntitySpecService.findTypeByKey("TYPE1.SUBTYPE1");
List<TagSpec> tagsSpecs = specType.getTags();
Set<String> specTagsKeys = tagsSpecs.stream().map(TagSpec::getKey).collect(toSet());
Set<String> tagsKeys = tags.stream().map(Tag::getTypeKey).collect(toSet());
assertTrue("Tag type not from tag specification", specTagsKeys.containsAll(tagsKeys));
for (val tag : tags) {
assertFalse("Name of tag is empty", isBlank(tag.getName()));
}
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class XmTenantLifecycleServiceUnitTest method testNoService.
@Test
public void testNoService() {
XmEntity xmEntity = getEntity();
context.put(LepXmEntityMsConstants.BINDING_KEY_SERVICES, Collections.singletonList(SERVICE_NAME));
xmTenantLifecycleService.changeState(xmEntity, EntityState.ACTIVE.name(), context);
assertEquals(1, xmEntity.getData().size());
assertEquals(false, ((ServiceInfo) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).isSuccess());
assertEquals("Service client not found: test", ((ServiceInfo) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).getErrorMessage());
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class DeleteEntityTest method testDeleteLinkInner.
@Test
@SneakyThrows
public void testDeleteLinkInner() {
XmEntity parentEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE_PARENT"));
XmEntity entity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE"));
XmEntity breakLink = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_SEARCH"));
XmEntity cascadeDeleteLink = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_NEW"));
Link testLink = new Link();
parentEntity.addTargets(testLink);
testLink.setTypeKey("testLink");
testLink.setTarget(entity);
testLink.setSource(parentEntity);
xmEntityService.save(parentEntity);
Link link = new Link();
entity.addTargets(link);
link.setTypeKey("breakLinks");
link.setTarget(breakLink);
link.setSource(entity);
Link link2 = new Link();
link2.setTypeKey("cascadeDeleteLinks");
link2.setTarget(cascadeDeleteLink);
entity.addTargets(link2);
xmEntityService.save(entity);
XmEntity cascadeBreakSubLinks = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_SEARCH"));
XmEntity cascadeDeleteSubLinks = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_NEW"));
cascadeDeleteLink.addTargets(new Link().typeKey("cascadeBreakSubLinks").target(cascadeBreakSubLinks));
cascadeDeleteLink.addTargets(new Link().typeKey("cascadeDeleteSubLinks").target(cascadeDeleteSubLinks));
xmEntityService.save(cascadeDeleteLink);
xmEntityService.delete(entity.getId());
assertThat(xmEntityRepository.exists(parentEntity.getId())).isTrue();
assertThat(xmEntityRepository.exists(entity.getId())).isFalse();
assertThat(xmEntityRepository.exists(breakLink.getId())).isTrue();
assertThat(xmEntityRepository.exists(cascadeDeleteLink.getId())).isFalse();
assertThat(xmEntityRepository.exists(cascadeBreakSubLinks.getId())).isTrue();
assertThat(xmEntityRepository.exists(cascadeDeleteSubLinks.getId())).isFalse();
xmEntityService.delete(breakLink.getId());
xmEntityService.delete(cascadeBreakSubLinks.getId());
xmEntityService.delete(parentEntity.getId());
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class DeleteEntityTest method createXmEntity.
private XmEntity createXmEntity() {
XmEntity xmEntity = new XmEntity().key(randomUUID().toString()).typeKey("TEST_DELETE");
xmEntity.name("name").functionContexts(asSet(new FunctionContext().key("1").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("2").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("3").typeKey("A").xmEntity(xmEntity))).attachments(asSet(new Attachment().typeKey("A").name("1"), new Attachment().typeKey("A").name("2"), new Attachment().typeKey("A").name("3"))).calendars(asSet(new Calendar().typeKey("A").name("1").events(asSet(new Event().typeKey("A").title("1"), new Event().typeKey("A").title("2"))), new Calendar().typeKey("A").name("2").events(asSet(new Event().typeKey("A").title("3"), new Event().typeKey("A").title("4"))))).locations(asSet(new Location().typeKey("A").name("1"), new Location().typeKey("A").name("2"))).ratings(asSet(new Rating().typeKey("A").votes(asSet(new Vote().message("1").value(1.1).userKey("1"), new Vote().message("2").value(2.1).userKey("2"))))).tags(asSet(new Tag().typeKey("A").name("1"), new Tag().typeKey("A").name("2"))).comments(asSet(new Comment().message("1").userKey("1"), new Comment().message("2").userKey("1")));
return xmEntity;
}
Aggregations