private void writeDtaAndControls(Domain domain, OutputStream ddbOs, OutputStream dictGensOs) throws IOException { GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class); try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) { Path rootDir = fileSystem.getPath("/"); ddbClient.dumpDtaFile(rootDir, DTA_FILE_NAME, network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap(), parameters); } archive.as(ZipExporter.class).exportTo(ddbOs); //put just the generators dict csv file (extracted from the ddb files) in the common files set, to be used by wp43 transient stability index if (archive.get(DDB_DICT_GENS_CSV) != null) { ByteStreams.copy(archive.get(DDB_DICT_GENS_CSV).getAsset().openStream(), dictGensOs); } else { LOGGER.warn(DDB_DICT_GENS_CSV + " is missing in the dynamic data files set: some security indexers (e.g. transient stability) need this file"); } }
@Test public void testImportArchiveAsTypeFromFilterUsingDefaultFormat() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); Collection<JavaArchive> jars = archive.getAsType(JavaArchive.class, Filters.include(".*jar")); Assert.assertEquals("Unexpected result found", 1, jars.size()); JavaArchive jar = jars.iterator().next().add(new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }
@Test public void testImportArchiveAsTypeFromFilter() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); Collection<JavaArchive> jars = archive .getAsType(JavaArchive.class, Filters.include(".*jar"), ArchiveFormat.ZIP); Assert.assertEquals("Unexpected result found", 1, jars.size()); JavaArchive jar = jars.iterator().next().add(new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }
@Test public void testImportArchiveAsTypeFromStringUsingDefaultFormat() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); JavaArchive jar = archive.getAsType(JavaArchive.class, resourcePath).add(new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }
@Test public void testImportArchiveAsTypeFromString() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); JavaArchive jar = archive.getAsType(JavaArchive.class, resourcePath, ArchiveFormat.ZIP).add( new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }
@Test public void testImportArchiveAsTypeFromArchivePathUsingDefaultFormat() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); JavaArchive jar = archive.getAsType(JavaArchive.class, ArchivePaths.create(resourcePath)).add( new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain an archive asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }
@Test public void testImportArchiveAsTypeFromArchivePath() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); JavaArchive jar = archive.getAsType(JavaArchive.class, ArchivePaths.create(resourcePath), ArchiveFormat.ZIP) .add(new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain an archive asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }