New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report status code before schema #338
Changes from 4 commits
011815d
25a82f4
45aa2bc
a1e35d1
6d73300
f53a1d2
9d6c0ce
eb960b9
0e69390
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import com.twosigma.webtau.http.datanode.DataNode | |
import com.twosigma.webtau.http.datanode.GroovyDataNode | ||
import com.twosigma.webtau.http.testserver.TestServerResponse | ||
import com.twosigma.webtau.http.validation.HttpResponseValidator | ||
import com.twosigma.webtau.http.validation.HttpValidationHandlers | ||
import com.twosigma.webtau.utils.ResourceUtils | ||
import com.twosigma.webtau.utils.UrlUtils | ||
import org.junit.* | ||
|
@@ -982,6 +983,75 @@ class HttpGroovyTest implements HttpConfiguration { | |
http.lastValidationResult.errorMessage.should == ~/java.lang.IllegalArgumentException: Request header is null/ | ||
} | ||
|
||
@Test | ||
void "implicit status code mismatch reported before additional validators"() { | ||
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wonder if we should use the |
||
try { | ||
code { | ||
http.get("/notfound") {} | ||
} should throwException(AssertionError, ~/(?s)header.statusCode.*404.*200/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order is not clear based on the assertion |
||
} finally { | ||
HttpValidationHandlers.reset() | ||
} | ||
} | ||
|
||
@Test | ||
void "explicit status code mismatch reported before additional validators"() { | ||
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") } | ||
try { | ||
code { | ||
http.get("/notfound") { | ||
statusCode.should == 200 | ||
} | ||
} should throwException(AssertionError, ~/(?s)header.statusCode.*404.*200/) | ||
} finally { | ||
HttpValidationHandlers.reset() | ||
} | ||
} | ||
|
||
@Test | ||
void "status code mismatch reported before additional validators and failing body assertions"() { | ||
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") } | ||
try { | ||
code { | ||
http.get("/notfound") { | ||
id.should == 'foo' | ||
} | ||
} should throwException(AssertionError, ~/(?s)header.statusCode.*404.*200/) | ||
} finally { | ||
HttpValidationHandlers.reset() | ||
} | ||
} | ||
|
||
@Test | ||
void "assertion and additional validation errors"() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style of the test name mismatches the other ones. |
||
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") } | ||
try { | ||
code { | ||
http.get("/notfound") { | ||
statusCode.should == 404 | ||
id.should == 'foo' | ||
} | ||
} should throwException(AssertionError, ~/expected: "foo"/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not clear by this check if the |
||
} finally { | ||
HttpValidationHandlers.reset() | ||
} | ||
} | ||
|
||
@Test | ||
void "additional validator errors reported if status code is correct"() { | ||
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (as per other comment) we don't introduce a |
||
try { | ||
code { | ||
http.get("/notfound") { | ||
statusCode.should == 404 | ||
} | ||
} should throwException(AssertionError, ~/schema validation error/) | ||
} finally { | ||
HttpValidationHandlers.reset() | ||
} | ||
} | ||
|
||
@Override | ||
String fullUrl(String url) { | ||
if (UrlUtils.isFull(url)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,15 @@ | |
public class HttpValidationHandlers { | ||
private static final List<HttpValidationHandler> configurations = ServiceLoaderUtils.load(HttpValidationHandler.class); | ||
|
||
public static void register(HttpValidationHandler handler) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the times I call these methods simply |
||
configurations.add(handler); | ||
} | ||
|
||
public static void reset() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer to maintain as fewer |
||
configurations.clear(); | ||
configurations.addAll(ServiceLoaderUtils.load(HttpValidationHandler.class)); | ||
} | ||
|
||
public static void validate(HttpValidationResult validationResult) { | ||
configurations.forEach(c -> c.validate(validationResult)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need a failed case?