Program: 172220
Project: 172220
Buggy source:
public void testSnapshot() throws Exception {
  String CONTENT_STRING="String_Node_Str";
  Locale CONTENT_LOCALE=Locale.TAIWAN;
  String CONTENT_TITLE="String_Node_Str";
  String CONTENT_NAME="String_Node_Str";
  String CONTENT_ASSOC_NAME="String_Node_Str";
  String snapshotMe="String_Node_Str";
  String title="String_Node_Str";
  String description="String_Node_Str";
  String endpointProtocol="String_Node_Str";
  String endpointHost="String_Node_Str";
  int endpointPort=8080;
  String endpointPath="String_Node_Str";
  String username="String_Node_Str";
  char[] password="String_Node_Str".toCharArray();
  Map<NodeRef,TransferManifestNode> sentNodes=new HashMap<NodeRef,TransferManifestNode>();
  TransferManifestNodeFactoryImpl nodeFactory=new TransferManifestNodeFactoryImpl();
  nodeFactory.setNodeService(nodeService);
  TransferTarget target=transferService.createTransferTarget(snapshotMe,title,description,endpointProtocol,endpointHost,endpointPort,endpointPath,username,password);
  File snapshotFile=null;
  try {
    ChildAssociationRef child=nodeService.createNode(target.getNodeRef(),ContentModel.ASSOC_CONTAINS,QName.createQName(CONTENT_ASSOC_NAME),ContentModel.TYPE_CONTENT);
    NodeRef childNodeRef=child.getChildRef();
    ContentWriter writer=contentService.getWriter(childNodeRef,ContentModel.PROP_CONTENT,true);
    writer.setLocale(CONTENT_LOCALE);
    writer.putContent(CONTENT_STRING);
    nodeService.setProperty(childNodeRef,ContentModel.PROP_TITLE,CONTENT_TITLE);
    nodeService.setProperty(childNodeRef,ContentModel.PROP_NAME,CONTENT_NAME);
    snapshotFile=TempFileProvider.createTempFile("String_Node_Str","String_Node_Str");
    FileWriter snapshotWriter=new FileWriter(snapshotFile);
    Set<NodeRef> nodes=new HashSet<NodeRef>();
    nodes.add(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE));
    nodes.add(target.getNodeRef());
    nodes.add(childNodeRef);
    TransferManifestWriter formatter=new XMLTransferManifestWriter();
    TransferManifestHeader header=new TransferManifestHeader();
    header.setCreatedDate(new Date());
    formatter.startTransferManifest(snapshotWriter);
    formatter.writeTransferManifestHeader(header);
    for (    NodeRef nodeRef : nodes) {
      TransferManifestNode node=nodeFactory.createTransferManifestNode(nodeRef);
      formatter.writeTransferManifestNode(node);
      sentNodes.put(nodeRef,node);
    }
    formatter.endTransferManifest();
    snapshotWriter.close();
    outputFile(snapshotFile);
    TestTransferManifestProcessor processor=new TestTransferManifestProcessor();
    XMLTransferManifestReader reader=new XMLTransferManifestReader(processor);
    SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
    SAXParser parser=saxParserFactory.newSAXParser();
    parser.parse(snapshotFile,reader);
    assertEquals("String_Node_Str",nodes.size(),processor.getNodes().size());
    assertNotNull("String_Node_Str",processor.getHeader());
    for (    NodeRef nodeId : nodes) {
      System.out.println("String_Node_Str" + nodeId);
      TransferManifestNormalNode readNode=(TransferManifestNormalNode)processor.getNodes().get(nodeId);
      TransferManifestNormalNode writeNode=(TransferManifestNormalNode)sentNodes.get(nodeId);
      assertNotNull("String_Node_Str",readNode);
      assertNotNull("String_Node_Str",writeNode);
      assertEquals("String_Node_Str",writeNode.getType(),readNode.getType());
      assertEquals("String_Node_Str",writeNode.getNodeRef(),readNode.getNodeRef());
      assertEquals("String_Node_Str",writeNode.getPrimaryParentAssoc(),readNode.getPrimaryParentAssoc());
      if (writeNode.getParentPath() != null) {
        assertEquals("String_Node_Str",writeNode.getParentPath().toString(),readNode.getParentPath().toString());
      }
      assertEquals("String_Node_Str",writeNode.getAspects().size(),readNode.getAspects().size());
      for (      QName aspect : writeNode.getAspects()) {
        assertTrue("String_Node_Str",readNode.getAspects().contains(aspect));
      }
      assertEquals("String_Node_Str",writeNode.getProperties().size(),readNode.getProperties().size());
      for (      QName prop : writeNode.getProperties().keySet()) {
        assertTrue("String_Node_Str",readNode.getProperties().containsKey(prop));
      }
      assertEquals("String_Node_Str",writeNode.getChildAssocs().size(),readNode.getChildAssocs().size());
      assertEquals("String_Node_Str",writeNode.getParentAssocs().size(),readNode.getParentAssocs().size());
      assertEquals("String_Node_Str",writeNode.getSourceAssocs().size(),readNode.getSourceAssocs().size());
      assertEquals("String_Node_Str",writeNode.getTargetAssocs().size(),readNode.getTargetAssocs().size());
      if (readNode.getNodeRef().equals(childNodeRef)) {
        ContentData data=(ContentData)readNode.getProperties().get(ContentModel.PROP_CONTENT);
        assertEquals("String_Node_Str",data.getSize(),CONTENT_STRING.length());
        assertEquals("String_Node_Str",data.getLocale(),CONTENT_LOCALE);
        String childTitle=(String)readNode.getProperties().get(ContentModel.PROP_TITLE);
        assertEquals("String_Node_Str",childTitle,CONTENT_TITLE);
        String childName=(String)readNode.getProperties().get(ContentModel.PROP_NAME);
        assertEquals("String_Node_Str",childName,CONTENT_NAME);
        assertTrue("String_Node_Str",readNode.getParentAssocs().size() == 1);
        assertTrue("String_Node_Str",readNode.getParentAssocs().get(0).isPrimary());
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getQName(),QName.createQName(CONTENT_ASSOC_NAME));
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getTypeQName(),ContentModel.ASSOC_CONTAINS);
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getChildRef(),childNodeRef);
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getParentRef(),readNode.getPrimaryParentAssoc());
        assertTrue("String_Node_Str",readNode.getChildAssocs().size() == 0);
        assertEquals(readNode.getParentAssocs().get(0),TransferManifestNodeHelper.getPrimaryParentAssoc(readNode));
        Set<ContentData> content=TransferManifestNodeHelper.getContentData(readNode);
        assertEquals("String_Node_Str",content.size(),1);
      }
    }
  }
  finally {
    if (snapshotFile != null) {
      snapshotFile.delete();
    }
    transferService.deleteTransferTarget(snapshotMe);
  }
}

