Example #1
0
  /**
   * Tests that we can update the content of an s-ramp artifact.
   *
   * @throws Exception
   */
  @Test
  public void testUpdateContent() throws Exception {
    // First, add an artifact to the repo
    String artifactFileName = "PO.xsd";
    InputStream POXsd =
        this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
    BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXsd);
    Assert.assertNotNull(artifact);
    log.info("persisted PO.xsd to JCR, returned artifact uuid=" + artifact.getUuid());
    Assert.assertEquals(XsdDocument.class, artifact.getClass());
    long size = ((DocumentArtifactType) artifact).getContentSize();
    Assert.assertTrue(
        size
            >= 2376L); // Not doing an equals here due to the vagaries of Windows vs *nix line
                       // endings
    Assert.assertEquals(artifactFileName, artifact.getName());

    // Now update the artifact content
    InputStream otherXsd = this.getClass().getResourceAsStream("/sample-files/xsd/XMLSchema.xsd");
    persistenceManager.updateArtifactContent(
        artifact.getUuid(), ArtifactType.XsdDocument(), otherXsd);

    // Now verify the content was updated
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument());
    size = ((DocumentArtifactType) artifact).getContentSize();
    Assert.assertTrue(
        size
            >= 87677L); // Not doing an equals here due to the vagaries of Windows vs *nix line
                        // endings
  }
Example #2
0
  @Test
  public void testGetArtifact_XSD() throws Exception {
    String artifactFileName = "PO.xsd";
    InputStream POXsd =
        this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);

    BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXsd);

    Assert.assertNotNull(artifact);
    log.info("persisted PO.xsd to JCR, returned artifact uuid=" + artifact.getUuid());

    Assert.assertEquals(XsdDocument.class, artifact.getClass());
    long size = ((DocumentArtifactType) artifact).getContentSize();
    Assert.assertTrue(
        size
            >= 2376L); // Not doing an equals here due to the vagaries of Windows vs *nix line
                       // endings

    BaseArtifactType artifact2 =
        persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument());
    Assert.assertEquals(artifact.getUuid(), artifact2.getUuid());
    Assert.assertEquals(artifact.getCreatedBy(), artifact2.getCreatedBy());
    Assert.assertEquals(artifact.getDescription(), artifact2.getDescription());
    Assert.assertEquals(artifact.getLastModifiedBy(), artifact2.getLastModifiedBy());
    Assert.assertEquals(artifact.getName(), artifact2.getName());
    Assert.assertEquals(artifact.getVersion(), artifact2.getVersion());
    Assert.assertEquals(artifact.getLastModifiedTimestamp(), artifact2.getLastModifiedTimestamp());
  }
Example #3
0
  @Test
  public void testPersistArtifactPO_XML() throws Exception {
    String artifactFileName = "PO.xml";
    InputStream POXml =
        this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);

    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.XML_DOCUMENT);

    BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXml);

    Assert.assertNotNull(artifact);
    log.info("persisted PO.xml to JCR, returned artifact uuid=" + artifact.getUuid());

    // print out the derived node
    if (log.isDebugEnabled()) {
      persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.XmlDocument());
    }
    Assert.assertEquals(XmlDocument.class, artifact.getClass());
    long size = ((DocumentArtifactType) artifact).getContentSize();
    Assert.assertTrue(
        size
            >= 825L); // Not doing an equals here due to the vagaries of Windows vs *nix line
                      // endings
  }
 /** @throws SrampException */
 private Document addDocument(String name, String... classifications) throws SrampException {
   InputStream contentStream = null;
   try {
     String artifactFileName = "s-ramp-press-release.pdf"; // $NON-NLS-1$
     contentStream =
         this.getClass()
             .getResourceAsStream("/sample-files/core/" + artifactFileName); // $NON-NLS-1$
     Document document = new Document();
     document.setName(name);
     document.setArtifactType(BaseArtifactEnum.DOCUMENT);
     for (String classification : classifications) {
       document.getClassifiedBy().add(classification);
     }
     return (Document) persistenceManager.persistArtifact(document, contentStream);
   } finally {
     IOUtils.closeQuietly(contentStream);
   }
 }
