Search in sources :

Example 6 with TemporaryFolder

use of org.talend.sdk.component.junit.base.junit5.TemporaryFolder in project component-runtime by Talend.

the class StudioInstallerTest method run.

@Test
void run(final TemporaryFolder temporaryFolder, final TestInfo info) throws IOException {
    final String testName = info.getTestMethod().get().getName();
    final File studioHome = new File(temporaryFolder.getRoot(), testName);
    final File configuration = org.apache.ziplock.Files.mkdir(new File(studioHome, "configuration"));
    try (final Writer configIni = new FileWriter(new File(configuration, "config.ini"))) {
    // no-op
    }
    final File artifact = new File(temporaryFolder.getRoot(), testName + ".jar");
    try (final JarOutputStream out = new JarOutputStream(new FileOutputStream(artifact))) {
        out.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
        out.closeEntry();
    }
    final StudioInstaller installer = new StudioInstaller("gtest:atest:1.0-SNAPSHOT", studioHome, singletonMap("gtest:atest:1.0-SNAPSHOT", artifact), new Log() {

        @Override
        public void debug(final String s) {
            log.info(s);
        }

        @Override
        public void error(final String s) {
            log.error(s);
        }

        @Override
        public void info(final String s) {
            log.info(s);
        }
    });
    installer.run();
    final File backup = new File(studioHome, "configuration/backup");
    {
        assertTrue(backup.exists());
        assertEquals(1, backup.listFiles((dir, name) -> name.startsWith("config.ini")).length);
        assertSetup(studioHome);
    }
    installer.run();
    {
        assertSetup(studioHome);
        // 1 again cause already here so no other backup
        assertEquals(1, backup.listFiles((dir, name) -> name.startsWith("config.ini")).length);
    }
}
Also used : Files(java.nio.file.Files) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) JarEntry(java.util.jar.JarEntry) Slf4j(lombok.extern.slf4j.Slf4j) Collections.singleton(java.util.Collections.singleton) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) Writer(java.io.Writer) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JarOutputStream(java.util.jar.JarOutputStream) Collectors.toSet(java.util.stream.Collectors.toSet) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.jupiter.api.Test)

Aggregations

TemporaryFolder (org.talend.sdk.component.junit.base.junit5.TemporaryFolder)6 File (java.io.File)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Test (org.junit.jupiter.api.Test)5 WithTemporaryFolder (org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder)5 IOException (java.io.IOException)4 List (java.util.List)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 FileOutputStream (java.io.FileOutputStream)3 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)3 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 Collection (java.util.Collection)2 Collections.singletonList (java.util.Collections.singletonList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 UUID (java.util.UUID)2 Collectors.toList (java.util.stream.Collectors.toList)2 Assertions.fail (org.junit.jupiter.api.Assertions.fail)2