Added better Metadata Reporting. Further fixes to RESOScripts

This commit is contained in:
Joshua Darnell 2020-03-27 22:28:23 -07:00
parent a47e03d91e
commit 4b84bc5ead
6 changed files with 66 additions and 28 deletions

Binary file not shown.

View File

@ -521,19 +521,19 @@
<Request
RequestId="REQ-WA103-QO29.1"
OutputFile="REQ-WA103-QO29.1.json"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_ExpandField*&amp;$expand=*Parameter_ExpandField*"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_KeyOrKeyNumericField*,*Parameter_ExpandField*&amp;$expand=*Parameter_ExpandField*"
/>
<Request
RequestId="REQ-WA103-QO29.2"
OutputFile="REQ-WA103-QO29.2.json"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_ExpandField*&amp;$expand=*Parameter_ExpandField*&amp;$filter=PhotosCount gt 0"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_KeyOrKeyNumericField*,*Parameter_ExpandField*&amp;$expand=*Parameter_ExpandField*&amp;$filter=PhotosCount gt 0"
/>
<Request
RequestId="REQ-WA103-QO29.3"
OutputFile="REQ-WA103-QO29.3.json"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_ExpandField*&amp;$expand=*Parameter_ExpandField**Parameter_RequiredParametersFilter*"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_KeyOrKeyNumericField*,*Parameter_ExpandField*&amp;$expand=*Parameter_ExpandField**Parameter_RequiredParametersFilter*"
/>
<Request

View File

@ -7,8 +7,8 @@ Feature: Web API Server 1.0.2 Certification
Background:
Given a RESOScript file was provided
And Client Settings and Parameters were read from the file
And a test environment was successfully created from the given RESOScript
And the test environment uses an authorization_code or client_credentials for authentication
And a test container was successfully created from the given RESOScript
And the test container uses an authorization_code or client_credentials for authentication
#######################################

View File

