コード例 #1
0
  @Test
  public void testRoom() throws Exception {
    // create room
    WebRequest request =
        new PostMethodWebRequest(
            getCreateUrl(),
            new ByteArrayInputStream(objectMapper.writeValueAsString(baseRoom).getBytes()),
            MediaType.APPLICATION_JSON_VALUE);
    WebResponse response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    Room room = objectMapper.readValue(response.getText(), Room.class);
    assertNotNull(room);
    assertTrue(room.getId() != 0);
    assertTrue(compare(baseRoom, room, "id"));

    // update room
    baseRoom = room;
    baseRoom.setName("New name");
    request =
        new PutMethodWebRequest(
            getUpdateUrl(),
            new ByteArrayInputStream(objectMapper.writeValueAsString(baseRoom).getBytes()),
            MediaType.APPLICATION_JSON_VALUE);
    response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    room = objectMapper.readValue(response.getText(), Room.class);
    assertNotNull(room);
    assertEquals(room, baseRoom);

    // get room
    request = new GetMethodWebRequest(getViewUrl(baseRoom.getId()));
    response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    room = objectMapper.readValue(response.getText(), Room.class);
    assertNotNull(room);
    assertEquals(room, baseRoom);

    // remove room
    request =
        new WebRequest(getDeleteUrl(baseRoom.getId())) {

          @Override
          public String getMethod() {
            return RequestMethod.DELETE.toString();
          }
        };
    response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // check removed
    URL url = new URL(getViewUrl(baseRoom.getId()));
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.connect();
    assertEquals(HttpURLConnection.HTTP_NO_CONTENT, connection.getResponseCode());
  }
コード例 #2
0
  @Before
  public void setUp() {
    conversation = new WebConversation();

    baseRoom = new Room();
    baseRoom.setName("Test room");
    baseRoom.setDescription("Test room description");
    List<Account> users = new ArrayList<Account>();
    for (int i = 0; i < 5; i++) {
      users.add(prepareAccount(i + 1));
    }
    baseRoom.setUsers(users);
  }