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