use of org.jbehave.core.io.ResourceLoader in project jbehave-core by jbehave.
the class ExamplesTableFactoryBehaviour method shouldCreateExamplesTableFromResourceInput.
@Test
public void shouldCreateExamplesTableFromResourceInput() {
// Given
ResourceLoader resourceLoader = mock(ResourceLoader.class);
ExamplesTableFactory factory = new ExamplesTableFactory(resourceLoader, new TableTransformers());
// When
String resourcePath = "/path/to/table";
when(resourceLoader.loadResourceAsText(resourcePath)).thenReturn(TABLE_AS_STRING);
ExamplesTable examplesTable = factory.createExamplesTable(resourcePath);
// Then
assertThat(examplesTable.asString(), equalTo(TABLE_AS_STRING));
}
use of org.jbehave.core.io.ResourceLoader in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldCreateJsonFromResourceInput.
@Test
public void shouldCreateJsonFromResourceInput() {
// Given
ResourceLoader resourceLoader = mock(ResourceLoader.class);
ParameterConverters.JsonFactory factory = new ParameterConverters.JsonFactory(resourceLoader);
// When
String resourcePath = "/path/to/json";
when(resourceLoader.loadResourceAsText(resourcePath)).thenReturn(JSON_AS_STRING);
MyJsonDto json = (MyJsonDto) factory.createJson(resourcePath, MyJsonDto.class);
// Then
assertThat(new Gson().toJson(json), equalTo(JSON_AS_STRING));
}
use of org.jbehave.core.io.ResourceLoader 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.ResourceLoader 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.ResourceLoader in project jbehave-core by jbehave.
the class RESTSteps method storyIsLoaded.
@When("story $name text contains '$text'")
public void storyIsLoaded(String name, String text) {
ResourceLoader loader = resourceLoader();
Resource resource = index.get(name);
String asText = loader.loadResourceAsText(resource.getURI());
assertThat(asText, containsString(text));
}
Aggregations