Search in sources :

Example 1 with Content

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

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

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

the class ContentResourceIntTest method createContent.

@Test
@Transactional
public void createContent() throws Exception {
    int databaseSizeBeforeCreate = contentRepository.findAll().size();
    // Create the Content
    restContentMockMvc.perform(post("/api/contents").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(content))).andExpect(status().isCreated());
    // Validate the Content in the database
    List<Content> contentList = contentRepository.findAll();
    assertThat(contentList).hasSize(databaseSizeBeforeCreate + 1);
    Content testContent = contentList.get(contentList.size() - 1);
    assertThat(testContent.getValue()).isEqualTo(DEFAULT_VALUE);
}
Also used : Content(com.icthh.xm.ms.entity.domain.Content) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Content

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

the class ContentResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Content.class);
    Content content1 = new Content();
    content1.setId(1L);
    Content content2 = new Content();
    content2.setId(content1.getId());
    assertThat(content1).isEqualTo(content2);
    content2.setId(2L);
    assertThat(content1).isNotEqualTo(content2);
    content1.setId(null);
    assertThat(content1).isNotEqualTo(content2);
}
Also used : Content(com.icthh.xm.ms.entity.domain.Content) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Content

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

the class ContentResourceIntTest method updateContent.

@Test
@Transactional
public void updateContent() throws Exception {
    // Initialize the database
    contentRepository.saveAndFlush(content);
    int databaseSizeBeforeUpdate = contentRepository.findAll().size();
    // Update the content
    Content updatedContent = contentRepository.findOne(content.getId());
    updatedContent.value(UPDATED_VALUE);
    restContentMockMvc.perform(put("/api/contents").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedContent))).andExpect(status().isOk());
    // Validate the Content in the database
    List<Content> contentList = contentRepository.findAll();
    assertThat(contentList).hasSize(databaseSizeBeforeUpdate);
    Content testContent = contentList.get(contentList.size() - 1);
    assertThat(testContent.getValue()).isEqualTo(UPDATED_VALUE);
}
Also used : Content(com.icthh.xm.ms.entity.domain.Content) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Content (com.icthh.xm.ms.entity.domain.Content)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 Location (com.icthh.xm.ms.entity.domain.Location)2 Tag (com.icthh.xm.ms.entity.domain.Tag)2 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)2 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 PropertyAccessor (com.fasterxml.jackson.annotation.PropertyAccessor)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ExceptionTranslator (com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator)1 THREAD_CONTEXT_KEY_AUTH_CONTEXT (com.icthh.xm.commons.lep.XmLepConstants.THREAD_CONTEXT_KEY_AUTH_CONTEXT)1 THREAD_CONTEXT_KEY_TENANT_CONTEXT (com.icthh.xm.commons.lep.XmLepConstants.THREAD_CONTEXT_KEY_TENANT_CONTEXT)1 XmAuthenticationContext (com.icthh.xm.commons.security.XmAuthenticationContext)1 XmAuthenticationContextHolder (com.icthh.xm.commons.security.XmAuthenticationContextHolder)1