/** * @throws RepositoryException * @throws DerivedArtifactsCreationException */ private XsdDocument addXsdDoc() throws SrampException { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream contentStream = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ try { XsdDocument xsdDoc = new XsdDocument(); xsdDoc.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); xsdDoc.setName(artifactFileName); xsdDoc.setContentEncoding("application/xml"); //$NON-NLS-1$ // Persist the artifact BaseArtifactType artifact = persistenceManager.persistArtifact(xsdDoc, contentStream); Assert.assertNotNull(artifact); return (XsdDocument) artifact; } finally { IOUtils.closeQuietly(contentStream); } }
@Override public void visit(XsdDocument artifact) { super.visit(artifact); if (oldArtifact == null) { verifyEmptyDerivedRelationships("importedXsds", artifact.getImportedXsds()); verifyEmptyDerivedRelationships("includedXsds", artifact.getIncludedXsds()); verifyEmptyDerivedRelationships("redefinedXsds", artifact.getRedefinedXsds()); } else { XsdDocument castOld = (XsdDocument) oldArtifact; verifyUnchangedDerivedRelationships("importedXsds", artifact.getImportedXsds(), castOld.getImportedXsds()); verifyUnchangedDerivedRelationships("includedXsds", artifact.getIncludedXsds(), castOld.getIncludedXsds()); verifyUnchangedDerivedRelationships("redefinedXsds", artifact.getRedefinedXsds(), castOld.getRedefinedXsds()); } }
/** * @see org.overlord.sramp.common.visitors.HierarchicalArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.XsdDocument) */ @Override public void visit(XsdDocument artifact) { super.visit(artifact); try { setProperty("sramp:targetNamespace", artifact.getTargetNamespace()); //$NON-NLS-1$ } catch (Exception e) { error = e; } }
/** * Sets some meta data on the artifact model. * @param artifactMetaData * @param name * @param version * @param desc */ private void setMetaData(XsdDocument artifactMetaData, String name, String version, String desc) { artifactMetaData.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); artifactMetaData.setName(name); artifactMetaData.setVersion(version); artifactMetaData.setDescription(desc); }
/** * @see org.artificer.common.visitors.HierarchicalArtifactVisitor#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.XsdDocument) */ @Override public void visit(XsdDocument artifact) { super.visit(artifact); artifact.setTargetNamespace(getProperty("targetNamespace")); try { artifact.getImportedXsds().addAll(getRelationships( "importedXsds", artificerArtifact, XsdDocumentTarget.class)); artifact.getIncludedXsds().addAll(getRelationships( "includedXsds", artificerArtifact, XsdDocumentTarget.class)); artifact.getRedefinedXsds().addAll(getRelationships( "redefinedXsds", artificerArtifact, XsdDocumentTarget.class)); } catch (Exception e) { throw new RuntimeException(e); } }
XsdDocument xsdDocument = new XsdDocument(); xsdDocument.setName("accountingTypes.xsd"); xsdDocument.setDescription("accountingTypes.xsd"); xsdDocument.setCreatedBy("Bellwood"); xsdDocument.setVersion("1.0"); xsdDocument.setUuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6a"); XMLGregorianCalendar createdTS = DatatypeFactory.newInstance().newXMLGregorianCalendar("2009-05-26T13:13:55.013+02:00"); xsdDocument.setCreatedTimestamp(createdTS); XMLGregorianCalendar lastModifiedTS = DatatypeFactory.newInstance().newXMLGregorianCalendar("2009-06-26T13:13:55.013+02:00"); xsdDocument.setLastModifiedTimestamp(lastModifiedTS); xsdDocument.setLastModifiedBy("Pospisil"); xsdDocument.setContentType("application/xml"); xsdDocument.setContentEncoding("UTF-8"); xsdDocument.setContentSize(4096l); xsdDocument.getClassifiedBy().add("http://example.org/ontologies/accounting.owl/accounts"); new QName("xlink:href"), "http://example.org/s-ramp/xsd/XsdDocument/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6b"); xsdDocument.getImportedXsds().add(importedXsdTarget); "http://example.org/s-ramp/xsd/XsdDocument/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6c"); relationship.getRelationshipTarget().add(relationshipTarget2); xsdDocument.getRelationship().add(relationship); xsdDocument.getProperty().add(property);
XsdDocument testSrcArtifact = new XsdDocument(); testSrcArtifact.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); testSrcArtifact.setUuid(UUID.randomUUID().toString()); testSrcArtifact.setName("ws-humantask.xsd"); //$NON-NLS-1$ testSrcArtifact.setVersion("1.0"); //$NON-NLS-1$ testSrcArtifact.setContentEncoding("UTF-8"); //$NON-NLS-1$ testSrcArtifact.setContentType("application/xml"); //$NON-NLS-1$ testSrcArtifact.setContentSize(31723L); testSrcArtifact.setCreatedBy("anonymous"); //$NON-NLS-1$ XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar()); testSrcArtifact.setCreatedTimestamp(xmlGC); testSrcArtifact.setDescription("Hello world."); //$NON-NLS-1$ testSrcArtifact.setLastModifiedBy("anonymous"); //$NON-NLS-1$ testSrcArtifact.setLastModifiedTimestamp(xmlGC); for (BaseArtifactType derivedArtifact : derivedArtifacts) { DerivedArtifactType dat = (DerivedArtifactType) derivedArtifact; Assert.assertEquals(testSrcArtifact.getUuid(), dat.getRelatedDocument().getValue()); Assert.assertEquals(DocumentArtifactEnum.XSD_DOCUMENT, dat.getRelatedDocument().getArtifactType());
/** * @return a new artifact * @throws SrampException */ private BaseArtifactType createXsdArtifact() throws SrampException { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream content = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ XsdDocument document = new XsdDocument(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, content); Assert.assertNotNull(artifact); log.info("persisted PO.xsd to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ return artifact; }
BaseArtifactType metaData = new XsdDocument(); metaData.setName("PO.xsd"); //$NON-NLS-1$ metaData.setVersion("1.1"); //$NON-NLS-1$ metaData = new XsdDocument(); metaData.setName("PO.xml"); //$NON-NLS-1$ metaData.setVersion("1.2"); //$NON-NLS-1$ Assert.assertEquals("PO.xsd", xsdDoc.getName()); //$NON-NLS-1$ Assert.assertEquals("1.1", xsdDoc.getVersion()); //$NON-NLS-1$
/** * Test method for {@link SrampAtomApiClient#uploadArtifact(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String)}. */ @Test public void testUploadArtifactAndContent() throws Exception { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream is = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ try { SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ XsdDocument xsdDocument = new XsdDocument(); xsdDocument.setName(artifactFileName); xsdDocument.setUuid("my-client-side-supplied-UUID"); //$NON-NLS-1$ BaseArtifactType artifact = client.uploadArtifact(xsdDocument, is); Assert.assertNotNull(artifact); Assert.assertEquals(artifactFileName, artifact.getName()); Assert.assertEquals("my-client-side-supplied-UUID", artifact.getUuid()); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(is); } }
@Test public void testWsdlBatch() throws Exception { List<BatchItem> items = new ArrayList<BatchItem>(); BatchItem item = createBatchItem("/sample-files/wsdl/jcr-sample-externalrefs.xsd", new XsdDocument(), BaseArtifactEnum.XSD_DOCUMENT); //$NON-NLS-1$ items.add(item); item = createBatchItem("/sample-files/wsdl/jcr-sample-externalrefs.wsdl", new WsdlDocument(), BaseArtifactEnum.WSDL_DOCUMENT); //$NON-NLS-1$ Assert.assertEquals("jcr-sample-externalrefs.xsd", xsd.getName()); //$NON-NLS-1$ Assert.assertEquals("urn:s-ramp:test:jcr-sample-externalrefs:types", xsd.getTargetNamespace()); //$NON-NLS-1$
String path4 = "s-ramp/xlink.xsd"; //$NON-NLS-1$ XsdDocument artifact1MetaData = new XsdDocument(); XsdDocument artifact2MetaData = new XsdDocument(); XsdDocument artifact3MetaData = new XsdDocument(); XsdDocument artifact4MetaData = new XsdDocument(); Assert.assertEquals("sample.xsd", sampleXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("1.0.3", sampleXsdMetaData.getVersion()); //$NON-NLS-1$ Assert.assertEquals("Just a sample XML Schema.", sampleXsdMetaData.getDescription()); //$NON-NLS-1$ Assert.assertEquals("PO.xsd", poXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("2.1.4", poXsdMetaData.getVersion()); //$NON-NLS-1$ Assert.assertEquals("The Purchase Order schema.", poXsdMetaData.getDescription()); //$NON-NLS-1$ Assert.assertEquals("coremodel.xsd", coremodelXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("1.6.1", coremodelXsdMetaData.getVersion()); //$NON-NLS-1$ Assert.assertEquals("S-RAMP core schema.", coremodelXsdMetaData.getDescription()); //$NON-NLS-1$ Assert.assertEquals("xlink.xsd", xlinkXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("1.6.1", xlinkXsdMetaData.getVersion()); //$NON-NLS-1$ Assert.assertEquals("X-LINK schema.", xlinkXsdMetaData.getDescription()); //$NON-NLS-1$ } finally { SrampArchive.closeQuietly(archive);
/** * Create an instance of {@link XsdDocument } * */ public XsdDocument createXsdDocument() { return new XsdDocument(); }
@Test public void testWsdlDocumentWithExternalRefs() throws Exception { String xsdUuid = addWsdlArtifact("jcr-sample-externalrefs.xsd", new XsdDocument(), BaseArtifactEnum.XSD_DOCUMENT); //$NON-NLS-1$ String uuid = addWsdlArtifact("jcr-sample-externalrefs.wsdl", new WsdlDocument(), BaseArtifactEnum.WSDL_DOCUMENT); //$NON-NLS-1$ Assert.assertEquals("urn:s-ramp:test:jcr-sample-externalrefs:types", xsd.getTargetNamespace()); //$NON-NLS-1$
} else if (artifact instanceof XsdDocument) { XsdDocument xsdDocument = (XsdDocument) artifact; String[] key = new String[] { xsdDocument.getTargetNamespace(), xsdDocument.getName() }; xsdDocumentIndex.put(key, xsdDocument); } else if (artifact instanceof WsdlDocument) {
/** * Test method for {@link org.overlord.sramp.atom.archive.jar.ZipToSrampArchive.jar.JarToSrampArchive#createSrampArchive()}. */ @Test public void testMetaData() throws Exception { InputStream resourceAsStream = ZipToSrampArchiveTest.class.getResourceAsStream("sample-webservice-0.0.1.jar"); //$NON-NLS-1$ ZipToSrampArchive j2sramp = null; SrampArchive archive = null; try { j2sramp = new ZipToSrampArchive(resourceAsStream){}; archive = j2sramp.createSrampArchive(); Assert.assertNotNull(archive); SrampArchiveEntry entry = archive.getEntry("schema/teetime.xsd"); //$NON-NLS-1$ Assert.assertNotNull(entry); BaseArtifactType metaData = entry.getMetaData(); Assert.assertNotNull(metaData); Assert.assertTrue(metaData instanceof XsdDocument); XsdDocument md = (XsdDocument) metaData; Assert.assertEquals("teetime.xsd", md.getName()); //$NON-NLS-1$ Assert.assertNotNull(md.getUuid()); } finally { ZipToSrampArchive.closeQuietly(j2sramp); SrampArchive.closeQuietly(archive); } }
/** * Unmarshall an xml fragment. */ @Test public void unmarshall() { try { JAXBContext jaxbContext=JAXBContext.newInstance("org.oasis_open.docs.s_ramp.ns.s_ramp_v1"); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); Assert.assertNotNull("Cannot locate file XsdDocument-entry.xml", this.getClass().getResourceAsStream("XsdDocument-entry.xml")); String expectedXML = new Scanner(this.getClass().getResourceAsStream("XsdDocument-entry.xml")).useDelimiter("\\Z").next(); StringReader reader = new StringReader(expectedXML); JAXBElement<Artifact> element = unMarshaller.unmarshal(new StreamSource(reader),Artifact.class); Artifact artifact = element.getValue(); Assert.assertEquals("accountingTypes.xsd", artifact.getXsdDocument().getName()); } catch (JAXBException jaxbe) { jaxbe.printStackTrace(); fail("No exception should be thrown"); } }
/** * @see org.overlord.sramp.common.visitors.HierarchicalArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.XsdDocument) */ @Override public void visit(XsdDocument artifact) { super.visit(artifact); artifact.setTargetNamespace(getProperty(jcrNode, "sramp:targetNamespace")); //$NON-NLS-1$ }
private void processImportedXsds(Element schema, String targetNS) throws XPathExpressionException { if (getPrimaryArtifact() instanceof XsdDocument) { processImportedXsds(((XsdDocument) getPrimaryArtifact()).getImportedXsds(), schema, targetNS); } }
protected void processImportedXsds(List<XsdDocumentTarget> targetCollection, Element schema, String targetNS) throws XPathExpressionException { NodeList nodes = (NodeList) query(schema, "./xsd:import", XPathConstants.NODESET); for (int idx = 0; idx < nodes.getLength(); idx++) { Element node = (Element) nodes.item(idx); if (node.hasAttribute("namespace") && node.hasAttribute("schemaLocation")) { String namespace = node.getAttribute("namespace"); String schemaLocation = node.getAttribute("schemaLocation"); stripPath(schemaLocation); XsdDocument xsdDocumentRef = derivedArtifacts.lookupXsdDocument(namespace, schemaLocation); XsdDocumentTarget xsdDocumentTarget = new XsdDocumentTarget(); xsdDocumentTarget.setArtifactType(XsdDocumentEnum.XSD_DOCUMENT); if (xsdDocumentRef != null) { xsdDocumentTarget.setValue(xsdDocumentRef.getUuid()); } else { relationshipSources.add(new NamespaceRelationshipSource(namespace, schemaLocation, xsdDocumentTarget, targetCollection, ArtifactTypeEnum.XsdDocument.getModel(), ArtifactTypeEnum.XsdDocument.getType())); } targetCollection.add(xsdDocumentTarget); } } }