-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add framework to allow test-specific assertions on HTTP response.
Motivation: Individual tests may expect IDS to respond in a specific fashion. Currently there is no way for tests that execise IDS request that return content to assert the HTTP response. This is because, for these interactions, the test client returns the content from IDS and not the HTTP response. Modification: Add the ability for a test to make an HTTP request that includes an assertion on the HTTP response. This is done by providing the assertions as a `Consumer` object. Lambdas provides a light-weight mechanism for writing such assertions. An interceptor is used to create a custom client that asserts the response. The existing code is refactored to take advantage of this. To keep code DRY, two new static methods are introduced that provide lambdas that assert that the response is chunked or is not chunked. Some existing tests are updated to take advantage of this framework. Result: It is now possible to write tests that make test-specific assertions on the HTTP response from IDS, even for interactions where IDS returns content.
- Loading branch information
1 parent
1e32fb4
commit 3105926
Showing
5 changed files
with
166 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/org/icatproject/ids/integration/util/LongValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.icatproject.ids.integration.util; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
|
||
/** | ||
* A Matcher that checks whether a String argument is a Long value. The code is | ||
* heavily based on an answer from Ezequiel to | ||
* <a href="https://stackoverflow.com/questions/58099695/is-there-a-way-in-hamcrest-to-test-for-a-value-to-be-a-number"> | ||
* a stack overview question</a>. | ||
*/ | ||
public class LongValue extends TypeSafeMatcher<String> { | ||
|
||
@Override | ||
protected boolean matchesSafely(String s) { | ||
try { | ||
Long.valueOf(s); | ||
} catch (NumberFormatException nfe) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("is long"); | ||
} | ||
|
||
public static Matcher<String> longValue() { | ||
return new LongValue(); | ||
} | ||
} |
Oops, something went wrong.