Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ jobs:
shell: bash
run: docker rmi "testlum:${VERSION}" || true

- name: Clean Up Docker
shell: bash
run: docker system prune -af

- name: Build Testlum Docker image
shell: bash
working-directory: testlum-core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.List;
import java.util.function.Predicate;

import static com.knubisoft.comparator.util.LogMessage.CONTENT_DOES_MATCH;
import com.knubisoft.comparator.util.LogMessage;

public class Comparator extends AbstractObjectComparator<String> {

Expand Down Expand Up @@ -51,7 +51,7 @@ public void compare(final String expected, final String actual) {
);

if (handlers.stream().noneMatch(handler -> handler.test(request))) {
throw new MatchException(CONTENT_DOES_MATCH);
throw new MatchException(LogMessage.CONTENT_DOES_MATCH);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.List;
import java.util.Map;

import static com.knubisoft.comparator.ErrorHelper.raise;

public class JsonComparator extends AbstractObjectComparator<JsonNode> {

public JsonComparator(final Mode mode) {
Expand All @@ -25,12 +23,12 @@ public void compare(final JsonNode expected, final JsonNode actual) throws Match
JsonNodeType actualType = actual.getNodeType();

if (expectedType == JsonNodeType.BOOLEAN && actualType == JsonNodeType.BOOLEAN) {
raise(expected.asBoolean() != actual.asBoolean(),
ErrorHelper.raise(expected.asBoolean() != actual.asBoolean(),
"Property [" + expected.asText() + "] is not equal to [" + actual.asText() + "]");

} else if (expectedType == JsonNodeType.NUMBER && actualType == JsonNodeType.NUMBER) {

raise(!new BigDecimal(expected.asText()).equals(new BigDecimal(actual.asText())),
ErrorHelper.raise(!new BigDecimal(expected.asText()).equals(new BigDecimal(actual.asText())),
"Property [" + expected.asText() + "] is not equal to [" + actual.asText() + "]");

} else if (expectedType == JsonNodeType.STRING && actualType == JsonNodeType.STRING
Expand All @@ -49,7 +47,7 @@ public void compare(final JsonNode expected, final JsonNode actual) throws Match
iteratorToList(actual.properties().iterator()));

} else {
raise(expected.getNodeType() != actual.getNodeType(),
ErrorHelper.raise(expected.getNodeType() != actual.getNodeType(),
"Expected [" + expected.getNodeType() + "] but was [" + actual.getNodeType() + "]");
}
}
Expand All @@ -62,7 +60,7 @@ private <T> List<T> iteratorToList(final Iterator<T> iterator) {
}

private void compareElements(final List<JsonNode> expected, final List<JsonNode> actual) throws MatchException {
raise(expected.size() != actual.size(),
ErrorHelper.raise(expected.size() != actual.size(),
"Expected array length is [" + expected.size() + "] actual [" + actual.size() + "]");

for (int i = 0, size = expected.size(); i < size; i++) {
Expand All @@ -75,7 +73,7 @@ private void compareElements(final List<JsonNode> expected, final List<JsonNode>

private void compareFields(final List<Map.Entry<String, JsonNode>> expected,
final List<Map.Entry<String, JsonNode>> actual) throws MatchException {
mode.onStrict(() -> raise(expected.size() != actual.size(),
mode.onStrict(() -> ErrorHelper.raise(expected.size() != actual.size(),
"Difference in properties or count Missing"));

for (Map.Entry<String, JsonNode> expectedEntry : expected) {
Expand All @@ -87,7 +85,7 @@ private void compareFields(final List<Map.Entry<String, JsonNode>> expected,

private void validateActualValue(final Map.Entry<String, JsonNode> expectedEntry, final JsonNode actualValue) {
if (actualValue == null) {
raise("Property with name [" + expectedEntry.getKey() + "] not found");
ErrorHelper.raise("Property with name [" + expectedEntry.getKey() + "] not found");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import java.util.Objects;
import java.util.regex.Pattern;

import static com.knubisoft.comparator.ErrorHelper.raise;
import static com.knubisoft.comparator.constant.CommonConstant.*;
import static com.knubisoft.comparator.constant.RegexpConstant.*;
import static java.lang.String.format;
import com.knubisoft.comparator.constant.RegexpConstant;

public class StringComparator extends AbstractObjectComparator<String> {

Expand All @@ -34,7 +31,7 @@ public void compare(final String expected, final String actual) {
} else if (result instanceof ConditionComparison) {
conditionComparison(actual, (ConditionComparison) result);
} else {
raise(format(LogMessage.PROPERTY_NOT_EQUAL, expected, actual));
ErrorHelper.raise(String.format(LogMessage.PROPERTY_NOT_EQUAL, expected, actual));
}
}
}
Expand All @@ -43,7 +40,8 @@ public void compare(final String expected, final String actual) {
private void patternComparison(final String actual, final PatternComparison result) {
String aliasOrRawPattern = result.getPattern();
Pattern pattern = Alias.getPattern(aliasOrRawPattern);
raise(!pattern.matcher(actual).matches(), format(LogMessage.PROPERTY_NOT_MATCH, actual, aliasOrRawPattern));
ErrorHelper.raise(!pattern.matcher(actual).matches(),
String.format(LogMessage.PROPERTY_NOT_MATCH, actual, aliasOrRawPattern));
}

private void treeComparison(final String actual, final TreeComparison result) {
Expand All @@ -54,13 +52,13 @@ private void conditionComparison(final String actual, final ConditionComparison
Operator operator = Operator.getOperatorFromExpression(conditionComparison.getExpression());
String expected = conditionComparison.getExpression().replace(operator.getOperatorSign(), CommonConstant.EMPTY);
boolean result = conditionComparison.getConditionalComparator().compare(actual, expected, operator);
raise(!result, format(LogMessage.CONDITIONALS_DO_NOT_MATCH, actual, expected));
ErrorHelper.raise(!result, String.format(LogMessage.CONDITIONALS_DO_NOT_MATCH, actual, expected));
}


private ComparisonResult extractAction(final String v) {
if (v.length() > EXTRACT_ACTION_THREE) {
if (v.startsWith(T_LEFT_BRACKET) && v.endsWith(RIGHT_BRACKET)) {
if (v.length() > CommonConstant.EXTRACT_ACTION_THREE) {
if (v.startsWith(CommonConstant.T_LEFT_BRACKET) && v.endsWith(CommonConstant.RIGHT_BRACKET)) {
return new TreeComparison(v.substring(2, v.length() - 1));
} else {
return getComparisonResult(v);
Expand All @@ -70,17 +68,17 @@ private ComparisonResult extractAction(final String v) {
}

private ComparisonResult getComparisonResult(final String expression) {
if (P_BRACKETS.matcher(expression).find()) {
if (RegexpConstant.P_BRACKETS.matcher(expression).find()) {
return getPatternComparison(expression);
} else if (ALL_EXPRESSION_IN_C_BRACKETS.matcher(expression).matches()) {
} else if (RegexpConstant.ALL_EXPRESSION_IN_C_BRACKETS.matcher(expression).matches()) {
return getConditionComparison(expression.substring(2, expression.length() - 1));
} else {
return new Empty();
}
}

private PatternComparison getPatternComparison(final String expression) {
if (ALL_EXPRESSION_IN_P_BRACKETS.matcher(expression).matches()) {
if (RegexpConstant.ALL_EXPRESSION_IN_P_BRACKETS.matcher(expression).matches()) {
return new PatternComparison(expression.substring(2, expression.length() - 1));
} else {
return new PatternComparison(Parser.parseAllPBracketsToRegexp(expression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;
import java.util.Objects;

import static com.knubisoft.comparator.util.LogMessage.CONTENT_DOES_MATCH;
import com.knubisoft.comparator.util.LogMessage;

public class StringLinesComparator extends AbstractObjectComparator<String> {

Expand All @@ -22,7 +22,7 @@ public void compare(final String expected, final String actual) throws MatchExce
List<String> actualLines = getLines(actual);

if (expectedLines.size() != actualLines.size()) {
throw new MatchException(CONTENT_DOES_MATCH);
throw new MatchException(LogMessage.CONTENT_DOES_MATCH);
}

for (int i = 0, size = expectedLines.size(); i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.Objects;
import java.util.Set;

import static com.knubisoft.comparator.ErrorHelper.raise;

public class XMLComparator extends AbstractObjectComparator<Node> {

public XMLComparator(final Mode mode) {
Expand All @@ -20,7 +18,7 @@ public XMLComparator(final Mode mode) {

@Override
public void compare(final Node expected, final Node actual) throws MatchException {
raise(!Objects.equals(expected.getNodeName(), actual.getNodeName()),
ErrorHelper.raise(!Objects.equals(expected.getNodeName(), actual.getNodeName()),
"Expected node name [" + expected.getNodeName() + "] but was [" + actual.getNodeName() + "]");

if (expected.hasAttributes()) {
Expand All @@ -33,25 +31,26 @@ public void compare(final Node expected, final Node actual) throws MatchExceptio

private void compareChildNodes(final Node expected, final Node actual) throws MatchException {
if (expected.hasChildNodes()) {
raise(!actual.hasChildNodes(), "Child nodes not found");
ErrorHelper.raise(!actual.hasChildNodes(), "Child nodes not found");
compareNodesList(expected.getChildNodes(), actual.getChildNodes());
}
mode.onStrict(() -> raise(actual.hasChildNodes(), "Additional child nodes found"));
mode.onStrict(() -> ErrorHelper.raise(actual.hasChildNodes(), "Additional child nodes found"));
}


private void compareNodesList(final NodeList expected, final NodeList actual) throws MatchException {
raise(expected.getLength() != actual.getLength(), "Child nodes length not equals");
ErrorHelper.raise(expected.getLength() != actual.getLength(), "Child nodes length not equals");

for (int i = 0, length = expected.getLength(); i < length; i++) {
compare(expected.item(i), actual.item(i));
}
}

private void compareNodes(final Node expected, final Node actual) throws MatchException {
raise(!actual.hasAttributes(), "Attributes not found in actual document for node " + actual.getNodeName());
ErrorHelper.raise(!actual.hasAttributes(),
"Attributes not found in actual document for node " + actual.getNodeName());
compareAttributes(expected.getAttributes(), actual.getAttributes());
mode.onStrict(() -> raise(actual.hasAttributes(),
mode.onStrict(() -> ErrorHelper.raise(actual.hasAttributes(),
"Additional attributes found in actual document for node " + actual.getNodeName()));
}

Expand All @@ -63,7 +62,7 @@ private void compareAttributes(final NamedNodeMap expected, final NamedNodeMap a

for (Map.Entry<String, String> expectedEntry : expectedMap.entrySet()) {
String actualValue = actualMap.get(expectedEntry.getKey());
raise(actualValue == null, "Attribute with name " + expectedMap.keySet());
ErrorHelper.raise(actualValue == null, "Attribute with name " + expectedMap.keySet());
new StringComparator(mode).compare(expectedEntry.getValue(), actualValue);
}
}
Expand All @@ -75,8 +74,8 @@ private void validateAttributesLength(final NamedNodeMap expected,
if (expected.getLength() != actual.getLength()) {
Set<String> props = expectedMap.keySet();
props.removeAll(actualMap.keySet());
raise(!props.isEmpty(), "Attributes length not match. Missing property");
raise("Attributes length not match. Found unexpected property " + String.join(", ", props));
ErrorHelper.raise(!props.isEmpty(), "Attributes length not match. Missing property");
ErrorHelper.raise("Attributes length not match. Found unexpected property " + String.join(", ", props));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Arrays;
import java.util.regex.Pattern;

import static com.knubisoft.comparator.constant.RegexpConstant.*;
import com.knubisoft.comparator.constant.RegexpConstant;

@Getter
@RequiredArgsConstructor
Expand All @@ -29,9 +29,9 @@ public enum Alias {
+ "//(?:(?:[a-zA-Z0-9$\\-_.+!*'()"
+ ",;?&=]|(?:%[a-fA-F0-9]{2})){1,64}(?::(?:[a-zA-Z0-9$\\-_"
+ ".+!*'(),;?&=]|%[a-fA-F0-9]{2}){1,25})?@)?)?"
+ "(?:" + DOMAIN_NAME + ")"
+ "(?:" + RegexpConstant.DOMAIN_NAME + ")"
+ "(?::\\d{1,5})?)"
+ "(/(?:(?:[" + GOOD_IRI_CHAR + ";/?:@&=#~"
+ "(/(?:(?:[" + RegexpConstant.GOOD_IRI_CHAR + ";/?:@&=#~"
+ "\\-.+!*'(),_])|(?:%[a-fA-F0-9]{2}))*)?"
+ "(?:\\b|$)")),
UUID("uuid",
Expand All @@ -42,7 +42,7 @@ public enum Alias {
D_M_Y_DASH("d-m-y", Pattern.compile("((?:0[1-9]|[12][0-9]|3[01])-(?:0[1-9]|1[012])-\\d{4})")),
D_M_Y_SLASH("d/m/y", Pattern.compile("((?:0[1-9]|[12][0-9]|3[01])/(?:0[1-9]|1[012])/\\d{4})")),
NOT_EMPTY("notEmpty", Pattern.compile("(?=\\s*\\S).*", Pattern.DOTALL)),
DATE_TIME("dateTime", Pattern.compile(DATE_TIME_WITH_DASH));
DATE_TIME("dateTime", Pattern.compile(RegexpConstant.DATE_TIME_WITH_DASH));

private final String aliasName;
private final Pattern pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.List;
import java.util.regex.Pattern;

import static java.lang.String.format;

@RequiredArgsConstructor
@Getter
public enum ConditionType {
Expand Down Expand Up @@ -62,6 +60,6 @@ public static ConditionType getType(final String expression) {
return Arrays.stream(ConditionType.values())
.filter(type -> type.getPatterns().stream().anyMatch(pattern -> pattern.matcher(expression).matches()))
.findFirst()
.orElseThrow(() -> new MatchException(format(LogMessage.WRONG_OPERATION, expression)));
.orElseThrow(() -> new MatchException(String.format(LogMessage.WRONG_OPERATION, expression)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
import java.util.Arrays;
import java.util.regex.Pattern;

import static com.knubisoft.comparator.constant.CommonConstant.*;
import static java.lang.String.format;

@Getter
@RequiredArgsConstructor
public enum DateFormat {
DATE_TIME_FORMAT_WITH_DASH(format(DATE_TIME_TEMPLATE, DASH, DASH), RegexpConstant.DATE_TIME_WITH_DASH_PATTERN),
DATE_TIME_FORMAT_WITH_SLASH(format(DATE_TIME_TEMPLATE, SLASH, SLASH), RegexpConstant.DATE_TIME_WITH_SLASH_PATTERN),
DATE_FORMAT_WITH_DASH(format(DATE_TEMPLATE, DASH, DASH), RegexpConstant.DATE_WITH_DASH_PATTERN),
DATE_FORMAT_WITH_SLASH(format(DATE_TEMPLATE, SLASH, SLASH), RegexpConstant.DATE_WITH_SLASH_PATTERN),
DATE_TIME_FORMAT_WITH_DASH(String.format(CommonConstant.DATE_TIME_TEMPLATE,
CommonConstant.DASH, CommonConstant.DASH),
RegexpConstant.DATE_TIME_WITH_DASH_PATTERN),
DATE_TIME_FORMAT_WITH_SLASH(String.format(CommonConstant.DATE_TIME_TEMPLATE,
CommonConstant.SLASH, CommonConstant.SLASH),
RegexpConstant.DATE_TIME_WITH_SLASH_PATTERN),
DATE_FORMAT_WITH_DASH(String.format(CommonConstant.DATE_TEMPLATE, CommonConstant.DASH, CommonConstant.DASH),
RegexpConstant.DATE_WITH_DASH_PATTERN),
DATE_FORMAT_WITH_SLASH(String.format(CommonConstant.DATE_TEMPLATE, CommonConstant.SLASH, CommonConstant.SLASH),
RegexpConstant.DATE_WITH_SLASH_PATTERN),
TIME_FORMAT(CommonConstant.TIME_FORMAT, Pattern.compile(RegexpConstant.TIME));

private final String format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.Arrays;
import java.util.regex.Pattern;

import static java.lang.String.format;

@Getter
@RequiredArgsConstructor
public enum Operator {
Expand All @@ -25,7 +23,7 @@ public static Operator getOperatorFromExpression(final String expression) {
return Arrays.stream(Operator.values())
.filter(o -> o.getPattern().matcher(expression).matches())
.findFirst()
.orElseThrow(() -> new MatchException(format(LogMessage.WRONG_OPERATOR, expression)));
.orElseThrow(() -> new MatchException(String.format(LogMessage.WRONG_OPERATOR, expression)));
}

}
Loading
Loading