Search in sources :

Example 21 with Link

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

the class EntityServiceImplIntTest method createLink.

private Link createLink(XmEntity source, XmEntity target) {
    Link link = new Link();
    link.setSource(source);
    link.setTarget(target);
    link.setStartDate(new Date().toInstant());
    link.setTypeKey(TEST_LINK_KEY);
    return link;
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) Date(java.util.Date)

Example 22 with Link

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

the class EntityServiceImplIntTest method deleteSelfLinkTarget.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void deleteSelfLinkTarget() {
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
    Link link = createLink(self.getXmentity(), targetEntity);
    linkRepository.save(link);
    xmEntityService.deleteLinkTarget(IdOrKey.SELF, link.getId().toString());
    assertThat(linkRepository.findAll()).hasSize(BigInteger.ZERO.intValue());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) 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 23 with Link

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

the class EntityServiceImplIntTest method saveSelfLinkTarget.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void saveSelfLinkTarget() throws Exception {
    when(storageService.store(Mockito.any(MultipartFile.class), Mockito.any())).thenReturn("test.txt");
    int databaseSizeBeforeCreate = linkRepository.findAll().size();
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
    Link link = createSelfLink(targetEntity);
    // Create link with attachment
    MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "TEST".getBytes());
    xmEntityService.saveLinkTarget(IdOrKey.SELF, link, file);
    // Validate the link in the database
    List<Link> linkList = linkRepository.findAll();
    assertThat(linkList).hasSize(databaseSizeBeforeCreate + BigInteger.ONE.intValue());
    // validate attachment in database
    List<Attachment> attachments = attachmentService.findAll(null);
    assertThat(attachments).hasSize(BigInteger.ONE.intValue());
    Attachment attachment = attachments.stream().findFirst().get();
    assertThat(attachment.getContentUrl()).contains("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) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Link(com.icthh.xm.ms.entity.domain.Link) 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 24 with Link

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

the class EntityServiceImplIntTest method testGetLinkTargetsSelfKey.

@Test
@Transactional
public void testGetLinkTargetsSelfKey() throws Exception {
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
    Link link = createSelfLink(targetEntity);
    linkRepository.save(link);
    List<Link> result = xmEntityService.getLinkTargets(IdOrKey.SELF, TARGET_TYPE_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 25 with Link

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

the class EntityServiceImplIntTest method deleteForeignLinkTarget.

@Test(expected = BusinessException.class)
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void deleteForeignLinkTarget() {
    XmEntity sourceEntity = xmEntityRepository.save(createEntity(25l, "ACCOUNT.USER"));
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
    Link link = createLink(sourceEntity, targetEntity);
    linkRepository.save(link);
    xmEntityService.deleteLinkTarget(IdOrKey.SELF, link.getId().toString());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) 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)

Aggregations

Link (com.icthh.xm.ms.entity.domain.Link)32 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)20 Test (org.junit.Test)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 Transactional (org.springframework.transaction.annotation.Transactional)16 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 Timed (com.codahale.metrics.annotation.Timed)2 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)2 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 SneakyThrows (lombok.SneakyThrows)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)1 Comment (com.icthh.xm.ms.entity.domain.Comment)1 Location (com.icthh.xm.ms.entity.domain.Location)1 Rating (com.icthh.xm.ms.entity.domain.Rating)1 Tag (com.icthh.xm.ms.entity.domain.Tag)1