Search in sources :

Example 41 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project flow by vaadin.

the class DevModeInitializerTest method onStartup_fallbackBaseDirIsNotProjectDirectory_throws.

@Test(expected = IllegalStateException.class)
public void onStartup_fallbackBaseDirIsNotProjectDirectory_throws() throws Exception {
    Mockito.when(appConfig.getStringProperty(FrontendUtils.PROJECT_BASEDIR, null)).thenReturn(null);
    TemporaryFolder tmp = new TemporaryFolder();
    tmp.create();
    baseDir = tmp.getRoot().getPath();
    String originalUserDirValue = null;
    try {
        originalUserDirValue = System.getProperty("user.dir");
        System.setProperty("user.dir", baseDir);
        devModeStartupListener.onStartup(classes, servletContext);
    } finally {
        if (originalUserDirValue != null) {
            System.setProperty("user.dir", originalUserDirValue);
        }
    }
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) Test(org.junit.Test)

Example 42 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project flow by vaadin.

the class DevModeInitializerTest method onStartup_fallbackBaseDirIsMavenProjectDirectory_isAccepted.

@Test
public void onStartup_fallbackBaseDirIsMavenProjectDirectory_isAccepted() throws Exception {
    Mockito.when(appConfig.getStringProperty(FrontendUtils.PROJECT_BASEDIR, null)).thenReturn(null);
    TemporaryFolder tmp = new TemporaryFolder();
    tmp.create();
    tmp.newFile("pom.xml");
    baseDir = tmp.getRoot().getPath();
    String originalUserDirValue = null;
    try {
        originalUserDirValue = System.getProperty("user.dir");
        System.setProperty("user.dir", baseDir);
        devModeStartupListener.onStartup(classes, servletContext);
    } finally {
        if (originalUserDirValue != null) {
            System.setProperty("user.dir", originalUserDirValue);
        }
    }
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) Test(org.junit.Test)

Example 43 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project flow by vaadin.

the class BuildFrontendUtilTest method testWebpackRequiredFlagsPassedToNodeEnvironment.

@Test
public void testWebpackRequiredFlagsPassedToNodeEnvironment() throws IOException, URISyntaxException, TimeoutException {
    Assume.assumeFalse("Test not runnable on Windows", FrontendUtils.isWindows());
    Assume.assumeTrue("Test requires /bin/bash", new File("/bin/bash").exists());
    TemporaryFolder tmpDir = new TemporaryFolder();
    tmpDir.create();
    File baseDir = tmpDir.newFolder();
    // setup: mock a webpack executable
    File webpackBin = new File(baseDir, "node_modules/webpack/bin");
    Assert.assertTrue(webpackBin.mkdirs());
    File webPackExecutableMock = new File(webpackBin, "webpack.js");
    Assert.assertTrue(webPackExecutableMock.createNewFile());
    PluginAdapterBase adapter = Mockito.mock(PluginAdapterBase.class);
    Mockito.when(adapter.npmFolder()).thenReturn(baseDir);
    Mockito.when(adapter.projectBaseDirectory()).thenReturn(tmpDir.getRoot().toPath());
    FrontendTools tools = Mockito.mock(FrontendTools.class);
    // given: "node" stub that exits normally only if expected environment
    // set
    File fakeNode = new File(baseDir, "node");
    try (PrintWriter out = new PrintWriter(fakeNode)) {
        out.println("#!/bin/bash");
        out.println("[ x$NODE_OPTIONS == xexpected ]");
        out.println("exit $?");
    }
    Assert.assertTrue(fakeNode.setExecutable(true));
    Mockito.when(tools.getNodeExecutable()).thenReturn(fakeNode.getAbsolutePath());
    Map<String, String> environment = new HashMap<>();
    environment.put("NODE_OPTIONS", "expected");
    Mockito.when(tools.getWebpackNodeEnvironment()).thenReturn(environment);
    // then
    BuildFrontendUtil.runWebpack(adapter, tools);
// terminates successfully
}
Also used : HashMap(java.util.HashMap) TemporaryFolder(org.junit.rules.TemporaryFolder) File(java.io.File) FrontendTools(com.vaadin.flow.server.frontend.FrontendTools) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 44 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project pentaho-kettle by pentaho.

the class ResultFileTest method testGetRow.

@Test
public void testGetRow() throws KettleFileException, FileSystemException {
    File tempDir = new File(new TemporaryFolder().toString());
    FileObject tempFile = KettleVFS.createTempFile("prefix", "suffix", tempDir.toString());
    Date timeBeforeFile = Calendar.getInstance().getTime();
    ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, tempFile, "myOriginParent", "myOrigin");
    Date timeAfterFile = Calendar.getInstance().getTime();
    assertNotNull(resultFile);
    RowMetaInterface rm = resultFile.getRow().getRowMeta();
    assertEquals(7, rm.getValueMetaList().size());
    assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(0).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(1).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(2).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(3).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(4).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(5).getType());
    assertEquals(ValueMetaInterface.TYPE_DATE, rm.getValueMeta(6).getType());
    assertEquals(ResultFile.FILE_TYPE_GENERAL, resultFile.getType());
    assertEquals("myOrigin", resultFile.getOrigin());
    assertEquals("myOriginParent", resultFile.getOriginParent());
    assertTrue("ResultFile timestamp is created in the expected window", timeBeforeFile.compareTo(resultFile.getTimestamp()) <= 0 && timeAfterFile.compareTo(resultFile.getTimestamp()) >= 0);
    tempFile.delete();
    tempDir.delete();
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 45 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project pentaho-kettle by pentaho.

the class SFTPPutIntegrationIT method startServer.

@BeforeClass
public static void startServer() throws Exception {
    KettleEnvironment.init();
    folder = new TemporaryFolder();
    folder.create();
    server = SftpServer.createDefaultServer(folder);
    server.start();
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) BeforeClass(org.junit.BeforeClass)

Aggregations

TemporaryFolder (org.junit.rules.TemporaryFolder)88 File (java.io.File)33 Test (org.junit.Test)25 Before (org.junit.Before)24 BeforeClass (org.junit.BeforeClass)13 Path (java.nio.file.Path)7 URL (java.net.URL)6 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 UserState (alluxio.security.user.UserState)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 RocksDBPersistenceProvider (com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider)2 DocumentMetaData (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URISyntaxException (java.net.URISyntaxException)2 BdpDataPlanePlugin (org.batfish.bdp.BdpDataPlanePlugin)2 Batfish (org.batfish.main.Batfish)2 DefaultSafeModeManager (alluxio.master.DefaultSafeModeManager)1 InMemoryReferenceSequenceFile (au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile)1 SynchronousReferenceLookupAdapter (au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter)1