/** * Create an instance of {@link Document } * */ public Document createDocument() { return new Document(); }
/** * Create an instance of {@link Document } * */ public Document createDocument() { return new Document(); }
@Override public Collection<BaseArtifactType> findArtifacts(String model, String type, Map<String, String> criteria) { BaseArtifactType doc = new Document(); doc.setArtifactType(BaseArtifactEnum.DOCUMENT); doc.setName("Mock Artifact"); //$NON-NLS-1$ doc.setUuid(UUID.randomUUID().toString()); return Collections.singletonList(doc); } };
@Override public BaseArtifactType createMetaData(DiscoveredArtifact artifact) { BaseArtifactType md = new Document(); md.setUuid(UUID.randomUUID().toString()); md.setName("custom-" + artifact.getName()); //$NON-NLS-1$ return md; } });
/** * Creates the artifact instance based on the type of the discovered artifact. * @param discoveredArtifact */ protected BaseArtifactType createArtifact(DiscoveredArtifact discoveredArtifact) { BaseArtifactType metaData = null; String archivePath = discoveredArtifact.getArchivePath().toLowerCase(); if (archivePath.endsWith(".xml")) { //$NON-NLS-1$ metaData = new XmlDocument(); metaData.setArtifactType(BaseArtifactEnum.XML_DOCUMENT); } else if (archivePath.endsWith(".wsdl")) { //$NON-NLS-1$ metaData = new WsdlDocument(); metaData.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT); } else if (archivePath.endsWith(".xsd")) { //$NON-NLS-1$ metaData = new XsdDocument(); metaData.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); } else if (archivePath.endsWith(".wspolicy")) { //$NON-NLS-1$ metaData = new XsdDocument(); metaData.setArtifactType(BaseArtifactEnum.POLICY_DOCUMENT); } else { metaData = new Document(); metaData.setArtifactType(BaseArtifactEnum.DOCUMENT); } return metaData; }
/** * @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); } }
@Test public void testSimpleBatch() throws Exception { List<BatchItem> items = new ArrayList<BatchItem>(); BatchItem item = createBatchItem("/sample-files/batch/simple-1.txt", new Document(), BaseArtifactEnum.DOCUMENT); //$NON-NLS-1$ items.add(item); item = createBatchItem("/sample-files/batch/simple-2.txt", new Document(), BaseArtifactEnum.DOCUMENT); //$NON-NLS-1$ items.add(item); List<Object> response = persistenceManager.persistBatch(items); for (Object object : response) { Assert.assertTrue(object instanceof BaseArtifactType); } BaseArtifactType simple1 = (BaseArtifactType) response.get(0); BaseArtifactType simple2 = (BaseArtifactType) response.get(1); Assert.assertEquals("simple-1.txt", simple1.getName()); //$NON-NLS-1$ Assert.assertEquals("simple-2.txt", simple2.getName()); //$NON-NLS-1$ }
/** * @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; }
/** * @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 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 }
@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 }
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 = new Document(); document.setName(artifactFileName + "-2"); //$NON-NLS-1$ document.setArtifactType(BaseArtifactEnum.DOCUMENT);
@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);
InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setContentType("application/pdf"); //$NON-NLS-1$
Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); Document document2 = new Document(); document2.setName(artifactFileName); document2.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document3 = new Document(); document3.setName(artifactFileName); document3.setArtifactType(BaseArtifactEnum.XML_DOCUMENT);
Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
@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()); }