Program: 188542
Project: 188542
Buggy source:
@Test public void testSiegfried() throws RODAException, FileAlreadyExistsException, InterruptedException, IOException, SolrServerException, XmlException {
  AIP aip=ingestCorpora();
  TestsHelper.executeJob(PremisSkeletonPlugin.class,PluginType.AIP_TO_AIP,SelectedItemsList.create(AIP.class,aip.getId()));
  Map<String,String> parameters=new HashMap<>();
  parameters.put(RodaConstants.PLUGIN_PARAMS_REPORTING_CLASS,FAKE_REPORTING_CLASS);
  Job job=TestsHelper.executeJob(SiegfriedPlugin.class,parameters,PluginType.AIP_TO_AIP,SelectedItemsList.create(AIP.class,aip.getId()));
  TestsHelper.getJobReports(index,job,true);
  aip=model.retrieveAIP(aip.getId());
  AssertJUnit.assertEquals(CORPORA_FILES_COUNT,Iterables.size(model.listOtherMetadata(aip.getId(),RodaConstants.OTHER_METADATA_TYPE_SIEGFRIED,true)));
  Binary om=model.retrieveOtherMetadataBinary(aip.getId(),aip.getRepresentations().get(0).getId(),Arrays.asList(CORPORA_TEST1),CORPORA_TEST1_TXT,SiegfriedPlugin.FILE_SUFFIX,RodaConstants.OTHER_METADATA_TYPE_SIEGFRIED);
  AssertJUnit.assertNotNull(om);
  Binary fpo_bin=model.retrievePreservationFile(aip.getId(),aip.getRepresentations().get(0).getId(),Arrays.asList(CORPORA_TEST1),CORPORA_TEST1_TXT);
  gov.loc.premis.v3.File fpo=PremisV3Utils.binaryToFile(fpo_bin.getContent(),true);
  FormatComplexType format=fpo.getObjectCharacteristicsArray(0).getFormatArray(0);
  AssertJUnit.assertEquals("String_Node_Str",format.getFormatDesignation().getFormatName().getStringValue());
  FormatRegistryComplexType pronomRegistry=PremisV3Utils.getFormatRegistry(fpo,RodaConstants.PRESERVATION_REGISTRY_PRONOM);
  AssertJUnit.assertEquals(RodaConstants.PRESERVATION_REGISTRY_PRONOM,pronomRegistry.getFormatRegistryName().getStringValue());
  AssertJUnit.assertEquals("String_Node_Str",pronomRegistry.getFormatRegistryKey().getStringValue());
  FormatRegistryComplexType mimeRegistry=PremisV3Utils.getFormatRegistry(fpo,RodaConstants.PRESERVATION_REGISTRY_MIME);
  String mimetype="String_Node_Str";
  AssertJUnit.assertEquals(mimetype,mimeRegistry.getFormatRegistryKey().getStringValue());
  index.commitAIPs();
  IndexedFile indFile=index.retrieve(IndexedFile.class,IdUtils.getFileId(aip.getId(),aip.getRepresentations().get(0).getId(),Arrays.asList(CORPORA_TEST1),CORPORA_TEST1_TXT));
  AssertJUnit.assertEquals(mimetype,indFile.getFileFormat().getMimeType());
  AssertJUnit.assertEquals("String_Node_Str",indFile.getFileFormat().getPronom());
  AssertJUnit.assertEquals("String_Node_Str",indFile.getFileFormat().getFormatDesignationName());
  List<String> suggest=index.suggest(IndexedFile.class,RodaConstants.FILE_FORMAT_MIMETYPE,mimetype.substring(0,1),null,false);
  MatcherAssert.assertThat(suggest,Matchers.contains(mimetype));
  Plugin<? extends IsRODAObject> plugin=RodaCoreFactory.getPluginManager().getPlugin(SiegfriedPlugin.class.getName());
  String agentID=IdUtils.getPluginAgentId(plugin);
  boolean found=false;
  CloseableIterable<OptionalWithCause<PreservationMetadata>> preservationMetadataList=model.listPreservationMetadata(aip.getId(),true);
  for (  OptionalWithCause<PreservationMetadata> opm : preservationMetadataList) {
    if (opm.isPresent()) {
      PreservationMetadata pm=opm.get();
      if (pm.getType().equals(PreservationMetadataType.EVENT)) {
        EventComplexType event=PremisV3Utils.binaryToEvent(model.retrievePreservationEvent(pm.getAipId(),pm.getRepresentationId(),pm.getId()).getContent().createInputStream());
        if (event.getLinkingAgentIdentifierArray() != null && event.getLinkingAgentIdentifierArray().length > 0) {
          for (          LinkingAgentIdentifierComplexType laict : event.getLinkingAgentIdentifierArray()) {
            if (laict.getLinkingAgentIdentifierValue() != null && laict.getLinkingAgentIdentifierValue().equalsIgnoreCase(agentID)) {
              found=true;
              break;
            }
          }
          if (found) {
            break;
          }
        }
      }
    }
  }
  IOUtils.closeQuietly(preservationMetadataList);
  AssertJUnit.assertTrue(found);
  Filter filter=new Filter();
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_TYPE,PreservationEventType.FORMAT_IDENTIFICATION.toString()));
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_AIP_ID,aip.getId()));
  IndexResult<IndexedPreservationEvent> events=index.find(IndexedPreservationEvent.class,filter,null,new Sublist(0,10));
  AssertJUnit.assertEquals(1,events.getTotalCount());
}

