use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.
the class LocationResourceIntTest 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 Location createEntity(EntityManager em) {
Location location = new Location().typeKey(DEFAULT_TYPE_KEY).countryKey(DEFAULT_COUNTRY_KEY).longitude(DEFAULT_LONGITUDE).latitude(DEFAULT_LATITUDE).name(DEFAULT_NAME).addressLine1(DEFAULT_ADDRESS_LINE_1).addressLine2(DEFAULT_ADDRESS_LINE_2).city(DEFAULT_CITY).region(DEFAULT_REGION).zip(DEFAULT_ZIP);
// Add required entity
XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
em.persist(xmEntity);
em.flush();
location.setXmEntity(xmEntity);
return location;
}
use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.
the class LocationResourceIntTest method updateLocation.
@Test
@Transactional
public void updateLocation() throws Exception {
// Initialize the database
locationRepository.saveAndFlush(location);
locationSearchRepository.save(location);
int databaseSizeBeforeUpdate = locationRepository.findAll().size();
// Update the location
Location updatedLocation = locationRepository.findOne(location.getId());
updatedLocation.typeKey(UPDATED_TYPE_KEY).countryKey(UPDATED_COUNTRY_KEY).longitude(UPDATED_LONGITUDE).latitude(UPDATED_LATITUDE).name(UPDATED_NAME).addressLine1(UPDATED_ADDRESS_LINE_1).addressLine2(UPDATED_ADDRESS_LINE_2).city(UPDATED_CITY).region(UPDATED_REGION).zip(UPDATED_ZIP);
restLocationMockMvc.perform(put("/api/locations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedLocation))).andExpect(status().isOk());
// Validate the Location in the database
List<Location> locationList = locationRepository.findAll();
assertThat(locationList).hasSize(databaseSizeBeforeUpdate);
Location testLocation = locationList.get(locationList.size() - 1);
assertThat(testLocation.getTypeKey()).isEqualTo(UPDATED_TYPE_KEY);
assertThat(testLocation.getCountryKey()).isEqualTo(UPDATED_COUNTRY_KEY);
assertThat(testLocation.getLongitude()).isEqualTo(UPDATED_LONGITUDE);
assertThat(testLocation.getLatitude()).isEqualTo(UPDATED_LATITUDE);
assertThat(testLocation.getName()).isEqualTo(UPDATED_NAME);
assertThat(testLocation.getAddressLine1()).isEqualTo(UPDATED_ADDRESS_LINE_1);
assertThat(testLocation.getAddressLine2()).isEqualTo(UPDATED_ADDRESS_LINE_2);
assertThat(testLocation.getCity()).isEqualTo(UPDATED_CITY);
assertThat(testLocation.getRegion()).isEqualTo(UPDATED_REGION);
assertThat(testLocation.getZip()).isEqualTo(UPDATED_ZIP);
// Validate the Location in Elasticsearch
Location locationEs = locationSearchRepository.findOne(testLocation.getId());
assertThat(locationEs).isEqualToComparingFieldByField(testLocation);
}
use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.
the class XmEntityGeneratorServiceIntTest method generateXmEntityWithLocations.
@Test
@SneakyThrows
public void generateXmEntityWithLocations() {
XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity(ENTITY_TYPE_WITH_TAGS_AND_LOCATIONS_KEY);
log.info(new ObjectMapper().writeValueAsString(generatedEntity));
Set<Location> locations = generatedEntity.getLocations();
assertFalse("No locations generated", isEmpty(locations));
TypeSpec specType = xmEntitySpecService.findTypeByKey("TYPE1.SUBTYPE1");
List<LocationSpec> locationSpecs = specType.getLocations();
Set<String> locationSpecKeys = locationSpecs.stream().map(LocationSpec::getKey).collect(toSet());
Set<String> locationKeys = locations.stream().map(Location::getTypeKey).collect(toSet());
assertTrue("Tag type not from locations specification", locationSpecKeys.containsAll(locationKeys));
for (val location : locations) {
assertFalse("Name of location is empty", isBlank(location.getName()));
assertFalse("Coordinates and address is empty", isBlank(location.getAddressLine1()) && (location.getLatitude() == null || location.getLongitude() == null));
}
}
use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.
the class DeleteEntityTest method createXmEntity.
private XmEntity createXmEntity() {
XmEntity xmEntity = new XmEntity().key(randomUUID().toString()).typeKey("TEST_DELETE");
xmEntity.name("name").functionContexts(asSet(new FunctionContext().key("1").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("2").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("3").typeKey("A").xmEntity(xmEntity))).attachments(asSet(new Attachment().typeKey("A").name("1"), new Attachment().typeKey("A").name("2"), new Attachment().typeKey("A").name("3"))).calendars(asSet(new Calendar().typeKey("A").name("1").events(asSet(new Event().typeKey("A").title("1"), new Event().typeKey("A").title("2"))), new Calendar().typeKey("A").name("2").events(asSet(new Event().typeKey("A").title("3"), new Event().typeKey("A").title("4"))))).locations(asSet(new Location().typeKey("A").name("1"), new Location().typeKey("A").name("2"))).ratings(asSet(new Rating().typeKey("A").votes(asSet(new Vote().message("1").value(1.1).userKey("1"), new Vote().message("2").value(2.1).userKey("2"))))).tags(asSet(new Tag().typeKey("A").name("1"), new Tag().typeKey("A").name("2"))).comments(asSet(new Comment().message("1").userKey("1"), new Comment().message("2").userKey("1")));
return xmEntity;
}
use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.
the class LocationResource method updateLocation.
/**
* PUT /locations : Updates an existing location.
*
* @param location the location to update
* @return the ResponseEntity with status 200 (OK) and with body the updated location,
* or with status 400 (Bad Request) if the location is not valid,
* or with status 500 (Internal Server Error) if the location couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/locations")
@Timed
@PreAuthorize("hasPermission({'id': #location.id, 'newLocation': #location}, 'location', 'LOCATION.UPDATE')")
public ResponseEntity<Location> updateLocation(@Valid @RequestBody Location location) throws URISyntaxException {
if (location.getId() == null) {
// in order to call method with permissions check
return this.locationResource.createLocation(location);
}
Location result = locationRepository.save(location);
locationSearchRepository.save(result);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, location.getId().toString())).body(result);
}
Aggregations