Search in sources :

Example 1 with ResourceIndexer

use of org.jbehave.core.io.rest.ResourceIndexer in project jbehave-core by jbehave.

the class RESTSteps method indexIsRetrieved.

@When("index is retrieved from $uri")
public void indexIsRetrieved(String uri) {
    ResourceIndexer indexer = resourceIndexer();
    index = indexer.indexResources(uri);
}
Also used : ResourceIndexer(org.jbehave.core.io.rest.ResourceIndexer) When(org.jbehave.core.annotations.When)

Example 2 with ResourceIndexer

use of org.jbehave.core.io.rest.ResourceIndexer in project jbehave-core by jbehave.

the class ExportFromFilesystemBehaviour method canExportFromFilesystem.

@Test
public void canExportFromFilesystem() throws IOException {
    // Given
    ResourceIndexer indexer = mock(ResourceIndexer.class);
    ResourceUploader uploader = mock(ResourceUploader.class);
    String rootURI = "http://wiki";
    String text1 = "story1";
    String text2 = "story2";
    String sourcePath = "target/stories";
    String sourceExt = ".story";
    String sourceSyntax = "jbehave/3.0";
    File file1 = new File(sourcePath + "/A_story" + sourceExt);
    write(text1, file1);
    File file2 = new File(sourcePath + "/Another_story" + sourceExt);
    write(text2, file2);
    Map<String, Resource> index = new HashMap<>();
    Resource aResource = new Resource(rootURI + "/A_story");
    index.put("A_story", aResource);
    Resource anotherResource = new Resource(rootURI + "/Another_story");
    index.put("Another_story", anotherResource);
    String includes = "**";
    when(indexer.indexResources(rootURI, sourcePath, sourceSyntax, includes)).thenReturn(index);
    // When
    ResourceExporter exporter = new ExportFromFilesystem(indexer, uploader, sourcePath, sourceExt, sourceSyntax, includes);
    exporter.exportResources(rootURI);
    // Then
    verify(uploader).uploadResource(aResource);
    verify(uploader).uploadResource(anotherResource);
}
Also used : ResourceUploader(org.jbehave.core.io.rest.ResourceUploader) HashMap(java.util.HashMap) Resource(org.jbehave.core.io.rest.Resource) ResourceExporter(org.jbehave.core.io.rest.ResourceExporter) File(java.io.File) ResourceIndexer(org.jbehave.core.io.rest.ResourceIndexer) Test(org.junit.Test)

Example 3 with ResourceIndexer

use of org.jbehave.core.io.rest.ResourceIndexer 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 4 with ResourceIndexer

use of org.jbehave.core.io.rest.ResourceIndexer in project jbehave-core by jbehave.

the class ImportToFilesystemMojoBehaviour method canImportToFilesystem.

@Test
public void canImportToFilesystem() throws IOException, MojoExecutionException, MojoFailureException {
    // Given
    final ResourceIndexer indexer = mock(ResourceIndexer.class);
    final 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";
    ImportToFilesystemMojo mojo = new ImportToFilesystemMojo() {

        @Override
        ResourceIndexer newResourceIndexer() {
            return indexer;
        }

        @Override
        ResourceLoader newResourceLoader() {
            return loader;
        }
    };
    mojo.restProvider = "wiki";
    mojo.restRootURI = rootURI;
    mojo.resourcesPath = targetPath;
    mojo.resourcesExt = targetExt;
    mojo.execute();
    // 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) 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 5 with ResourceIndexer

use of org.jbehave.core.io.rest.ResourceIndexer in project jbehave-core by jbehave.

the class ExportFromFilesystemMojo method createExporter.

private ResourceExporter createExporter() {
    ResourceIndexer indexer = newResourceIndexer();
    ResourceUploader uploader = newResourceUploader();
    getLog().info("Creating exporter from filesystem using REST provider " + restProvider + " with resourcesPath " + resourcesPath + ", resourcesExt " + resourcesExt + ", resourcesSyntax " + resourcesSyntax + " and resourcesIncludes " + resourcesIncludes);
    return new ExportFromFilesystem(indexer, uploader, resourcesPath, resourcesExt, resourcesSyntax, resourcesIncludes);
}
Also used : ResourceUploader(org.jbehave.core.io.rest.ResourceUploader) ExportFromFilesystem(org.jbehave.core.io.rest.filesystem.ExportFromFilesystem) ResourceIndexer(org.jbehave.core.io.rest.ResourceIndexer)

Aggregations

ResourceIndexer (org.jbehave.core.io.rest.ResourceIndexer)6 File (java.io.File)3 HashMap (java.util.HashMap)3 ResourceLoader (org.jbehave.core.io.ResourceLoader)3 Resource (org.jbehave.core.io.rest.Resource)3 Test (org.junit.Test)3 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)2 ResourceUploader (org.jbehave.core.io.rest.ResourceUploader)2 ImportToFilesystem (org.jbehave.core.io.rest.filesystem.ImportToFilesystem)2 When (org.jbehave.core.annotations.When)1 ResourceExporter (org.jbehave.core.io.rest.ResourceExporter)1 ResourceImporter (org.jbehave.core.io.rest.ResourceImporter)1 ExportFromFilesystem (org.jbehave.core.io.rest.filesystem.ExportFromFilesystem)1