-
Notifications
You must be signed in to change notification settings - Fork 14
Add abstract client tests #246
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f84f83d
adding AbstractHttpClientTest and an echo target in TestHttpServer
shashank11p 029e2dd
updating AbstractHttpClientTest
shashank11p d775706
updating AbstractHttpClientTest
shashank11p b7190b2
updating okHttp and apache http client tests
shashank11p 7cbcb85
review comments, refactoring
shashank11p a405879
review comments and removing apache async http client changes
shashank11p e163156
review comments
shashank11p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
adding AbstractHttpClientTest and an echo target in TestHttpServer
- Loading branch information
commit f84f83d45b279857f63c38bb858757937df10091
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java
This file contains hidden or 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,105 @@ | ||
| /* | ||
| * Copyright The Hypertrace 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 org.hypertrace.agent.testing; | ||
|
|
||
| import io.opentelemetry.sdk.trace.data.SpanData; | ||
| import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
|
|
||
| public abstract class AbstractHttpClientTest extends AbstractInstrumenterTest { | ||
|
|
||
| protected static final TestHttpServer testHttpServer = new TestHttpServer(); | ||
|
|
||
| public static final String GET_NO_CONTENT_PATH = "http://localhost:%d/get_no_content"; | ||
|
|
||
| public static final String GET_JSON_PATH = "http://localhost:%d/get_json"; | ||
|
|
||
| public static final String POST_PATH = "http://localhost:%d/post"; | ||
|
|
||
| public static final String POST_REDIRECT_PATH = | ||
| "http://localhost:%d/post_redirect_to_get_no_content"; | ||
|
|
||
| public static final String ECHO_PATH = "http://localhost:%d/echo"; | ||
|
|
||
| @BeforeAll | ||
| public static void startServer() throws Exception { | ||
| testHttpServer.start(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void closeServer() throws Exception { | ||
| testHttpServer.close(); | ||
| } | ||
|
|
||
| /** | ||
| * Test for post request with json body. Use ECHO_PATH as url string | ||
| */ | ||
| public abstract void echoJson() throws Exception; | ||
|
|
||
| /** | ||
| * Test for post request with url encoded form body. Use ECHO_PATH as url string | ||
| */ | ||
| public abstract void echoUrlEncoded() throws Exception; | ||
|
|
||
|
shashank11p marked this conversation as resolved.
|
||
| /** | ||
| * Test for post request with plain text body. Use ECHO_PATH as url string | ||
| */ | ||
| public abstract void echoPlainText() throws Exception; | ||
|
|
||
| public void assertResponseHeaders(SpanData spanData) { | ||
|
shashank11p marked this conversation as resolved.
Outdated
|
||
| Assertions.assertEquals( | ||
| TestHttpServer.RESPONSE_HEADER_VALUE, | ||
| spanData | ||
| .getAttributes() | ||
| .get( | ||
| HypertraceSemanticAttributes.httpResponseHeader( | ||
| TestHttpServer.RESPONSE_HEADER_NAME))); | ||
| } | ||
|
|
||
| public void assertGetJsonResponseBody(SpanData spanData) { | ||
| Assertions.assertEquals( | ||
|
shashank11p marked this conversation as resolved.
|
||
| TestHttpServer.GetJsonHandler.RESPONSE_BODY, | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); | ||
| } | ||
|
|
||
| public void assertEchoJson(SpanData spanData) { | ||
| assertResponseHeaders(spanData); | ||
| Assertions.assertNotNull(spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); | ||
| Assertions.assertEquals( | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY), | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); | ||
| } | ||
|
|
||
| public void assertEchoUrlEncoded(SpanData spanData) { | ||
| assertResponseHeaders(spanData); | ||
| Assertions.assertNotNull(spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); | ||
| Assertions.assertEquals( | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY), | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); | ||
| } | ||
|
|
||
| public void assertEchoPlainText(SpanData spanData) { | ||
|
shashank11p marked this conversation as resolved.
Outdated
|
||
| assertResponseHeaders(spanData); | ||
|
shashank11p marked this conversation as resolved.
Outdated
|
||
| Assertions.assertNull( | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); | ||
| Assertions.assertNull( | ||
| spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.