@Test @Transactional public void updateLocation() throws Exception { // Initialize the database locationRepository.saveAndFlush(location); int databaseSizeBeforeUpdate = locationRepository.findAll().size(); // Update the location location.setAddress(UPDATED_ADDRESS); location.setLatitude(UPDATED_LATITUDE); location.setLongitude(UPDATED_LONGITUDE); restLocationMockMvc .perform( put("/api/locations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(location))) .andExpect(status().isOk()); // Validate the Location in the database List<Location> locations = locationRepository.findAll(); assertThat(locations).hasSize(databaseSizeBeforeUpdate); Location testLocation = locations.get(locations.size() - 1); assertThat(testLocation.getAddress()).isEqualTo(UPDATED_ADDRESS); assertThat(testLocation.getLatitude()).isEqualTo(UPDATED_LATITUDE); assertThat(testLocation.getLongitude()).isEqualTo(UPDATED_LONGITUDE); }
@Test @Transactional public void deleteLocation() throws Exception { // Initialize the database locationRepository.saveAndFlush(location); int databaseSizeBeforeDelete = locationRepository.findAll().size(); // Get the location restLocationMockMvc .perform( delete("/api/locations/{id}", location.getId()).accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate the database is empty List<Location> locations = locationRepository.findAll(); assertThat(locations).hasSize(databaseSizeBeforeDelete - 1); }
@Test @Transactional public void checkLongitudeIsRequired() throws Exception { int databaseSizeBeforeTest = locationRepository.findAll().size(); // set the field null location.setLongitude(null); // Create the Location, which fails. restLocationMockMvc .perform( post("/api/locations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(location))) .andExpect(status().isBadRequest()); List<Location> locations = locationRepository.findAll(); assertThat(locations).hasSize(databaseSizeBeforeTest); }
@Test @Transactional public void createLocation() throws Exception { int databaseSizeBeforeCreate = locationRepository.findAll().size(); // Create the Location restLocationMockMvc .perform( post("/api/locations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(location))) .andExpect(status().isCreated()); // Validate the Location in the database List<Location> locations = locationRepository.findAll(); assertThat(locations).hasSize(databaseSizeBeforeCreate + 1); Location testLocation = locations.get(locations.size() - 1); assertThat(testLocation.getAddress()).isEqualTo(DEFAULT_ADDRESS); assertThat(testLocation.getLatitude()).isEqualTo(DEFAULT_LATITUDE); assertThat(testLocation.getLongitude()).isEqualTo(DEFAULT_LONGITUDE); }
@Test @Transactional public void getLocation() throws Exception { // Initialize the database locationRepository.saveAndFlush(location); // Get the location restLocationMockMvc .perform(get("/api/locations/{id}", location.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(location.getId().intValue())) .andExpect(jsonPath("$.address").value(DEFAULT_ADDRESS.toString())) .andExpect(jsonPath("$.latitude").value(DEFAULT_LATITUDE.doubleValue())) .andExpect(jsonPath("$.longitude").value(DEFAULT_LONGITUDE.doubleValue())); }