opentelemetry-java-instrume.../instrumentation/ratpack-1.4/src/test/groovy/client/RatpackHttpClientTest.groovy

69 lines
1.8 KiB
Groovy

/*
* Copyright 2020, OpenTelemetry Authors
*
* 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 client
import io.opentelemetry.auto.instrumentation.netty41.client.NettyHttpClientDecorator
import io.opentelemetry.auto.test.base.HttpClientTest
import ratpack.exec.ExecResult
import ratpack.http.client.HttpClient
import ratpack.test.exec.ExecHarness
import spock.lang.AutoCleanup
import spock.lang.Shared
class RatpackHttpClientTest extends HttpClientTest<NettyHttpClientDecorator> {
@AutoCleanup
@Shared
ExecHarness exec = ExecHarness.harness()
@Shared
def client = HttpClient.of {}
@Override
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
ExecResult<Integer> result = exec.yield {
def resp = client.request(uri) { spec ->
spec.method(method)
spec.headers { headersSpec ->
headers.entrySet().each {
headersSpec.add(it.key, it.value)
}
}
}
return resp.map {
callback?.call()
it.status.code
}
}
return result.value
}
@Override
NettyHttpClientDecorator decorator() {
return NettyHttpClientDecorator.DECORATE
}
@Override
boolean testRedirects() {
false
}
@Override
boolean testConnectionFailure() {
false
}
}