/**
   * Test to ensure that the export process accepts an archive with only directories, no assets.
   *
   * @throws Exception
   */
  @Test
  public void testExportArchiveWithOnlyDirectories() throws IOException {
    // Create an archive with directories
    final ArchivePath path = ArchivePaths.create("/test/game");
    final Archive<?> archive =
        ShrinkWrap.create(JavaArchive.class, NAME_ARCHIVE).addAsDirectories(path);

    // Fully export by reading all content (export is on-demand)
    final InputStream content = this.exportAsInputStream(archive);
    final ByteArrayOutputStream exportedContents = new ByteArrayOutputStream();
    IOUtil.copyWithClose(content, exportedContents);

    final GenericArchive roundtrip =
        ShrinkWrap.create(this.getImporterClass(), "roundtrip.zip")
            .importFrom(new ByteArrayInputStream(exportedContents.toByteArray()))
            .as(GenericArchive.class);
    log.info(roundtrip.toString(true));
    Assert.assertTrue(roundtrip.contains(path));
  }
Exemplo n.º 2
0
  @Override
  @BeforeClass(groups = "live")
  public void setup() {
    super.setup();
    for (String regionId : regions) {
      boolean created = getApi().getContainerApi(regionId).create(containerName);
      if (!created) {
        deleteAllObjectsInContainer(regionId, containerName);
      }
    }
    GenericArchive files = ShrinkWrap.create(GenericArchive.class, "files.tar.gz");
    StringAsset content = new StringAsset("foo");
    for (int i = 0; i < OBJECT_COUNT; i++) {
      paths.add(containerName + "/file" + i);
      files.add(content, "/file" + i);
    }

    try {
      tarGz = ByteStreams2.toByteArrayAndClose(files.as(TarGzExporter.class).exportAsInputStream());
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
 /** SHRINKWRAP-259 */
 @Test
 public void createZipImporter() {
   final GenericArchive importer = ShrinkWrap.create(ZipImporter.class).as(GenericArchive.class);
   Assert.assertTrue("Archive did not have expected suffix", importer.getName().endsWith(".jar"));
 }