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());
}
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());
}
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());
}
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");
}
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);
}
Aggregations