* #137: Added enhanced logging for Lookup tests * #137: Don't fast fail when the Lookup Resource tests fail
This commit is contained in:
parent
abc27aa9df
commit
1c6e831dba
|
@ -40,8 +40,7 @@ import java.util.stream.Collectors;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.reso.commander.Commander.*;
|
import static org.reso.commander.Commander.*;
|
||||||
import static org.reso.commander.common.ErrorMsg.getDefaultErrorMessage;
|
import static org.reso.commander.common.ErrorMsg.getDefaultErrorMessage;
|
||||||
import static org.reso.commander.common.TestUtils.HEADER_ODATA_VERSION;
|
import static org.reso.commander.common.TestUtils.*;
|
||||||
import static org.reso.commander.common.TestUtils.JSON_VALUE_PATH;
|
|
||||||
import static org.reso.models.Request.loadFromRESOScript;
|
import static org.reso.models.Request.loadFromRESOScript;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,7 +389,8 @@ public final class WebAPITestContainer implements TestContainer {
|
||||||
|
|
||||||
URI pathToMetadata = getCommander().getPathToMetadata(request.getRequestUrl());
|
URI pathToMetadata = getCommander().getPathToMetadata(request.getRequestUrl());
|
||||||
if (pathToMetadata != null) {
|
if (pathToMetadata != null) {
|
||||||
LOG.info("Requesting XML Metadata from: " + pathToMetadata.toString());
|
LOG.info("Requesting XML Metadata from: " + pathToMetadata);
|
||||||
|
|
||||||
ODataTransportWrapper wrapper = getCommander().executeODataGetRequest(pathToMetadata.toString());
|
ODataTransportWrapper wrapper = getCommander().executeODataGetRequest(pathToMetadata.toString());
|
||||||
setODataRawResponse(wrapper.getODataRawResponse());
|
setODataRawResponse(wrapper.getODataRawResponse());
|
||||||
responseCode.set(wrapper.getHttpResponseCode());
|
responseCode.set(wrapper.getHttpResponseCode());
|
||||||
|
@ -404,8 +404,8 @@ public final class WebAPITestContainer implements TestContainer {
|
||||||
xmlResponseData.set(wrapper.getResponseData());
|
xmlResponseData.set(wrapper.getResponseData());
|
||||||
xmlMetadata.set(Commander.deserializeXMLMetadata(xmlResponseData.get(), getCommander().getClient()));
|
xmlMetadata.set(Commander.deserializeXMLMetadata(xmlResponseData.get(), getCommander().getClient()));
|
||||||
} else {
|
} else {
|
||||||
LOG.error(getDefaultErrorMessage("could not create metadata URI from given requestUri:", request.getRequestUrl()));
|
failAndExitWithErrorMessage(getDefaultErrorMessage("Could not create metadata URI from given requestUri:",
|
||||||
System.exit(NOT_OK);
|
request.getRequestUrl()), LOG);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
haveMetadataBeenRequested.set(true);
|
haveMetadataBeenRequested.set(true);
|
||||||
|
@ -706,15 +706,23 @@ public final class WebAPITestContainer implements TestContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processODataRequestException(ODataClientErrorException exception) {
|
private void processODataRequestException(ODataClientErrorException exception) {
|
||||||
LOG.debug("ODataClientErrorException caught. Check tests for asserted conditions...");
|
/*
|
||||||
LOG.debug(exception);
|
TODO: determine whether these additional lines are needed or whether the bubbled error is sufficient
|
||||||
|
LOG.error("ODataClientErrorException caught. Check tests for asserted conditions...");
|
||||||
|
LOG.error(exception);
|
||||||
|
*/
|
||||||
|
|
||||||
setODataClientErrorException(exception);
|
setODataClientErrorException(exception);
|
||||||
setServerODataHeaderVersion(TestUtils.getHeaderData(HEADER_ODATA_VERSION, Arrays.asList(exception.getHeaderInfo())));
|
setServerODataHeaderVersion(TestUtils.getHeaderData(HEADER_ODATA_VERSION, Arrays.asList(exception.getHeaderInfo())));
|
||||||
setResponseCode(exception.getStatusLine().getStatusCode());
|
setResponseCode(exception.getStatusLine().getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processODataRequestException(ODataServerErrorException exception) {
|
private void processODataRequestException(ODataServerErrorException exception) {
|
||||||
LOG.debug("ODataServerErrorException thrown in executeGetRequest. Check tests for asserted conditions...");
|
/*
|
||||||
|
TODO: determine whether these additional lines are needed or whether the bubbled error is sufficient
|
||||||
|
LOG.error("ODataServerErrorException thrown in executeGetRequest. Check tests for asserted conditions...");
|
||||||
|
*/
|
||||||
|
|
||||||
//TODO: look for better ways to do this in Olingo or open PR
|
//TODO: look for better ways to do this in Olingo or open PR
|
||||||
if (exception.getMessage().contains(Integer.toString(HttpStatus.SC_NOT_IMPLEMENTED))) {
|
if (exception.getMessage().contains(Integer.toString(HttpStatus.SC_NOT_IMPLEMENTED))) {
|
||||||
setResponseCode(HttpStatus.SC_NOT_IMPLEMENTED);
|
setResponseCode(HttpStatus.SC_NOT_IMPLEMENTED);
|
||||||
|
@ -722,7 +730,6 @@ public final class WebAPITestContainer implements TestContainer {
|
||||||
setODataServerErrorException(exception);
|
setODataServerErrorException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean getIsValidXMLMetadata() {
|
public boolean getIsValidXMLMetadata() {
|
||||||
return isValidXMLMetadata.get();
|
return isValidXMLMetadata.get();
|
||||||
}
|
}
|
||||||
|
@ -769,7 +776,7 @@ public final class WebAPITestContainer implements TestContainer {
|
||||||
&& edm.get() != null && getIsValidEdm();
|
&& edm.get() != null && getIsValidEdm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final WebAPITestContainer validateMetadata() {
|
public WebAPITestContainer validateMetadata() {
|
||||||
try {
|
try {
|
||||||
if (!haveMetadataBeenRequested.get()) fetchXMLMetadata();
|
if (!haveMetadataBeenRequested.get()) fetchXMLMetadata();
|
||||||
assertNotNull(getDefaultErrorMessage("no XML response data found!"), getXMLResponseData());
|
assertNotNull(getDefaultErrorMessage("no XML response data found!"), getXMLResponseData());
|
||||||
|
|
|
@ -24,8 +24,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
import static org.reso.certification.stepdefs.DataAvailability.CERTIFICATION_RESULTS_PATH;
|
import static org.reso.certification.stepdefs.DataAvailability.CERTIFICATION_RESULTS_PATH;
|
||||||
|
import static org.reso.commander.common.ErrorMsg.getDefaultErrorMessage;
|
||||||
import static org.reso.commander.common.ODataUtils.*;
|
import static org.reso.commander.common.ODataUtils.*;
|
||||||
import static org.reso.commander.common.TestUtils.failAndExitWithErrorMessage;
|
import static org.reso.commander.common.TestUtils.failAndExitWithErrorMessage;
|
||||||
import static org.reso.commander.common.Utils.wrapColumns;
|
import static org.reso.commander.common.Utils.wrapColumns;
|
||||||
|
@ -37,7 +39,9 @@ public class LookupResource {
|
||||||
private static final String PATH_TO_RESOSCRIPT_ARG = "pathToRESOScript";
|
private static final String PATH_TO_RESOSCRIPT_ARG = "pathToRESOScript";
|
||||||
private static final AtomicReference<Map<String, List<ClientEntity>>> lookupResourceCache = new AtomicReference<>(new LinkedHashMap<>());
|
private static final AtomicReference<Map<String, List<ClientEntity>>> lookupResourceCache = new AtomicReference<>(new LinkedHashMap<>());
|
||||||
private static final String LOOKUP_RESOURCE_LOOKUP_METADATA_FILE_NAME = "lookup-resource-lookup-metadata.json";
|
private static final String LOOKUP_RESOURCE_LOOKUP_METADATA_FILE_NAME = "lookup-resource-lookup-metadata.json";
|
||||||
private static final String LOOKUP_RESOURCE_FIELD_METADATA_FILE_NAME = "lookup-resource-field-metadata.json";
|
|
||||||
|
//TODO: only output file in DEBUG mode
|
||||||
|
//private static final String LOOKUP_RESOURCE_FIELD_METADATA_FILE_NAME = "lookup-resource-field-metadata.json";
|
||||||
|
|
||||||
private static final String LOOKUP_NAME_FIELD = "LookupName";
|
private static final String LOOKUP_NAME_FIELD = "LookupName";
|
||||||
|
|
||||||
|
@ -78,9 +82,8 @@ public class LookupResource {
|
||||||
|
|
||||||
lookupResourceCache.get().get(resourceName).addAll(results);
|
lookupResourceCache.get().get(resourceName).addAll(results);
|
||||||
|
|
||||||
final JsonObject metadata = new JsonObject();
|
Utils.createFile(CERTIFICATION_RESULTS_PATH, LOOKUP_RESOURCE_LOOKUP_METADATA_FILE_NAME,
|
||||||
metadata.add("lookups", ODataUtils.serializeLookupMetadata(container.get().getCommander().getClient(), results));
|
ODataUtils.serializeLookupMetadata(container.get().getCommander().getClient(), results).toString());
|
||||||
Utils.createFile(CERTIFICATION_RESULTS_PATH, LOOKUP_RESOURCE_LOOKUP_METADATA_FILE_NAME, metadata.toString());
|
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
failAndExitWithErrorMessage("Unable to retrieve data from the Lookup Resource! " + exception.getMessage(), scenario);
|
failAndExitWithErrorMessage("Unable to retrieve data from the Lookup Resource! " + exception.getMessage(), scenario);
|
||||||
|
@ -145,6 +148,7 @@ public class LookupResource {
|
||||||
standardLookupFieldCache.get(resourceName).values().stream()
|
standardLookupFieldCache.get(resourceName).values().stream()
|
||||||
.filter(referenceStandardField -> referenceStandardField.getLookupName() != null)).collect(Collectors.toSet());
|
.filter(referenceStandardField -> referenceStandardField.getLookupName() != null)).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
final ArrayList<String> fieldsWithMissingAnnotations = new ArrayList<>();
|
||||||
lookupFields.forEach(referenceStandardField -> {
|
lookupFields.forEach(referenceStandardField -> {
|
||||||
LOG.debug("Standard Field: { "
|
LOG.debug("Standard Field: { "
|
||||||
+ "resourceName: \"" + referenceStandardField.getParentResourceName() + "\""
|
+ "resourceName: \"" + referenceStandardField.getParentResourceName() + "\""
|
||||||
|
@ -155,15 +159,19 @@ public class LookupResource {
|
||||||
final boolean isStringDataType = foundElement != null &&
|
final boolean isStringDataType = foundElement != null &&
|
||||||
foundElement.getType().getFullQualifiedName().toString().contentEquals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString());
|
foundElement.getType().getFullQualifiedName().toString().contentEquals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString());
|
||||||
|
|
||||||
if (foundElement != null && isStringDataType) {
|
|
||||||
if (!hasAnnotationTerm(foundElement, annotationTerm)) {
|
if (foundElement != null && isStringDataType && !hasAnnotationTerm(foundElement, annotationTerm)) {
|
||||||
final String message = "Could not find required annotation with term \"" + annotationTerm + "\" for field: "
|
fieldsWithMissingAnnotations.add(referenceStandardField.getStandardName());
|
||||||
+ referenceStandardField.getStandardName();
|
|
||||||
LOG.info("WARN: " + message);
|
|
||||||
failAndExitWithErrorMessage(message, scenario);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (fieldsWithMissingAnnotations.size() > 0) {
|
||||||
|
final String msg = "The following fields are missing the required '" + annotationTerm + "' annotation: "
|
||||||
|
+ wrapColumns(String.join(", ", fieldsWithMissingAnnotations)) + "\n";
|
||||||
|
|
||||||
|
LOG.error(getDefaultErrorMessage(msg));
|
||||||
|
fail(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@And("fields with the annotation term {string} MUST have a LookupName in the Lookup Resource")
|
@And("fields with the annotation term {string} MUST have a LookupName in the Lookup Resource")
|
||||||
|
@ -185,18 +193,14 @@ public class LookupResource {
|
||||||
final Set<String> missingLookupNames = Utils.getDifference(annotatedLookupNames, lookupNamesFromLookupData);
|
final Set<String> missingLookupNames = Utils.getDifference(annotatedLookupNames, lookupNamesFromLookupData);
|
||||||
|
|
||||||
if (missingLookupNames.size() > 0) {
|
if (missingLookupNames.size() > 0) {
|
||||||
failAndExitWithErrorMessage("LookupName elements missing from LookupMetadata: "
|
final String msg = "The following fields have LookupName annotations but are missing from the Lookup Resource: "
|
||||||
+ wrapColumns(String.join(", ", missingLookupNames)), scenario);
|
+ wrapColumns(String.join(", ", missingLookupNames)) + "\n";
|
||||||
} else {
|
|
||||||
if (filteredResourceFieldMap.size() > 0) {
|
|
||||||
scenario.log("Found all annotated LookupName elements in the Lookup data. Unique count: " + annotatedLookupNames.size());
|
|
||||||
scenario.log("LookupNames: " + wrapColumns(String.join(", ", annotatedLookupNames)));
|
|
||||||
|
|
||||||
Utils.createFile(CERTIFICATION_RESULTS_PATH, LOOKUP_RESOURCE_FIELD_METADATA_FILE_NAME,
|
LOG.error(getDefaultErrorMessage(msg));
|
||||||
ODataUtils.serializeFieldMetadataForLookupFields(filteredResourceFieldMap).toString());
|
fail(msg);
|
||||||
} else {
|
} else {
|
||||||
scenario.log("No annotated lookup names found in the OData XML Metadata.");
|
scenario.log("Found all annotated LookupName elements in the Lookup data. Unique count: " + annotatedLookupNames.size());
|
||||||
}
|
scenario.log("LookupNames: " + wrapColumns(String.join(", ", annotatedLookupNames)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static io.restassured.path.json.JsonPath.from;
|
import static io.restassured.path.json.JsonPath.from;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -49,7 +48,6 @@ import static org.reso.commander.common.ErrorMsg.getDefaultErrorMessage;
|
||||||
import static org.reso.commander.common.TestUtils.DateParts.FRACTIONAL;
|
import static org.reso.commander.common.TestUtils.DateParts.FRACTIONAL;
|
||||||
import static org.reso.commander.common.TestUtils.*;
|
import static org.reso.commander.common.TestUtils.*;
|
||||||
import static org.reso.commander.common.TestUtils.Operators.*;
|
import static org.reso.commander.common.TestUtils.Operators.*;
|
||||||
import static org.reso.models.Request.loadFromRESOScript;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the glue code for Web API Core 2.0.0 Certification as well as previous Platinum tests,
|
* Contains the glue code for Web API Core 2.0.0 Certification as well as previous Platinum tests,
|
||||||
|
@ -89,13 +87,6 @@ public class WebAPIServerCore implements En {
|
||||||
|
|
||||||
if (!container.get().getIsInitialized()) {
|
if (!container.get().getIsInitialized()) {
|
||||||
container.get().setSettings(Settings.loadFromRESOScript(new File(System.getProperty(PATH_TO_RESOSCRIPT_KEY))));
|
container.get().setSettings(Settings.loadFromRESOScript(new File(System.getProperty(PATH_TO_RESOSCRIPT_KEY))));
|
||||||
|
|
||||||
//moved to container initialization
|
|
||||||
// //overwrite any requests loaded with the reference queries
|
|
||||||
// container.get().getSettings().setRequests(loadFromRESOScript(new File(Objects.requireNonNull(
|
|
||||||
// getClass().getClassLoader().getResource(WEB_API_CORE_REFERENCE_REQUESTS)).getPath()))
|
|
||||||
// .stream().map(request -> Settings.resolveParameters(request, container.get().getSettings())).collect(Collectors.toList()));
|
|
||||||
|
|
||||||
container.get().initialize();
|
container.get().initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,11 +252,10 @@ public class WebAPIServerCore implements En {
|
||||||
* Rather than returning an integer response, this implementation expects the @odata.count property to be
|
* Rather than returning an integer response, this implementation expects the @odata.count property to be
|
||||||
* available when requested, and a $top=0 may be used to restrict the number of items returned as results.
|
* available when requested, and a $top=0 may be used to restrict the number of items returned as results.
|
||||||
*/
|
*/
|
||||||
And("^the \"([^\"]*)\" value is greater than or equal to the number of results$", (String field) -> {
|
And("^the \"([^\"]*)\" value is greater than or equal to the number of results$", (String field) ->
|
||||||
assertTrue(getDefaultErrorMessage("the @odata.count value MUST be present",
|
assertTrue(getDefaultErrorMessage("the @odata.count value MUST be present",
|
||||||
"and contain a non-zero value greater than or equal to the number of results!"),
|
"and contain a non-zero value greater than or equal to the number of results!"),
|
||||||
TestUtils.validateODataCount(container.get().getResponseData()));
|
TestUtils.validateODataCount(container.get().getResponseData())));
|
||||||
});
|
|
||||||
|
|
||||||
And("^data in the \"([^\"]*)\" fields are different in the second request than in the first$", (String parameterUniqueId) -> {
|
And("^data in the \"([^\"]*)\" fields are different in the second request than in the first$", (String parameterUniqueId) -> {
|
||||||
try {
|
try {
|
||||||
|
@ -469,7 +459,7 @@ public class WebAPIServerCore implements En {
|
||||||
String op = andOrOp.toLowerCase();
|
String op = andOrOp.toLowerCase();
|
||||||
boolean isAndOp = op.contains(AND);
|
boolean isAndOp = op.contains(AND);
|
||||||
|
|
||||||
//these should default to true when And and false when Or for the purpose of boolean comparisons
|
//these should default to true when And, and false when Or for the purpose of boolean comparisons
|
||||||
AtomicBoolean lhsResult = new AtomicBoolean(isAndOp);
|
AtomicBoolean lhsResult = new AtomicBoolean(isAndOp);
|
||||||
AtomicBoolean rhsResult = new AtomicBoolean(isAndOp);
|
AtomicBoolean rhsResult = new AtomicBoolean(isAndOp);
|
||||||
AtomicBoolean itemResult = new AtomicBoolean(isAndOp);
|
AtomicBoolean itemResult = new AtomicBoolean(isAndOp);
|
||||||
|
@ -620,7 +610,7 @@ public class WebAPIServerCore implements En {
|
||||||
|
|
||||||
from(container.get().getResponseData()).getList(JSON_VALUE_PATH, ObjectNode.class).forEach(item -> {
|
from(container.get().getResponseData()).getList(JSON_VALUE_PATH, ObjectNode.class).forEach(item -> {
|
||||||
fieldValue.set(item.get(fieldName).toString());
|
fieldValue.set(item.get(fieldName).toString());
|
||||||
String assertMessage = EMPTY_STRING;
|
String assertMessage;
|
||||||
if (useCollections) {
|
if (useCollections) {
|
||||||
if (item.get(fieldName).isArray()) {
|
if (item.get(fieldName).isArray()) {
|
||||||
result.set(result.get() && TestUtils.testAnyOperator(item, fieldName, assertedValue.get()));
|
result.set(result.get() && TestUtils.testAnyOperator(item, fieldName, assertedValue.get()));
|
||||||
|
@ -795,16 +785,16 @@ public class WebAPIServerCore implements En {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ensures that the server metadata for the given resource in parameterResourceName contains
|
* Ensures that the server metadata for the given resource in parameterResourceName contains
|
||||||
* all of the fields in the given parameterSelectList.
|
* each of the fields in the given parameterSelectList.
|
||||||
*/
|
*/
|
||||||
And("^resource metadata for \"([^\"]*)\" contains the fields in the given select list$", (String parameterResourceName) -> {
|
And("^resource metadata for \"([^\"]*)\" contains the fields in the given select list$", (String parameterResourceName) -> {
|
||||||
assertTrue(getDefaultErrorMessage("no $select list found for requestId:", container.get().getRequest().getRequestId()),
|
assertTrue(getDefaultErrorMessage("no $select list found for requestId:", container.get().getRequest().getRequestId()),
|
||||||
container.get().getSelectList().size() > 0);
|
container.get().getSelectList().size() > 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LOG.info("Searching metadata for fields in given select list: " + container.get().getSelectList().toString());
|
LOG.info("Searching metadata for fields in given select list: " + container.get().getSelectList());
|
||||||
container.get().getSelectList().forEach(fieldName -> {
|
container.get().getSelectList().forEach(fieldName -> {
|
||||||
//need to skip the expand field when looking through the metadata
|
//need to skip the expanded field when looking through the metadata
|
||||||
if (container.get().getExpandField() != null && !fieldName.contentEquals(container.get().getExpandField())) {
|
if (container.get().getExpandField() != null && !fieldName.contentEquals(container.get().getExpandField())) {
|
||||||
try {
|
try {
|
||||||
assertNotNull(getDefaultErrorMessage("Field name '" + fieldName + "' is not present in server metadata!"),
|
assertNotNull(getDefaultErrorMessage("Field name '" + fieldName + "' is not present in server metadata!"),
|
||||||
|
@ -850,16 +840,13 @@ public class WebAPIServerCore implements En {
|
||||||
try {
|
try {
|
||||||
if (container.get().fetchXMLMetadata() == null) {
|
if (container.get().fetchXMLMetadata() == null) {
|
||||||
//force exit rather than allowing the tests to finish
|
//force exit rather than allowing the tests to finish
|
||||||
LOG.error(getDefaultErrorMessage("could not retrieve valid XML Metadata for given service root:", serviceRoot));
|
failAndExitWithErrorMessage("Could not retrieve valid XML Metadata for given service root: " + serviceRoot, LOG);
|
||||||
System.exit(NOT_OK);
|
|
||||||
}
|
}
|
||||||
} catch (ODataClientErrorException cex) {
|
} catch (ODataClientErrorException cex) {
|
||||||
container.get().setResponseCode(cex.getStatusLine().getStatusCode());
|
container.get().setResponseCode(cex.getStatusLine().getStatusCode());
|
||||||
LOG.error(getDefaultErrorMessage(cex));
|
failAndExitWithErrorMessage(getDefaultErrorMessage(cex), LOG);
|
||||||
System.exit(NOT_OK);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error(getDefaultErrorMessage(ex));
|
failAndExitWithErrorMessage(getDefaultErrorMessage(ex), LOG);
|
||||||
System.exit(NOT_OK);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1107,7 +1094,7 @@ public class WebAPIServerCore implements En {
|
||||||
*/
|
*/
|
||||||
void prepareAndExecuteRawGetRequest(String requestId) {
|
void prepareAndExecuteRawGetRequest(String requestId) {
|
||||||
try {
|
try {
|
||||||
//reset local state each time a get request request is run
|
//reset local state each time a get request is run
|
||||||
container.get().resetState();
|
container.get().resetState();
|
||||||
|
|
||||||
assertNotNull(getDefaultErrorMessage("request Id cannot be null!"), requestId);
|
assertNotNull(getDefaultErrorMessage("request Id cannot be null!"), requestId);
|
||||||
|
@ -1130,10 +1117,9 @@ public class WebAPIServerCore implements En {
|
||||||
//execute request
|
//execute request
|
||||||
container.get().executePreparedRawGetRequest();
|
container.get().executePreparedRawGetRequest();
|
||||||
} catch (MalformedURLException urlException) {
|
} catch (MalformedURLException urlException) {
|
||||||
LOG.info("Malformed URL was thrown in " + this.getClass() + ": " + urlException.toString()
|
LOG.info("Malformed URL was thrown in " + this.getClass() + ": " + urlException + "\nSkipping Request!");
|
||||||
+ "\nSkipping Request!");
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.info("Exception was thrown in " + this.getClass() + "!\n" + ex.toString());
|
LOG.info("Exception was thrown in " + this.getClass() + "!\n" + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -549,27 +549,24 @@ public class Commander {
|
||||||
* @return a URI with the metadata path included
|
* @return a URI with the metadata path included
|
||||||
*/
|
*/
|
||||||
public URI getPathToMetadata(String requestUri) {
|
public URI getPathToMetadata(String requestUri) {
|
||||||
if (requestUri == null) {
|
if (requestUri == null || requestUri.length() == 0) {
|
||||||
LOG.error(getDefaultErrorMessage("service root is null!"));
|
TestUtils.failAndExitWithErrorMessage("OData service root is missing!", LOG);
|
||||||
System.exit(NOT_OK);
|
} else {
|
||||||
}
|
try {
|
||||||
|
String uri = requestUri;
|
||||||
try {
|
if (!requestUri.contains(METADATA_PATH)) {
|
||||||
String uri = requestUri;
|
uri += METADATA_PATH;
|
||||||
if (!requestUri.contains(METADATA_PATH)) {
|
}
|
||||||
uri += METADATA_PATH;
|
return new URI(uri).normalize();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
TestUtils.failAndExitWithErrorMessage("Could not create metadata URI.\n\t" + ex, LOG);
|
||||||
}
|
}
|
||||||
return new URI(uri);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error(getDefaultErrorMessage("could not create path to metadata.\n" + ex.toString()));
|
|
||||||
System.exit(NOT_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes an OData GET Request w ith the current Commander instance
|
* Executes an OData GET Request with the current Commander instance
|
||||||
* @param wrapper the OData transport wrapper to use for the request
|
* @param wrapper the OData transport wrapper to use for the request
|
||||||
* @return and OData transport wrapper with the response, or exception if one was thrown
|
* @return and OData transport wrapper with the response, or exception if one was thrown
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -80,22 +80,33 @@ public class ODataUtils {
|
||||||
/**
|
/**
|
||||||
* Serializes a list of OData ClientEntity items in a JSON Array with those properties.
|
* Serializes a list of OData ClientEntity items in a JSON Array with those properties.
|
||||||
*
|
*
|
||||||
* @param results list of OData ClientEntity results
|
* @param lookups list of OData ClientEntity results
|
||||||
* @param client OData client to use as serializer
|
* @param client OData client to use as serializer
|
||||||
* @return a JsonArray of results
|
* @return a JsonArray of results
|
||||||
*/
|
*/
|
||||||
public static JsonArray serializeLookupMetadata(ODataClient client, List<ClientEntity> results) {
|
public static JsonObject serializeLookupMetadata(ODataClient client, List<ClientEntity> lookups) {
|
||||||
final JsonArray lookups = new JsonArray();
|
final String
|
||||||
|
DESCRIPTION_KEY = "description", DESCRIPTION = "Data Dictionary Lookup Resource Metadata",
|
||||||
|
VERSION_KEY = "version", VERSION = "1.7",
|
||||||
|
GENERATED_ON_KEY = "generatedOn",
|
||||||
|
LOOKUPS_KEY = "lookups";
|
||||||
|
|
||||||
|
JsonObject metadataReport = new JsonObject();
|
||||||
|
metadataReport.addProperty(DESCRIPTION_KEY, DESCRIPTION);
|
||||||
|
metadataReport.addProperty(VERSION_KEY, VERSION);
|
||||||
|
metadataReport.addProperty(GENERATED_ON_KEY, Utils.getIsoTimestamp());
|
||||||
|
|
||||||
|
final JsonArray lookupsArray = new JsonArray();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Gson gson = new Gson();
|
final Gson gson = new Gson();
|
||||||
final JsonSerializer jsonSerializer = new JsonSerializer(false, ContentType.APPLICATION_JSON);
|
final JsonSerializer jsonSerializer = new JsonSerializer(false, ContentType.APPLICATION_JSON);
|
||||||
results.forEach(clientEntity -> {
|
lookups.forEach(clientEntity -> {
|
||||||
try {
|
try {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
jsonSerializer.write(writer, client.getBinder().getEntity(clientEntity));
|
jsonSerializer.write(writer, client.getBinder().getEntity(clientEntity));
|
||||||
Optional<JsonElement> element = Optional.ofNullable(gson.fromJson(writer.toString(), JsonElement.class));
|
Optional<JsonElement> element = Optional.ofNullable(gson.fromJson(writer.toString(), JsonElement.class));
|
||||||
element.ifPresent(lookups::add);
|
element.ifPresent(lookupsArray::add);
|
||||||
} catch (ODataSerializerException e) {
|
} catch (ODataSerializerException e) {
|
||||||
LOG.error("ERROR: could not deserialize. Exception: " + e);
|
LOG.error("ERROR: could not deserialize. Exception: " + e);
|
||||||
}
|
}
|
||||||
|
@ -104,15 +115,17 @@ public class ODataUtils {
|
||||||
LOG.error(exception);
|
LOG.error(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lookups;
|
metadataReport.add(LOOKUPS_KEY, lookupsArray);
|
||||||
|
return metadataReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Only output the field metadata in DEBUG mode
|
||||||
public static JsonObject serializeFieldMetadataForLookupFields(Map<String, Set<EdmElement>> resourceFieldMap) {
|
public static JsonObject serializeFieldMetadataForLookupFields(Map<String, Set<EdmElement>> resourceFieldMap) {
|
||||||
//TODO: migrate to test file
|
//TODO: migrate to test file
|
||||||
final String LOOKUP_ANNOTATION_TERM = "RESO.OData.Metadata.LookupName";
|
final String LOOKUP_ANNOTATION_TERM = "RESO.OData.Metadata.LookupName";
|
||||||
|
|
||||||
final String
|
final String
|
||||||
DESCRIPTION_KEY = "description", DESCRIPTION = "Lookup Resource Annotated Fields Metadata",
|
DESCRIPTION_KEY = "description", DESCRIPTION = "Data Dictionary Lookup Resource Annotated Fields Metadata",
|
||||||
VERSION_KEY = "version", VERSION = "1.7",
|
VERSION_KEY = "version", VERSION = "1.7",
|
||||||
GENERATED_ON_KEY = "generatedOn",
|
GENERATED_ON_KEY = "generatedOn",
|
||||||
FIELDS_KEY = "fields";
|
FIELDS_KEY = "fields";
|
||||||
|
|
|
@ -65,7 +65,7 @@ public final class TestUtils {
|
||||||
return URI.create(
|
return URI.create(
|
||||||
queryString.replace(" ", "%20")
|
queryString.replace(" ", "%20")
|
||||||
/* add other handlers here */
|
/* add other handlers here */
|
||||||
);
|
).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -560,7 +560,7 @@ public final class TestUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to find headers with a given key in an an array of headers
|
* Helper method to find headers with a given key in an array of headers
|
||||||
*
|
*
|
||||||
* @param key the header to get
|
* @param key the header to get
|
||||||
* @param headers an array containing Header objects
|
* @param headers an array containing Header objects
|
||||||
|
@ -701,7 +701,7 @@ public final class TestUtils {
|
||||||
*/
|
*/
|
||||||
public static String convertInputStreamToString(InputStream inputStream) {
|
public static String convertInputStreamToString(InputStream inputStream) {
|
||||||
try {
|
try {
|
||||||
InputStreamReader isReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8.name());
|
InputStreamReader isReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
BufferedReader reader = new BufferedReader(isReader);
|
BufferedReader reader = new BufferedReader(isReader);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String str;
|
String str;
|
||||||
|
@ -796,27 +796,29 @@ public final class TestUtils {
|
||||||
*/
|
*/
|
||||||
public static void assertXMLMetadataAreRequestedFromTheServer(WebAPITestContainer container, Scenario scenario) {
|
public static void assertXMLMetadataAreRequestedFromTheServer(WebAPITestContainer container, Scenario scenario) {
|
||||||
if (container == null || container.getCommander() == null) {
|
if (container == null || container.getCommander() == null) {
|
||||||
failAndExitWithErrorMessage("Cannot create Commander instance!", scenario);
|
failAndExitWithErrorMessage("Cannot create Commander instance!", LOG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!container.getHaveMetadataBeenRequested()) {
|
if (!container.getHaveMetadataBeenRequested()) {
|
||||||
final String serviceRoot = Settings.resolveParametersString(container.getServiceRoot(), container.getSettings());
|
final String serviceRoot = Settings.resolveParametersString(container.getServiceRoot(), container.getSettings());
|
||||||
if (!serviceRoot.contentEquals(container.getCommander().getServiceRoot())) {
|
if (!serviceRoot.contentEquals(container.getCommander().getServiceRoot())) {
|
||||||
failAndExitWithErrorMessage("given service root doesn't match the one configured in the Commander", scenario);
|
failAndExitWithErrorMessage("Given service root doesn't match the one configured in the Commander", scenario);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (container.fetchXMLMetadata() == null) {
|
if (container.fetchXMLMetadata() == null) {
|
||||||
failAndExitWithErrorMessage("could not retrieve valid XML Metadata for given service root: " + serviceRoot, scenario);
|
failAndExitWithErrorMessage("Could not retrieve valid XML Metadata for given service root: "
|
||||||
|
+ serviceRoot, LOG);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ODataClientErrorException cex) {
|
} catch (ODataClientErrorException cex) {
|
||||||
container.setResponseCode(cex.getStatusLine().getStatusCode());
|
container.setResponseCode(cex.getStatusLine().getStatusCode());
|
||||||
failAndExitWithErrorMessage(cex.getMessage(), scenario);
|
failAndExitWithErrorMessage("Could not retrieve valid XML Metadata for given service root: "
|
||||||
|
+ serviceRoot + "\n\tException: " + cex.getMessage(), LOG);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
failAndExitWithErrorMessage(ex.toString(), scenario);
|
failAndExitWithErrorMessage("Could not retrieve valid XML Metadata for given service root: "
|
||||||
|
+ serviceRoot + "\n\tException: " + ex, LOG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -829,11 +831,17 @@ public final class TestUtils {
|
||||||
public static void assertXMLMetadataHasValidServiceDocument(WebAPITestContainer container, Scenario scenario) {
|
public static void assertXMLMetadataHasValidServiceDocument(WebAPITestContainer container, Scenario scenario) {
|
||||||
try {
|
try {
|
||||||
if (container == null || container.getEdm() == null || container.getEdm().getEntityContainer() == null) {
|
if (container == null || container.getEdm() == null || container.getEdm().getEntityContainer() == null) {
|
||||||
failAndExitWithErrorMessage("Could not find default entity container for given service root: " + container.getServiceRoot(), scenario);
|
final String serviceRoot = container != null && container.getServiceRoot() != null
|
||||||
|
? container.getServiceRoot() : "<null>";
|
||||||
|
|
||||||
|
failAndExitWithErrorMessage("Could not find default entity container for given service root: " + serviceRoot, scenario);
|
||||||
|
} else {
|
||||||
|
LOG.info("Found Default Entity Container: '" + container.getEdm().getEntityContainer().getNamespace() + "'");
|
||||||
}
|
}
|
||||||
LOG.info("Found Default Entity Container: '" + container.getEdm().getEntityContainer().getNamespace() + "'");
|
|
||||||
} catch (ODataClientErrorException cex) {
|
} catch (ODataClientErrorException cex) {
|
||||||
container.setResponseCode(cex.getStatusLine().getStatusCode());
|
if (container != null) {
|
||||||
|
container.setResponseCode(cex.getStatusLine().getStatusCode());
|
||||||
|
}
|
||||||
failAndExitWithErrorMessage(cex.toString(), scenario);
|
failAndExitWithErrorMessage(cex.toString(), scenario);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
failAndExitWithErrorMessage(getDefaultErrorMessage(ex), scenario);
|
failAndExitWithErrorMessage(getDefaultErrorMessage(ex), scenario);
|
||||||
|
@ -863,7 +871,7 @@ public final class TestUtils {
|
||||||
* Validates that the given response data have a valid OData count
|
* Validates that the given response data have a valid OData count
|
||||||
*
|
*
|
||||||
* @param responseData the data to check for a count against
|
* @param responseData the data to check for a count against
|
||||||
* @return true if the there is a count present and it's greater than or equal to the number of results
|
* @return true if the there is a count present, and it's greater than or equal to the number of results
|
||||||
*/
|
*/
|
||||||
public static boolean validateODataCount(String responseData) {
|
public static boolean validateODataCount(String responseData) {
|
||||||
List<String> items = from(responseData).getList(JSON_VALUE_PATH);
|
List<String> items = from(responseData).getList(JSON_VALUE_PATH);
|
||||||
|
@ -948,6 +956,13 @@ public final class TestUtils {
|
||||||
System.exit(NOT_OK);
|
System.exit(NOT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void failAndExitWithErrorMessage(String msg, Logger logger) {
|
||||||
|
if (logger != null) {
|
||||||
|
logger.error(getDefaultErrorMessage(msg));
|
||||||
|
}
|
||||||
|
System.exit(NOT_OK);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a Data Dictionary Cache
|
* Builds a Data Dictionary Cache
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue