Improved file names and structure

This commit is contained in:
Joshua Darnell 2020-04-11 15:19:14 -07:00
parent e80d1fc172
commit dea7e62634
10 changed files with 94 additions and 72 deletions

View File

@ -10,7 +10,7 @@ on:
branches: [ master ] branches: [ master ]
jobs: jobs:
test: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -22,5 +22,5 @@ jobs:
java-version: 1.8 java-version: 1.8
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
- name: Run acceptance tests - name: Build and Run acceptance tests
run: ./gradlew test run: ./gradlew build

View File

@ -249,58 +249,6 @@ public class Commander {
return reportBuilder.toString(); return reportBuilder.toString();
} }
/**
* Static version of the metadata validator that can work with a given client
*
* @param metadata the XML Metadata to validate
* @param client the OData client to use for validation
* @return true if the given XML metadata is valid, false otherwise
*/
public static boolean validateMetadata(XMLMetadata metadata, ODataClient client) {
try {
// call the probably-useless metadata validator. can't hurt though
// SEE: https://github.com/apache/olingo-odata4/blob/master/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataMetadataValidationImpl.java#L77-L116
client.metadataValidation().validateMetadata(metadata);
// also check whether metadata contains a valid service document in OData v4 format
return client.metadataValidation().isServiceDocument(metadata)
&& client.metadataValidation().isV4Metadata(metadata);
} catch (NullPointerException nex) {
LOG.error("ERROR: Validation Failed! Null pointer exception while trying to validate metadata.");
} catch (Exception ex) {
LOG.error("ERROR: Validation Failed! General error occurred when validating metadata.\n" + ex.getMessage());
if (ex.getCause() != null) {
LOG.error("Caused by: " + ex.getCause().getMessage());
}
}
return false;
}
/**
* Static version of the metadata validator that can work with a given client
*
* @param edm the Edm to validate
* @param client the OData client to use for validation
* @return true if the given XML metadata is valid, false otherwise
*/
public static boolean validateMetadata(Edm edm, ODataClient client) {
try {
// call the probably-useless metadata validator. can't hurt though
// SEE: https://github.com/apache/olingo-odata4/blob/master/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataMetadataValidationImpl.java#L77-L116
client.metadataValidation().validateMetadata(edm);
//if Edm metadata are invalid, the previous line will throw an exception and this line won't be reached.
return true;
} catch (NullPointerException nex) {
LOG.error("ERROR: Validation Failed! Null pointer exception while trying to validate metadata.");
} catch (Exception ex) {
LOG.error("ERROR: Validation Failed! General error occurred when validating metadata.\n" + ex.getMessage());
if (ex.getCause() != null) {
LOG.error("Caused by: " + ex.getCause().getMessage());
}
}
return false;
}
/** /**
* Deserializes XML Metadata from a string * Deserializes XML Metadata from a string
* *
@ -432,6 +380,59 @@ public class Commander {
client.getSerializer(ContentType.APPLICATION_XML).write(writer, metadata); client.getSerializer(ContentType.APPLICATION_XML).write(writer, metadata);
} }
/**
* Static version of the metadata validator that can work with a given client
*
* @param metadata the XML Metadata to validate
* @param client the OData client to use for validation
* @return true if the given XML metadata is valid, false otherwise
*/
public static boolean validateMetadata(XMLMetadata metadata, ODataClient client) {
try {
// call the probably-useless metadata validator. can't hurt though
// SEE: https://github.com/apache/olingo-odata4/blob/master/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataMetadataValidationImpl.java#L77-L116
client.metadataValidation().validateMetadata(metadata);
// also check whether metadata contains a valid service document in OData v4 format
return client.metadataValidation().isServiceDocument(metadata)
&& client.metadataValidation().isV4Metadata(metadata);
} catch (NullPointerException nex) {
LOG.error("ERROR: Validation Failed! Null pointer exception while trying to validate metadata.");
} catch (Exception ex) {
LOG.error("ERROR: Validation Failed! General error occurred when validating metadata.\n" + ex.getMessage());
if (ex.getCause() != null) {
LOG.error("Caused by: " + ex.getCause().getMessage());
}
}
return false;
}
/**
* Static version of the metadata validator that can work with a given client
*
* @param edm the Edm to validate
* @param client the OData client to use for validation
* @return true if the given XML metadata is valid, false otherwise
*/
public static boolean validateMetadata(Edm edm, ODataClient client) {
try {
// call the probably-useless metadata validator. can't hurt though
// SEE: https://github.com/apache/olingo-odata4/blob/master/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataMetadataValidationImpl.java#L77-L116
client.metadataValidation().validateMetadata(edm);
//if Edm metadata are invalid, the previous line will throw an exception and this line won't be reached.
return true;
} catch (NullPointerException nex) {
LOG.error("ERROR: Validation Failed! Null pointer exception while trying to validate metadata.");
} catch (Exception ex) {
LOG.error("ERROR: Validation Failed! General error occurred when validating metadata.\n" + ex.getMessage());
if (ex.getCause() != null) {
LOG.error("Caused by: " + ex.getCause().getMessage());
}
}
return false;
}
/** /**
* Validates given XMLMetadata * Validates given XMLMetadata
* *

View File

@ -1,13 +1,15 @@
Feature: Commander Platinum Web API Test Container Feature: Commander Platinum Web API Test Container
Background: Background:
Given a Web API test container was created using the RESOScript "mock.platinum.resoscript" Given a Web API test container was created using the RESOScript "mock-platinum.resoscript"
And metadata were loaded from the sample resource "good.edmx-and-edm.xml" And metadata were loaded from the sample resource "good-edmx-and-edm.xml"
Scenario: Test Container is using Token-Based Authentication Scenario: Test Container is using Token-Based Authentication
Given a Commander instance exists within the test container Given a Commander instance exists within the test container
And Settings are present in the test container
And an auth token is provided in "ClientSettings_BearerToken" And an auth token is provided in "ClientSettings_BearerToken"
Then the Commander is created using auth token client mode Then the Commander is created using auth token client mode
And the auth token has a value of "testTokenValue" And the auth token has a value of "testTokenValue"
But the Commander is not created using client credentials mode But the Commander is not created using client credentials mode
Scenario: Test that the container can validate known-good metadata

View File

@ -8,12 +8,12 @@ Feature: Commander XML and Metadata Validation
# XML Validation Tests # XML Validation Tests
####################################### #######################################
Scenario: XML Validation using OASIS reference XSDs Scenario: XML Validation using OASIS reference XSDs
Given metadata were loaded from the sample resource "good.edmx-and-edm.xml" Given metadata were loaded from the sample resource "good-edmx-and-edm.xml"
When XML validation is performed on the resource data When XML validation is performed on the resource data
Then XML validation succeeds Then XML validation succeeds
Scenario: XML Validation fails when XML are malformed Scenario: XML Validation fails when XML are malformed
Given metadata were loaded from the sample resource "bad.edmx-unparsable-xml.xml" Given metadata were loaded from the sample resource "bad-edmx-unparsable-xml.xml"
When XML validation is performed on the resource data When XML validation is performed on the resource data
Then XML validation fails Then XML validation fails
@ -22,12 +22,12 @@ Feature: Commander XML and Metadata Validation
# XML Metadata Validation Tests # XML Metadata Validation Tests
####################################### #######################################
Scenario: XML Metadata validation succeeds when XML Metadata are valid Scenario: XML Metadata validation succeeds when XML Metadata are valid
Given metadata were loaded from the sample resource "good.edmx-and-edm.xml" Given metadata were loaded from the sample resource "good-edmx-and-edm.xml"
When XML Metadata validation is performed on the resource data When XML Metadata validation is performed on the resource data
Then XML Metadata validation succeeds Then XML Metadata validation succeeds
Scenario: XML Validation fails when XML Metadata are missing Key element in EntityType definition Scenario: XML Validation fails when XML Metadata are missing Key element in EntityType definition
Given metadata were loaded from the sample resource "bad.edmx-no-keyfield.xml" Given metadata were loaded from the sample resource "bad-edmx-no-keyfield.xml"
When XML Metadata validation is performed on the resource data When XML Metadata validation is performed on the resource data
Then XML Metadata validation fails Then XML Metadata validation fails
@ -36,11 +36,11 @@ Feature: Commander XML and Metadata Validation
# Edm Validation Tests # Edm Validation Tests
####################################### #######################################
Scenario: Edm validation succeeds when XML Metadata contain a valid Edm Scenario: Edm validation succeeds when XML Metadata contain a valid Edm
Given metadata were loaded from the sample resource "good.edmx-and-edm.xml" Given metadata were loaded from the sample resource "good-edmx-and-edm.xml"
When Edm validation is performed on the resource data When Edm validation is performed on the resource data
Then Edm Metadata validation succeeds Then Edm Metadata validation succeeds
Scenario: Edm validation fails when XML Metadata don't contain a valid service document Scenario: Edm validation fails when XML Metadata don't contain a valid service document
Given metadata were loaded from the sample resource "bad.edmx-wrong-edm-binding-target.xml" Given metadata were loaded from the sample resource "bad-edmx-wrong-edm-binding-target.xml"
When Edm validation is performed on the resource data When Edm validation is performed on the resource data
Then Edm Metadata validation fails Then Edm Metadata validation fails

View File

@ -26,11 +26,11 @@ public class TestWebAPITestContainer implements En {
URL resource = getClass().getClassLoader().getResource(fileName); URL resource = getClass().getClassLoader().getResource(fileName);
assertNotNull(getDefaultErrorMessage("was unable to find the given RESOScript:", fileName), resource); assertNotNull(getDefaultErrorMessage("was unable to find the given RESOScript:", fileName), resource);
testContainer.set(new WebAPITestContainer()); setTestContainer(new WebAPITestContainer());
testContainer.get().setSettings(Settings.loadFromRESOScript(new File(resource.getFile()))); getTestContainer().setSettings(Settings.loadFromRESOScript(new File(resource.getFile())));
assertNotNull(getDefaultErrorMessage("could not load mock RESOScript: " + resource.getFile()), testContainer.get().getSettings()); assertNotNull(getDefaultErrorMessage("could not load mock RESOScript: " + resource.getFile()), getTestContainer().getSettings());
testContainer.get().initialize(); getTestContainer().initialize();
} catch (Exception ex) { } catch (Exception ex) {
fail(getDefaultErrorMessage(ex)); fail(getDefaultErrorMessage(ex));
} }
@ -41,28 +41,41 @@ public class TestWebAPITestContainer implements En {
* auth settings validation * auth settings validation
*/ */
When("^an auth token is provided in \"([^\"]*)\"$", (String clientSettingsAuthToken) -> { When("^an auth token is provided in \"([^\"]*)\"$", (String clientSettingsAuthToken) -> {
String token = Settings.resolveParametersString(clientSettingsAuthToken, testContainer.get().getSettings()); String token = Settings.resolveParametersString(clientSettingsAuthToken, getTestContainer().getSettings());
assertNotNull(getDefaultErrorMessage("BearerToken is null in the ClientSettings section!"), token); assertNotNull(getDefaultErrorMessage("BearerToken is null in the ClientSettings section!"), token);
}); });
Then("^the Commander is created using auth token client mode$", () -> { Then("^the Commander is created using auth token client mode$", () -> {
assertTrue(getDefaultErrorMessage("expected auth token Commander client!"), assertTrue(getDefaultErrorMessage("expected auth token Commander client!"),
testContainer.get().getCommander().isAuthTokenClient()); getTestContainer().getCommander().isAuthTokenClient());
}); });
And("^the auth token has a value of \"([^\"]*)\"$", (String assertedTokenValue) -> { And("^the auth token has a value of \"([^\"]*)\"$", (String assertedTokenValue) -> {
assertEquals(getDefaultErrorMessage("asserted token value is not equal to the one provided in the container!"), assertEquals(getDefaultErrorMessage("asserted token value is not equal to the one provided in the container!"),
assertedTokenValue, testContainer.get().getAuthToken()); assertedTokenValue, getTestContainer().getAuthToken());
}); });
And("^a Commander instance exists within the test container$", () -> { And("^a Commander instance exists within the test container$", () -> {
assertNotNull(getDefaultErrorMessage("Commander instance is null in the container!"), assertNotNull(getDefaultErrorMessage("Commander instance is null in the container!"),
testContainer.get().getCommander()); getTestContainer().getCommander());
}); });
But("^the Commander is not created using client credentials mode$", () -> { But("^the Commander is not created using client credentials mode$", () -> {
assertFalse(getDefaultErrorMessage("expected that the Commander was not using client credentials"), assertFalse(getDefaultErrorMessage("expected that the Commander was not using client credentials"),
testContainer.get().getCommander().isOAuth2Client()); getTestContainer().getCommander().isOAuth2Client());
});
And("^Settings are present in the test container$", () -> {
assertNotNull(getDefaultErrorMessage("settings were not found in the Web API test container!"),
getTestContainer().getSettings());
}); });
} }
private WebAPITestContainer getTestContainer() {
return testContainer.get();
}
private void setTestContainer(WebAPITestContainer testContainer) {
this.testContainer.set(testContainer);
}
} }

View File

@ -10,6 +10,12 @@
<Property Name="ListingKey" Type="Edm.String" MaxLength="255" Nullable="false"/> <Property Name="ListingKey" Type="Edm.String" MaxLength="255" Nullable="false"/>
<Property Name="ListingId" Type="Edm.String" MaxLength="255" /> <Property Name="ListingId" Type="Edm.String" MaxLength="255" />
</EntityType> </EntityType>
<EnumType Name="FileAccess" UnderlyingType="Edm.Int32" IsFlags="true">
<Member Name="Read" Value="1" />
<Member Name="Write" Value="2" />
<Member Name="Create" Value="4" />
<Member Name="Delete" Value="8" />
</EnumType>
</Schema> </Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default"> <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default">
<EntityContainer Name="Container"> <EntityContainer Name="Container">