Example #5
0
  @Test
  public void testPersistArtifact_PDF() throws Exception {
    String artifactFileName = "s-ramp-press-release.pdf";
    InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.DOCUMENT);

    BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf);

    Assert.assertNotNull(artifact);
    log.info(
        "persisted s-ramp-press-release.pdf to JCR, returned artifact uuid=" + artifact.getUuid());

    // print out the derived node
    if (log.isDebugEnabled()) {
      persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.Document());
    }
    Assert.assertEquals(Document.class, artifact.getClass());
    Assert.assertEquals(new Long(18873l), ((DocumentArtifactType) artifact).getContentSize());
  }
Example #6
0
  @Test
  public void testDeleteArtifact() throws Exception {
    String artifactFileName = "s-ramp-press-release.pdf";
    InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.DOCUMENT);

    // Add an artifact
    BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf);
    Assert.assertNotNull(artifact);
    Assert.assertEquals(Document.class, artifact.getClass());
    Assert.assertEquals(new Long(18873l), ((DocumentArtifactType) artifact).getContentSize());
    log.info(
        "persisted s-ramp-press-release.pdf to JCR, returned artifact uuid=" + artifact.getUuid());

    // Now delete that artifact
    ArtifactType at = ArtifactType.valueOf(artifact);
    persistenceManager.deleteArtifact(document.getUuid(), at);

    // Now make sure we can't load it back up
    BaseArtifactType deleted = persistenceManager.getArtifact(document.getUuid(), at);
    Assert.assertNull(deleted);

    SrampQuery query = queryManager.createQuery("/s-ramp[@uuid = ?]");
    query.setString(document.getUuid());
    ArtifactSet artifactSet = query.executeQuery();
    Assert.assertEquals(0, artifactSet.size());
  }
Example #7
0
  @Test
  public void testPersistDuplicateArtifact() throws Exception {
    String artifactFileName = "s-ramp-press-release.pdf";
    InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.DOCUMENT);
    document.setUuid("12345"); // amazing - that's the same UUID as my luggage!
    BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf);
    Assert.assertNotNull(artifact);

    // Now try to persist another artifact of the same type with the same UUID.
    pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    document = new Document();
    document.setName(artifactFileName + "-2");
    document.setArtifactType(BaseArtifactEnum.DOCUMENT);
    document.setUuid("12345"); // amazing - that's the same UUID as my luggage!
    try {
      persistenceManager.persistArtifact(document, pdf);
      Assert.fail("Expected an ArtifactAlreadyExistsException.");
    } catch (ArtifactAlreadyExistsException e) {
      // Expected this!
      Assert.assertEquals("Artifact with UUID 12345 already exists.", e.getMessage());
    }

    // Now try to persist another artifact with a *different* type but the same UUID.
    pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    ExtendedArtifactType extendedArtifact = new ExtendedArtifactType();
    extendedArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE);
    extendedArtifact.setExtendedType("FooArtifactType");
    extendedArtifact.setName("MyExtendedArtifact");
    extendedArtifact.setUuid("12345");
    try {
      persistenceManager.persistArtifact(document, pdf);
      Assert.fail("Expected an ArtifactAlreadyExistsException.");
    } catch (ArtifactAlreadyExistsException e) {
      // Expected this!
      Assert.assertEquals("Artifact with UUID 12345 already exists.", e.getMessage());
    }
  }
