|
| 1 | +/** |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | + * a copy of this software and associated documentation files (the |
| 8 | + * "Software"), to deal in the Software without restriction, including |
| 9 | + * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | + * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | + * permit persons to whom the Software is furnished to do so, subject to |
| 12 | + * the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be |
| 15 | + * included in all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 21 | + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | + */ |
| 25 | + |
| 26 | +package BehaviorTests; |
| 27 | + |
| 28 | +import kong.unirest.Unirest; |
| 29 | +import org.junit.jupiter.api.Test; |
| 30 | + |
| 31 | +public class BaseUrlTest extends BddTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + void canConfigureADefaultBaseUrl() { |
| 35 | + Unirest.config().defaultBaseUrl(MockServer.HOST); |
| 36 | + |
| 37 | + Unirest.get("/get") |
| 38 | + .asObject(RequestCapture.class) |
| 39 | + .getBody() |
| 40 | + .assertUrl(MockServer.GET); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void willNotUseTheDefaultIfOverridden() { |
| 45 | + Unirest.config().defaultBaseUrl("http://somewhere"); |
| 46 | + |
| 47 | + Unirest.get(MockServer.GET) |
| 48 | + .asObject(RequestCapture.class) |
| 49 | + .getBody() |
| 50 | + .assertUrl(MockServer.GET); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void defaultUrlsCanHavePlaceholders() { |
| 55 | + Unirest.config().defaultBaseUrl(MockServer.PASSED_PATH_PARAM); |
| 56 | + |
| 57 | + Unirest.get("/{another}") |
| 58 | + .routeParam("params", "George") |
| 59 | + .routeParam("another", "Ringo") |
| 60 | + .asObject(RequestCapture.class) |
| 61 | + .getBody() |
| 62 | + .assertUrl("http://localhost:4567/get/George/passed/Ringo"); |
| 63 | + } |
| 64 | +} |
0 commit comments