Search in sources :

Example 1 with Resource

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

the class RESTSteps method storyIsUploaded.

@When("story $name is uploaded appending '$text'")
public void storyIsUploaded(String name, String text) {
    ResourceUploader uploader = resourceupLoader();
    Resource resource = index.get(name);
    resource.setContent(resource.getContent() + " " + text);
    uploader.uploadResource(resource);
}
Also used : ResourceUploader(org.jbehave.core.io.rest.ResourceUploader) Resource(org.jbehave.core.io.rest.Resource) When(org.jbehave.core.annotations.When)

Example 2 with Resource

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

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

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

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

the class IndexFromRedmine method createIndexFromEntity.

protected Map<String, Resource> createIndexFromEntity(String rootURI, String entity) {
    Collection<Page> pages = parse(entity);
    Map<String, Resource> index = new HashMap<>();
    for (Page page : pages) {
        String parentName = (page.parent != null ? resolveName(page.parent.title) : null);
        String uri = format(PAGE_URI, rootURI, page.title);
        Resource resource = new Resource(uri, resolveName(page.title), parentName);
        index.put(resource.getName(), resource);
    }
    return index;
}
Also used : HashMap(java.util.HashMap) Resource(org.jbehave.core.io.rest.Resource)

Aggregations

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