-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve lowLevelHttpRequest, so that it's available to tests.
When lowLevelHttpRequest is not set via MockHttpTransport.Builder, buildRequest() creates a new instance of MockLowLevelHttpTransport. Due to what seems to be a bug, the newly created MLLHT wasn't saved to MHT instance. That means, getLowLevelHttpRequest() called on such instance returns null, making it impossible to inspect actual request being sent. For example, this bug made it impossible to verify headers of outbound HTTP requests.
- Loading branch information
1 parent
8fda4a1
commit 8b59272
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
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
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
45 changes: 45 additions & 0 deletions
45
...e-http-client/src/test/java/com/google/api/client/testing/http/MockHttpTransportTest.java
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,45 @@ | ||
/* | ||
* Copyright (c) 2013 Google 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 com.google.api.client.testing.http; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.api.client.http.GenericUrl; | ||
import com.google.api.client.http.HttpRequest; | ||
import com.google.api.client.http.HttpRequestFactory; | ||
|
||
import junit.framework.TestCase; | ||
|
||
/** | ||
* Tests {@link MockHttpTransport}. | ||
* | ||
* @author Paweł Zuzelski | ||
*/ | ||
public final class MockHttpTransportTest extends TestCase { | ||
// The purpose of this test is to verify, that the actual lowLevelHttpRequest used is preserved | ||
// so that the content of the request can be verified in tests. | ||
public void testBuildGetRequest_preservesLoLevelHttpRequest() throws Exception { | ||
MockHttpTransport httpTransport = new MockHttpTransport(); | ||
GenericUrl url = new GenericUrl("http://example.org"); | ||
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(); | ||
HttpRequest request = requestFactory.buildGetRequest(url); | ||
request.getHeaders().set("foo", "bar"); | ||
Object unusedOnlyInspectingSideEffects = request.execute(); | ||
MockLowLevelHttpRequest actualRequest = httpTransport.getLowLevelHttpRequest(); | ||
assertThat(actualRequest.getHeaders()).containsKey("foo"); | ||
assertThat(actualRequest.getHeaders().get("foo")).containsExactly("bar"); | ||
} | ||
} | ||
|
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