@Test
  public void testModifyDatastreamByReferenceWithChecksum() throws Exception {
    String pid = "file:m_ds_test_add"; // file pid namespace should work as well as demo
    String checksumType = "MD5";
    apim.ingest(getAtomObject(pid, null), ATOM1_1.uri, null);
    File temp = null;
    try {
      temp = File.createTempFile("foo", "bar");
      String contentLocation = getFedoraClient().uploadFile(temp);
      String checksum = computeChecksum(checksumType, new FileInputStream(temp));
      String dsId = addDatastream(pid, contentLocation, checksumType, checksum);
      assertEquals("DS", dsId);

      FileOutputStream os = new FileOutputStream(temp);
      os.write("testModifyDatastreamByReferenceWithChecksum".getBytes());
      os.close();
      contentLocation = getFedoraClient().uploadFile(temp);
      checksum = computeChecksum(checksumType, new FileInputStream(temp));
      modifyDatastreamByReference(pid, contentLocation, checksumType, checksum);

      // Now ensure that bogus checksums do indeed fail
      checksum = "bogus";
      try {
        modifyDatastreamByReference(pid, contentLocation, checksumType, checksum);
        fail("Modifying datastream with bogus checksum should have failed.");
      } catch (RemoteException e) {
        assertTrue(e.getMessage().contains("Checksum Mismatch"));
      }
    } finally {
      apim.purgeObject(pid, "test", false);
      if (temp != null) {
        temp.delete();
      }
    }
  }
  @Test
  public void testModifyDatastreamByReference() throws Exception {
    String pid = "demo:m_ds_test_add";
    String dsLocation = getBaseURL() + "/get/fedora-system:ContentModel-3.0/DC";
    apim.ingest(getAtomObject(pid, dsLocation), ATOM1_1.uri, null);

    try {
      for (String contentLocation : copyTempFileLocations) {
        try {
          modifyDatastreamByReference(pid, contentLocation);
          fail("modifyDatastreamByReference should have failed with " + contentLocation);
        } catch (RemoteException e) {
          assertTrue(e.getMessage().contains("ValidationException"));
        }
      }

      for (String contentLocation : uploadedLocations) {
        try {
          modifyDatastreamByReference(pid, contentLocation);
          fail("modifyDatastreamByReference should have failed with " + contentLocation);
        } catch (RemoteException e) {
          assertTrue(e.getMessage().contains("StreamReadException"));
        }
      }

      // A null contentLocation should cause the server to generate a
      // copy:// url
      modifyDatastreamByReference(pid, null);
    } finally {
      apim.purgeObject(pid, "test", false);
    }
  }
  @Test
  public void testAddDatastreamWithChecksum() throws Exception {
    String pid = "demo:m_ds_test_add";
    String checksumType = "MD5";
    apim.ingest(getAtomObject(pid, null), ATOM1_1.uri, null);
    File temp = null;

    try {
      temp = File.createTempFile("foo", "bar");
      String contentLocation = getFedoraClient().uploadFile(temp);
      String checksum = computeChecksum(checksumType, new FileInputStream(temp));
      String dsId = addDatastream(pid, contentLocation, checksumType, checksum);
      assertEquals("DS", dsId);

      // Now ensure that bogus checksums do indeed fail
      apim.purgeDatastream(pid, dsId, null, null, null, false);
      checksum = "bogus";
      try {
        addDatastream(pid, contentLocation, checksumType, checksum);
        fail("Adding datastream with bogus checksum should have failed.");
      } catch (RemoteException e) {
        assertTrue(e.getMessage().contains("Checksum Mismatch"));
      }
    } finally {
      apim.purgeObject(pid, "test", false);
      if (temp != null) {
        temp.delete();
      }
    }
  }
  @Test
  public void testAddDatastream() throws Exception {
    String pid = "demo:m_ds_test_add";

    apim.ingest(getAtomObject(pid, null), ATOM1_1.uri, null);

    try {
      for (String contentLocation : copyTempFileLocations) {
        try {
          addDatastream(pid, contentLocation);
          fail("addDatastream should have failed with " + contentLocation);
        } catch (RemoteException e) {
          assertTrue(e.getMessage().contains("ValidationException"));
        }
      }

      for (String contentLocation : uploadedLocations) {
        try {
          addDatastream(pid, contentLocation);
          fail("addDatastream should have failed with " + contentLocation);
        } catch (RemoteException e) {
          assertTrue(e.getMessage().contains("StreamReadException"));
        }
      }

    } finally {
      apim.purgeObject(pid, "test", false);
    }
  }
Beispiel #5
0
 public void delPolicy(String policyId) throws Exception {
   String pid = "demo:" + policyId;
   apim.purgeObject(pid, "removing test policy object", false);
 }