コード例 #1
0
  @Test
  public void shouldSendUpdateWhenOnePlayerRequested() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(screenFor("vasya", "vasyaboard").asMap());

    assertContainsPlayerBoard(response.getContentAsString(), "vasya", "vasyaboard");
  }
コード例 #2
0
  @Test
  public void shouldIgnoreNonRequestedPlayerData() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(screenFor("petya", "petyaboard").asMap());

    assertTrue(asyncContext.isComplete());
  }
コード例 #3
0
  @Test
  public void shouldCompleteResponseWhenExceptionOnWrite() throws IOException {
    response.setCharacterEncoding("NON_EXISTENT_ENCODING_FOR_IO_EXCEPTION");
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(screenFor("vasya", "vasyaboard").asMap());

    assertTrue(asyncContext.isComplete());
  }
コード例 #4
0
  @Test
  public void shouldSendScores() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(screenFor("vasya", 345, "vasyaboard").asMap());

    JsonPath jsonPath = from(response.getContentAsString());
    assertEquals(345, jsonPath.getInt("vasya.score"));
  }
コード例 #5
0
  @Test
  public void shouldSendToRequestedPlayersOnly() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(
        screenFor("petya", "petyaboard").addScreenFor("vasya", 123, "vasyaboard").asMap());

    JsonPath jsonPath = from(response.getContentAsString());
    assertNull("Should contain only requested user screens", jsonPath.get("petyaboard"));
  }
コード例 #6
0
  @Test
  public void shouldSendUpdateForAllPlayersWhenRequested() throws UnsupportedEncodingException {
    sender.scheduleUpdate(new UpdateRequest(asyncContext, true, null));

    sender.sendUpdates(
        screenFor("petya", "petyaboard").addScreenFor("vasya", 123, "vasyaboard").asMap());

    assertContainsPlayerBoard(response.getContentAsString(), "vasya", "vasyaboard");
    assertContainsPlayerBoard(response.getContentAsString(), "petya", "petyaboard");
  }
コード例 #7
0
  @Test
  public void shouldRemoveRequestWhenProcessed() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));
    sender.sendUpdates(screenFor("vasya", "vasyaboard").asMap());
    response.setWriterAccessAllowed(false);

    try {
      sender.sendUpdates(screenFor("vasya", "vasyaboard").asMap());
    } catch (Exception e) {
      fail("Should send only once");
    }
  }
コード例 #8
0
  @Test
  public void shouldSendOtherUpdatesWhenExceptionOnWrite() throws UnsupportedEncodingException {
    MockHttpServletResponse exceptionResponse = new MockHttpServletResponse();
    exceptionResponse.setCharacterEncoding("NON_EXISTENT_ENCODING_FOR_IO_EXCEPTION");
    MockAsyncContext exceptionContext = new MockAsyncContext(exceptionResponse);
    sender.scheduleUpdate(new UpdateRequest(exceptionContext, "exception"));
    sender.scheduleUpdate(updateRequestFor("petya"));

    sender.sendUpdates(
        screenFor("petya", "petyaboard").addScreenFor("exception", 123, "exceptionboard").asMap());

    assertContainsPlayerBoard(response.getContentAsString(), "petya", "petyaboard");
    assertTrue(exceptionContext.isComplete());
  }