-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add triming of the URI in the HTTPRequest class (#23)
- Before this change, seting a baseUrl ending with a "/" and setting a endpoint beginning with a "/" would result in "//" in the url. This change will trim the url so it doesn't matter if you add trailing slash on the baseurl or not as well as the leading slash on the endpoint. - Adding tests for this new functionality.
- Loading branch information
1 parent
e675355
commit b60ea57
Showing
2 changed files
with
86 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
42 changes: 42 additions & 0 deletions
42
src/test/java/com/ericsson/eiffelcommons/Utilstest/HttpRequestTest.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,42 @@ | ||
package com.ericsson.eiffelcommons.Utilstest; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
import org.apache.http.client.utils.URIBuilder; | ||
import org.junit.Test; | ||
|
||
import com.ericsson.eiffelcommons.utils.HttpRequest; | ||
import com.ericsson.eiffelcommons.utils.HttpRequest.HttpMethod; | ||
|
||
public class HttpRequestTest { | ||
@Test | ||
public void testBuildingOfURI() throws NoSuchFieldException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException { | ||
String expectedURI = "http://something.com/testing/test/"; | ||
HttpRequest request= new HttpRequest(HttpMethod.POST); | ||
Method method = request.getClass().getDeclaredMethod("createURIBuilder"); | ||
method.setAccessible(true); | ||
|
||
request.setBaseUrl("http://something.com"); | ||
request.setEndpoint("/testing/test/"); | ||
URIBuilder builder = (URIBuilder) method.invoke(request); | ||
assertEquals(expectedURI, builder.toString()); | ||
|
||
request.setBaseUrl("http://something.com/"); | ||
request.setEndpoint("/testing/test/"); | ||
builder = (URIBuilder) method.invoke(request); | ||
assertEquals(expectedURI, builder.toString()); | ||
|
||
request.setBaseUrl("http://something.com/"); | ||
request.setEndpoint("testing/test/"); | ||
builder = (URIBuilder) method.invoke(request); | ||
assertEquals(expectedURI, builder.toString()); | ||
|
||
request.setBaseUrl("http://something.com"); | ||
request.setEndpoint("testing/test/"); | ||
builder = (URIBuilder) method.invoke(request); | ||
assertEquals(expectedURI, builder.toString()); | ||
} | ||
} |