diff --git a/distribution/src/site/content/tabular-parameters.html b/distribution/src/site/content/tabular-parameters.html
index 2a7c0d5af..268b9cb1f 100755
--- a/distribution/src/site/content/tabular-parameters.html
+++ b/distribution/src/site/content/tabular-parameters.html
@@ -372,16 +372,27 @@
Loading tabular parameter from an external resource
Inlined properties can be applied to the tabular parameter loaded from an external
-resource
+resource, though keep in mind that parsing related properties like headerSeparator,
+valueSeparator and ignorableSeparator must be placed inside the external
+resource they belong to.
+org/jbehave/examples/trader/stories/traders.table
+
+{headerSeparator=!,valueSeparator=!}
+!name !rank !
+!Larry!Stooge 3!
+!Moe !Stooge 1!
+!Curly!Stooge 2!
+
+
If the external tabular parameters contains transformers, they will be applied immediately after the resource is loaded. Consequently, transformers from the current story/scenario will be applied subsequently.
Scenario:
@@ -395,7 +406,6 @@ Loading tabular parameter from an external resource
{transformer=REPLACING, replacing=url1, replacement=url2}
|urls |
|https://www.url1.com |
-
We need to enable theExamplesTable parameter converter to find
the resource with the appropriate resource loader configured via the
Then the trader is alerted with
Examples:
-{transfomer=LANDSCAPE, headerSeparator=!, valueSeparator=!}
org/jbehave/examples/core/stories/trades_transposed.table
diff --git a/examples/core/src/main/java/org/jbehave/examples/core/stories/trades_transposed.table b/examples/core/src/main/java/org/jbehave/examples/core/stories/trades_transposed.table
index 987d5fa8e..3c7ca4864 100755
--- a/examples/core/src/main/java/org/jbehave/examples/core/stories/trades_transposed.table
+++ b/examples/core/src/main/java/org/jbehave/examples/core/stories/trades_transposed.table
@@ -1,3 +1,4 @@
+{transformer=FROM_LANDSCAPE, headerSeparator=!, valueSeparator=!}
!symbol !STK1!STK1!STK1!
!threshold!15.0!15.0!15.0!
!price !5.0 !11.0!16.0!
diff --git a/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java b/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java
index e163b452b..2126841e0 100755
--- a/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java
+++ b/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java
@@ -1,5 +1,7 @@
package org.jbehave.core.model;
+import static org.apache.commons.lang3.Validate.isTrue;
+
import java.util.Deque;
import org.jbehave.core.configuration.Configuration;
@@ -92,6 +94,7 @@ public ExamplesTable createExamplesTable(String input) {
Deque properties = tablePropertiesQueue.getProperties();
if (!isTable(tableAsString, properties.peekFirst()) && !tableAsString.isEmpty()) {
+ checkResourceProperties(input, properties.peekFirst());
String loadedTable = resourceLoader.loadResourceAsText(tableAsString.trim());
tablePropertiesQueue = tableParsers.parseProperties(loadedTable);
Deque target = tablePropertiesQueue.getProperties();
@@ -110,6 +113,14 @@ public ExamplesTable createExamplesTable(String input) {
tableTransformers, tableTransformerMonitor);
}
+ private void checkResourceProperties(String table, TableProperties properties) {
+ isTrue(keywords.examplesTableHeaderSeparator().equals(properties.getHeaderSeparator())
+ && keywords.examplesTableValueSeparator().equals(properties.getValueSeparator())
+ && keywords.examplesTableIgnorableSeparator().equals(properties.getIgnorableSeparator()),
+ "Examples table parsing separators are not allowed to be applied outside of external table they "
+ + "belong to:%n%s", table);
+ }
+
protected boolean isTable(String table, TableProperties properties) {
String headerSeparator = properties == null ? keywords.examplesTableHeaderSeparator()
: properties.getHeaderSeparator();
diff --git a/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java b/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java
index 36cc06ab6..a1f4ac70f 100755
--- a/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java
+++ b/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java
@@ -2,12 +2,16 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.ResourceLoader;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
class ExamplesTableFactoryBehaviour {
@@ -142,4 +146,25 @@ void shouldLoadAndProperlyApplyTransformersForExamplesTableFromResourceInput() {
+ lineFromFirstInnerTransformer
+ lineFromSecondInnerTransformer));
}
+
+ @ValueSource(strings = {
+ "headerSeparator",
+ "valueSeparator",
+ "ignorableSeparator"
+ })
+ @ParameterizedTest
+ void shouldFailIfExamplesTableParsingSeparatorsArePlacesOutsideOfExternalTableTheyBelongTo(String separator) {
+ // Given
+ ExamplesTableFactory factory = new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers());
+
+ // When
+ String tableAsString = String.format("{%s=!}\ndata.table", separator);
+ IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
+ () -> factory.createExamplesTable(tableAsString));
+
+ // Then
+ String message = String.format("Examples table parsing separators are not allowed to be applied outside of "
+ + "external table they belong to:%n{%s=!}\ndata.table", separator);
+ assertEquals(message, thrown.getMessage());
+ }
}