Search in sources :

Example 1 with FileConfiguration

use of org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration in project jbehave-core by jbehave.

the class FilePrintStreamFactoryBehaviour method shouldAllowOverrideOfDefaultConfiguration.

@Test
public void shouldAllowOverrideOfDefaultConfiguration() {
    // Given
    URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
    String storyPath = "org/jbehave/examples/trader/stories/my_given.story";
    FileConfiguration configuration = new FileConfiguration("ext");
    // When
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration);
    assertThat(factory.configuration(), equalTo(configuration));
    FileConfiguration newConfiguration = new FileConfiguration();
    factory.useConfiguration(newConfiguration);
    // Then
    assertThat(factory.configuration(), not(equalTo(configuration)));
    assertThat(factory.configuration().toString(), containsString(FileConfiguration.EXTENSION));
    assertThat(factory.configuration().toString(), containsString(FileConfiguration.RELATIVE_DIRECTORY));
}
Also used : FileConfiguration(org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration) StoryLocation(org.jbehave.core.io.StoryLocation) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(java.net.URL) Test(org.junit.Test)

Example 2 with FileConfiguration

use of org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration in project jbehave-core by jbehave.

the class FilePrintStreamFactoryBehaviour method shouldFailIfPrintStreamCannotBeCreated.

@Test(expected = PrintStreamCreationFailed.class)
public void shouldFailIfPrintStreamCannotBeCreated() {
    // Given
    URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
    String storyPath = "org/jbehave/examples/trader/stories/my_given.story";
    FileConfiguration configuration = new FileConfiguration("ext");
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration) {

        protected File outputDirectory() {
            return new File((String) null);
        }
    };
    // When
    factory.createPrintStream();
// Then fail as expected
}
Also used : FileConfiguration(org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration) StoryLocation(org.jbehave.core.io.StoryLocation) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 3 with FileConfiguration

use of org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration in project jbehave-core by jbehave.

the class FilePrintStreamFactoryBehaviour method assertThatOutputNameIs.

private void assertThatOutputNameIs(String storyPath, String outputName, FilePathResolver pathResolver) {
    // Given
    URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
    String extension = "ext";
    FileConfiguration configuration = (pathResolver != null ? new FileConfiguration("", extension, pathResolver) : new FileConfiguration(extension));
    // When
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration);
    // Then
    assertThat(factory.outputName(), equalTo(outputName));
}
Also used : FileConfiguration(org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration) StoryLocation(org.jbehave.core.io.StoryLocation) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(java.net.URL)

Example 4 with FileConfiguration

use of org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration in project jbehave-core by jbehave.

the class FilePrintStreamFactoryBehaviour method ensureOutputFileIsSame.

private void ensureOutputFileIsSame(URL codeLocation, String storyPath) {
    FileConfiguration configuration = new FileConfiguration("ext");
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration);
    factory.createPrintStream();
    File outputFile = factory.getOutputFile();
    String expected = new File(codeLocation.getFile()).getParent().replace('\\', '/') + "/" + configuration.getRelativeDirectory() + "/" + "org.jbehave.examples.trader.stories.my_given." + configuration.getExtension();
    assertThat(outputFile.toString().replace('\\', '/'), equalTo(expected));
}
Also used : FileConfiguration(org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration) StoryLocation(org.jbehave.core.io.StoryLocation) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File)

Example 5 with FileConfiguration

use of org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration in project jbehave-core by jbehave.

the class SpringStoryReporterBuilderBehaviour method shouldAllowUseOfGettersAndSetters.

@Test
public void shouldAllowUseOfGettersAndSetters() {
    SpringStoryReporterBuilder builder = new SpringStoryReporterBuilder();
    URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
    builder.setCodeLocation(codeLocation);
    assertThat(builder.getCodeLocation(), equalTo(codeLocation));
    List<Format> formats = asList(Format.CONSOLE, Format.HTML);
    builder.setFormats(formats);
    assertThat(builder.getFormats(), equalTo(formats));
    Keywords keywords = new LocalizedKeywords();
    builder.setKeywords(keywords);
    assertThat(builder.getKeywords(), equalTo(keywords));
    String relativeDirectory = "reports";
    builder.setRelativeDirectory(relativeDirectory);
    assertThat(builder.getRelativeDirectory(), equalTo(relativeDirectory));
    assertThat(builder.getOutputDirectory(), endsWith(relativeDirectory));
    Properties viewResources = new Properties();
    builder.setViewResources(viewResources);
    assertThat(builder.getViewResources(), equalTo(viewResources));
    boolean reportFailureTrace = true;
    builder.setReportFailureTrace(reportFailureTrace);
    assertThat(builder.isReportFailureTrace(), equalTo(reportFailureTrace));
    FilePathResolver pathResolver = new FileConfiguration().getPathResolver();
    builder.setPathResolver(pathResolver);
    assertThat(builder.getPathResolver(), equalTo(pathResolver));
}
Also used : FileConfiguration(org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration) FilePathResolver(org.jbehave.core.reporters.FilePrintStreamFactory.FilePathResolver) Format(org.jbehave.core.reporters.Format) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) URL(java.net.URL) Test(org.junit.Test)

Aggregations

FileConfiguration (org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration)5 URL (java.net.URL)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 StoryLocation (org.jbehave.core.io.StoryLocation)4 Test (org.junit.Test)3 File (java.io.File)2 Properties (java.util.Properties)1 Keywords (org.jbehave.core.configuration.Keywords)1 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)1 FilePathResolver (org.jbehave.core.reporters.FilePrintStreamFactory.FilePathResolver)1 Format (org.jbehave.core.reporters.Format)1