Program: 12982
Project: 12982
Buggy source:
/** 
 * Tests the BRMS packages.
 * @throws Exception
 */
@Test public void testBrmsPackages() throws Exception {
  String artifactFileName="String_Node_Str";
  InputStream contentStream=this.getClass().getResourceAsStream("String_Node_Str" + artifactFileName);
  ClientRequest request=new ClientRequest(generateURL("String_Node_Str"));
  request.header("String_Node_Str",artifactFileName);
  request.body("String_Node_Str",contentStream);
  ClientResponse<Entry> response=request.post(Entry.class);
  Entry entry=response.getEntity();
  BaseArtifactType arty=SrampAtomUtils.unwrapSrampArtifact(entry);
  ClientRequest request1=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<InputStream> response1=request1.get(InputStream.class);
  if (response1.getStatus() != 200) {
    throw new RuntimeException("String_Node_Str" + response1.getStatus());
  }
  InputStream in=response1.getEntity();
  File file=new File("String_Node_Str");
  OutputStream out=new FileOutputStream(file);
  IOUtils.copy(in,out);
  out.flush();
  IOUtils.closeQuietly(in);
  IOUtils.closeQuietly(out);
  ClientRequest request2=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<Packages> response2=request2.get(Packages.class);
  Packages packages=response2.getEntity();
  Assert.assertEquals(1,packages.getPackage().size());
  Assert.assertEquals("String_Node_Str",packages.getPackage().get(0).getTitle());
  Assert.assertTrue(arty instanceof ExtendedDocument);
  ExtendedDocument brmsPkgDocument=(ExtendedDocument)arty;
  Property assetsProperty=new Property();
  assetsProperty.setPropertyName(BrmsConstants.ASSET_INFO_XML);
  InputStream assetsInputStream=this.getClass().getResourceAsStream("String_Node_Str");
  String assetsXml=TestUtils.convertStreamToString(assetsInputStream);
  IOUtils.closeQuietly(assetsInputStream);
  assetsXml=assetsXml.replaceAll("String_Node_Str","String_Node_Str");
  assetsProperty.setPropertyValue(assetsXml);
  brmsPkgDocument.getProperty().add(assetsProperty);
  Entry entry3=new Entry();
  ClientRequest request3=new ClientRequest(generateURL("String_Node_Str" + brmsPkgDocument.getUuid()));
  Artifact artifact=new Artifact();
  artifact.setExtendedDocument(brmsPkgDocument);
  entry3.setAnyOtherJAXBObject(artifact);
  request3.body(MediaType.APPLICATION_ATOM_XML_ENTRY,entry3);
  request3.put(Void.class);
  ClientRequest request4=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<Assets> response4=request4.get(Assets.class);
  Assets assets=response4.getEntity();
  Assert.assertEquals(8,assets.getAsset().size());
  for (  Assets.Asset asset : assets.getAsset()) {
    String fileFormat=asset.getMetadata().getFormat().toLowerCase();
    if (fileFormat.equals("String_Node_Str")) {
    }
 else {
      String fileName=asset.getTitle() + "String_Node_Str" + asset.getMetadata().getFormat();
      String uuid=asset.getMetadata().getUuid();
      InputStream assetInputStream=this.getClass().getResourceAsStream("String_Node_Str" + fileName);
      @SuppressWarnings("String_Node_Str") ArtifactType artifactType=ArtifactType.fromFileExtension(asset.getMetadata().getFormat());
      BaseArtifactType baseArtifactType=artifactType.newArtifactInstance();
      baseArtifactType.setName(fileName);
      baseArtifactType.setUuid(uuid);
      String path="String_Node_Str" + artifactType.getModel() + "String_Node_Str"+ artifactType.getType();
      ClientRequest request5=new ClientRequest(generateURL(path));
      MultipartRelatedOutput output=new MultipartRelatedOutput();
      Entry atomEntry=new Entry();
      MediaType mediaType=new MediaType("String_Node_Str","String_Node_Str");
      artifact=new Artifact();
      String methodStr="String_Node_Str" + artifactType.getArtifactType();
      Method method=artifact.getClass().getMethod(methodStr,artifactType.getArtifactType().getTypeClass());
      method.invoke(artifact,baseArtifactType);
      atomEntry.setAnyOtherJAXBObject(artifact);
      output.addPart(atomEntry,mediaType);
      MediaType mediaType2=MediaType.getInstance(artifactType.getMimeType());
      output.addPart(assetInputStream,mediaType2);
      System.out.println("String_Node_Str" + fileName + "String_Node_Str"+ artifactType);
      request5.body(MultipartConstants.MULTIPART_RELATED,output);
      ClientResponse<Entry> assetResponse=request5.post(Entry.class);
      IOUtils.closeQuietly(assetInputStream);
      Entry assetEntry=assetResponse.getEntity();
      BaseArtifactType assetArtifact=SrampAtomUtils.unwrapSrampArtifact(assetEntry);
      System.out.println("String_Node_Str" + assetArtifact.getName() + "String_Node_Str"+ assetArtifact.getUuid());
    }
  }
  ClientRequest request7=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<InputStream> response7=request7.get(InputStream.class);
  if (response1.getStatus() != 200) {
    throw new RuntimeException("String_Node_Str" + response.getStatus());
  }
  InputStream in7=response7.getEntity();
  File file7=new File("String_Node_Str");
  OutputStream out7=new FileOutputStream(file7);
  IOUtils.copy(in7,out7);
  out7.flush();
  IOUtils.closeQuietly(in7);
  IOUtils.closeQuietly(out7);
  Assert.assertTrue(file7.exists());
  long size=file7.length();
  Assert.assertTrue(size >= 12483L);
  ClientRequest request8=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<InputStream> response8=request8.get(InputStream.class);
  if (response1.getStatus() != 200) {
    throw new RuntimeException("String_Node_Str" + response.getStatus());
  }
  InputStream in8=response8.getEntity();
  File file8=new File("String_Node_Str");
  OutputStream out8=new FileOutputStream(file8);
  IOUtils.copy(in8,out8);
  out8.flush();
  IOUtils.closeQuietly(in8);
  IOUtils.closeQuietly(out8);
  Assert.assertTrue(file8.exists());
  Assert.assertEquals(14029l,file8.length());
}

