-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mateusz Rzeszutek
committed
Mar 8, 2021
1 parent
3277dab
commit 61f1e82
Showing
2 changed files
with
48 additions
and
88 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...tion/spring/spring-web-3.1/library/src/test/groovy/RestTemplateInstrumentationTest.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,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import io.opentelemetry.instrumentation.spring.httpclients.RestTemplateInterceptor | ||
import io.opentelemetry.instrumentation.test.LibraryTestTrait | ||
import io.opentelemetry.instrumentation.test.base.HttpClientTest | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.web.client.ResourceAccessException | ||
import org.springframework.web.client.RestTemplate | ||
import spock.lang.Shared | ||
|
||
class RestTemplateInstrumentationTest extends HttpClientTest implements LibraryTestTrait { | ||
@Shared | ||
RestTemplate restTemplate | ||
|
||
def setupSpec() { | ||
if (restTemplate == null) { | ||
restTemplate = new RestTemplate() | ||
restTemplate.getInterceptors().add(new RestTemplateInterceptor(getOpenTelemetry())) | ||
} | ||
} | ||
|
||
@Override | ||
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) { | ||
try { | ||
return restTemplate.execute(uri, HttpMethod.valueOf(method), { request -> | ||
headers.forEach(request.getHeaders().&add) | ||
}, { response -> | ||
callback?.call() | ||
response.statusCode.value() | ||
}) | ||
} catch (ResourceAccessException exception) { | ||
throw exception.getCause() | ||
} | ||
} | ||
|
||
@Override | ||
boolean testCircularRedirects() { | ||
false | ||
} | ||
|
||
@Override | ||
boolean testRemoteConnection() { | ||
false | ||
} | ||
} |
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