Program: 89736
Project: 89736
Buggy source:
/** 
 * Test that the OnBatchReply method updates state and responds correctly. This is a rather complex test, but should not attempt to test processCheckSum().  It has to set up the following: outstandingChecksumFiles should contain an entry replyOfId->arcfilename msg should contain id, errmsg, resultfile, filesprocessed, filesfailed, but the channels are not used. ad should contain some checksum for the arcfilename but no replyinfo -- we can check the effect by seeing warnings and state.
 * @throws Exception if exception is thrown
 */
@SuppressWarnings("String_Node_Str") public void testOnBatchReply() throws Exception {
  ArcRepository a=ArcRepository.getInstance();
  UpdateableAdminData ad=UpdateableAdminData.getUpdateableInstance();
  Field ocf=a.getClass().getDeclaredField("String_Node_Str");
  ocf.setAccessible(true);
  Map<String,String> outstanding=(Map<String,String>)ocf.get(a);
  Field adm=ad.getClass().getSuperclass().getDeclaredField("String_Node_Str");
  adm.setAccessible(true);
  Map<String,ArcRepositoryEntry> admindataentries=(Map<String,ArcRepositoryEntry>)adm.get(ad);
  String id1="String_Node_Str";
  String arcname1="String_Node_Str";
  outstanding.put(id1,arcname1);
  ad.addEntry(arcname1,null,"String_Node_Str");
  BatchReplyMessage bamsg0=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new StringRemoteFile(arcname1 + dk.netarkivet.archive.arcrepository.bitpreservation.Constants.STRING_FILENAME_SEPARATOR + "String_Node_Str"));
  JMSConnectionMockupMQ.updateMsgID(bamsg0,id1);
  a.onBatchReply(bamsg0);
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileNotContains("String_Node_Str",TestInfo.LOG_FILE,"String_Node_Str");
  assertEquals("String_Node_Str",ReplicaStoreState.UPLOAD_COMPLETED,ad.getState(arcname1,Channels.getTheBamon().getName()));
  outstanding.put(id1,arcname1);
  ad.addEntry(arcname1,null,"String_Node_Str");
  BatchReplyMessage bamsg2=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new NullRemoteFile());
  JMSConnectionMockupMQ.updateMsgID(bamsg2,id1);
  bamsg2.setNotOk("String_Node_Str");
  a.onBatchReply(bamsg2);
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",TestInfo.LOG_FILE);
  assertEquals("String_Node_Str",ReplicaStoreState.UPLOAD_FAILED,ad.getState(arcname1,Channels.getTheBamon().getName()));
  admindataentries.remove(arcname1);
  outstanding.put(id1,arcname1);
  BatchReplyMessage bamsg3=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new NullRemoteFile());
  JMSConnectionMockupMQ.updateMsgID(bamsg3,id1);
  bamsg3.setNotOk("String_Node_Str");
  try {
    a.onBatchReply(bamsg3);
    fail("String_Node_Str" + "String_Node_Str" + arcname1);
  }
 catch (  UnknownID e) {
    StringAsserts.assertStringContains("String_Node_Str" + "String_Node_Str",arcname1,e.getMessage());
  }
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",TestInfo.LOG_FILE);
  assertFalse("String_Node_Str",ad.hasEntry(arcname1));
  BatchReplyMessage bamsg1=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new NullRemoteFile());
  a.onBatchReply(bamsg1);
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str" + id1,TestInfo.LOG_FILE);
  assertFalse("String_Node_Str",ad.hasEntry(arcname1));
}

Fixed version (ground truth):
/** 
 * Test that the OnBatchReply method updates state and responds correctly. This is a rather complex test, but should not attempt to test processCheckSum().  It has to set up the following: outstandingChecksumFiles should contain an entry replyOfId->arcfilename msg should contain id, errmsg, resultfile, filesprocessed, filesfailed, but the channels are not used. ad should contain some checksum for the arcfilename but no replyinfo -- we can check the effect by seeing warnings and state.
 * @throws Exception if exception is thrown
 */
@SuppressWarnings("String_Node_Str") public void testOnBatchReply() throws Exception {
  ArcRepository a=ArcRepository.getInstance();
  UpdateableAdminData ad=UpdateableAdminData.getUpdateableInstance();
  Field ocf=a.getClass().getDeclaredField("String_Node_Str");
  ocf.setAccessible(true);
  Map<String,String> outstanding=(Map<String,String>)ocf.get(a);
  Field adm=ad.getClass().getSuperclass().getDeclaredField("String_Node_Str");
  adm.setAccessible(true);
  Map<String,ArcRepositoryEntry> admindataentries=(Map<String,ArcRepositoryEntry>)adm.get(ad);
  String id1="String_Node_Str";
  String arcname1="String_Node_Str";
  outstanding.put(id1,arcname1);
  ad.addEntry(arcname1,null,"String_Node_Str");
  BatchReplyMessage bamsg0=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new StringRemoteFile(arcname1 + ChecksumJob.STRING_FILENAME_SEPARATOR + "String_Node_Str"));
  JMSConnectionMockupMQ.updateMsgID(bamsg0,id1);
  a.onBatchReply(bamsg0);
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileNotContains("String_Node_Str",TestInfo.LOG_FILE,"String_Node_Str");
  assertEquals("String_Node_Str",ReplicaStoreState.UPLOAD_COMPLETED,ad.getState(arcname1,Channels.getTheBamon().getName()));
  outstanding.put(id1,arcname1);
  ad.addEntry(arcname1,null,"String_Node_Str");
  BatchReplyMessage bamsg2=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new NullRemoteFile());
  JMSConnectionMockupMQ.updateMsgID(bamsg2,id1);
  bamsg2.setNotOk("String_Node_Str");
  a.onBatchReply(bamsg2);
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",TestInfo.LOG_FILE);
  assertEquals("String_Node_Str",ReplicaStoreState.UPLOAD_FAILED,ad.getState(arcname1,Channels.getTheBamon().getName()));
  admindataentries.remove(arcname1);
  outstanding.put(id1,arcname1);
  BatchReplyMessage bamsg3=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new NullRemoteFile());
  JMSConnectionMockupMQ.updateMsgID(bamsg3,id1);
  bamsg3.setNotOk("String_Node_Str");
  try {
    a.onBatchReply(bamsg3);
    fail("String_Node_Str" + "String_Node_Str" + arcname1);
  }
 catch (  UnknownID e) {
    StringAsserts.assertStringContains("String_Node_Str" + "String_Node_Str",arcname1,e.getMessage());
  }
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str",TestInfo.LOG_FILE);
  assertFalse("String_Node_Str",ad.hasEntry(arcname1));
  BatchReplyMessage bamsg1=new BatchReplyMessage(Channels.getTheRepos(),Channels.getTheBamon(),id1,0,new ArrayList<File>(0),new NullRemoteFile());
  a.onBatchReply(bamsg1);
  LogUtils.flushLogs(ArcRepository.class.getName());
  FileAsserts.assertFileContains("String_Node_Str","String_Node_Str" + id1,TestInfo.LOG_FILE);
  assertFalse("String_Node_Str",ad.hasEntry(arcname1));
}