Skip to content
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

test(mockwebserver): verify ANY method expectations #5670

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
manusa marked this conversation as resolved.
Show resolved Hide resolved
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()
manusa marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}
Loading