Permalink
Browse files

#281 finished implementing changes to support clear logs or exceptio…

…ns or both
  • Loading branch information...
1 parent de3290e commit b8f0b418d15ffa10904828c1feb8991f2862c1ae @jamesdbloom committed Oct 13, 2016
@@ -199,6 +199,7 @@ public MockServerClient clear(HttpRequest httpRequest) {
* Clear expectations, logs or both that match the http
*
* @param httpRequest the http request that is matched against when deciding whether to clear each expectation if null all expectations are cleared
+ * @param type the type to clear, EXPECTATION, LOG or BOTH
*/
public MockServerClient clear(HttpRequest httpRequest, TYPE type) {
sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withQueryStringParameter("type", type.name().toLowerCase()).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8));
@@ -213,8 +214,8 @@ void sendExpectation(Expectation expectation) {
}
public enum TYPE {
- LOGS,
- EXPECTATIONS,
+ LOG,
+ EXPECTATION,
BOTH;
}
@@ -422,14 +422,14 @@ public void shouldSendClearRequestWithType() throws Exception {
when(mockHttpRequestSerializer.serialize(someRequestMatcher)).thenReturn(someRequestMatcher.toString());
// when
- mockServerClient.clear(someRequestMatcher, MockServerClient.TYPE.LOGS);
+ mockServerClient.clear(someRequestMatcher, MockServerClient.TYPE.LOG);
// then
verify(mockHttpClient).sendRequest(outboundRequest("localhost", 1080, "",
request()
.withMethod("PUT")
.withPath("/clear")
- .withQueryStringParameter("type", "logs")
+ .withQueryStringParameter("type", "log")
.withBody(someRequestMatcher.toString(), Charsets.UTF_8))
);
}
@@ -202,9 +202,11 @@ var mockServerClient = function (host, port) {
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to
* decide which expectations to cleared, however if an object is passed
* in the value will be treated as a full request matcher object
+ * @param type if a string is passed in the value will be treated as the type to clear
+ * either expectations, logs or both.
*/
- var clear = function (pathOrRequestMatcher) {
- xmlhttp.open("PUT", mockServerUrl + "/clear", false);
+ var clear = function (pathOrRequestMatcher, type) {
+ xmlhttp.open("PUT", mockServerUrl + "/clear" + (type ? "?type=" + type : ""), false);
xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
if (typeof pathOrRequestMatcher === "string") {
xmlhttp.send(JSON.stringify(createResponseMatcher(pathOrRequestMatcher)));
@@ -235,7 +237,7 @@ var mockServerClient = function (host, port) {
} else {
xmlhttp.send(JSON.stringify(createResponseMatcher(".*")));
}
- return JSON.parse(xmlhttp.responseText);
+ return xmlhttp.responseText && JSON.parse(xmlhttp.responseText);
};
/**
* Retrieve the setup expectations that match the parameter,
Oops, something went wrong.

0 comments on commit b8f0b41

Please sign in to comment.