예제 #1
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetCountryAXml() throws Exception {

    URI uri = getBaseUri().path("all").queryParam("country", countryA).build();
    Response response = client.target(uri).request("application/xml").get();

    String xml = response.readEntity(String.class);
    EventListDto dto = fromXml(EventListDto.class, xml);

    assertTrue(dto.getEvents().size() == 2);
    assertFalse(dto.getEvents().stream().anyMatch(e -> e.getAttendees().size() > 0));
  }
예제 #2
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetAllXml() throws Exception {

    URI uri = getBaseUri().path("all").build();
    Response response = client.target(uri).request().accept(MediaType.APPLICATION_XML_TYPE).get();

    String xml = response.readEntity(String.class);
    EventListDto dto = fromXml(EventListDto.class, xml);

    assertTrue(dto.getEvents().size() >= 3);
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventA)));
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventB)));
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventC)));

    assertFalse(dto.getEvents().stream().anyMatch(e -> e.getAttendees().size() > 0));
  }
예제 #3
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetAllJson() throws Exception {

    URI uri = getBaseUri().path("all").build();
    Response response = client.target(uri).request("application/json").get();

    String json = response.readEntity(String.class);
    Gson gson = new Gson();
    EventListDto dto = gson.fromJson(json, EventListDto.class);

    assertTrue(dto.getEvents().size() >= 3);
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventA)));
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventB)));
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventC)));

    assertFalse(dto.getEvents().stream().anyMatch(e -> e.getAttendees().size() > 0));
  }
예제 #4
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetEventJSon() throws Exception {
    URI uri = getBaseUri().path("all").build();
    Response response = client.target(uri).request("application/json").get();

    Gson gson = new Gson();

    EventListDto dto = gson.fromJson(response.readEntity(String.class), EventListDto.class);

    Long id = dto.getEvents().get(0).getId();

    uri = getBaseUri().queryParam("id", id).build();
    response = client.target(uri).request("application/json").get();
    EventDto other = gson.fromJson(response.readEntity(String.class), EventDto.class);

    assertEquals(id, other.getId());
    assertFalse(other.getAttendees().size() > 0);
  }
예제 #5
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetEventXml() throws Exception {
    URI uri = getBaseUri().path("all").build();
    Response response = client.target(uri).request("application/xml").get();
    String xml = response.readEntity(String.class);
    EventListDto dto = fromXml(EventListDto.class, xml);

    Long id = dto.getEvents().get(0).getId();

    uri = getBaseUri().queryParam("id", id).build();
    response = client.target(uri).request("application/xml").get();

    xml = response.readEntity(String.class);
    EventDto other = fromXml(EventDto.class, xml);

    assertEquals(id, other.getId());

    assertFalse(other.getAttendees().size() > 0);
  }
예제 #6
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetEventWithAttendeesXml() throws Exception {

    URI uri = getBaseUri().path("all").build();
    Response response = client.target(uri).request("application/xml").get();
    String xml = response.readEntity(String.class);
    EventListDto dto = fromXml(EventListDto.class, xml);

    Optional<Long> id =
        dto.getEvents()
            .stream()
            .filter(e -> e.getTitle().equals(eventA))
            .map(EventDto::getId)
            .findFirst();
    assertTrue(id.isPresent());

    uri = getBaseUri().queryParam("id", id.get()).queryParam("attendees", "true").build();
    response = client.target(uri).request("application/xml").get();
    xml = response.readEntity(String.class);
    EventDto event = fromXml(EventDto.class, xml);

    assertEquals(3, event.getAttendees().size());
  }
예제 #7
0
파일: RestIT.java 프로젝트: arcuri82/pg6100
  @Test
  public void testGetAllWithAttendeesXml() throws Exception {

    URI uri = getBaseUri().path("all").queryParam("attendees", "true").build();
    Response response = client.target(uri).request("application/xml").get();

    String xml = response.readEntity(String.class);
    EventListDto dto = fromXml(EventListDto.class, xml);

    assertTrue(dto.getEvents().size() >= 3);
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventA)));
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventB)));
    assertTrue(dto.getEvents().stream().anyMatch(e -> e.getTitle().equals(eventC)));

    assertTrue(
        dto.getEvents()
                .stream()
                .filter(e -> e.getTitle().equals(eventA))
                .flatMap(e -> e.getAttendees().stream())
                .count()
            == 3);
    assertTrue(
        dto.getEvents()
                .stream()
                .filter(e -> e.getTitle().equals(eventB))
                .flatMap(e -> e.getAttendees().stream())
                .count()
            == 2);
    assertTrue(
        dto.getEvents()
                .stream()
                .filter(e -> e.getTitle().equals(eventC))
                .flatMap(e -> e.getAttendees().stream())
                .count()
            == 1);
  }