String comparison functions working
This commit is contained in:
parent
521920a1f8
commit
dbabae2158
Binary file not shown.
|
@ -680,7 +680,7 @@
|
||||||
MetallicLevel="Platinum"
|
MetallicLevel="Platinum"
|
||||||
Capability="Filterability ($filter)"
|
Capability="Filterability ($filter)"
|
||||||
WebAPIReference="2.4.4"
|
WebAPIReference="2.4.4"
|
||||||
OutputFile="REQ-WA103-QO13_Contains.json"
|
OutputFile="REQ-WA103-QO13.json"
|
||||||
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&$select=*Parameter_SelectList*&$filter=*Parameter_ContainsField* ne null and contains(*Parameter_ContainsField*,'*Parameter_ContainsValue*')*Parameter_RequiredParameters*"
|
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&$select=*Parameter_SelectList*&$filter=*Parameter_ContainsField* ne null and contains(*Parameter_ContainsField*,'*Parameter_ContainsValue*')*Parameter_RequiredParameters*"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -325,3 +325,43 @@ Feature: Web API Server 1.0.2 Certification
|
||||||
And the response is valid JSON
|
And the response is valid JSON
|
||||||
And the response has results
|
And the response has results
|
||||||
And "fractional" data in Timestamp Field "Parameter_TimestampField" "lt" "Parameter_FractionalValue"
|
And "fractional" data in Timestamp Field "Parameter_TimestampField" "lt" "Parameter_FractionalValue"
|
||||||
|
|
||||||
|
@REQ-WA103-QO13 @platinum @2.4.4 @filterability-endorsement
|
||||||
|
Scenario: Query Support: $filter - String: contains
|
||||||
|
When a GET request is made to the resolved Url in "REQ-WA103-QO13"
|
||||||
|
Then the server responds with a status code of 200
|
||||||
|
And the response is valid JSON
|
||||||
|
And the response has results
|
||||||
|
And String data in "Parameter_ContainsField" "contains" "Parameter_ContainsValue"
|
||||||
|
|
||||||
|
@REQ-WA103-QO14 @platinum @2.4.4 @filterability-endorsement
|
||||||
|
Scenario: Query Support: $filter - String: ends with
|
||||||
|
When a GET request is made to the resolved Url in "REQ-WA103-QO14"
|
||||||
|
Then the server responds with a status code of 200
|
||||||
|
And the response is valid JSON
|
||||||
|
And the response has results
|
||||||
|
And String data in "Parameter_EndsWithField" "endswith" "Parameter_EndsWithValue"
|
||||||
|
|
||||||
|
@REQ-WA103-QO15 @platinum @2.4.4 @filterability-endorsement
|
||||||
|
Scenario: Query Support: $filter - String: starts with
|
||||||
|
When a GET request is made to the resolved Url in "REQ-WA103-QO15"
|
||||||
|
Then the server responds with a status code of 200
|
||||||
|
And the response is valid JSON
|
||||||
|
And the response has results
|
||||||
|
And String data in "Parameter_StartsWithField" "startswith" "Parameter_StartsWithValue"
|
||||||
|
|
||||||
|
@REQ-WA103-QO16 @platinum @2.4.4 @filterability-endorsement
|
||||||
|
Scenario: Query Support: $filter - String: tolower() support
|
||||||
|
When a GET request is made to the resolved Url in "REQ-WA103-QO16"
|
||||||
|
Then the server responds with a status code of 200
|
||||||
|
And the response is valid JSON
|
||||||
|
And the response has results
|
||||||
|
And String data in "Parameter_ToLowerField" "tolower" "Parameter_ToLowerValue"
|
||||||
|
|
||||||
|
@REQ-WA103-QO17 @platinum @2.4.4 @filterability-endorsement
|
||||||
|
Scenario: Query Support: $filter - String: toupper() support
|
||||||
|
When a GET request is made to the resolved Url in "REQ-WA103-QO17"
|
||||||
|
Then the server responds with a status code of 200
|
||||||
|
And the response is valid JSON
|
||||||
|
And the response has results
|
||||||
|
And String data in "Parameter_ToUpperField" "toupper" "Parameter_ToUpperValue"
|
|
@ -603,6 +603,7 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
AtomicReference<Integer> fieldValue = new AtomicReference<>();
|
AtomicReference<Integer> fieldValue = new AtomicReference<>();
|
||||||
AtomicInteger assertedValue = new AtomicInteger();
|
AtomicInteger assertedValue = new AtomicInteger();
|
||||||
AtomicReference<String> datePart = new AtomicReference<>(stringDatePart.toLowerCase());
|
AtomicReference<String> datePart = new AtomicReference<>(stringDatePart.toLowerCase());
|
||||||
|
AtomicReference<String> operator = new AtomicReference<>(op.toLowerCase());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertedValue.set(Integer.parseInt(Settings.resolveParametersString(parameterAssertedValue, settings)));
|
assertedValue.set(Integer.parseInt(Settings.resolveParametersString(parameterAssertedValue, settings)));
|
||||||
|
@ -611,7 +612,7 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
from(responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> {
|
from(responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> {
|
||||||
try {
|
try {
|
||||||
fieldValue.set(Utils.getDatePart(datePart.get(), item.get(fieldName)));
|
fieldValue.set(Utils.getDatePart(datePart.get(), item.get(fieldName)));
|
||||||
assertTrue(Utils.compare(fieldValue.get(), op, assertedValue.get()));
|
assertTrue(Utils.compare(fieldValue.get(), operator.get(), assertedValue.get()));
|
||||||
} catch (Exception ex){
|
} catch (Exception ex){
|
||||||
//fail();
|
//fail();
|
||||||
LOG.error("ERROR: exception thrown." + ex);
|
LOG.error("ERROR: exception thrown." + ex);
|
||||||
|
@ -632,6 +633,7 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
AtomicReference<Integer> fieldValue = new AtomicReference<>();
|
AtomicReference<Integer> fieldValue = new AtomicReference<>();
|
||||||
AtomicReference<Integer> assertedValue = new AtomicReference<>();
|
AtomicReference<Integer> assertedValue = new AtomicReference<>();
|
||||||
AtomicReference<String> datePart = new AtomicReference<>(stringDatePart.toLowerCase());
|
AtomicReference<String> datePart = new AtomicReference<>(stringDatePart.toLowerCase());
|
||||||
|
AtomicReference<String> operator = new AtomicReference<>(op.toLowerCase());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertedValue.set(Integer.parseInt(Settings.resolveParametersString(parameterAssertedValue, settings)));
|
assertedValue.set(Integer.parseInt(Settings.resolveParametersString(parameterAssertedValue, settings)));
|
||||||
|
@ -640,7 +642,7 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
from(responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> {
|
from(responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> {
|
||||||
try {
|
try {
|
||||||
fieldValue.set(Utils.getTimestampPart(datePart.get(), item.get(fieldName).toString()));
|
fieldValue.set(Utils.getTimestampPart(datePart.get(), item.get(fieldName).toString()));
|
||||||
assertTrue(Utils.compare(fieldValue.get(), op, assertedValue.get()));
|
assertTrue(Utils.compare(fieldValue.get(), operator.get(), assertedValue.get()));
|
||||||
} catch (Exception ex){
|
} catch (Exception ex){
|
||||||
fail();
|
fail();
|
||||||
LOG.error("ERROR: exception thrown." + ex);
|
LOG.error("ERROR: exception thrown." + ex);
|
||||||
|
@ -651,6 +653,21 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
LOG.error("ERROR: exception thrown." + ex);
|
LOG.error("ERROR: exception thrown." + ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* String functions
|
||||||
|
*/
|
||||||
|
And("^String data in \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\"$", (String parameterFieldName, String op, String parameterAssertedValue) -> {
|
||||||
|
String fieldName = Settings.resolveParametersString(parameterFieldName, settings);
|
||||||
|
AtomicReference<String> fieldValue = new AtomicReference<>();
|
||||||
|
AtomicReference<String> assertedValue = new AtomicReference(Settings.resolveParametersString(parameterAssertedValue, settings));
|
||||||
|
AtomicReference<String> operator = new AtomicReference<>(op.toLowerCase());
|
||||||
|
|
||||||
|
from(responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> {
|
||||||
|
assertTrue(Utils.compare(item.get(fieldName).toString(), operator.get(), assertedValue.get()));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -665,7 +682,12 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
GREATER_THAN = "gt",
|
GREATER_THAN = "gt",
|
||||||
GREATER_THAN_OR_EQUAL = "ge",
|
GREATER_THAN_OR_EQUAL = "ge",
|
||||||
LESS_THAN = "lt",
|
LESS_THAN = "lt",
|
||||||
LESS_THAN_OR_EQUAL = "le";
|
LESS_THAN_OR_EQUAL = "le",
|
||||||
|
CONTAINS = "contains",
|
||||||
|
ENDS_WITH = "endswith",
|
||||||
|
STARTS_WITH = "startswith",
|
||||||
|
TO_LOWER = "tolower",
|
||||||
|
TO_UPPER = "toupper";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DateParts {
|
private static class DateParts {
|
||||||
|
@ -750,6 +772,33 @@ public class WebAPIServer_1_0_2 implements En {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if each item in the list is true
|
||||||
|
* @param lhs Integer value
|
||||||
|
* @param op an OData binary operator for use for comparisons
|
||||||
|
* @param rhs Integer value
|
||||||
|
* @return true if lhs op rhs produces true, false otherwise
|
||||||
|
*/
|
||||||
|
private static boolean compare(String lhs, String op, String rhs) {
|
||||||
|
String operator = op.toLowerCase();
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
if (operator.contentEquals(Operators.CONTAINS)) {
|
||||||
|
result = lhs.contains(rhs);
|
||||||
|
} else if (operator.contentEquals(Operators.STARTS_WITH)) {
|
||||||
|
result = lhs.startsWith(rhs);
|
||||||
|
} else if (operator.contentEquals(Operators.ENDS_WITH)) {
|
||||||
|
result = lhs.endsWith(rhs);
|
||||||
|
} else if (operator.contentEquals(Operators.TO_LOWER)) {
|
||||||
|
result = lhs.toLowerCase().equals(rhs);
|
||||||
|
} else if (operator.contentEquals(Operators.TO_UPPER)) {
|
||||||
|
result = lhs.toUpperCase().equals(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Compare: " + operator + "(" + lhs + ") == " + rhs + " ==> " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timestamp Comparator
|
* Timestamp Comparator
|
||||||
* @param lhs Timestamp to compare
|
* @param lhs Timestamp to compare
|
||||||
|
|
Loading…
Reference in New Issue