use of org.jbehave.core.io.rest.ResourceImporter in project jbehave-core by jbehave.
the class ImportToFilesystemBehaviour method canImportToFilesystem.
@Test
public void canImportToFilesystem() throws IOException {
// Given
ResourceIndexer indexer = mock(ResourceIndexer.class);
ResourceLoader loader = mock(ResourceLoader.class);
String rootURI = "http://wiki";
Map<String, Resource> index = new HashMap<>();
index.put("one", new Resource(rootURI + "/one"));
index.put("two", new Resource(rootURI + "/two"));
when(indexer.indexResources(rootURI)).thenReturn(index);
String text1 = "story text 1";
when(loader.loadResourceAsText(index.get("one").getURI())).thenReturn(text1);
String text2 = "story text 2";
when(loader.loadResourceAsText(index.get("two").getURI())).thenReturn(text2);
// When
String targetPath = "target/stories";
String targetExt = ".story";
ResourceImporter importer = new ImportToFilesystem(indexer, loader, targetPath, targetExt);
importer.importResources(rootURI);
// Then
File file1 = new File(targetPath + "/one" + targetExt);
assertThat(file1.exists(), equalTo(true));
assertThat(readFileToString(file1, StandardCharsets.UTF_8), equalTo(text1));
File file2 = new File(targetPath + "/two" + targetExt);
assertThat(file2.exists(), equalTo(true));
assertThat(readFileToString(file2, StandardCharsets.UTF_8), equalTo(text2));
}
use of org.jbehave.core.io.rest.ResourceImporter in project jbehave-core by jbehave.
the class ImportToFilesystemMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
try {
getLog().info("Importing to filesystem resources from REST root URI " + restRootURI);
ResourceImporter importer = createImporter();
importer.importResources(restRootURI);
} catch (Exception e) {
String message = "Failed to import to filesystem resources from REST root URI " + restRootURI;
getLog().warn(message);
throw new MojoExecutionException(message, e);
}
}
Aggregations