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);
}
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");
}
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());
}
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;
}
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"));
}
Aggregations