-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mockwebserver): verify ANY method expectations
Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...kwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerAnyMethodTest.groovy
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,89 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.mockwebserver | ||
|
||
import io.vertx.core.Vertx | ||
import io.vertx.ext.web.client.WebClient | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
import spock.util.concurrent.AsyncConditions | ||
|
||
class DefaultMockServerAnyMethodTest extends Specification { | ||
|
||
@Shared | ||
static def vertx = Vertx.vertx() | ||
|
||
DefaultMockServer server | ||
|
||
WebClient client | ||
|
||
def setup() { | ||
server = new DefaultMockServer() | ||
server.start() | ||
client = WebClient.create(vertx) | ||
} | ||
|
||
def cleanup() { | ||
server.shutdown() | ||
client.close() | ||
} | ||
|
||
def cleanupSpec() { | ||
vertx.close() | ||
} | ||
|
||
def "when setting an expectation for ANY should respond to POST"() { | ||
given: "An expectation with any" | ||
server.expect().any().withPath("/api/v1/resource").andReturn(200, "OK").always() | ||
and: "A POST request" | ||
def req1 = client.post(server.port, server.getHostName(), "/api/v1/resource") | ||
.send() | ||
and: "An instance of AsyncConditions" | ||
def async = new AsyncConditions(1) | ||
|
||
when: "The request is sent and completed" | ||
req1.onComplete { isr -> | ||
async.evaluate { | ||
assert req1.result().statusCode() == 200 | ||
assert req1.result().body().toString() == "OK" | ||
} | ||
} | ||
|
||
then: "Expect the result to be completed in the specified time" | ||
async.await(10) | ||
} | ||
|
||
def "when setting an expectation for ANY should respond to PUT"() { | ||
given: "An expectation with any" | ||
server.expect().any().withPath("/api/v1/resource").andReturn(200, "OK").always() | ||
and: "A PUT request" | ||
def req1 = client.put(server.port, server.getHostName(), "/api/v1/resource") | ||
.send() | ||
and: "An instance of AsyncConditions" | ||
def async = new AsyncConditions(1) | ||
|
||
when: "The request is sent and completed" | ||
req1.onComplete { isr -> | ||
async.evaluate { | ||
assert req1.result().statusCode() == 200 | ||
assert req1.result().body().toString() == "OK" | ||
} | ||
} | ||
|
||
then: "Expect the result to be completed in the specified time" | ||
async.await(10) | ||
} | ||
} |