Search in sources :

Example 71 with XmEntity

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));
    }
}
Also used : lombok.val(lombok.val) LocationSpec(com.icthh.xm.ms.entity.domain.spec.LocationSpec) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Location(com.icthh.xm.ms.entity.domain.Location) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 72 with XmEntity

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()));
    }
}
Also used : lombok.val(lombok.val) TagSpec(com.icthh.xm.ms.entity.domain.spec.TagSpec) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Tag(com.icthh.xm.ms.entity.domain.Tag) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 73 with XmEntity

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());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 74 with XmEntity

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());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 75 with XmEntity

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;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) Vote(com.icthh.xm.ms.entity.domain.Vote) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Rating(com.icthh.xm.ms.entity.domain.Rating) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Event(com.icthh.xm.ms.entity.domain.Event) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Location(com.icthh.xm.ms.entity.domain.Location)

Aggregations

XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)102 Test (org.junit.Test)60 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)46 Transactional (org.springframework.transaction.annotation.Transactional)32 Link (com.icthh.xm.ms.entity.domain.Link)22 Tag (com.icthh.xm.ms.entity.domain.Tag)10 ConstraintViolation (javax.validation.ConstraintViolation)9 WithMockUser (org.springframework.security.test.context.support.WithMockUser)9 MvcResult (org.springframework.test.web.servlet.MvcResult)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SneakyThrows (lombok.SneakyThrows)8 Attachment (com.icthh.xm.ms.entity.domain.Attachment)7 Location (com.icthh.xm.ms.entity.domain.Location)7 lombok.val (lombok.val)7 Calendar (com.icthh.xm.ms.entity.domain.Calendar)6 Profile (com.icthh.xm.ms.entity.domain.Profile)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Rating (com.icthh.xm.ms.entity.domain.Rating)5 Timed (com.codahale.metrics.annotation.Timed)4