/** * Creates a new extended artifact type for a SwitchYard artifact. * @param name */ private static final ExtendedArtifactType newArtifact(String switchYardType, String name) { ExtendedArtifactType artifact = new ExtendedArtifactType(); artifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); artifact.setExtendedType(switchYardType); artifact.setUuid(UUID.randomUUID().toString()); artifact.setName(name); return artifact; }
/** * @param derivedArtifacts * @param artifact * @param rootElement * @param xpath * @throws XPathExpressionException */ private void processRoot(Collection<BaseArtifactType> derivedArtifacts, BaseArtifactType artifact, Element rootElement, XPath xpath) throws XPathExpressionException { NodeList nodes = (NodeList) this.query(xpath, rootElement, "./credit", XPathConstants.NODESET); //$NON-NLS-1$ for (int idx = 0; idx < nodes.getLength(); idx++) { Element node = (Element) nodes.item(idx); ExtendedArtifactType credit = new ExtendedArtifactType(); credit.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); credit.setUuid(UUID.randomUUID().toString()); String type = node.getAttribute("type"); //$NON-NLS-1$ String name = node.getAttribute("name"); //$NON-NLS-1$ String part = node.getAttribute("part"); //$NON-NLS-1$ String year = node.getAttribute("year"); //$NON-NLS-1$ credit.setExtendedType(StringUtils.capitalize(type) + "Credit"); //$NON-NLS-1$ credit.setName(name); SrampModelUtils.setCustomProperty(credit, "part", part); //$NON-NLS-1$ SrampModelUtils.setCustomProperty(credit, "year", year); //$NON-NLS-1$ derivedArtifacts.add(credit); // Set a relationship from original artifact to the listener credit.setUuid(UUID.randomUUID().toString()); SrampModelUtils.addGenericRelationship(artifact, "hasCredit", credit.getUuid()); //$NON-NLS-1$ } }
@Test public void testPersistArtifact_ExtendedArtifactType() throws Exception { ExtendedArtifactType extendedArtifact = new ExtendedArtifactType(); extendedArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); extendedArtifact.setExtendedType("FooArtifactType"); //$NON-NLS-1$ extendedArtifact.setName("MyExtendedArtifact"); //$NON-NLS-1$ extendedArtifact.setDescription("This is a simple description for testing."); //$NON-NLS-1$ BaseArtifactType artifact = persistenceManager.persistArtifact(extendedArtifact, null); Assert.assertNotNull(artifact); log.info("persisted extended artifact 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(ExtendedArtifactType.class, artifact.getClass()); String name = ((ExtendedArtifactType) artifact).getName(); String description = ((ExtendedArtifactType) artifact).getDescription(); Assert.assertEquals("MyExtendedArtifact", name); //$NON-NLS-1$ Assert.assertEquals("This is a simple description for testing.", description); //$NON-NLS-1$ }
extendedArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); extendedArtifact.setExtendedType("FooArtifactType"); //$NON-NLS-1$ extendedArtifact.setName("MyExtendedArtifact"); //$NON-NLS-1$ extendedArtifact.setUuid("12345"); //$NON-NLS-1$ try {
/** * Test method for {@link SrampAtomApiClient#createArtifact(BaseArtifactType)}. */ @Test public void testCreateArtifact() throws Exception { ExtendedArtifactType artifact = new ExtendedArtifactType(); artifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); artifact.setExtendedType("TestArtifact"); //$NON-NLS-1$ artifact.setName("My Test Artifact"); //$NON-NLS-1$ artifact.setDescription("Description of my test artifact."); //$NON-NLS-1$ SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ BaseArtifactType createdArtifact = client.createArtifact(artifact); Assert.assertNotNull(artifact); Assert.assertEquals("My Test Artifact", createdArtifact.getName()); //$NON-NLS-1$ Assert.assertEquals("Description of my test artifact.", createdArtifact.getDescription()); //$NON-NLS-1$ }
nonDocArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); nonDocArtifact.setExtendedType("TestArtifact"); //$NON-NLS-1$ nonDocArtifact.setName("My Test Artifact"); //$NON-NLS-1$