Search in sources :

Example 76 with XmEntity

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

the class DeleteEntityTest method testDelete.

@Test
public void testDelete() {
    XmEntity entity = xmEntityService.save(createXmEntity());
    xmEntityService.delete(entity.getId());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 77 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity 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 78 with XmEntity

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

the class EntityServiceImplIntTest method createEntity.

private XmEntity createEntity(Long id, String typeKey) {
    XmEntity entity = new XmEntity();
    entity.setId(id);
    entity.setName("Name");
    entity.setTypeKey(typeKey);
    entity.setStartDate(new Date().toInstant());
    entity.setUpdateDate(new Date().toInstant());
    entity.setKey("KEY-" + id);
    entity.setStateKey("STATE1");
    entity.setData(ImmutableMap.<String, Object>builder().put("AAAAAAAAAA", "BBBBBBBBBB").build());
    return entity;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Date(java.util.Date)

Example 79 with XmEntity

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

the class EntityServiceImplIntTest method beforeTransaction.

@BeforeTransaction
public void beforeTransaction() {
    TenantContextUtils.setTenant(tenantContextHolder, "RESINTTEST");
    MockitoAnnotations.initMocks(this);
    when(authContextHolder.getContext()).thenReturn(context);
    when(context.getRequiredUserKey()).thenReturn("userKey");
    XmEntity sourceEntity = xmEntityRepository.save(createEntity(1l, TARGET_TYPE_KEY));
    self = new Profile();
    self.setXmentity(sourceEntity);
    when(profileService.getSelfProfile()).thenReturn(self);
    xmEntityService = new XmEntityServiceImpl(xmEntitySpecService, xmEntityRepository, xmEntitySearchRepository, lifecycleService, null, profileService, linkService, storageService, attachmentService, permittedSearchRepository, startUpdateDateGenerationStrategy, authContextHolder);
    xmEntityService.setSelf(xmEntityService);
    lepManager.beginThreadContext(ctx -> {
        ctx.setValue(THREAD_CONTEXT_KEY_TENANT_CONTEXT, tenantContextHolder.getContext());
        ctx.setValue(THREAD_CONTEXT_KEY_AUTH_CONTEXT, authContextHolder.getContext());
    });
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Profile(com.icthh.xm.ms.entity.domain.Profile) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction)

Example 80 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity 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)

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