Search in sources :

Example 1 with ResourceImporter

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));
}
Also used : ResourceLoader(org.jbehave.core.io.ResourceLoader) HashMap(java.util.HashMap) ImportToFilesystem(org.jbehave.core.io.rest.filesystem.ImportToFilesystem) ResourceImporter(org.jbehave.core.io.rest.ResourceImporter) Resource(org.jbehave.core.io.rest.Resource) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) File(java.io.File) ResourceIndexer(org.jbehave.core.io.rest.ResourceIndexer) Test(org.junit.Test)

Example 2 with ResourceImporter

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ResourceImporter(org.jbehave.core.io.rest.ResourceImporter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

ResourceImporter (org.jbehave.core.io.rest.ResourceImporter)2 File (java.io.File)1 HashMap (java.util.HashMap)1 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 ResourceLoader (org.jbehave.core.io.ResourceLoader)1 Resource (org.jbehave.core.io.rest.Resource)1 ResourceIndexer (org.jbehave.core.io.rest.ResourceIndexer)1 ImportToFilesystem (org.jbehave.core.io.rest.filesystem.ImportToFilesystem)1 Test (org.junit.Test)1