@After
 public void tearDown() throws Exception {
   AdminData.getUpdateableInstance().close();
   mtf.tearDown();
   rs.tearDown();
   // super.tearDown();
 }
  @Test
  public void testProcessMissingRequest() throws Exception {

    Settings.set(
        ArchiveSettings.DIR_ARCREPOSITORY_BITPRESERVATION, TestInfo.WORKING_DIR.getAbsolutePath());
    Settings.set(ArchiveSettings.DIRS_ARCREPOSITORY_ADMIN, TestInfo.WORKING_DIR.getAbsolutePath());

    // Ensure that a admin data exists before we start.
    AdminData.getUpdateableInstance();

    MockFileBasedActiveBitPreservation mockabp = new MockFileBasedActiveBitPreservation();
    MockHttpServletRequest request = new MockHttpServletRequest();
    String replicaID1 = "ONE";
    String replicaID2 = "TWO";
    String filename1 = "foo";
    String filename2 = "bar";
    Locale defaultLocale = new Locale("da");

    // First test a working set of params
    Map<String, String[]> args = new HashMap<String, String[]>();
    args.put(
        ADD_COMMAND,
        new String[] {
          Replica.getReplicaFromId(replicaID1).getName() + STRING_FILENAME_SEPARATOR + filename1
        });
    request.setupAddParameter(
        ADD_COMMAND,
        new String[] {
          Replica.getReplicaFromId(replicaID1).getName() + STRING_FILENAME_SEPARATOR + filename1
        });
    args.put(GET_INFO_COMMAND, new String[] {filename1});
    request.setupAddParameter(GET_INFO_COMMAND, new String[] {filename1});
    args.put(BITARCHIVE_NAME_PARAM, new String[] {Replica.getReplicaFromId(replicaID1).getName()});
    request.setupAddParameter(
        BITARCHIVE_NAME_PARAM, new String[] {Replica.getReplicaFromId(replicaID1).getName()});
    request.setupGetParameterMap(args);
    request.setupGetParameterNames(new Vector<String>(args.keySet()).elements());
    Map<String, PreservationState> status =
        BitpreserveFileState.processMissingRequest(
            WebinterfaceTestCase.getDummyPageContext(defaultLocale, request), new StringBuilder());
    assertEquals("Should have one call to reestablish", 1, mockabp.getCallCount(ADD_METHOD));
    assertEquals(
        "Should have one call to getFilePreservationStatus",
        1,
        mockabp.getCallCount(GET_INFO_METHOD));
    assertEquals("Should have one info element (with mock results)", null, status.get(filename1));

    // Check that we can call without any params
    mockabp.calls.clear();
    request = new MockHttpServletRequest();
    args.clear();
    args.put(BITARCHIVE_NAME_PARAM, new String[] {Replica.getReplicaFromId(replicaID1).getName()});
    request.setupAddParameter(
        BITARCHIVE_NAME_PARAM, new String[] {Replica.getReplicaFromId(replicaID1).getName()});
    request.setupGetParameterMap(args);
    status =
        BitpreserveFileState.processMissingRequest(
            WebinterfaceTestCase.getDummyPageContext(defaultLocale, request), new StringBuilder());
    assertEquals("Should have no call to restablish", 0, mockabp.getCallCount(ADD_METHOD));
    assertEquals(
        "Should have no call to getFilePreservationStatus",
        0,
        mockabp.getCallCount(GET_INFO_METHOD));
    assertEquals("Should have no status", 0, status.size());

    // Check that we can handle more than one call to each and that the
    // args are correct.
    mockabp.calls.clear();
    request = new MockHttpServletRequest();
    args.clear();
    args.put(BITARCHIVE_NAME_PARAM, new String[] {Replica.getReplicaFromId(replicaID2).getName()});
    request.setupAddParameter(
        BITARCHIVE_NAME_PARAM, new String[] {Replica.getReplicaFromId(replicaID2).getName()});
    request.setupAddParameter(
        ADD_COMMAND,
        new String[] {
          Replica.getReplicaFromId(replicaID2).getName() + STRING_FILENAME_SEPARATOR + filename1,
          Replica.getReplicaFromId(replicaID2).getName() + STRING_FILENAME_SEPARATOR + filename1
        });
    args.put(
        ADD_COMMAND,
        new String[] {
          Replica.getReplicaFromId(replicaID2).getName() + STRING_FILENAME_SEPARATOR + filename1,
          Replica.getReplicaFromId(replicaID2).getName() + STRING_FILENAME_SEPARATOR + filename1
        });
    request.setupAddParameter(GET_INFO_COMMAND, new String[] {filename1, filename2, filename1});
    args.put(GET_INFO_COMMAND, new String[] {filename1, filename2, filename1});
    request.setupGetParameterMap(args);
    status =
        BitpreserveFileState.processMissingRequest(
            WebinterfaceTestCase.getDummyPageContext(defaultLocale, request), new StringBuilder());
    assertEquals("Should have two calls to restablish", 2, mockabp.getCallCount(ADD_METHOD));
    assertEquals(
        "Should have three calls to getFilePreservationStatus",
        3,
        mockabp.getCallCount(GET_INFO_METHOD));
    assertEquals("Should have two info elements", 2, status.size());
    assertEquals("Should have info for filename1", null, status.get(filename1));
    assertEquals("Should have info for filename2", null, status.get(filename2));

    // Iterator<String> it = mockabp.calls.get(ADD_METHOD).iterator();
    // while (it.hasNext()) {
    // System.out.println(it.next());
    // }

    CollectionAsserts.assertIteratorEquals(
        "Should have the args given add",
        Arrays.asList(new String[] {filename1 + "," + replicaID2, filename1 + "," + replicaID2})
            .iterator(),
        mockabp.calls.get(ADD_METHOD).iterator());

    CollectionAsserts.assertIteratorEquals(
        "Should have the args given info",
        Arrays.asList(new String[] {filename1, filename2, filename1}).iterator(),
        mockabp.calls.get(GET_INFO_METHOD).iterator());
  }