Skip to content

Commit

Permalink
Added asserts to web steps mandatory columns
Browse files Browse the repository at this point in the history
  • Loading branch information
xsmrcek authored and Daniel.Smrcek committed Nov 2, 2019
1 parent 850829f commit 51e7580
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.apache.commons.lang3.StringUtils.prependIfMissing;
import static org.apache.commons.lang3.StringUtils.removeEnd;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType;
import static java.util.Arrays.asList;
import static java.lang.String.join;
Expand All @@ -13,10 +14,13 @@
import static org.jbehavesupport.core.web.WebScreenshotType.FAILED;

import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.jbehavesupport.core.TestContext;
import org.jbehavesupport.core.expression.ExpressionEvaluatingParameter;
import org.jbehavesupport.core.verification.VerifierNames;
Expand Down Expand Up @@ -130,6 +134,7 @@ public void openUrl(String application, String path, ExamplesTable queryParamete

@When("on [$page] page these actions are performed:$actionTable")
public void performActions(String page, ExamplesTable actionTable) {
assertMandatoryColumns(actionTable, Arrays.asList(ELEMENT, ACTION));
for (Row actionRow : actionTable.getRowsAsParameters()) {
Map<String, String> actionValues = actionRow.values();

Expand All @@ -151,6 +156,8 @@ public void performActions(String page, ExamplesTable actionTable) {
@Given("on [$page] page these values are saved:$table")
@Then("on [$page] page these values are saved:$table")
public void storePropertiesInContext(String page, ExamplesTable table) {
assertMandatoryColumns(table, Arrays.asList(ELEMENT, PROPERTY, ExampleTableConstraints.ALIAS));

for (Row row : table.getRowsAsParameters()) {
Map<String, String> values = row.values();
Object value = resolvePropertyValue(page, values);
Expand All @@ -161,6 +168,8 @@ public void storePropertiesInContext(String page, ExamplesTable table) {

@Then("on [$page] page these conditions are verified:$table")
public void verifyProperties(String page, ExamplesTable table) {
assertMandatoryColumns(table, Arrays.asList(ELEMENT, PROPERTY, ExampleTableConstraints.DATA));

for (Row row : table.getRowsAsParameters()) {
Map<String, String> values = row.values();

Expand Down Expand Up @@ -350,4 +359,13 @@ private String getLastOpenedWindowHandler() {
return handles.stream().skip(handles.size() - 1).findFirst().get();
}

private void assertMandatoryColumns(ExamplesTable examplesTable, List<String> expectedColumns) {
SoftAssertions softly = new SoftAssertions();
expectedColumns.forEach(key -> {
if (examplesTable.getHeaders().stream().noneMatch(column -> column.equals(key))) {
softly.fail("Examples table must contain column'" + key + "'");
}
});
softly.assertAll();
}
}

0 comments on commit 51e7580

Please sign in to comment.