Search in sources :

Example 11 with Link

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

the class XmEntityResourceExtendedIntTest method testNoCycleJson.

@Test(expected = JsonMappingException.class)
@Transactional
public void testNoCycleJson() throws Exception {
    XmEntity target = new XmEntity().typeKey("TARGET");
    XmEntity source = new XmEntity().typeKey("SOURCE");
    source.targets(Collections.singleton(new Link().typeKey("LINK1").source(source).target(target))).setId(1L);
    target.targets(Collections.singleton(new Link().typeKey("LINK2").source(source).target(target))).setId(2L);
    String targetJson = jacksonMessageConverter.getObjectMapper().writeValueAsString(target);
    String sourceJson = jacksonMessageConverter.getObjectMapper().writeValueAsString(source);
    assertEquals("1", JsonPath.read(targetJson, "$.targets[0].id"));
    assertEquals("2", JsonPath.read(sourceJson, "$.targets[0].id"));
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) 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 12 with Link

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

the class LinkResourceExtendedIntTest method createLinkWithEntryDate.

@Test
@Transactional
public void createLinkWithEntryDate() throws Exception {
    int databaseSizeBeforeCreate = linkRepository.findAll().size();
    // Create the Link
    restLinkMockMvc.perform(post("/api/links").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(link))).andExpect(status().isCreated()).andExpect(jsonPath("$.startDate").value(MOCKED_START_DATE.toString()));
    // Validate the Link in the database
    List<Link> voteList = linkRepository.findAll();
    assertThat(voteList).hasSize(databaseSizeBeforeCreate + 1);
    Link testLink = voteList.get(voteList.size() - 1);
    assertThat(testLink.getStartDate()).isEqualTo(MOCKED_START_DATE);
    // Validate the Link in Elasticsearch
    Link linkEs = linkSearchRepository.findOne(testLink.getId());
    assertThat(linkEs).isEqualToComparingFieldByField(testLink);
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Link

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

the class LinkResourceExtendedIntTest method checkStartDateIsRequiredInDb.

@Test
@Transactional
public void checkStartDateIsRequiredInDb() throws Exception {
    Link o = linkService.save(link);
    // set the field null
    when(startUpdateDateGenerationStrategy.generateStartDate()).thenReturn(null);
    o.setStartDate(null);
    linkService.save(o);
    try {
        linkRepository.flush();
        fail("DataIntegrityViolationException exception was expected!");
    } catch (DataIntegrityViolationException e) {
        assertThat(e.getMostSpecificCause().getMessage()).containsIgnoringCase("NULL not allowed for column \"START_DATE\"");
    }
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Link

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

the class LinkResourceExtendedIntTest method checkStartDateIsNotRequired.

@Test
@Transactional
public void checkStartDateIsNotRequired() throws Exception {
    int databaseSizeBeforeTest = linkRepository.findAll().size();
    // set the field null
    link.setStartDate(null);
    // Create the Link.
    restLinkMockMvc.perform(post("/api/links").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(link))).andExpect(status().isCreated()).andExpect(jsonPath("$.startDate").value(MOCKED_START_DATE.toString()));
    List<Link> linkList = linkRepository.findAll();
    assertThat(linkList).hasSize(databaseSizeBeforeTest + 1);
    Link testLink = linkList.get(linkList.size() - 1);
    assertThat(testLink.getStartDate()).isEqualTo(MOCKED_START_DATE);
    // Validate the Link in Elasticsearch
    Link linkEs = linkSearchRepository.findOne(testLink.getId());
    assertThat(linkEs).isEqualToComparingFieldByField(testLink);
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Link

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

the class LinkResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Link.class);
    Link link1 = new Link();
    link1.setId(1L);
    Link link2 = new Link();
    link2.setId(link1.getId());
    assertThat(link1).isEqualTo(link2);
    link2.setId(2L);
    assertThat(link1).isNotEqualTo(link2);
    link1.setId(null);
    assertThat(link1).isNotEqualTo(link2);
}
Also used : 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)

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