Search in sources :

Example 11 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class DeleteEntityTest method testDeleteLink.

@Test
public void testDeleteLink() {
    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 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(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());
}
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)

Example 12 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class DeleteEntityTest method testDeleteLinkDifferentLinkTypes.

@Test
@SneakyThrows
public void testDeleteLinkDifferentLinkTypes() {
    XmEntity deletedEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE_NEW_LINK"));
    XmEntity otherEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE_SEARCH_LINK"));
    XmEntity sharedEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TARGET_ENTITY"));
    Link newLink = new Link();
    newLink.setTypeKey("newLink");
    newLink.setTarget(sharedEntity);
    deletedEntity.addTargets(newLink);
    Link searchLink = new Link();
    searchLink.setTypeKey("cascadeDeleteLinks");
    searchLink.setTarget(sharedEntity);
    otherEntity.addTargets(searchLink);
    xmEntityService.save(deletedEntity);
    xmEntityService.save(otherEntity);
    xmEntityService.delete(deletedEntity.getId());
    assertThat(xmEntityRepository.exists(otherEntity.getId())).isTrue();
    assertThat(xmEntityRepository.exists(sharedEntity.getId())).isTrue();
    assertThat(xmEntityRepository.exists(deletedEntity.getId())).isFalse();
    xmEntityService.delete(sharedEntity.getId());
    xmEntityService.delete(otherEntity.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 13 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class EntityServiceImplIntTest method testGetLinkSourcesSelfKey.

@Test
@Transactional
public void testGetLinkSourcesSelfKey() throws Exception {
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, "ACCOUNT.USER"));
    Link link = createSelfLink(targetEntity);
    linkRepository.save(link);
    List<Link> result = xmEntityService.getLinkSources(IdOrKey.of(targetEntity.getId()), TEST_LINK_KEY);
    assertThat(result).isNotNull();
    assertThat(result.size()).isEqualTo(BigInteger.ONE.intValue());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class EntityServiceImplIntTest method addFileAttachment.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void addFileAttachment() {
    when(storageService.store(Mockito.any(MultipartFile.class), Mockito.any())).thenReturn("test.txt");
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
    MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "TEST".getBytes());
    xmEntityService.addFileAttachment(targetEntity, file);
    XmEntity foundEntity = xmEntityService.findOne(IdOrKey.of(targetEntity.getId()));
    assertThat(foundEntity).isNotNull();
    assertThat(foundEntity.getAttachments()).hasSize(BigInteger.ONE.intValue());
    assertThat(foundEntity.getAttachments().stream().findFirst().get().getContentUrl()).isEqualTo("test.txt");
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class EntityServiceImplIntTest method updateAvatar.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
@SneakyThrows
@SuppressWarnings("unchecked")
public void updateAvatar() throws Exception {
    when(storageService.store(Mockito.any(HttpEntity.class), Mockito.any())).thenReturn("test.txt");
    MockMultipartFile file = new MockMultipartFile("file", "test.jpg", "image/jpg", "TEST".getBytes());
    HttpEntity<Resource> avatarEntity = XmHttpEntityUtils.buildAvatarHttpEntity(file);
    URI uri = xmEntityService.updateAvatar(IdOrKey.SELF, avatarEntity);
    assertThat(uri != null);
    XmEntity storedEntity = xmEntityService.findOne(IdOrKey.SELF);
    assertThat(storedEntity.getAvatarUrl() != null);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) HttpEntity(org.springframework.http.HttpEntity) Resource(org.springframework.core.io.Resource) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows) Transactional(org.springframework.transaction.annotation.Transactional)

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