Example #8
0
  /**
   * Tests that we can manage s-ramp properties.
   *
   * @throws Exception
   */
  @Test
  public void testGenericRelationships() throws Exception {
    String uuid1 = null;
    String uuid2 = null;
    String uuid3 = null;

    // First, add an artifact to the repo
    String artifactFileName = "PO.xsd";
    InputStream contentStream =
        this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
    BaseArtifactType artifact = persistenceManager.persistArtifact(document, contentStream);
    Assert.assertNotNull(artifact);
    uuid1 = artifact.getUuid();
    contentStream.close();

    // Now update the artifact's generic relationships
    artifact = persistenceManager.getArtifact(uuid1, ArtifactType.XsdDocument());
    Assert.assertTrue("Expected 0 relationships.", artifact.getRelationship().isEmpty());
    SrampModelUtils.addGenericRelationship(artifact, "NoTargetRelationship", null);
    persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument());

    // Now verify that the relationship was stored
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument());
    Assert.assertEquals("Expected 1 relationship.", 1, artifact.getRelationship().size());
    Assert.assertEquals(
        "NoTargetRelationship", artifact.getRelationship().get(0).getRelationshipType());
    Assert.assertEquals(
        Collections.EMPTY_LIST, artifact.getRelationship().get(0).getRelationshipTarget());

    // Add a second artifact.
    artifactFileName = "XMLSchema.xsd";
    contentStream = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName);
    Document document2 = new Document();
    document2.setName(artifactFileName);
    document2.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
    BaseArtifactType artifact2 = persistenceManager.persistArtifact(document2, contentStream);
    Assert.assertNotNull(artifact2);
    uuid2 = artifact2.getUuid();

    // Add a second relationship, this time with a target.
    SrampModelUtils.addGenericRelationship(artifact, "TargetedRelationship", uuid2);
    persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument());

    // Now verify that the targeted relationship was stored
    artifact = persistenceManager.getArtifact(uuid1, ArtifactType.XsdDocument());
    Assert.assertEquals("Expected 2 relationships.", 2, artifact.getRelationship().size());
    Relationship relationship =
        SrampModelUtils.getGenericRelationship(artifact, "NoTargetRelationship");
    Assert.assertNotNull(relationship);
    Assert.assertEquals("NoTargetRelationship", relationship.getRelationshipType());
    Assert.assertEquals(Collections.EMPTY_LIST, relationship.getRelationshipTarget());
    relationship = SrampModelUtils.getGenericRelationship(artifact, "TargetedRelationship");
    Assert.assertNotNull(relationship);
    Assert.assertEquals("TargetedRelationship", relationship.getRelationshipType());
    Assert.assertEquals(1, relationship.getRelationshipTarget().size()); // has only one target
    Assert.assertEquals(uuid2, relationship.getRelationshipTarget().get(0).getValue());

    // Add a third artifact.
    artifactFileName = "PO.xml";
    contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    Document document3 = new Document();
    document3.setName(artifactFileName);
    document3.setArtifactType(BaseArtifactEnum.XML_DOCUMENT);
    BaseArtifactType artifact3 = persistenceManager.persistArtifact(document3, contentStream);
    Assert.assertNotNull(artifact3);
    uuid3 = artifact3.getUuid();

    // Add a third relationship, again with a target.
    SrampModelUtils.addGenericRelationship(artifact, "TargetedRelationship", uuid3);
    persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument());

    // More verifications
    artifact = persistenceManager.getArtifact(uuid1, ArtifactType.XsdDocument());
    Assert.assertEquals("Expected 2 relationships.", 2, artifact.getRelationship().size());
    relationship = SrampModelUtils.getGenericRelationship(artifact, "NoTargetRelationship");
    Assert.assertNotNull(relationship);
    Assert.assertEquals("NoTargetRelationship", relationship.getRelationshipType());
    Assert.assertEquals(Collections.EMPTY_LIST, relationship.getRelationshipTarget());
    relationship = SrampModelUtils.getGenericRelationship(artifact, "TargetedRelationship");
    Assert.assertNotNull(relationship);
    Assert.assertEquals("TargetedRelationship", relationship.getRelationshipType());
    Assert.assertEquals(2, relationship.getRelationshipTarget().size());
    Set<String> expected = new HashSet<String>();
    Set<String> actual = new HashSet<String>();
    expected.add(uuid2);
    expected.add(uuid3);
    actual.add(relationship.getRelationshipTarget().get(0).getValue());
    actual.add(relationship.getRelationshipTarget().get(1).getValue());
    Assert.assertEquals(expected, actual);

    // Add a fourth (bogus) relationship
    SrampModelUtils.addGenericRelationship(artifact, "TargetedRelationship", "not-a-valid-uuid");
    try {
      persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument());
      Assert.fail("Expected an update failure.");
    } catch (Exception e) {
      Assert.assertEquals(ArtifactNotFoundException.class, e.getClass());
      Assert.assertEquals("No artifact found with UUID: not-a-valid-uuid", e.getMessage());
    }
  }