@ -80,14 +80,14 @@ public class WebAPIServer_1_0_2 implements En {
LOG.info("RESOScript loaded successfully!");
});
Given("^a test environment was successfully created from the given RESOScript$", () -> {
Given("^a test container was successfully created from the given RESOScript$", () -> {
getTestContainer().initialize();
});
/*
* Ensures that the client either uses Authorization Codes or Client Credentials
*/
And("^the test environment uses an authorization_code or client_credentials for authentication$", () -> {
And("^the test container uses an authorization_code or client_credentials for authentication$", () -> {
assertNotNull(getTestContainer().getCommander());
assertTrue("ERROR: Commander must either have a valid Authorization Code or Client Credentials configuration.",
getTestContainer().getCommander().isTokenClient() || (getTestContainer().getCommander().isOAuthClient() && getTestContainer().getCommander().hasValidAuthConfig()));
@ -289,7 +289,7 @@ public class WebAPIServer_1_0_2 implements En {
//TODO: convert to OData filter factory
getTestContainer().setRequestUri(Commander.prepareURI(
Settings.resolveParameters(getTestContainer().getSettings().getRequest(requestId), getTestContainer().getSettings()).getUrl()
+ AMPERSAND + DOLLAR_SIGN + QueryOption.SKIP.toString() + EQUALS + skipCount));
+ AMPERSAND + ODATA_QUERY_PARAMS.SKIP + EQUALS + skipCount));
getTestContainer().executePreparedGetRequest();
} catch (Exception ex) {
fail(ex.toString());
@ -816,6 +816,7 @@ public class WebAPIServer_1_0_2 implements En {
final String serviceRoot = Settings.resolveParametersString(clientSettingsServiceRoot, getTestContainer().getSettings());
assertEquals("ERROR: given service root doesn't match the one configured in the Commander", serviceRoot, getTestContainer().getCommander().getServiceRoot());
LOG.info("Requesting XML Metadata from: " + serviceRoot);
try {
assertNotNull("ERROR: could not find valid XML Metadata for given service root: " + serviceRoot, getTestContainer().getXMLMetadata());
} catch (ODataClientErrorException cex) {
@ -833,8 +834,10 @@ public class WebAPIServer_1_0_2 implements En {
final String serviceRoot = Settings.resolveParametersString(clientSettingsServiceRoot, getTestContainer().getSettings());
assertEquals("ERROR: given service root doesn't match the one configured in the Commander", serviceRoot, getTestContainer().getCommander().getServiceRoot());
LOG.info("Requesting Edm Metadata from: " + serviceRoot);
try {
assertNotNull("ERROR: could not find valid Edm Metadata for given service root: " + serviceRoot, getTestContainer().getEdm());
if (showResponses) LOG.info(Commander.getMetadataReport(getTestContainer().getEdm()));
} catch (ODataClientErrorException cex) {
getTestContainer().setResponseCode(cex.getStatusLine().getStatusCode());
fail(cex.toString());
@ -881,27 +884,32 @@ public class WebAPIServer_1_0_2 implements En {
clientEntity.getProperties().forEach(clientProperty -> {
assertNotNull("ERROR: field name cannot be null!", clientProperty.getName());
assertNotNull("ERROR: data type could not be found for " + clientProperty.getName() + "! "
+ "\nCheck the NavigationProperty for your $expand field.", clientProperty.getValue().getTypeName());
if (clientProperty.getName().equals(expandField)) {
assertNotNull("ERROR: '" + parameterExpandField + "' contains no data!", clientProperty.getValue());
LOG.info("\tExpanded Field Name: " + expandField);
clientProperty.getValue().asComplex().forEach(expandedClientProperty -> {
assertNotNull("ERROR: field name cannot be null!", expandedClientProperty.getName());
assertNotNull("ERROR: data type could not be found for " + expandedClientProperty.getName(), expandedClientProperty.getValue().getTypeName());
LOG.info("\t\tField Name: " + expandedClientProperty.getName());
LOG.info("\t\tField Value: " + expandedClientProperty.getValue().toString());
LOG.info("\t\tType Name: " + expandedClientProperty.getValue().getTypeName());
LOG.info("\t\t" + REPORT_DIVIDER_SMALL);
assertNotNull("ERROR: data type could not be found for: " + expandedClientProperty.getName(),
expandedClientProperty.getValue().getTypeName());
if (expandedClientProperty.getValue().asPrimitive().toValue() != null) {
LOG.info("\t\tField Name: " + expandedClientProperty.getName());
LOG.info("\t\tField Value: " + expandedClientProperty.getValue().toString());
LOG.info("\t\tType Name: " + expandedClientProperty.getValue().getTypeName());
LOG.info("\t\t" + REPORT_DIVIDER_SMALL);
}
});
} else {
LOG.info("\tField Name: " + clientProperty.getName());
LOG.info("\tField Value: " + clientProperty.getValue().toString());
LOG.info("\tType Name: " + clientProperty.getValue().getTypeName());
LOG.info("\t" + REPORT_DIVIDER);
}
assertNotNull("ERROR: data type could not be found for " + clientProperty.getName(), clientProperty.getValue().getTypeName());
});
});
});

View File

@ -251,28 +251,44 @@ public class Commander {
reportBuilder.append("\n" + REPORT_DIVIDER_SMALL);
schema.getTypeDefinitions().forEach(a ->
reportBuilder.append("\n\n\tType Definition:").append(a.getName()));
reportBuilder.append("\nType Definition:").append(a.getName()));
schema.getEntityTypes().forEach(a -> {
reportBuilder.append("\n\n\tEntity Type: ").append(a.getName());
reportBuilder.append("\nEntity Type: ").append(a.getName());
a.getKeyPropertyRefs().forEach(ref ->
reportBuilder.append("\n\t\tKey Field: ").append(ref.getName()));
a.getPropertyNames().forEach(n -> reportBuilder.append("\n\t\tName: ").append(n));
reportBuilder.append("\n\tKey Field: ").append(ref.getName()));
a.getPropertyNames().forEach(n -> reportBuilder.append("\n\tName: ").append(n));
});
schema.getEnumTypes().forEach(a -> {
reportBuilder.append("\n\n\tEnum Type: ").append(a.getName());
a.getMemberNames().forEach(n -> reportBuilder.append("\n\t\tName: ").append(n));
schema.getEnumTypes().forEach(edmEnumType -> {
reportBuilder.append("\nEnum Type: ")
.append(edmEnumType.getName())
.append(" (").append(schema.getNamespace()).append(", ")
.append(edmEnumType.getUnderlyingType().getFullQualifiedName().getFullQualifiedNameAsString())
.append(")");
edmEnumType.getMemberNames().forEach(n -> {
reportBuilder
.append("\n\tName: ").append(n);
if (edmEnumType.getMember(n).getAnnotations().size() > 0) {
reportBuilder
.append("\n\tAnnotations: ")
.append(edmEnumType.getMember(n).getAnnotations().toString())
.append("\n\n");
}
});
});
schema.getComplexTypes().forEach(a ->
reportBuilder.append("\n\n\tComplex Entity Type: ").append(a.getFullQualifiedName().getFullQualifiedNameAsString()));
reportBuilder.append("\nComplex Entity Type: ").append(a.getFullQualifiedName().getFullQualifiedNameAsString()));
schema.getAnnotationGroups().forEach(a ->
reportBuilder.append("\n\n\tAnnotation: ").append(a.getQualifier()).append(", Target Path: ").append(a.getTargetPath()));
reportBuilder.append("\nAnnotation: ").append(a.getQualifier()).append(", Target Path: ").append(a.getTargetPath()));
schema.getTerms().forEach(a ->
reportBuilder.append("\n\n\tTerm: ").append(a.getFullQualifiedName().getFullQualifiedNameAsString()));
reportBuilder.append("\nTerm: ").append(a.getFullQualifiedName().getFullQualifiedNameAsString()));
});
return reportBuilder.toString();

View File

@ -44,6 +44,21 @@ public final class WebApiTestContainer implements TestContainer {
public static final String DOLLAR_SIGN = "$";
public static final String PRETTY_FIELD_SEPARATOR = FIELD_SEPARATOR + SINGLE_SPACE;
public static final class ODATA_QUERY_PARAMS {
private static String format = DOLLAR_SIGN + "%s";
//TODO: add additional items as needed, and see if there's a lib for this in Olingo
public static final String
COUNT = String.format(format, QueryOption.COUNT),
EXPAND = String.format(format, QueryOption.EXPAND),
FILTER = String.format(format, QueryOption.FILTER),
ORDERBY = String.format(format, QueryOption.ORDERBY),
SELECT = String.format(format, QueryOption.SELECT),
SEARCH = String.format(format, QueryOption.SEARCH),
SKIP = String.format(format, QueryOption.SKIP),
TOP = String.format(format, QueryOption.TOP);
}
private AtomicReference<Commander> commander = new AtomicReference<>();
private AtomicReference<XMLMetadata> xmlMetadata = new AtomicReference<>();
private AtomicReference<Edm> edm = new AtomicReference<>();
@ -198,10 +213,9 @@ public final class WebApiTestContainer implements TestContainer {
}
public Collection<String> getSelectList() {
final String SELECT_OPERATOR = DOLLAR_SIGN + QueryOption.SELECT.toString();
Arrays.stream(getRequestUri().getQuery().split(AMPERSAND)).forEach(fragment -> {
if (fragment.contains(QueryOption.SELECT.toString())) {
selectList.set(fragment.replace(SELECT_OPERATOR, EMPTY_STRING).replace(EQUALS, EMPTY_STRING));
selectList.set(fragment.replace(ODATA_QUERY_PARAMS.SELECT, EMPTY_STRING).replace(EQUALS, EMPTY_STRING));
}
});