@Test public void testUpdate() { User bruno = admin("bruno").build(); City cidade = city("São Paulo").build(); Hotel c = hotel("Days Inn", cidade).build(); saveall(cidade, c, bruno); signIn(bruno); String name = "newname"; c.setName(name); ResponseEntity<HotelDTO> response = put("/hotel/%s", c.getId()) .json(convert.toDTO(c)) .expectedStatus(HttpStatus.OK) .getResponse(HotelDTO.class); assertThat(response.getBody().getName(), equalTo(name)); assertThat(response.getBody().getCity().getName(), not("teste")); Hotel entity = repository.findByIdWithCity(c.getId()); assertThat(entity.getName(), equalTo(name)); assertThat(entity.getCity().getName(), not("teste")); }
@Test public void testDelete() { User bruno = admin("bruno").build(); City cidade = city("São Paulo").build(); Hotel c1 = hotel("Days Inn", cidade).build(); saveall(cidade, c1, bruno); signIn(bruno); assertThat(repository.findAll(), hasSize(1)); ResponseEntity<HotelDTO> response = delete("/hotel/%s", c1.getId()).expectedStatus(HttpStatus.OK).getResponse(HotelDTO.class); assertThat(response.getBody().getId(), equalTo(c1.getId())); assertThat(repository.findAll(), hasSize(0)); assertThat(cityRepository.findAll(), hasSize(1)); }
@Test public void testCreateInvalidCity() { User bruno = admin("bruno").build(); City cidade = city("São Paulo").build(); saveall(bruno, cidade); signIn(bruno); Hotel c = hotel("Days Inn", cidade).build(); c.getCity().setId(9999l); post("/hotel").json(convert.toDTO(c)).expectedStatus(HttpStatus.NOT_FOUND).getResponse(); assertThat(repository.findAll(), hasSize(0)); }
@Test public void testUpdateWithInvalidCity() { User bruno = admin("bruno").build(); City cidade = city("São Paulo").build(); Hotel c = hotel("Days Inn", cidade).build(); saveall(cidade, c, bruno); signIn(bruno); String name = "newname"; c.setName(name); c.getCity().setId(9999l); put("/hotel/%s", c.getId()) .json(convert.toDTO(c)) .expectedStatus(HttpStatus.NOT_FOUND) .getResponse(); Hotel entity = repository.findByIdWithCity(c.getId()); assertThat(entity.getName(), not(name)); assertThat(entity.getCity().getName(), not("teste")); }
@Test public void testCreate() { User bruno = admin("bruno").build(); City cidade = city("São Paulo").build(); saveall(bruno, cidade); signIn(bruno); Hotel c = hotel("Days Inn", cidade).build(); ResponseEntity<HotelDTO> response = post("/hotel") .json(convert.toDTO(c)) .expectedStatus(HttpStatus.CREATED) .getResponse(HotelDTO.class); c.setId(response.getBody().getId()); HotelDTO dto = convert.toDTO(c); assertThat(response.getBody(), equalTo(dto)); assertThat(response.getBody().getCity(), equalTo(dto.getCity())); assertThat(repository.findAll(), hasSize(1)); }