use of org.junit.rules.TemporaryFolder in project iaf by ibissource.
the class StatusRecordingTransactionManagerTest method setup.
@Before
public void setup() throws IOException {
folder = new TemporaryFolder();
folder.create();
}
use of org.junit.rules.TemporaryFolder in project iaf by ibissource.
the class BtmJtaTransactionManagerTest method setup.
@Before
public void setup() throws IOException {
folder = new TemporaryFolder();
folder.create();
}
use of org.junit.rules.TemporaryFolder in project iaf by ibissource.
the class AmazonS3FileSystemTestHelper method _createFile.
@Override
public OutputStream _createFile(final String foldername, final String filename) throws IOException {
TemporaryFolder folder = new TemporaryFolder();
folder.create();
String fileName = folder.getRoot().getAbsolutePath() + "tempFile";
final File file = new File(fileName);
final FileOutputStream fos = new FileOutputStream(file);
final BufferedOutputStream bos = new BufferedOutputStream(fos);
FilterOutputStream filterOutputStream = new FilterOutputStream(bos) {
@Override
public void close() throws IOException {
super.close();
bos.close();
FileInputStream fis = new FileInputStream(file);
ObjectMetadata metaData = new ObjectMetadata();
metaData.setContentLength(file.length());
String filePath = foldername == null ? filename : foldername + "/" + filename;
s3Client.putObject(bucketName, filePath, fis, metaData);
fis.close();
file.delete();
}
};
return filterOutputStream;
}
use of org.junit.rules.TemporaryFolder in project iaf by ibissource.
the class LocalFileSystemActorTest method setUp.
@Override
public void setUp() throws Exception {
folder = new TemporaryFolder();
folder.create();
super.setUp();
}
use of org.junit.rules.TemporaryFolder in project flow by vaadin.
the class StaticFileServerTest method concurrentRequestsToJarResources_checksAreCorrect.
@Test
public void concurrentRequestsToJarResources_checksAreCorrect() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
fileServer.writeResponse = false;
Assert.assertTrue("Can not run concurrently with other test", StaticFileServer.openFileSystems.isEmpty());
final TemporaryFolder folder = TemporaryFolder.builder().build();
folder.create();
Path tempArchive = generateZipArchive(folder);
setupRequestURI("", "", "/frontend/.");
final URL folderResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/frontend");
Mockito.when(servletService.getStaticResource("/frontend/.")).thenReturn(folderResourceURL);
int THREADS = 5;
List<Callable<Result>> folderNotResource = IntStream.range(0, THREADS).mapToObj(i -> {
Callable<Result> callable = () -> {
try {
if (fileServer.serveStaticResource(request, response)) {
throw new IllegalArgumentException("Folder 'frontend' in jar should not be a static resource.");
}
} catch (Exception e) {
return new Result(e);
}
return new Result(null);
};
return callable;
}).collect(Collectors.toList());
ExecutorService executor = Executors.newFixedThreadPool(THREADS);
List<Future<Result>> futures = executor.invokeAll(folderNotResource);
List<String> exceptions = new ArrayList<>();
executor.shutdown();
for (Future<Result> resultFuture : futures) {
Result result = resultFuture.get();
if (result.exception != null) {
exceptions.add(result.exception.getMessage());
}
}
Assert.assertTrue("There were exceptions in concurrent requests {" + exceptions + "}", exceptions.isEmpty());
Assert.assertFalse("Folder URI should have been cleared", StaticFileServer.openFileSystems.containsKey(folderResourceURL.toURI()));
try {
FileSystems.getFileSystem(folderResourceURL.toURI());
Assert.fail("FileSystem for folder resource should be closed");
} catch (FileSystemNotFoundException fsnfe) {
// This should happen as we should not have an open FileSystem here.
}
setupRequestURI("", "", "/file.txt");
final URL fileResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/file.txt");
Mockito.when(servletService.getStaticResource("/file.txt")).thenReturn(fileResourceURL);
List<Callable<Result>> fileIsResource = IntStream.range(0, THREADS).mapToObj(i -> {
Callable<Result> callable = () -> {
try {
if (!fileServer.serveStaticResource(request, response)) {
throw new IllegalArgumentException("File 'file.txt' inside jar should be a static resource.");
}
} catch (Exception e) {
return new Result(e);
}
return new Result(null);
};
return callable;
}).collect(Collectors.toList());
executor = Executors.newFixedThreadPool(THREADS);
futures = executor.invokeAll(fileIsResource);
exceptions = new ArrayList<>();
executor.shutdown();
for (Future<Result> resultFuture : futures) {
Result result = resultFuture.get();
if (result.exception != null) {
exceptions.add(result.exception.getMessage());
}
}
Assert.assertTrue("There were exceptions in concurrent requests {" + exceptions + "}", exceptions.isEmpty());
Assert.assertFalse("URI should have been cleared", fileServer.openFileSystems.containsKey(fileResourceURL.toURI()));
try {
FileSystems.getFileSystem(fileResourceURL.toURI());
Assert.fail("FileSystem for file resource should be closed");
} catch (FileSystemNotFoundException fsnfe) {
// This should happen as we should not have an open FileSystem here.
}
folder.delete();
}
Aggregations