Example #9
0
  /**
   * Tests that we can manage s-ramp properties on a /core/Document.
   *
   * @throws Exception
   */
  @Test
  public void testUpdateProperties_Document() throws Exception {
    // First, add an artifact to the repo
    String artifactFileName = "s-ramp-press-release.pdf";
    InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);

    Document document = new Document();
    document.setName(artifactFileName);
    document.setContentType("application/pdf");
    document.setArtifactType(BaseArtifactEnum.DOCUMENT);
    BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf);
    Assert.assertNotNull(artifact);
    log.info("persisted PDF to JCR, returned artifact uuid=" + artifact.getUuid());
    Assert.assertEquals(Document.class, artifact.getClass());
    Assert.assertEquals(new Long(18873l), ((DocumentArtifactType) artifact).getContentSize());

    // Now update the artifact
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.Document());
    Assert.assertTrue("Expected 0 properties.", artifact.getProperty().isEmpty());
    Property prop1 = new Property();
    prop1.setPropertyName("prop1");
    prop1.setPropertyValue("propval1");
    artifact.getProperty().add(prop1);
    Property prop2 = new Property();
    prop2.setPropertyName("prop2");
    prop2.setPropertyValue("propval2");
    artifact.getProperty().add(prop2);
    persistenceManager.updateArtifact(artifact, ArtifactType.Document());

    // Now verify that the properties were stored
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.Document());
    Assert.assertTrue("Expected 2 properties.", artifact.getProperty().size() == 2);
    String p1 =
        artifact.getProperty().get(0).getPropertyName()
            + "="
            + artifact.getProperty().get(0).getPropertyValue();
    String p2 =
        artifact.getProperty().get(1).getPropertyName()
            + "="
            + artifact.getProperty().get(1).getPropertyValue();
    Set<String> ps = new HashSet<String>();
    ps.add(p1);
    ps.add(p2);
    Assert.assertTrue("Prop1 missing from properties.", ps.contains("prop1=propval1"));
    Assert.assertTrue("Prop2 missing from properties.", ps.contains("prop2=propval2"));
    Assert.assertFalse("Prop3 somehow existed!.", ps.contains("prop3=propval3"));

    // Now remove one property, add another one, and change the value of one
    artifact.getProperty().clear();
    prop1 = new Property();
    prop1.setPropertyName("prop1");
    prop1.setPropertyValue("propval1-updated");
    artifact.getProperty().add(prop1);
    Property prop3 = new Property();
    prop3.setPropertyName("prop3");
    prop3.setPropertyValue("propval3");
    artifact.getProperty().add(prop3);
    persistenceManager.updateArtifact(artifact, ArtifactType.Document());

    // Now verify that the properties were updated
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.Document());
    Assert.assertTrue("Expected 2 properties.", artifact.getProperty().size() == 2);
    p1 =
        artifact.getProperty().get(0).getPropertyName()
            + "="
            + artifact.getProperty().get(0).getPropertyValue();
    p2 =
        artifact.getProperty().get(1).getPropertyName()
            + "="
            + artifact.getProperty().get(1).getPropertyValue();
    ps.clear();
    ps.add(p1);
    ps.add(p2);
    Assert.assertFalse("Prop1 wasn't updated (old value detected).", ps.contains("prop1=propval1"));
    Assert.assertTrue(
        "Prop1 wasn't updated (new value not found).", ps.contains("prop1=propval1-updated"));
    Assert.assertFalse("Prop2 existed unexpectedly.", ps.contains("prop2=propval2"));
    Assert.assertTrue("Prop3 missing from properties.", ps.contains("prop3=propval3"));
  }
