コード例 #1
0
 @Test(timeout = 2000)
 public void testSerDeser1() {
   ClientMessage cm = new ClientMessage();
   cm.setType(ClientMessage.Type.CREATE)
       .setAuthor("AdnanAziz1968")
       .setSubject("Hello World")
       .setBody("My first posting!");
   String cmJson = cm.toJson();
   ClientMessage cmobj = ClientMessage.fromJson(cmJson);
   assertEquals(cm, cmobj);
   score += 5;
 }
コード例 #2
0
  @Test(timeout = 5000)
  public void testQuery1() {
    ClientMessage cmAdd1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Hello World")
            .setBody("My first posting!");

    ClientMessage cmAdd2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("Don Bradman")
            .setSubject("29")
            .setBody("Still the greatest!");

    ClientMessage cmAdd3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Random musings")
            .setBody("My second posting!");

    ClientMessage cmQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setAuthor("AdnanAziz1968");

    ServerMessage result = doTxRx(cmAdd1, cmAdd2, cmAdd3, cmQuery);

    assertEquals(result.getPostings().size(), 2);
    for (Posting p : result.getPostings()) {
      assert (p.getAuthor().equals(cmQuery.getAuthor()));
    }

    ClientMessage cmBodyQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setBody("posting My");
    assertEquals(2, result.getPostings().size());
    for (Posting p : result.getPostings()) {
      assertTrue(p.getBody().contains("My"));
      assertTrue(p.getBody().contains("posting"));
    }
    score += 15;
  }