Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski committed Nov 7, 2024
1 parent 8d420ff commit 2e20730
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -253,10 +254,6 @@ public Properties getProperties() {
return lastTableProperties().getProperties();
}

public String getPropertiesAsString() {
return lastTableProperties().getPropertiesAsString();
}

private String replaceNamedParameters(String text) {
return parameterControls.replaceAllDelimitedNames(text, namedParameters);
}
Expand Down Expand Up @@ -369,12 +366,10 @@ public String asString() {
return EMPTY_VALUE;
}
StringBuilder sb = new StringBuilder();
for (TableProperties properties : tablePropertiesQueue) {
String propertiesAsString = properties.getPropertiesAsString();
if (!propertiesAsString.isEmpty()) {
sb.append(properties.asString()).append(lastTableProperties().getRowSeparator());
}
}
tablePropertiesQueue.stream().filter(Predicate.not(TableProperties::isEmpty))
.map(TableProperties::asString)
.forEach(props -> sb.append(props)
.append(lastTableProperties().getRowSeparator()));
sb.append(ExamplesTableStringBuilder.buildExamplesTableString(lastTableProperties(), getHeaders(),
tableRows.getRows()));

Expand Down Expand Up @@ -409,6 +404,9 @@ public enum Decorator {
private static final String EQUAL = "=";
private static final String PIPE_REGEX = "\\|";

private static final char PROPERTIES_OPEN_CHAR = '{';
private static final char PROPERTIES_CLOSE_CHAR = '}';

private static final String DECORATORS_REGEX = Stream.of(Decorator.values())
.map(Decorator::name)
.collect(Collectors.joining("|", "(", ")"));
Expand Down Expand Up @@ -477,7 +475,7 @@ private String decoratePropertyValue(String value, Decorator decorator) {
}

public String asString() {
return String.format("{%s}", propertiesAsString);
return PROPERTIES_OPEN_CHAR + propertiesAsString + PROPERTIES_CLOSE_CHAR;
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -555,8 +553,11 @@ public Properties getProperties() {
return properties;
}

public String getPropertiesAsString() {
return propertiesAsString;
public boolean isEmpty() {
return propertiesAsString.replace(PROPERTIES_OPEN_CHAR, Character.MIN_VALUE)
.replace(PROPERTIES_CLOSE_CHAR, Character.MIN_VALUE)
.trim()
.isEmpty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Deque;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.Keywords;
import org.jbehave.core.i18n.LocalizedKeywords;
Expand Down Expand Up @@ -108,7 +107,8 @@ public ExamplesTable createExamplesTable(String input) {

String table = tablePropertiesQueue.getTable();
if (isExternal(tablePropertiesQueue.getTable(), headProperties)) {
table = target.stream().map(TableProperties::asString)
table = target.stream().filter(t -> !t.isEmpty())
.map(TableProperties::asString)
.collect(Collectors.joining(
System.lineSeparator(),
"",
Expand All @@ -122,7 +122,7 @@ public ExamplesTable createExamplesTable(String input) {
tablePropertiesQueue.getTable(), tableParsers, target, tableTransformerMonitor);
tablePropertiesQueue = tableParsers.parseProperties(loadedTable);
TableProperties parsedProperties = tablePropertiesQueue.getProperties().getFirst();
if (StringUtils.isEmpty(parsedProperties.getPropertiesAsString())) {
if (parsedProperties.isEmpty()) {
TableProperties newProperties = new TableProperties("", keywords, parameterConverters);
newProperties.overrideSeparatorsFrom(target.peekLast());
target.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ void shouldLoadTableFromPathAndPreserveSeparators() {
ensureRowContentIs(rows, 2, asList("STK1", "15.0", "16.0", "ON"));
}

@Test
void shouldLoadTableFromAnotherTableContainingTableReferenceAndNoTableProperties() {
// Given
ExamplesTableFactory factory = new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers());

// When
ExamplesTable table = factory.createExamplesTable("data-simple-reference.table");

// Then
assertThat(table.getHeaders(), equalTo(asList("Language")));
List<Map<String, String>> rows = table.getRows();
assertThat(rows.size(), equalTo(1));
ensureRowContentIs(rows, 0, asList("Java"));
}

@Test
void shouldLoadTableFromAnotherTableContainingTableReference() {
// Given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jbehave.core.model;

import static org.jbehave.core.model.ExamplesTable.TableProperties;
import static org.jbehave.core.model.ExamplesTable.TablePropertiesQueue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -12,6 +10,8 @@

import org.jbehave.core.i18n.LocalizedKeywords;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.model.ExamplesTable.TableProperties;
import org.jbehave.core.model.ExamplesTable.TablePropertiesQueue;
import org.jbehave.core.steps.ParameterControls;
import org.jbehave.core.steps.ParameterConverters;
import org.junit.jupiter.api.Test;
Expand All @@ -30,14 +30,14 @@ void shouldApplyTransformers() {
String lineFromSecondTransformer = "\n!value2!";
String tableTransformed = table + lineFromFirstTransformer + lineFromSecondTransformer;
String firstTransformerName = "FIRST_TRANSFORMER";
String firstPropertiesAsString = String.format("transformer=%s, property=any_property1, valueSeparator=!",
String firstPropertiesAsString = String.format("{transformer=%s, property=any_property1, valueSeparator=!}",
firstTransformerName);
String secondTransformerName = "SECOND_TRANSFORMER";
String secondPropertiesAsString = String.format(
"transformer=%s, property=any_property2", secondTransformerName);
"{transformer=%s, property=any_property2}", secondTransformerName);
TablePropertiesQueue tablePropertiesQueue = TABLE_PARSERS.parseProperties(
"{" + firstPropertiesAsString + "}"
+ "{" + secondPropertiesAsString + "}"
firstPropertiesAsString
+ secondPropertiesAsString
+ "\n"
+ table);
Deque<TableProperties> tableProperties = tablePropertiesQueue.getProperties();
Expand All @@ -53,13 +53,13 @@ void shouldApplyTransformers() {

assertEquals(tableTransformed, output);
verify(tableTransformerMonitor).beforeTransformerApplying(eq(firstTransformerName), argThat(
p -> p.getPropertiesAsString().equals(firstPropertiesAsString)), eq(table));
p -> p.asString().equals(firstPropertiesAsString)), eq(table));
verify(tableTransformerMonitor).afterTransformerApplying(eq(firstTransformerName), argThat(p ->
p.getPropertiesAsString().equals(firstPropertiesAsString)), eq(table + lineFromFirstTransformer));
p.asString().equals(firstPropertiesAsString)), eq(table + lineFromFirstTransformer));
verify(tableTransformerMonitor).beforeTransformerApplying(eq(secondTransformerName), argThat(p ->
p.getPropertiesAsString().equals(secondPropertiesAsString)), eq(table + lineFromFirstTransformer));
p.asString().equals(secondPropertiesAsString)), eq(table + lineFromFirstTransformer));
verify(tableTransformerMonitor).afterTransformerApplying(eq(secondTransformerName), argThat(
p -> p.getPropertiesAsString().equals(secondPropertiesAsString)),
p -> p.asString().equals(secondPropertiesAsString)),
eq(table + lineFromFirstTransformer + lineFromSecondTransformer));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data-simple.table
2 changes: 2 additions & 0 deletions jbehave-core/src/test/resources/data-simple.table
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
|Language|
|Java |

0 comments on commit 2e20730

Please sign in to comment.