|
|
@ -17,7 +17,6 @@
|
|
|
|
package org.springframework.boot.autoconfigure.ws;
|
|
|
|
package org.springframework.boot.autoconfigure.ws;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
|
|
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
import org.junit.Rule;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
@ -35,18 +34,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
* Tests for {@link WsAutoConfiguration}.
|
|
|
|
* Tests for {@link WsAutoConfiguration}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Vedran Pavic
|
|
|
|
* @author Vedran Pavic
|
|
|
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class WsAutoConfigurationTests {
|
|
|
|
public class WsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
@Rule
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
private AnnotationConfigWebApplicationContext context;
|
|
|
|
public void setupContext() {
|
|
|
|
|
|
|
|
this.context.setServletContext(new MockServletContext());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
@After
|
|
|
|
public void close() {
|
|
|
|
public void close() {
|
|
|
@ -57,7 +52,7 @@ public class WsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void defaultConfiguration() {
|
|
|
|
public void defaultConfiguration() {
|
|
|
|
registerAndRefresh(WsAutoConfiguration.class);
|
|
|
|
load(WsAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
|
|
|
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -66,27 +61,19 @@ public class WsAutoConfigurationTests {
|
|
|
|
public void customPathMustBeginWithASlash() {
|
|
|
|
public void customPathMustBeginWithASlash() {
|
|
|
|
this.thrown.expect(BeanCreationException.class);
|
|
|
|
this.thrown.expect(BeanCreationException.class);
|
|
|
|
this.thrown.expectMessage("Path must start with /");
|
|
|
|
this.thrown.expectMessage("Path must start with /");
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load(WsAutoConfiguration.class, "spring.ws.path=invalid");
|
|
|
|
"spring.ws.path=invalid");
|
|
|
|
|
|
|
|
registerAndRefresh(WsAutoConfiguration.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void customPathWithTrailingSlash() {
|
|
|
|
public void customPathWithTrailingSlash() {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load(WsAutoConfiguration.class, "spring.ws.path=/valid/");
|
|
|
|
"spring.ws.path=/valid/");
|
|
|
|
|
|
|
|
registerAndRefresh(WsAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
|
|
|
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
|
|
|
.contains("/valid/*");
|
|
|
|
.contains("/valid/*");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void customPath() {
|
|
|
|
public void customPath() {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load(WsAutoConfiguration.class, "spring.ws.path=/valid");
|
|
|
|
"spring.ws.path=/valid");
|
|
|
|
|
|
|
|
registerAndRefresh(WsAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
|
|
|
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
|
|
|
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
|
|
|
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
|
|
|
.contains("/valid/*");
|
|
|
|
.contains("/valid/*");
|
|
|
@ -94,10 +81,7 @@ public class WsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void customLoadOnStartup() {
|
|
|
|
public void customLoadOnStartup() {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load(WsAutoConfiguration.class, "spring.ws.servlet.load-on-startup=1");
|
|
|
|
"spring.ws.servlet.load-on-startup=1");
|
|
|
|
|
|
|
|
registerAndRefresh(WsAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ServletRegistrationBean registrationBean = this.context
|
|
|
|
ServletRegistrationBean registrationBean = this.context
|
|
|
|
.getBean(ServletRegistrationBean.class);
|
|
|
|
.getBean(ServletRegistrationBean.class);
|
|
|
|
assertThat(ReflectionTestUtils.getField(registrationBean, "loadOnStartup"))
|
|
|
|
assertThat(ReflectionTestUtils.getField(registrationBean, "loadOnStartup"))
|
|
|
@ -106,19 +90,21 @@ public class WsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void customInitParameters() {
|
|
|
|
public void customInitParameters() {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load(WsAutoConfiguration.class, "spring.ws.servlet.init.key1=value1",
|
|
|
|
"spring.ws.init.key1=value1", "spring.ws.init.key2=value2");
|
|
|
|
"spring.ws.servlet.init.key2=value2");
|
|
|
|
registerAndRefresh(WsAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ServletRegistrationBean registrationBean = this.context
|
|
|
|
ServletRegistrationBean registrationBean = this.context
|
|
|
|
.getBean(ServletRegistrationBean.class);
|
|
|
|
.getBean(ServletRegistrationBean.class);
|
|
|
|
assertThat(registrationBean.getInitParameters()).containsEntry("key1", "value1");
|
|
|
|
assertThat(registrationBean.getInitParameters()).containsEntry("key1", "value1");
|
|
|
|
assertThat(registrationBean.getInitParameters()).containsEntry("key2", "value2");
|
|
|
|
assertThat(registrationBean.getInitParameters()).containsEntry("key2", "value2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerAndRefresh(Class<?>... annotatedClasses) {
|
|
|
|
private void load(Class<?> config, String... environment) {
|
|
|
|
this.context.register(annotatedClasses);
|
|
|
|
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
|
|
|
|
this.context.refresh();
|
|
|
|
ctx.setServletContext(new MockServletContext());
|
|
|
|
|
|
|
|
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
|
|
|
|
|
|
|
ctx.register(config);
|
|
|
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
this.context = ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|