parent
d31dbac69e
commit
300f6bf4d7
|
|
@ -70,11 +70,11 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
|
|||
* @param handler the delegate handler
|
||||
* @since 2.0.3
|
||||
*/
|
||||
public LocalHostUriTemplateHandler(Environment environment, String scheme, UriTemplateHandler handler) {
|
||||
public LocalHostUriTemplateHandler(Environment environment, String scheme,
|
||||
UriTemplateHandler handler) {
|
||||
super(handler);
|
||||
Assert.notNull(environment, "Environment must not be null");
|
||||
Assert.notNull(scheme, "Scheme must not be null");
|
||||
Assert.notNull(handler, "Handler must not be null");
|
||||
this.environment = environment;
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,13 +16,21 @@
|
|||
|
||||
package org.springframework.boot.test.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link LocalHostUriTemplateHandler}.
|
||||
|
|
@ -91,4 +99,18 @@ public class LocalHostUriTemplateHandlerTests {
|
|||
assertThat(handler.getRootUri()).isEqualTo("http://localhost:8080/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandShouldUseCustomHandler() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
|
||||
Map<String, ?> uriVariables = new HashMap<>();
|
||||
URI uri = URI.create("http://www.example.com");
|
||||
given(uriTemplateHandler.expand("https://localhost:8080/", uriVariables))
|
||||
.willReturn(uri);
|
||||
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
|
||||
environment, "https", uriTemplateHandler);
|
||||
assertThat(handler.expand("/", uriVariables)).isEqualTo(uri);
|
||||
verify(uriTemplateHandler).expand("https://localhost:8080/", uriVariables);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -38,6 +38,7 @@ public class RootUriTemplateHandler implements UriTemplateHandler {
|
|||
private final UriTemplateHandler handler;
|
||||
|
||||
protected RootUriTemplateHandler(UriTemplateHandler handler) {
|
||||
Assert.notNull(handler, "Handler must not be null");
|
||||
this.rootUri = null;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue