/** * 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); } }
/** * 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); } }
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, is2); //$NON-NLS-1$ } catch (Exception e) { SrampArchive.closeQuietly(archive);
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);
nonDocArtifact.setName("My Test Artifact"); //$NON-NLS-1$ archive.addEntry("myLogicalArtifact", nonDocArtifact, null); //$NON-NLS-1$ } catch (Exception e) { SrampArchive.closeQuietly(archive);