use of org.graalvm.polyglot.Context in project graal by oracle.
the class VirtualizedFileSystemTest method testGetLastModified.
@Test
public void testGetLastModified() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final FileTime lastModifiedTime = file.getLastModifiedTime();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertNotNull(cfg.formatErrorMessage("Has last modified"), lastModifiedTime);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class VirtualizedFileSystemTest method testRegularFile.
@Test
public void testRegularFile() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean isFile = file.isRegularFile();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertTrue(cfg.formatErrorMessage("Is file"), isFile);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class VirtualizedFileSystemTest method isExecutable.
@Test
public void isExecutable() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean executable = file.isExecutable();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertFalse(cfg.formatErrorMessage("Is executable"), executable);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class VirtualizedFileSystemTest method testExists.
@Test
public void testExists() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile toCreate = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean exists = toCreate.exists();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertTrue(cfg.formatErrorMessage("File should exist"), exists);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class VirtualizedFileSystemTest method testWriteUsingStream.
@Test
public void testWriteUsingStream() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
final boolean canWrite = cfg.canWrite();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final String expectedContent = "0123456789";
final TruffleFile file = root.resolve(FILE_NEW_WRITE_STREAM);
try (BufferedWriter out = file.newBufferedWriter(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) {
out.write(expectedContent, 0, expectedContent.length());
}
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canWrite);
if (canRead) {
Assert.assertEquals(cfg.formatErrorMessage("Expected file size"), 10, file.size());
}
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canWrite);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
Aggregations