Search in sources :

Example 26 with XmEntity

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

the class XmEntityLifeCycleSupportIntTest method createEntity.

public static XmEntity createEntity(String key) {
    val data = new HashMap<String, Object>();
    data.put("updateState", 0);
    data.put("updateByEntity", 0);
    data.put("updateByTargetState", 0);
    data.put("updateByTransition", 0);
    val entity = new XmEntity().key(key).typeKey("TEST_LIFECYCLE").stateKey("STATE1").name("DEFAULT_NAME").description("DEFAULT_DESCRIPTION");
    entity.setData(data);
    return entity;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

Example 27 with XmEntity

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

the class XmEntityLifeCycleSupportIntTest method testNotLep.

@Test
@Transactional
public void testNotLep() throws Exception {
    MutableLong id = new MutableLong();
    // Create the XmEntity
    restXmEntityMockMvc.perform(post("/api/xm-entities").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(createEntity("KEY1")))).andDo(r -> {
        log.info(r.getResponse().getContentAsString());
        final ObjectNode node = new ObjectMapper().readValue(r.getResponse().getContentAsString(), ObjectNode.class);
        id.setValue(node.get("id").longValue());
    }).andExpect(status().isCreated());
    changeState(id, "STATE2", updateStateNotCalled(), updateByEntityNotCalled(), updateByTargetStateNotCalled(), updateByTransitionNotCalled());
    initLeps();
    changeState(id, "STATE3", updateStateCalled(), updateByEntityCalled(), updateByTargetStateNotCalled(), updateByTransitionNotCalled());
    changeState(id, "STATE4", updateStateCalled(), updateByEntityCalled(), updateByTargetStateCalled(), updateByTransitionNotCalled());
    changeState(id, "STATE5", updateStateCalled(), updateByEntityCalled(), updateByTargetStateNotCalled(), updateByTransitionNotCalled());
    changeState(id, "STATE6", updateStateCalled(), updateByEntityCalled(), updateByTargetStateNotCalled(), updateByTransitionCalled());
    changeState(id, "STATE7", updateStateCalled(), updateByEntityCalled(), updateByTargetStateCalled(), updateByTransitionCalled());
}
Also used : Validator(org.springframework.validation.Validator) SneakyThrows(lombok.SneakyThrows) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TenantContextHolder(com.icthh.xm.commons.tenant.TenantContextHolder) WebappTenantOverrideConfiguration(com.icthh.xm.ms.entity.config.tenant.WebappTenantOverrideConfiguration) MockitoAnnotations(org.mockito.MockitoAnnotations) ExceptionTranslator(com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator) After(org.junit.After) EntityApp(com.icthh.xm.ms.entity.EntityApp) SpringRunner(org.springframework.test.context.junit4.SpringRunner) URI(java.net.URI) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction) MockMvcRequestBuilders.put(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) SecurityBeanOverrideConfiguration(com.icthh.xm.ms.entity.config.SecurityBeanOverrideConfiguration) IOUtils(org.apache.commons.io.IOUtils) Slf4j(lombok.extern.slf4j.Slf4j) 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) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) MutableLong(org.apache.commons.lang.mutable.MutableLong) Mockito.mock(org.mockito.Mockito.mock) THREAD_CONTEXT_KEY_TENANT_CONTEXT(com.icthh.xm.commons.lep.XmLepConstants.THREAD_CONTEXT_KEY_TENANT_CONTEXT) RunWith(org.junit.runner.RunWith) ClassPathResource(org.springframework.core.io.ClassPathResource) com.icthh.xm.ms.entity.service(com.icthh.xm.ms.entity.service) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) XmEntityServiceImpl(com.icthh.xm.ms.entity.service.impl.XmEntityServiceImpl) Before(org.junit.Before) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ProfileEventProducer(com.icthh.xm.ms.entity.repository.kafka.ProfileEventProducer) ResponseEntity(org.springframework.http.ResponseEntity) LepConfiguration(com.icthh.xm.ms.entity.config.LepConfiguration) XmLepScriptConfigServerResourceLoader(com.icthh.xm.commons.lep.XmLepScriptConfigServerResourceLoader) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) MutableLong(org.apache.commons.lang.mutable.MutableLong) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with XmEntity

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

the class XmEntityResourceExtendedIntTest method createXmEntityWithLargeData.

@Test
@Transactional
public void createXmEntityWithLargeData() throws Exception {
    int databaseSizeBeforeCreate = xmEntityRepository.findAll().size();
    xmEntityIncoming.setData(LARGE_DATA);
    // Create the XmEntity
    MvcResult result = performPost("/api/xm-entities", xmEntityIncoming).andExpect(status().isCreated()).andReturn();
    Integer id = JsonPath.read(result.getResponse().getContentAsString(), "$.id");
    // Get the xmEntityPersisted with tag by ID
    performGet("/api/xm-entities/{id}", id).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.id").value(id)).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(LARGE_VALUE));
    // Validate the XmEntity in the database
    List<XmEntity> xmEntityList = validateEntityInDB(databaseSizeBeforeCreate + 1);
    XmEntity testXmEntity = xmEntityList.get(xmEntityList.size() - 1);
    assertThat(testXmEntity.getData()).isEqualTo(LARGE_DATA);
    // Validate the XmEntity in Elasticsearch
    XmEntity xmEntityEs = xmEntitySearchRepository.findOne(testXmEntity.getId());
    assertThat(xmEntityEs).isEqualToComparingFieldByField(testXmEntity);
    assertThat(xmEntityEs.getData()).isEqualTo(LARGE_DATA);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with XmEntity

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

the class XmEntityResourceExtendedIntTest method xmEntityFildsNoRelationFields.

@Test
@Transactional
public void xmEntityFildsNoRelationFields() throws Exception {
    assertThat(xmEntityIncoming.getAttachments().size()).isGreaterThan(0);
    assertThat(xmEntityIncoming.getTags().size()).isGreaterThan(0);
    assertThat(xmEntityIncoming.getLocations().size()).isGreaterThan(0);
    // Create the XmEntity with tag
    MvcResult result = performPost("/api/xm-entities", xmEntityIncoming).andExpect(status().isCreated()).andExpect(jsonPath("$.key").value(DEFAULT_KEY)).andReturn();
    int id = JsonPath.read(result.getResponse().getContentAsString(), "$.id");
    List<XmEntity> xmEntityList = xmEntityRepository.findAll();
    em.detach(xmEntityList.get(xmEntityList.size() - 1));
    // );
    performGet("/api/xm-entities/{id}?embed=id", id).andExpect(status().isOk()).andDo(this::printMvcResult).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.id").value(id)).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("$.description").value(DEFAULT_DESCRIPTION)).andExpect(jsonPath("$.data.AAAAAAAAAA").value("BBBBBBBBBB")).andExpect(jsonPath("$.attachments").value(nullValue())).andExpect(jsonPath("$.tags").value(nullValue())).andExpect(jsonPath("$.locations").value(nullValue()));
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with XmEntity

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

the class XmEntityResourceExtendedIntTest method getAllXmEntitiesByTypeKeyNo.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void getAllXmEntitiesByTypeKeyNo() throws Exception {
    XmEntity entity = createEntityComplexPersisted(em);
    // Get all the xmEntityList
    performGet("/api/xm-entities?sort=id,desc&typeKey=PRICE").andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.[*].id").value(everyItem(nullValue())));
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) 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