/** * 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 }
@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()); }
@Test public void testPersistArtifactPO_XSD() throws Exception { String artifactFileName = "PO.xsd"; InputStream POXsd = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); XsdDocument document = new XsdDocument(); 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()); // print out the derived node if (log.isDebugEnabled()) { persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.XsdDocument()); } 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 }
/** * Try to figure out what kind of artifact we're dealing with. * * @param file */ private ArtifactType determineArtifactType(File file) { ArtifactType type = null; String extension = FilenameUtils.getExtension(file.getName()); if ("wsdl".equals(extension)) { // $NON-NLS-1$ type = ArtifactType.WsdlDocument(); } else if ("xsd".equals(extension)) { // $NON-NLS-1$ type = ArtifactType.XsdDocument(); } else if ("wspolicy".equals(extension)) { // $NON-NLS-1$ type = ArtifactType.PolicyDocument(); } else if ("xml".equals(extension)) { // $NON-NLS-1$ type = ArtifactType.XmlDocument(); } else { type = ArtifactType.Document(); } return type; }
/** * 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()); } }
/** * 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")); }