Fixed version (ground truth):
/** 
 * Tests the BRMS packages.
 * @throws Exception
 */
@Test public void testBrmsPackages() throws Exception {
  String artifactFileName="String_Node_Str";
  InputStream contentStream=this.getClass().getResourceAsStream("String_Node_Str" + artifactFileName);
  ClientRequest request=new ClientRequest(generateURL("String_Node_Str"));
  request.header("String_Node_Str",artifactFileName);
  request.body("String_Node_Str",contentStream);
  ClientResponse<Entry> response=request.post(Entry.class);
  Entry entry=response.getEntity();
  BaseArtifactType arty=SrampAtomUtils.unwrapSrampArtifact(entry);
  ClientRequest request1=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<InputStream> response1=request1.get(InputStream.class);
  if (response1.getStatus() != 200) {
    throw new RuntimeException("String_Node_Str" + response1.getStatus());
  }
  InputStream in=response1.getEntity();
  File file=new File("String_Node_Str");
  OutputStream out=new FileOutputStream(file);
  IOUtils.copy(in,out);
  out.flush();
  IOUtils.closeQuietly(in);
  IOUtils.closeQuietly(out);
  ClientRequest request2=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<Packages> response2=request2.get(Packages.class);
  Packages packages=response2.getEntity();
  Assert.assertEquals(1,packages.getPackage().size());
  Assert.assertEquals("String_Node_Str",packages.getPackage().get(0).getTitle());
  Assert.assertTrue(arty instanceof ExtendedDocument);
  ExtendedDocument brmsPkgDocument=(ExtendedDocument)arty;
  Property assetsProperty=new Property();
  assetsProperty.setPropertyName(BrmsConstants.ASSET_INFO_XML);
  InputStream assetsInputStream=this.getClass().getResourceAsStream("String_Node_Str");
  String assetsXml=TestUtils.convertStreamToString(assetsInputStream);
  IOUtils.closeQuietly(assetsInputStream);
  assetsXml=assetsXml.replaceAll("String_Node_Str","String_Node_Str");
  assetsProperty.setPropertyValue(assetsXml);
  brmsPkgDocument.getProperty().add(assetsProperty);
  Entry entry3=new Entry();
  ClientRequest request3=new ClientRequest(generateURL("String_Node_Str" + brmsPkgDocument.getUuid()));
  Artifact artifact=new Artifact();
  artifact.setExtendedDocument(brmsPkgDocument);
  entry3.setAnyOtherJAXBObject(artifact);
  request3.body(MediaType.APPLICATION_ATOM_XML_ENTRY,entry3);
  request3.put(Void.class);
  ClientRequest request4=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<Assets> response4=request4.get(Assets.class);
  Assets assets=response4.getEntity();
  Assert.assertEquals(8,assets.getAsset().size());
  for (  Assets.Asset asset : assets.getAsset()) {
    String fileFormat=asset.getMetadata().getFormat().toLowerCase();
    if (fileFormat.equals("String_Node_Str")) {
    }
 else {
      String fileName=asset.getTitle() + "String_Node_Str" + asset.getMetadata().getFormat();
      String uuid=asset.getMetadata().getUuid();
      InputStream assetInputStream=this.getClass().getResourceAsStream("String_Node_Str" + fileName);
      @SuppressWarnings("String_Node_Str") ArtifactType artifactType=ArtifactType.fromFileExtension(asset.getMetadata().getFormat());
      if (artifactType.isExtendedType()) {
        artifactType=ArtifactType.ExtendedDocument(artifactType.getExtendedType());
      }
      BaseArtifactType baseArtifactType=artifactType.newArtifactInstance();
      baseArtifactType.setName(fileName);
      baseArtifactType.setUuid(uuid);
      String path="String_Node_Str" + artifactType.getModel() + "String_Node_Str"+ artifactType.getType();
      ClientRequest request5=new ClientRequest(generateURL(path));
      MultipartRelatedOutput output=new MultipartRelatedOutput();
      Entry atomEntry=new Entry();
      MediaType mediaType=new MediaType("String_Node_Str","String_Node_Str");
      artifact=new Artifact();
      System.out.println("String_Node_Str" + artifactType.getArtifactType().getTypeClass());
      String methodStr="String_Node_Str" + artifactType.getArtifactType();
      Method method=artifact.getClass().getMethod(methodStr,artifactType.getArtifactType().getTypeClass());
      method.invoke(artifact,baseArtifactType);
      atomEntry.setAnyOtherJAXBObject(artifact);
      output.addPart(atomEntry,mediaType);
      MediaType mediaType2=MediaType.getInstance(artifactType.getMimeType());
      output.addPart(assetInputStream,mediaType2);
      System.out.println("String_Node_Str" + fileName + "String_Node_Str"+ artifactType);
      request5.body(MultipartConstants.MULTIPART_RELATED,output);
      ClientResponse<Entry> assetResponse=request5.post(Entry.class);
      IOUtils.closeQuietly(assetInputStream);
      Entry assetEntry=assetResponse.getEntity();
      BaseArtifactType assetArtifact=SrampAtomUtils.unwrapSrampArtifact(assetEntry);
      System.out.println("String_Node_Str" + assetArtifact.getName() + "String_Node_Str"+ assetArtifact.getUuid());
    }
  }
  ClientRequest request7=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<InputStream> response7=request7.get(InputStream.class);
  if (response1.getStatus() != 200) {
    throw new RuntimeException("String_Node_Str" + response.getStatus());
  }
  InputStream in7=response7.getEntity();
  File file7=new File("String_Node_Str");
  OutputStream out7=new FileOutputStream(file7);
  IOUtils.copy(in7,out7);
  out7.flush();
  IOUtils.closeQuietly(in7);
  IOUtils.closeQuietly(out7);
  Assert.assertTrue(file7.exists());
  long size=file7.length();
  Assert.assertTrue(size >= 12483L);
  ClientRequest request8=new ClientRequest(generateURL("String_Node_Str"));
  ClientResponse<InputStream> response8=request8.get(InputStream.class);
  if (response1.getStatus() != 200) {
    throw new RuntimeException("String_Node_Str" + response.getStatus());
  }
  InputStream in8=response8.getEntity();
  File file8=new File("String_Node_Str");
  OutputStream out8=new FileOutputStream(file8);
  IOUtils.copy(in8,out8);
  out8.flush();
  IOUtils.closeQuietly(in8);
  IOUtils.closeQuietly(out8);
  Assert.assertTrue(file8.exists());
  Assert.assertEquals(14029l,file8.length());
}