Fixed version (ground truth):
@Test public void testSiegfried() throws RODAException, FileAlreadyExistsException, InterruptedException, IOException, SolrServerException, XmlException {
  AIP aip=ingestCorpora();
  TestsHelper.executeJob(PremisSkeletonPlugin.class,PluginType.AIP_TO_AIP,SelectedItemsList.create(AIP.class,aip.getId()));
  Map<String,String> parameters=new HashMap<>();
  parameters.put(RodaConstants.PLUGIN_PARAMS_REPORTING_CLASS,FAKE_REPORTING_CLASS);
  Job job=TestsHelper.executeJob(SiegfriedPlugin.class,parameters,PluginType.AIP_TO_AIP,SelectedItemsList.create(AIP.class,aip.getId()));
  TestsHelper.getJobReports(index,job,true);
  aip=model.retrieveAIP(aip.getId());
  AssertJUnit.assertEquals(CORPORA_FILES_COUNT,Iterables.size(model.listOtherMetadata(aip.getId(),RodaConstants.OTHER_METADATA_TYPE_SIEGFRIED,true)));
  Binary om=model.retrieveOtherMetadataBinary(aip.getId(),aip.getRepresentations().get(0).getId(),Arrays.asList(CORPORA_TEST1),CORPORA_TEST1_TXT,SiegfriedPlugin.FILE_SUFFIX,RodaConstants.OTHER_METADATA_TYPE_SIEGFRIED);
  AssertJUnit.assertNotNull(om);
  Binary fpo_bin=model.retrievePreservationFile(aip.getId(),aip.getRepresentations().get(0).getId(),Arrays.asList(CORPORA_TEST1),CORPORA_TEST1_TXT);
  gov.loc.premis.v3.File fpo=PremisV3Utils.binaryToFile(fpo_bin.getContent(),true);
  FormatComplexType format=fpo.getObjectCharacteristicsArray(0).getFormatArray(0);
  AssertJUnit.assertEquals("String_Node_Str",format.getFormatDesignation().getFormatName().getStringValue());
  FormatRegistryComplexType pronomRegistry=PremisV3Utils.getFormatRegistry(fpo,RodaConstants.PRESERVATION_REGISTRY_PRONOM);
  AssertJUnit.assertEquals(RodaConstants.PRESERVATION_REGISTRY_PRONOM,pronomRegistry.getFormatRegistryName().getStringValue());
  AssertJUnit.assertEquals("String_Node_Str",pronomRegistry.getFormatRegistryKey().getStringValue());
  FormatRegistryComplexType mimeRegistry=PremisV3Utils.getFormatRegistry(fpo,RodaConstants.PRESERVATION_REGISTRY_MIME);
  String mimetype="String_Node_Str";
  AssertJUnit.assertEquals(mimetype,mimeRegistry.getFormatRegistryKey().getStringValue());
  index.commitAIPs();
  IndexedFile indFile=index.retrieve(IndexedFile.class,IdUtils.getFileId(aip.getId(),aip.getRepresentations().get(0).getId(),Arrays.asList(CORPORA_TEST1),CORPORA_TEST1_TXT));
  AssertJUnit.assertEquals(mimetype,indFile.getFileFormat().getMimeType());
  AssertJUnit.assertEquals("String_Node_Str",indFile.getFileFormat().getPronom());
  AssertJUnit.assertEquals("String_Node_Str",indFile.getFileFormat().getFormatDesignationName());
  List<String> suggest=index.suggest(IndexedFile.class,RodaConstants.FILE_FORMAT_MIMETYPE,mimetype.substring(0,1),null,false,false);
  MatcherAssert.assertThat(suggest,Matchers.contains(mimetype));
  Plugin<? extends IsRODAObject> plugin=RodaCoreFactory.getPluginManager().getPlugin(SiegfriedPlugin.class.getName());
  String agentID=IdUtils.getPluginAgentId(plugin);
  boolean found=false;
  CloseableIterable<OptionalWithCause<PreservationMetadata>> preservationMetadataList=model.listPreservationMetadata(aip.getId(),true);
  for (  OptionalWithCause<PreservationMetadata> opm : preservationMetadataList) {
    if (opm.isPresent()) {
      PreservationMetadata pm=opm.get();
      if (pm.getType().equals(PreservationMetadataType.EVENT)) {
        EventComplexType event=PremisV3Utils.binaryToEvent(model.retrievePreservationEvent(pm.getAipId(),pm.getRepresentationId(),pm.getId()).getContent().createInputStream());
        if (event.getLinkingAgentIdentifierArray() != null && event.getLinkingAgentIdentifierArray().length > 0) {
          for (          LinkingAgentIdentifierComplexType laict : event.getLinkingAgentIdentifierArray()) {
            if (laict.getLinkingAgentIdentifierValue() != null && laict.getLinkingAgentIdentifierValue().equalsIgnoreCase(agentID)) {
              found=true;
              break;
            }
          }
          if (found) {
            break;
          }
        }
      }
    }
  }
  IOUtils.closeQuietly(preservationMetadataList);
  AssertJUnit.assertTrue(found);
  Filter filter=new Filter();
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_TYPE,PreservationEventType.FORMAT_IDENTIFICATION.toString()));
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_AIP_ID,aip.getId()));
  IndexResult<IndexedPreservationEvent> events=index.find(IndexedPreservationEvent.class,filter,null,new Sublist(0,10));
  AssertJUnit.assertEquals(1,events.getTotalCount());
}