mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Add spring-boot tests to test starter
This commit is contained in:
parent
217ec5d564
commit
c5cfe54c80
@ -18,6 +18,11 @@
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2012-2013 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.
|
||||
* 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 org.springframework.boot.sample.simple;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleSimpleApplication}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = SampleSimpleApplication.class, loader=SpringApplicationContextLoader.class)
|
||||
public class SpringTestSampleSimpleApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testContextLoads() throws Exception {
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,12 @@
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
<classifier>tests</classifier>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -80,12 +80,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
|
||||
initializers.add(BeanUtils.instantiate(type));
|
||||
}
|
||||
if (mergedConfig instanceof WebMergedContextConfiguration) {
|
||||
WebMergedContextConfiguration webConfig = (WebMergedContextConfiguration) mergedConfig;
|
||||
MockServletContext servletContext = new MockServletContext(
|
||||
webConfig.getResourceBasePath());
|
||||
initializers.add(0, new ServletContextApplicationContextInitializer(
|
||||
servletContext));
|
||||
application.setApplicationContextClass(GenericWebApplicationContext.class);
|
||||
new WebConfigurer().setup(mergedConfig, application, initializers);
|
||||
}
|
||||
else {
|
||||
application.setWebEnvironment(false);
|
||||
@ -105,4 +100,17 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
|
||||
return "-context.xml";
|
||||
}
|
||||
|
||||
private static class WebConfigurer {
|
||||
void setup(MergedContextConfiguration mergedConfig,
|
||||
SpringApplication application,
|
||||
List<ApplicationContextInitializer<?>> initializers) {
|
||||
WebMergedContextConfiguration webConfig = (WebMergedContextConfiguration) mergedConfig;
|
||||
MockServletContext servletContext = new MockServletContext(
|
||||
webConfig.getResourceBasePath());
|
||||
initializers.add(0, new ServletContextApplicationContextInitializer(
|
||||
servletContext));
|
||||
application.setApplicationContextClass(GenericWebApplicationContext.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user