/** * @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); } }
/** * @throws SrampException */ private BaseArtifactType createDocument(int idx) throws SrampException { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream content = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName + "-" + idx); //$NON-NLS-1$ document.setVersion("1.0.3"); //$NON-NLS-1$ document.setArtifactType(BaseArtifactEnum.DOCUMENT); BaseArtifactType artifact1 = persistenceManager.persistArtifact(document, content); Assert.assertNotNull(artifact1); return artifact1; }
@Test public void testPersistArtifactPO_XML() throws Exception { String artifactFileName = "PO.xml"; //$NON-NLS-1$ InputStream POXml = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ 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()); //$NON-NLS-1$ //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 }
/** * @return a new artifact * @throws SrampException */ private BaseArtifactType createArtifact(Set<String> classifiers, String ... args) throws SrampException { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); document.setDescription("Sample description."); //$NON-NLS-1$ if (classifiers != null) { for (String classifier : classifiers) { document.getClassifiedBy().add(classifier); } } if (args != null && args.length > 0) { for (int i = 0; i < args.length; i+=2) { String propName = args[i]; String propVal = args[i+1]; SrampModelUtils.setCustomProperty(document, propName, propVal); } } BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf); Assert.assertNotNull(artifact); log.info("persisted s-ramp-press-release.pdf to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ return artifact; }
@Test public void testPersistArtifact_PDF() throws Exception { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ 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()); //$NON-NLS-1$ //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()); Assert.assertEquals("4ee67f4c9f12ebe58c0c6d55d20d9dab91d8ab39", ((DocumentArtifactType) artifact).getContentHash()); //$NON-NLS-1$ }
@Test public void testPersistClassifications() throws Exception { SrampOntology ontology = createOntology(); String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); document.getClassifiedBy().add(ontology.findClass("China").getUri().toString()); //$NON-NLS-1$ BaseArtifactType artifact = persistenceManager.persistArtifact(document, contentStream); Assert.assertNotNull(artifact); if (log.isDebugEnabled()) { persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.Document()); } artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.Document()); Assert.assertNotNull(artifact.getClassifiedBy()); Assert.assertEquals(1, artifact.getClassifiedBy().size()); Assert.assertEquals("urn:example.org/test2#China", artifact.getClassifiedBy().get(0)); //$NON-NLS-1$ }
/** * 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"; //$NON-NLS-1$ InputStream POXsd = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ 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()); //$NON-NLS-1$ 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"); //$NON-NLS-1$ 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 }
Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); document.setUuid("12345"); // amazing - that's the same UUID as my luggage! //$NON-NLS-1$ BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf); document = new Document(); document.setName(artifactFileName + "-2"); //$NON-NLS-1$ document.setArtifactType(BaseArtifactEnum.DOCUMENT); document.setUuid("12345"); // amazing - that's the same UUID as my luggage! //$NON-NLS-1$ try {
@Test public void testDeleteArtifact() throws Exception { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ 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()); //$NON-NLS-1$ // 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 = ?]"); //$NON-NLS-1$ query.setString(document.getUuid()); ArtifactSet artifactSet = query.executeQuery(); Assert.assertEquals(0, artifactSet.size()); }
Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXsd); Assert.assertNotNull(artifact);
document.setName(artifactFileName); document.setContentType("application/pdf"); //$NON-NLS-1$ document.setArtifactType(BaseArtifactEnum.DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf); Assert.assertNotNull(artifact);
Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, contentStream); Assert.assertNotNull(artifact); Document document2 = new Document(); document2.setName(artifactFileName); document2.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact2 = persistenceManager.persistArtifact(document2, contentStream); Assert.assertNotNull(artifact2); Document document3 = new Document(); document3.setName(artifactFileName); document3.setArtifactType(BaseArtifactEnum.XML_DOCUMENT); BaseArtifactType artifact3 = persistenceManager.persistArtifact(document3, contentStream); Assert.assertNotNull(artifact3);
Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXsd); Assert.assertNotNull(artifact);
@Test public void testGetArtifact_XSD() throws Exception { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream POXsd = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ 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()); //$NON-NLS-1$ 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()); }