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);
}
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);
}
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));
}
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));
}
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);
}
Aggregations