Search in sources :

Example 1 with StoryLocation

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

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

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

use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.

the class StoryReporterBuilderBehaviour method shouldBuildWithCustomReporterForAGivenFormat.

@Test
public void shouldBuildWithCustomReporterForAGivenFormat() throws IOException {
    // Given
    String storyPath = storyPath(MyStory.class);
    final FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(MyStory.class), storyPath));
    final StoryReporter txtReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    StoryReporterBuilder builder = new StoryReporterBuilder() {

        @Override
        public StoryReporter reporterFor(String storyPath, org.jbehave.core.reporters.Format format) {
            if (format == org.jbehave.core.reporters.Format.TXT) {
                factory.useConfiguration(new FilePrintStreamFactory.FileConfiguration("text"));
                return txtReporter;
            } else {
                return super.reporterFor(storyPath, format);
            }
        }
    };
    // When
    StoryReporter reporter = builder.withDefaultFormats().withFormats(TXT).build(storyPath);
    // Then
    assertThat(reporter, instanceOf(ConcurrentStoryReporter.class));
    StoryReporter delegate = ((ConcurrentStoryReporter) reporter).getDelegate();
    assertThat(delegate, instanceOf(DelegatingStoryReporter.class));
    Collection<StoryReporter> delegates = ((DelegatingStoryReporter) delegate).getDelegates();
    assertThat(delegates.size(), equalTo(2));
    assertThat(delegates.contains(txtReporter), is(true));
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) StoryLocation(org.jbehave.core.io.StoryLocation) Test(org.junit.Test)

Example 5 with StoryLocation

use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.

the class StoryReporterBuilderBehaviour method shouldBuildWithCustomReportersAsProvidedFormat.

@Test
public void shouldBuildWithCustomReportersAsProvidedFormat() throws IOException {
    // Given
    String storyPath = storyPath(MyStory.class);
    FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(MyStory.class), storyPath));
    StoryReporter txtReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    StoryReporter htmlReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    StoryReporterBuilder builder = new StoryReporterBuilder();
    // When
    StoryReporter reporter = builder.withReporters(txtReporter, htmlReporter).build(storyPath);
    // Then
    assertThat(reporter, instanceOf(ConcurrentStoryReporter.class));
    StoryReporter delegate = ((ConcurrentStoryReporter) reporter).getDelegate();
    assertThat(delegate, instanceOf(DelegatingStoryReporter.class));
    Collection<StoryReporter> delegates = ((DelegatingStoryReporter) delegate).getDelegates();
    assertThat(delegates.size(), equalTo(2));
    assertThat(delegates.contains(txtReporter), is(true));
    assertThat(delegates.contains(htmlReporter), is(true));
}
Also used : StoryLocation(org.jbehave.core.io.StoryLocation) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

StoryLocation (org.jbehave.core.io.StoryLocation)7 Test (org.junit.Test)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 FileConfiguration (org.jbehave.core.reporters.FilePrintStreamFactory.FileConfiguration)4 URL (java.net.URL)3 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)3 File (java.io.File)2 Properties (java.util.Properties)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Locale (java.util.Locale)1 Keywords (org.jbehave.core.configuration.Keywords)1 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)1