コード例 #1
0
  @Test
  public void testList() {
    User bruno = admin("bruno").build();
    City cidade = city("São Paulo").build();
    Hotel c1 = hotel("Macbook", cidade).build();
    Hotel c2 = hotel("IPhone", cidade).build();
    saveall(cidade, c1, c2, bruno);

    signIn(bruno);

    Page<HotelDTO> page = get("/hotel").expectedStatus(HttpStatus.OK).getPage(HotelDTO.class);

    assertThat(page.getNumber(), equalTo(0));
    assertThat(page.getSize(), equalTo(50));
    assertThat(page.getContent(), contains(convert.toDTO(c2), convert.toDTO(c1)));
  }
コード例 #2
0
  @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"));
  }
コード例 #3
0
  @Test
  public void testSearchByCityName() {
    User bruno = admin("bruno").build();
    City cidade = city("São Paulo").build();
    Hotel c1 = hotel("Days Inn", cidade).build();
    Hotel c2 = hotel("Hilton", cidade).build();
    saveall(cidade, c1, c2, bruno);

    signIn(bruno);

    Page<HotelDTO> page =
        get("/hotel")
            .queryParam("search", "paulo")
            .expectedStatus(HttpStatus.OK)
            .getPage(HotelDTO.class);

    assertThat(page.getTotalElements(), equalTo(2L));
    assertThat(page.getContent(), contains(convert.toDTO(c1), convert.toDTO(c2)));
  }
コード例 #4
0
  @Test
  public void testeListWithPagination() {
    User bruno = admin("bruno").build();
    City cidade = city("São Paulo").build();
    Hotel c1 = hotel("A-Hotel", cidade).build();
    Hotel c2 = hotel("B-Hotel", cidade).build();
    Hotel c3 = hotel("C-Hotel", cidade).build();
    Hotel c4 = hotel("D-Hotel", cidade).build();
    Hotel c5 = hotel("E-Hotel", cidade).build();
    saveall(cidade, c1, c2, c3, c4, c5, bruno);

    signIn(bruno);

    Page<HotelDTO> page =
        get("/hotel")
            .queryParam("page", "0")
            .queryParam("size", "2")
            .expectedStatus(HttpStatus.OK)
            .getPage(HotelDTO.class);

    assertThat(page.getNumber(), equalTo(0));
    assertThat(page.getSize(), equalTo(2));
    assertThat(page.getTotalElements(), equalTo(5l));
    assertThat(page.getTotalPages(), equalTo(3));
    assertThat(page.getContent(), hasSize(2));
    assertThat(page.getContent(), contains(convert.toDTO(c1), convert.toDTO(c2)));

    page =
        get("/hotel")
            .queryParam("size", "2")
            .queryParam("page", "2")
            .expectedStatus(HttpStatus.OK)
            .getPage(HotelDTO.class);

    assertThat(page.getNumber(), equalTo(2));
    assertThat(page.getSize(), equalTo(2));
    assertThat(page.getTotalElements(), equalTo(5l));
    assertThat(page.getTotalPages(), equalTo(3));
    assertThat(page.getContent(), hasSize(1));
    assertThat(page.getContent(), contains(convert.toDTO(c5)));
  }
コード例 #5
0
  @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));
  }
コード例 #6
0
  @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));
  }
コード例 #7
0
  @Test
  public void testRead() {
    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);

    ResponseEntity<HotelDTO> response =
        get("/hotel/" + c1.getId()).expectedStatus(HttpStatus.OK).getResponse(HotelDTO.class);
    HotelDTO dto = convert.toDTO(c1);
    assertThat(response.getBody(), equalTo(dto));
    assertThat(response.getBody().getCity(), equalTo(dto.getCity()));
  }
コード例 #8
0
  @Test
  public void testCreateNotPersistyCity() {
    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().setName("newname");

    ResponseEntity<HotelDTO> response =
        post("/hotel")
            .json(convert.toDTO(c))
            .expectedStatus(HttpStatus.CREATED)
            .getResponse(HotelDTO.class);

    assertThat(response.getBody().getCity().getName(), not("newname"));
    assertThat(cityRepository.findOne(cidade.getId()).getName(), not("newname"));
  }
コード例 #9
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"));
  }