Search in sources :

Example 31 with XmEntity

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

the class XmEntityResourceExtendedIntTest method checkJsonShemeDateTypeProperties.

@Test
@Transactional
public void checkJsonShemeDateTypeProperties() throws Exception {
    int databaseSizeBeforeTest = xmEntityRepository.findAll().size();
    XmEntity entity = xmEntityIncoming;
    entity.setData(ImmutableMap.of("numberProperties", "5"));
    performPut("/api/xm-entities", entity).andExpect(status().isBadRequest()).andExpect(jsonPath("$.error").value("error.validation"));
    // Validate the XmEntity in the database
    validateEntityInDB(databaseSizeBeforeTest);
    entity.setData(ImmutableMap.of("numberProperties", "testse"));
    performPut("/api/xm-entities", entity).andExpect(status().isBadRequest()).andExpect(jsonPath("$.error").value("error.validation"));
    // Validate the XmEntity in the database
    validateEntityInDB(databaseSizeBeforeTest);
    entity.setData(ImmutableMap.of("numberProperties", Boolean.FALSE));
    performPut("/api/xm-entities", entity).andExpect(status().isBadRequest()).andExpect(jsonPath("$.error").value("error.validation"));
    // Validate the XmEntity in the database
    validateEntityInDB(databaseSizeBeforeTest);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with XmEntity

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

the class XmEntityResourceExtendedIntTest method createXmEntityWithSourceLinks.

@Test
@Transactional
public void createXmEntityWithSourceLinks() throws Exception {
    XmEntity presaved = xmEntityService.save(createEntity(em));
    int databaseSizeBeforeCreate = xmEntityRepository.findAll().size();
    XmEntity entity = xmEntityIncoming;
    entity.setSources(Collections.singleton(new Link().typeKey(DEFAULT_LN_TARGET_KEY).name(DEFAULT_LN_TARGET_NAME).startDate(DEFAULT_LN_TARGET_START_DATE).source(presaved)));
    // Create the XmEntity with tag
    MvcResult result = performPost("/api/xm-entities", entity).andExpect(status().isCreated()).andExpect(jsonPath("$.key").value(DEFAULT_KEY)).andReturn();
    Integer id = JsonPath.read(result.getResponse().getContentAsString(), "$.id");
    em.detach(presaved);
    List<XmEntity> xmEntityList = validateEntityInDB(databaseSizeBeforeCreate + 1);
    XmEntity testXmEntity = xmEntityList.get(xmEntityList.size() - 1);
    presaved = xmEntityService.findOne(IdOrKey.of(presaved.getId()));
    // Get the xmEntityPersisted with tag by ID
    performGet("/api/xm-entities/{id}", presaved.getId()).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.id").value(presaved.getId())).andExpect(jsonPath("$.key").value(DEFAULT_KEY)).andExpect(jsonPath("$.typeKey").value(DEFAULT_TYPE_KEY)).andExpect(jsonPath("$.stateKey").value(DEFAULT_STATE_KEY)).andExpect(jsonPath("$.name").value(DEFAULT_NAME)).andExpect(jsonPath("$.startDate").value(sameInstant(MOCKED_START_DATE))).andExpect(jsonPath("$.updateDate").value(sameInstant(MOCKED_UPDATE_DATE))).andExpect(jsonPath("$.endDate").value(sameInstant(DEFAULT_END_DATE))).andExpect(jsonPath("$.avatarUrl").value(containsString("aaaaa.jpg"))).andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION)).andExpect(jsonPath("$.data.AAAAAAAAAA").value("BBBBBBBBBB")).andExpect(jsonPath("$.targets[0].id").value(notNullValue())).andExpect(jsonPath("$.targets[0].name").value(DEFAULT_LN_TARGET_NAME)).andExpect(jsonPath("$.targets[0].typeKey").value(DEFAULT_LN_TARGET_KEY)).andExpect(jsonPath("$.targets[0].source").value(presaved.getId())).andExpect(jsonPath("$.targets[0].target.id").value(id));
    // Validate the XmEntity in Elasticsearch
    XmEntity xmEntityEs = xmEntitySearchRepository.findOne(Long.valueOf(id.toString()));
    assertThat(xmEntityEs).isEqualToIgnoringGivenFields(testXmEntity, "sources", "avatarUrl");
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) MvcResult(org.springframework.test.web.servlet.MvcResult) 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 33 with XmEntity

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

the class XmEntityResourceExtendedIntTest method testAttachmentStartDate.

@Test
@Transactional
public void testAttachmentStartDate() throws Exception {
    Attachment attachment = new Attachment().typeKey("A").name("1");
    XmEntity entity = new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE").attachments(asSet(attachment));
    MutableObject<Instant> startDate = new MutableObject<>();
    MutableObject<XmEntity> entityHolder = new MutableObject<>();
    byte[] content = TestUtil.convertObjectToJsonBytes(entity);
    restXmEntityMockMvc.perform(post("/api/xm-entities").contentType(TestUtil.APPLICATION_JSON_UTF8).content(content)).andDo(r -> entityHolder.setValue(readValue(r))).andDo(r -> log.info(r.getResponse().getContentAsString())).andExpect(status().is2xxSuccessful());
    Long id = entityHolder.getValue().getId();
    restXmEntityMockMvc.perform(get("/api/xm-entities/" + id)).andDo(r -> startDate.setValue(readValue(r).getAttachments().iterator().next().getStartDate())).andDo(r -> log.info(r.getResponse().getContentAsString())).andExpect(status().is2xxSuccessful());
    assertNotNull(startDate.getValue());
    content = TestUtil.convertObjectToJsonBytes(entityHolder.getValue());
    restXmEntityMockMvc.perform(put("/api/xm-entities").contentType(TestUtil.APPLICATION_JSON_UTF8).content(content)).andDo(r -> log.info(r.getResponse().getContentAsString())).andExpect(status().is2xxSuccessful());
    restXmEntityMockMvc.perform(get("/api/xm-entities/" + id)).andDo(r -> log.info(r.getResponse().getContentAsString())).andDo(r -> assertEquals(startDate.getValue(), readValue(r).getAttachments().iterator().next().getStartDate())).andExpect(status().is2xxSuccessful());
}
Also used : MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) Validator(org.springframework.validation.Validator) SneakyThrows(lombok.SneakyThrows) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) TenantContextHolder(com.icthh.xm.commons.tenant.TenantContextHolder) WebappTenantOverrideConfiguration(com.icthh.xm.ms.entity.config.tenant.WebappTenantOverrideConfiguration) ResultActions(org.springframework.test.web.servlet.ResultActions) XmEntityPermittedRepository(com.icthh.xm.ms.entity.repository.XmEntityPermittedRepository) MockitoAnnotations(org.mockito.MockitoAnnotations) ExceptionTranslator(com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator) Matchers.everyItem(org.hamcrest.Matchers.everyItem) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Matchers.nullValue(org.hamcrest.Matchers.nullValue) After(org.junit.After) Spy(org.mockito.Spy) Map(java.util.Map) EntityApp(com.icthh.xm.ms.entity.EntityApp) SpringRunner(org.springframework.test.context.junit4.SpringRunner) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Content(com.icthh.xm.ms.entity.domain.Content) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction) MockMvcRequestBuilders.put(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put) Link(com.icthh.xm.ms.entity.domain.Link) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ImmutableMap(com.google.common.collect.ImmutableMap) MediaType(org.springframework.http.MediaType) JsonAutoDetect(com.fasterxml.jackson.annotation.JsonAutoDetect) XmEntitySearchRepository(com.icthh.xm.ms.entity.repository.search.XmEntitySearchRepository) Instant(java.time.Instant) SecurityBeanOverrideConfiguration(com.icthh.xm.ms.entity.config.SecurityBeanOverrideConfiguration) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LepManager(com.icthh.xm.lep.api.LepManager) Optional(java.util.Optional) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) Matchers.containsString(org.hamcrest.Matchers.containsString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CollectionHelper.asSet(org.hibernate.validator.internal.util.CollectionHelper.asSet) THREAD_CONTEXT_KEY_TENANT_CONTEXT(com.icthh.xm.commons.lep.XmLepConstants.THREAD_CONTEXT_KEY_TENANT_CONTEXT) Mock(org.mockito.Mock) Constants(com.icthh.xm.ms.entity.config.Constants) RunWith(org.junit.runner.RunWith) com.icthh.xm.ms.entity.service(com.icthh.xm.ms.entity.service) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) THREAD_CONTEXT_KEY_AUTH_CONTEXT(com.icthh.xm.commons.lep.XmLepConstants.THREAD_CONTEXT_KEY_AUTH_CONTEXT) TenantContextUtils(com.icthh.xm.commons.tenant.TenantContextUtils) MockMvc(org.springframework.test.web.servlet.MockMvc) PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) TestUtil.sameInstant(com.icthh.xm.ms.entity.web.rest.TestUtil.sameInstant) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) MvcResult(org.springframework.test.web.servlet.MvcResult) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) PropertyAccessor(com.fasterxml.jackson.annotation.PropertyAccessor) IdOrKey(com.icthh.xm.ms.entity.domain.ext.IdOrKey) XmEntityServiceImpl(com.icthh.xm.ms.entity.service.impl.XmEntityServiceImpl) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) StartUpdateDateGenerationStrategy(com.icthh.xm.ms.entity.service.impl.StartUpdateDateGenerationStrategy) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) EntityManager(javax.persistence.EntityManager) Tag(com.icthh.xm.ms.entity.domain.Tag) JsonPath(com.jayway.jsonpath.JsonPath) Location(com.icthh.xm.ms.entity.domain.Location) XmEntityPermittedSearchRepository(com.icthh.xm.ms.entity.repository.search.XmEntityPermittedSearchRepository) UUID.randomUUID(java.util.UUID.randomUUID) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Event(com.icthh.xm.ms.entity.domain.Event) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) XmEntityRepository(com.icthh.xm.ms.entity.repository.XmEntityRepository) Calendar(com.icthh.xm.ms.entity.domain.Calendar) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) ProfileEventProducer(com.icthh.xm.ms.entity.repository.kafka.ProfileEventProducer) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) LepConfiguration(com.icthh.xm.ms.entity.config.LepConfiguration) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) Instant(java.time.Instant) TestUtil.sameInstant(com.icthh.xm.ms.entity.web.rest.TestUtil.sameInstant) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Attachment(com.icthh.xm.ms.entity.domain.Attachment) MutableObject(org.apache.commons.lang3.mutable.MutableObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with XmEntity

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

the class XmEntityResourceExtendedIntTest method createEntityComplexIncoming.

/**
 * Creates incoming Entity as from HTTP request.
 * Potentially cam be moved to DTO
 *
 * @param em - Entity manager
 * @return XmEntity for incoming request
 */
public static XmEntity createEntityComplexIncoming(EntityManager em) {
    XmEntity entity = createEntity(em);
    entity.getTags().add(new Tag().typeKey(DEFAULT_TAG_KEY).startDate(DEFAULT_START_DATE).name(DEFAULT_TAG_NAME));
    entity.getAttachments().add(new Attachment().typeKey(DEFAULT_ATTACHMENT_KEY).name(DEFAULT_ATTACHMENT_NAME).startDate(DEFAULT_ATTACHMENT_START_DATE).endDate(DEFAULT_ATTACHMENT_END_DATE).valueContentType(DEFAULT_ATTACHMENT_CONTENT_TYPE).content(new Content().value(DEFAULT_ATTACHMENT_CONTENT_VALUE.getBytes())).contentUrl(DEFAULT_ATTACHMENT_URL).description(DEFAULT_ATTACHMENT_DESCRIPTION));
    entity.getLocations().add(new Location().typeKey(DEFAULT_LOCATION_KEY).name(DEFAULT_LOCATION_NAME).countryKey(DEFAULT_LOCATION_COUNTRY_KEY));
    return entity;
}
Also used : Content(com.icthh.xm.ms.entity.domain.Content) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) Location(com.icthh.xm.ms.entity.domain.Location)

Example 35 with XmEntity

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

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