Fixed version (ground truth):
public void testSnapshot() throws Exception {
  String CONTENT_STRING="String_Node_Str";
  Locale CONTENT_LOCALE=Locale.TAIWAN;
  String CONTENT_TITLE="String_Node_Str";
  String CONTENT_NAME="String_Node_Str";
  String CONTENT_ASSOC_NAME="String_Node_Str";
  String snapshotMe="String_Node_Str";
  String title="String_Node_Str";
  String description="String_Node_Str";
  String endpointProtocol="String_Node_Str";
  String endpointHost="String_Node_Str";
  int endpointPort=8080;
  String endpointPath="String_Node_Str";
  String username="String_Node_Str";
  char[] password="String_Node_Str".toCharArray();
  Map<NodeRef,TransferManifestNode> sentNodes=new HashMap<NodeRef,TransferManifestNode>();
  TransferManifestNodeFactoryImpl nodeFactory=new TransferManifestNodeFactoryImpl();
  nodeFactory.setNodeService(nodeService);
  TransferTarget target=transferService.createTransferTarget(snapshotMe,title,description,endpointProtocol,endpointHost,endpointPort,endpointPath,username,password);
  File snapshotFile=null;
  try {
    ChildAssociationRef child=nodeService.createNode(target.getNodeRef(),ContentModel.ASSOC_CONTAINS,QName.createQName(CONTENT_ASSOC_NAME),ContentModel.TYPE_CONTENT);
    NodeRef childNodeRef=child.getChildRef();
    ContentWriter writer=contentService.getWriter(childNodeRef,ContentModel.PROP_CONTENT,true);
    writer.setLocale(CONTENT_LOCALE);
    writer.putContent(CONTENT_STRING);
    nodeService.setProperty(childNodeRef,ContentModel.PROP_TITLE,CONTENT_TITLE);
    nodeService.setProperty(childNodeRef,ContentModel.PROP_NAME,CONTENT_NAME);
    snapshotFile=TempFileProvider.createTempFile("String_Node_Str","String_Node_Str");
    FileWriter snapshotWriter=new FileWriter(snapshotFile);
    Set<NodeRef> nodes=new HashSet<NodeRef>();
    nodes.add(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE));
    nodes.add(target.getNodeRef());
    nodes.add(childNodeRef);
    TransferManifestWriter formatter=new XMLTransferManifestWriter();
    TransferManifestHeader header=new TransferManifestHeader();
    header.setNodeCount(nodes.size());
    header.setCreatedDate(new Date());
    formatter.startTransferManifest(snapshotWriter);
    formatter.writeTransferManifestHeader(header);
    for (    NodeRef nodeRef : nodes) {
      TransferManifestNode node=nodeFactory.createTransferManifestNode(nodeRef);
      formatter.writeTransferManifestNode(node);
      sentNodes.put(nodeRef,node);
    }
    formatter.endTransferManifest();
    snapshotWriter.close();
    outputFile(snapshotFile);
    TestTransferManifestProcessor processor=new TestTransferManifestProcessor();
    XMLTransferManifestReader reader=new XMLTransferManifestReader(processor);
    SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
    SAXParser parser=saxParserFactory.newSAXParser();
    parser.parse(snapshotFile,reader);
    assertEquals("String_Node_Str",nodes.size(),processor.getNodes().size());
    assertNotNull("String_Node_Str",processor.getHeader());
    for (    NodeRef nodeId : nodes) {
      System.out.println("String_Node_Str" + nodeId);
      TransferManifestNormalNode readNode=(TransferManifestNormalNode)processor.getNodes().get(nodeId);
      TransferManifestNormalNode writeNode=(TransferManifestNormalNode)sentNodes.get(nodeId);
      assertNotNull("String_Node_Str",readNode);
      assertNotNull("String_Node_Str",writeNode);
      assertEquals("String_Node_Str",writeNode.getType(),readNode.getType());
      assertEquals("String_Node_Str",writeNode.getNodeRef(),readNode.getNodeRef());
      assertEquals("String_Node_Str",writeNode.getPrimaryParentAssoc(),readNode.getPrimaryParentAssoc());
      if (writeNode.getParentPath() != null) {
        assertEquals("String_Node_Str",writeNode.getParentPath().toString(),readNode.getParentPath().toString());
      }
      assertEquals("String_Node_Str",writeNode.getAspects().size(),readNode.getAspects().size());
      for (      QName aspect : writeNode.getAspects()) {
        assertTrue("String_Node_Str",readNode.getAspects().contains(aspect));
      }
      assertEquals("String_Node_Str",writeNode.getProperties().size(),readNode.getProperties().size());
      for (      QName prop : writeNode.getProperties().keySet()) {
        assertTrue("String_Node_Str",readNode.getProperties().containsKey(prop));
      }
      assertEquals("String_Node_Str",writeNode.getChildAssocs().size(),readNode.getChildAssocs().size());
      assertEquals("String_Node_Str",writeNode.getParentAssocs().size(),readNode.getParentAssocs().size());
      assertEquals("String_Node_Str",writeNode.getSourceAssocs().size(),readNode.getSourceAssocs().size());
      assertEquals("String_Node_Str",writeNode.getTargetAssocs().size(),readNode.getTargetAssocs().size());
      if (readNode.getNodeRef().equals(childNodeRef)) {
        ContentData data=(ContentData)readNode.getProperties().get(ContentModel.PROP_CONTENT);
        assertEquals("String_Node_Str",data.getSize(),CONTENT_STRING.length());
        assertEquals("String_Node_Str",data.getLocale(),CONTENT_LOCALE);
        String childTitle=(String)readNode.getProperties().get(ContentModel.PROP_TITLE);
        assertEquals("String_Node_Str",childTitle,CONTENT_TITLE);
        String childName=(String)readNode.getProperties().get(ContentModel.PROP_NAME);
        assertEquals("String_Node_Str",childName,CONTENT_NAME);
        assertTrue("String_Node_Str",readNode.getParentAssocs().size() == 1);
        assertTrue("String_Node_Str",readNode.getParentAssocs().get(0).isPrimary());
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getQName(),QName.createQName(CONTENT_ASSOC_NAME));
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getTypeQName(),ContentModel.ASSOC_CONTAINS);
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getChildRef(),childNodeRef);
        assertEquals("String_Node_Str",readNode.getParentAssocs().get(0).getParentRef(),target.getNodeRef());
        assertTrue("String_Node_Str",readNode.getChildAssocs().size() == 0);
        assertEquals(readNode.getParentAssocs().get(0),TransferManifestNodeHelper.getPrimaryParentAssoc(readNode));
        Set<ContentData> content=TransferManifestNodeHelper.getContentData(readNode);
        assertEquals("String_Node_Str",content.size(),1);
      }
    }
  }
  finally {
    if (snapshotFile != null) {
      snapshotFile.delete();
    }
    transferService.deleteTransferTarget(snapshotMe);
  }
}