Example #10
0
  /**
   * Tests that we can manage s-ramp properties.
   *
   * @throws Exception
   */
  @Test
  public void testUpdateProperties() throws Exception {
    // First, add an artifact to the repo
    String artifactFileName = "PO.xsd";
    InputStream POXsd =
        this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName);
    Document document = new Document();
    document.setName(artifactFileName);
    document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
    BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXsd);
    Assert.assertNotNull(artifact);
    log.info("persisted PO.xsd to JCR, returned artifact uuid=" + artifact.getUuid());
    Assert.assertEquals(XsdDocument.class, artifact.getClass());
    long size = ((DocumentArtifactType) artifact).getContentSize();
    Assert.assertTrue(
        size
            >= 2376L); // Not doing an equals here due to the vagaries of Windows vs *nix line
                       // endings

    // Now update the artifact
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument());
    Assert.assertTrue("Expected 0 properties.", artifact.getProperty().isEmpty());
    Property prop1 = new Property();
    prop1.setPropertyName("prop1");
    prop1.setPropertyValue("propval1");
    artifact.getProperty().add(prop1);
    Property prop2 = new Property();
    prop2.setPropertyName("prop2");
    prop2.setPropertyValue("propval2");
    artifact.getProperty().add(prop2);
    persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument());

    // Now verify that the properties were stored
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument());
    Assert.assertTrue("Expected 2 properties.", artifact.getProperty().size() == 2);
    String p1 =
        artifact.getProperty().get(0).getPropertyName()
            + "="
            + artifact.getProperty().get(0).getPropertyValue();
    String p2 =
        artifact.getProperty().get(1).getPropertyName()
            + "="
            + artifact.getProperty().get(1).getPropertyValue();
    Set<String> ps = new HashSet<String>();
    ps.add(p1);
    ps.add(p2);
    Assert.assertTrue("Prop1 missing from properties.", ps.contains("prop1=propval1"));
    Assert.assertTrue("Prop2 missing from properties.", ps.contains("prop2=propval2"));
    Assert.assertFalse("Prop3 somehow existed!.", ps.contains("prop3=propval3"));

    // Now remove one property, add another one, and change the value of one
    artifact.getProperty().clear();
    prop1 = new Property();
    prop1.setPropertyName("prop1");
    prop1.setPropertyValue("propval1-updated");
    artifact.getProperty().add(prop1);
    Property prop3 = new Property();
    prop3.setPropertyName("prop3");
    prop3.setPropertyValue("propval3");
    artifact.getProperty().add(prop3);
    persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument());

    // Now verify that the properties were updated
    artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument());
    Assert.assertTrue("Expected 2 properties.", artifact.getProperty().size() == 2);
    p1 =
        artifact.getProperty().get(0).getPropertyName()
            + "="
            + artifact.getProperty().get(0).getPropertyValue();
    p2 =
        artifact.getProperty().get(1).getPropertyName()
            + "="
            + artifact.getProperty().get(1).getPropertyValue();
    ps.clear();
    ps.add(p1);
    ps.add(p2);
    Assert.assertFalse("Prop1 wasn't updated (old value detected).", ps.contains("prop1=propval1"));
    Assert.assertTrue(
        "Prop1 wasn't updated (new value not found).", ps.contains("prop1=propval1-updated"));
    Assert.assertFalse("Prop2 existed unexpectedly.", ps.contains("prop2=propval2"));
    Assert.assertTrue("Prop3 missing from properties.", ps.contains("prop3=propval3"));
  }