protected void setUp() throws Exception {
   super.setUp();
   gateway = new MockMediaGateway();
   copy1 = gateway.addCopy(new Book("isbn", "War and Peace", "Tolstoy"));
   id1 = copy1.getId();
   copy2 = gateway.addCopy(new Book("isbn", "War and Peace", "Tolstoy"));
   id2 = copy2.getId();
 }
示例#2
0
 public MediaCopy findCopyById(String copyId) {
   Collection listsOfCopies = mediaCopies.values();
   for (Iterator i = listsOfCopies.iterator(); i.hasNext(); ) {
     List copies = (List) i.next();
     for (int j = 0; j < copies.size(); j++) {
       MediaCopy mediaCopy = (MediaCopy) copies.get(j);
       if (mediaCopy.getId().equals(copyId)) return mediaCopy;
     }
   }
   return null;
 }
  public void testDeleteThreeCopiesForValidIsbn() throws Exception {
    assertISBNKnownWithEntries("3", 3);
    assertEquals(6, mockInMemoryMediaGateway.copyCount());
    List copies = mockInMemoryMediaGateway.findAllCopies("3");
    for (Iterator iter = copies.iterator(); iter.hasNext(); ) {
      MediaCopy copy = (MediaCopy) iter.next();
      String id = copy.getId();
      request.setParameter("delete_" + id, "on");
    }

    ActionResult result = booksController.handle(request);
    assertTrue(mockInMemoryMediaGateway.contains("3"));
    assertISBNKnownWithEntries("3", 0);
    assertEquals(3, mockInMemoryMediaGateway.copyCount());

    assertTrue(result.getInfoMessage().length() > 0);
    assertEquals("", result.getWarningMessage());
    assertEquals("", result.getErrorMessage());
  }