@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; }
/** Compare Posting objects by id */ public int compare(Posting o1, Posting o2) { return o1.getId() - o2.getId(); }
Posting newPosting(Date date, String memo) { Posting p = new Posting(this); p.setPostingDate(date); p.setMemo(memo); return p; }