/** * Test method for {@link org.overlord.sramp.atom.archive.jar.ZipToSrampArchive.jar.JarToSrampArchive#createSrampArchive()}. */ @Test public void testCreateSrampArchive() 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); Collection<SrampArchiveEntry> entries = archive.getEntries(); Assert.assertEquals(2, entries.size()); Set<String> paths = new HashSet<String>(); for (SrampArchiveEntry entry : entries) { paths.add(entry.getPath()); } Assert.assertEquals(2, entries.size()); Assert.assertTrue(paths.contains("schema/teetime.xsd")); //$NON-NLS-1$ Assert.assertTrue(paths.contains("wsdl/teetime.wsdl")); //$NON-NLS-1$ } finally { ZipToSrampArchive.closeQuietly(j2sramp); SrampArchive.closeQuietly(archive); } }
private void assertXsd( final SrampArchive srampArchive, final String fileEntryPath ) { final SrampArchiveEntry manifestEntry = srampArchive.getEntry(fileEntryPath); assertThat(manifestEntry, is(not(nullValue()))); final BaseArtifactType manifestArtifact = manifestEntry.getMetaData(); assertThat(manifestArtifact, is(instanceOf(XsdDocument.class))); }
/** * Test method for {@link org.overlord.sramp.common.atom.archive.SrampArchive#addEntry(String, org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, InputStream)}. */ @Test public void testAddEntry() throws Exception { InputStream artifactContentStream = SrampArchiveTest.class.getResourceAsStream("sample.xsd"); //$NON-NLS-1$ XsdDocument artifactMetaData = new XsdDocument(); setMetaData(artifactMetaData, "sample.xsd", "1.0.3", "Just a sample XML Schema."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ SrampArchive archive = null; try { archive = new SrampArchive(); archive.addEntry("sample.xsd", artifactMetaData, artifactContentStream); //$NON-NLS-1$ File workDir = AtomTestUtils.getArchiveWorkDir(archive); Assert.assertNotNull(workDir); Assert.assertTrue(workDir.isDirectory()); Collection<File> files = FileUtils.listFiles(workDir, new String[] {"xsd", "atom"}, true); //$NON-NLS-1$ //$NON-NLS-2$ Assert.assertEquals(2, files.size()); Set<String> fnames = new HashSet<String>(); for (File f : files) { fnames.add(f.getName()); } Assert.assertTrue(fnames.contains("sample.xsd")); //$NON-NLS-1$ Assert.assertTrue(fnames.contains("sample.xsd.atom")); //$NON-NLS-1$ } finally { SrampArchive.closeQuietly(archive); } }
try { zipOutputStream = new ZipOutputStream(outputStream); Collection<SrampArchiveEntry> entries = getEntries(); for (SrampArchiveEntry entry : entries) { packEntry(entry, zipOutputStream);
/** * Test method for {@link SrampAtomApiClient#uploadBatch(SrampArchive)}. */ @Test public void testArchiveUpload_Empty() throws Exception { // First, create an s-ramp archive SrampArchive archive = null; try { archive = new SrampArchive(); } catch (Exception e) { SrampArchive.closeQuietly(archive); throw e; } finally { } try { // Now use the s-ramp atom api client to upload the s-ramp archive SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ Map<String, ?> results = client.uploadBatch(archive); Assert.assertTrue(results.isEmpty()); } finally { SrampArchive.closeQuietly(archive); } }
if (archive.getEntries().isEmpty()) { return new HashMap<String, Object>(); packageFile = archive.pack(); packageStream = FileUtils.openInputStream(packageFile); ClientRequest request = createClientRequest(this.endpoint);
setMetaData(artifact4MetaData, "xlink.xsd", "1.6.1", "X-LINK schema."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ archive = new SrampArchive(); archive.addEntry(path1, artifact1MetaData, artifact1ContentStream); archive.addEntry(path2, artifact2MetaData, artifact2ContentStream); archive.addEntry(path3, artifact3MetaData, artifact3ContentStream); archive.addEntry(path4, artifact4MetaData, artifact4ContentStream); archiveFile = archive.pack(); } finally { SrampArchive.closeQuietly(archive); archive = new SrampArchive(archiveFile); Collection<SrampArchiveEntry> entries = archive.getEntries(); Assert.assertEquals(4, entries.size()); Map<String, SrampArchiveEntry> entryMap = new HashMap<String, SrampArchiveEntry>(); Assert.assertEquals("X-LINK schema.", xlinkXsdMetaData.getDescription()); //$NON-NLS-1$ } finally { SrampArchive.closeQuietly(archive); FileUtils.deleteQuietly(archiveFile);
archive = new SrampArchive(tempFile); Collection<SrampArchiveEntry> entries = archive.getEntries(); Assert.assertEquals(1, entries.size()); SrampArchiveEntry entry = entries.iterator().next(); } finally { FileUtils.deleteQuietly(tempFile); SrampArchive.closeQuietly(archive);
/** * Asserts that the s-ramp archive was properly created. * @param archive * @throws SrampArchiveException */ private void doAllAssertions(SrampArchive archive) throws SrampArchiveException { Collection<SrampArchiveEntry> entries = archive.getEntries(); // Make sure all the entries we expect to be there are there. TreeSet<String> entryNames = new TreeSet<String>(); for (SrampArchiveEntry srampArchiveEntry : entries) { entryNames.add(srampArchiveEntry.getPath()); } StringBuilder buff = new StringBuilder(); for (String entryName : entryNames) { buff.append(entryName).append("\n"); //$NON-NLS-1$ } Assert.assertEquals(EXPECTED_ENTRIES, buff.toString()); // Now spot-check some representative entries. // Check the kmodule.xml SrampArchiveEntry entry = archive.getEntry("META-INF/kmodule.xml"); //$NON-NLS-1$ Assert.assertNotNull(entry); Assert.assertEquals("kmodule.xml", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals(BaseArtifactEnum.EXTENDED_DOCUMENT, entry.getMetaData().getArtifactType()); ExtendedDocument kieXmlDoc = (ExtendedDocument) entry.getMetaData(); Assert.assertEquals(KieJarModel.KieXmlDocument, kieXmlDoc.getExtendedType()); }
/** * 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); } }
@Test public void testKieIntegration() throws Exception { InputStream stream = getClass().getResourceAsStream("kie.jar"); //$NON-NLS-1$ SrampArchive archive = null; KieJarToSrampArchive kie2archive = null; try { kie2archive = new KieJarToSrampArchive(stream); archive = kie2archive.createSrampArchive(); Assert.assertNotNull(archive); doAllAssertions(archive); } finally { IOUtils.closeQuietly(stream); SrampArchive.closeQuietly(archive); ZipToSrampArchive.closeQuietly(kie2archive); } }
/** * Creates an S-RAMP archive from this JAR. * @return an S-RAMP archive * @throws ZipToSrampArchiveException */ public SrampArchive createSrampArchive() throws ZipToSrampArchiveException { this.artifactFilter.setContext(this.context); this.metaDataFactory.setContext(this.context); DiscoveredArtifacts discoveredArtifacts = discoverArtifacts(); discoveredArtifacts.index(jarWorkDir); generateMetaData(discoveredArtifacts); try { SrampArchive archive = new SrampArchive(); for (DiscoveredArtifact artifact : discoveredArtifacts) { String path = artifact.getArchivePath(); archive.addEntry(path, artifact.getMetaData(), artifact.getContent()); } return archive; } catch (Exception e) { throw new ZipToSrampArchiveException(e); } }
Collection<SrampArchiveEntry> entries = archive.getEntries(); SrampArchiveEntry entry = archive.getEntry("META-INF/switchyard.xml"); //$NON-NLS-1$ Assert.assertNotNull(entry); Assert.assertEquals("switchyard.xml", entry.getMetaData().getName()); //$NON-NLS-1$ entry = archive.getEntry("org/switchyard/quickstarts/bean/service/InventoryService.class"); //$NON-NLS-1$ Assert.assertNotNull(entry); Assert.assertEquals("InventoryService.class", entry.getMetaData().getName()); //$NON-NLS-1$ entry = archive.getEntry("wsdl/OrderService.wsdl"); //$NON-NLS-1$ Assert.assertNotNull(entry); Assert.assertEquals("OrderService.wsdl", entry.getMetaData().getName()); //$NON-NLS-1$
archive = j2sramp.createSrampArchive(); Assert.assertNotNull(archive); SrampArchiveEntry entry = archive.getEntry("schema/teetime.xsd"); //$NON-NLS-1$ Assert.assertNotNull(entry); BaseArtifactType metaData = entry.getMetaData(); } finally { ZipToSrampArchive.closeQuietly(j2sramp); SrampArchive.closeQuietly(archive);
archive = new SrampArchive(tempFile); } finally { FileUtils.deleteQuietly(tempFile); SrampArchive.closeQuietly(archive);
@Test public void testSwitchYardIntegration() throws Exception { InputStream stream = getClass().getResourceAsStream("switchyard-quickstart-bean-service.jar"); //$NON-NLS-1$ SrampArchive archive = null; SwitchYardAppToSrampArchive sy2archive = null; try { sy2archive = new SwitchYardAppToSrampArchive(stream); archive = sy2archive.createSrampArchive(); Assert.assertNotNull(archive); doAllAssertions(archive); } finally { IOUtils.closeQuietly(stream); SrampArchive.closeQuietly(archive); ZipToSrampArchive.closeQuietly(sy2archive); } }
@Test public void shouldExpandProductsVdb() throws Exception { final InputStream stream = getResourceAsStream("ProductsSS_VDB.vdb"); VdbToSrampArchive vdbArchive = null; SrampArchive srampArchive = null; try { vdbArchive = new VdbToSrampArchive(stream); srampArchive = vdbArchive.createSrampArchive(); assertThat(srampArchive, is(not(nullValue()))); assertThat(srampArchive.getEntries().size(), is(2)); // manifest + 1 xmi models // check the manifest assertManifest(srampArchive); // check the model assertModel(srampArchive, "TestProducts/ProductsSS.xmi"); } finally { IOUtils.closeQuietly(stream); SrampArchive.closeQuietly(srampArchive); ZipToSrampArchive.closeQuietly(vdbArchive); } }
InputStream is2 = null; try { archive = new SrampArchive(); metaData.setVersion("1.1"); //$NON-NLS-1$ metaData.setDescription("This is a test description (XSD)."); //$NON-NLS-1$ archive.addEntry("schemas/PO.xsd", metaData, is1); //$NON-NLS-1$ metaData.setVersion("1.2"); //$NON-NLS-1$ metaData.setDescription("This is a test description (XML)."); //$NON-NLS-1$ archive.addEntry("core/PO.xml", metaData, null); //$NON-NLS-1$ } catch (Exception e) { SrampArchive.closeQuietly(archive); throw e; } finally { Assert.assertNotNull(xmlError); } finally { SrampArchive.closeQuietly(archive);
IOUtils.closeQuietly(artifactsIS); ZipToSrampArchive.closeQuietly(sy2archive); SrampArchive.closeQuietly(archive); IOUtils.closeQuietly(artifactsIS); ZipToSrampArchive.closeQuietly(sy2archive); SrampArchive.closeQuietly(archive); IOUtils.closeQuietly(artifactsIS); ZipToSrampArchive.closeQuietly(sy2archive); SrampArchive.closeQuietly(archive);
private void assertManifest( final SrampArchive srampArchive ) { final SrampArchiveEntry manifestEntry = srampArchive.getEntry(VdbManifest.PATH); assertThat(manifestEntry, is(not(nullValue()))); final BaseArtifactType manifestArtifact = manifestEntry.getMetaData(); assertThat(manifestArtifact, is(instanceOf(ExtendedDocument.class))); assertThat(((ExtendedDocument)manifestArtifact).getExtendedType(), is(VdbManifest.ARTIFACT_TYPE.extendedType())); }