Search in sources :

Example 56 with XmEntity

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

the class XmEntityResourceExtendedIntTest method getAllXmEntitiesByTypeKey.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void getAllXmEntitiesByTypeKey() throws Exception {
    XmEntity entity = createEntityComplexPersisted(em);
    // Get all the xmEntityList
    performGet("/api/xm-entities?sort=id,desc&typeKey=ACCOUNT").andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.[*].id").value(hasItem(entity.getId().intValue()))).andExpect(jsonPath("$.[*].typeKey").value(hasItem(DEFAULT_TYPE_KEY)));
}
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)

Example 57 with XmEntity

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

the class XmEntityResourceExtendedIntTest method updateTenantXmEntity.

@Test
@Transactional
public void updateTenantXmEntity() throws Exception {
    // Initialize the database
    XmEntity tenantEntity = createEntity(em);
    tenantEntity.setTypeKey(Constants.TENANT_TYPE_KEY);
    tenantEntity.setStateKey(null);
    tenantEntity.setData(null);
    xmEntityRepository.save(tenantEntity);
    int databaseSizeBeforeUpdate = xmEntityRepository.findAll().size();
    // Update the xmEntity
    XmEntity updatedTenantEntity = createEntity(em);
    updatedTenantEntity.setId(tenantEntity.getId());
    updatedTenantEntity.setTypeKey(Constants.TENANT_TYPE_KEY);
    updatedTenantEntity.setStateKey(null);
    updatedTenantEntity.setData(null);
    updatedTenantEntity.setName("updatedName");
    restXmEntityMockMvc.perform(put("/api/xm-entities").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedTenantEntity))).andExpect(status().isOk());
    // Validate the XmEntity in the database
    List<XmEntity> xmEntityList = xmEntityRepository.findAll();
    assertThat(xmEntityList).hasSize(databaseSizeBeforeUpdate);
    XmEntity testXmEntity = xmEntityList.get(xmEntityList.size() - 1);
    assertThat(testXmEntity.getName()).isEqualTo(DEFAULT_NAME);
}
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 58 with XmEntity

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

the class XmEntityResourceExtendedIntTest method prepareCalendar.

private int prepareCalendar() throws Exception {
    // 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");
    xmEntityIncoming.setId((long) id);
    val calendar = new Calendar().name("name").typeKey("TYPEKEY").startDate(Instant.now()).xmEntity(xmEntityIncoming);
    MvcResult resultSaveCalendar = performPost("/api/calendars", calendar).andExpect(status().is2xxSuccessful()).andReturn();
    int calendarId = JsonPath.read(resultSaveCalendar.getResponse().getContentAsString(), "$.id");
    calendar.setId((long) calendarId);
    val event = new Event().typeKey("TYPEKEY").title("title").startDate(Instant.now()).calendar(calendar).assigned(xmEntityIncoming);
    MvcResult resultSaveEvent = performPost("/api/events", event).andExpect(status().is2xxSuccessful()).andReturn();
    List<XmEntity> xmEntityList = xmEntityRepository.findAll();
    em.detach(xmEntityList.get(xmEntityList.size() - 1));
    List<Calendar> calendarList = calendarService.findAll(null);
    em.detach(calendarList.get(calendarList.size() - 1));
    return id;
}
Also used : lombok.val(lombok.val) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Event(com.icthh.xm.ms.entity.domain.Event) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 59 with XmEntity

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

the class XmEntityResourceIntTest method changeStateError.

@Test
@Transactional
public void changeStateError() throws Exception {
    XmEntitySpecService xmEntitySpecService = Mockito.mock(XmEntitySpecService.class);
    StateSpec nextSpec = new StateSpec();
    nextSpec.setKey("NEXT_STATE");
    when(xmEntitySpecService.nextStates(eq(DEFAULT_TYPE_KEY), eq(DEFAULT_STATE_KEY))).thenReturn(Collections.singletonList(nextSpec));
    XmEntity tenant = createEntity(em);
    xmEntityServiceImpl.save(tenant);
    restXmEntityMockMvc.perform(put("/api/xm-entities/{idOrKey}/states/{stateKey}", tenant.getId(), "INVALID_NEXT_STATE").contentType(TestUtil.APPLICATION_JSON_UTF8)).andExpect(status().is4xxClientError());
}
Also used : StateSpec(com.icthh.xm.ms.entity.domain.spec.StateSpec) 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 60 with XmEntity

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

the class FunctionContextResourceIntTest method createEntity.

/**
 * Create an entity for this test.
 *
 * This is a static method, as tests for other entities might also need it,
 * if they test an entity which requires the current entity.
 */
public static FunctionContext createEntity(EntityManager em) {
    FunctionContext functionContext = new FunctionContext().key(DEFAULT_KEY).typeKey(DEFAULT_TYPE_KEY).description(DEFAULT_DESCRIPTION).startDate(DEFAULT_START_DATE).updateDate(DEFAULT_UPDATE_DATE).endDate(DEFAULT_END_DATE).data(DEFAULT_DATA);
    // Add required entity
    XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
    em.persist(xmEntity);
    em.flush();
    functionContext.setXmEntity(xmEntity);
    return functionContext;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext)

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