diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java index 98478d2538..ae19f42494 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -69,6 +69,7 @@ public class SpringBootCompilerAutoConfiguration extends CompilerAutoConfigurati "org.springframework.boot.context.properties.ConfigurationProperties", "org.springframework.boot.context.properties.EnableConfigurationProperties", "org.springframework.boot.autoconfigure.EnableAutoConfiguration", + "org.springframework.boot.autoconfigure.SpringBootApplication", "org.springframework.boot.context.properties.ConfigurationProperties", "org.springframework.boot.context.properties.EnableConfigurationProperties"); imports.addStarImports("org.springframework.stereotype", diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java index 46cfbac18d..e2716b2b39 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java @@ -41,8 +41,7 @@ public class SpringTestCompilerAutoConfiguration extends CompilerAutoConfigurati @Override public boolean matches(ClassNode classNode) { - return AstUtils.hasAtLeastOneAnnotation(classNode, - "SpringApplicationConfiguration"); + return AstUtils.hasAtLeastOneAnnotation(classNode, "SpringBootTest"); } @Override @@ -66,8 +65,10 @@ public class SpringTestCompilerAutoConfiguration extends CompilerAutoConfigurati @Override public void applyImports(ImportCustomizer imports) throws CompilationFailedException { imports.addStarImports("org.junit.runner", "org.springframework.boot.test", - "org.springframework.http", "org.springframework.test.context.junit4", - "org.springframework.test.annotation") - .addImports("org.springframework.test.context.web.WebAppConfiguration"); + "org.springframework.boot.test.context", + "org.springframework.boot.test.web.client", "org.springframework.http", + "org.springframework.test.context.junit4", + "org.springframework.test.annotation").addImports( + "org.springframework.boot.test.context.SpringBootTest.WebEnvironment"); } } diff --git a/spring-boot-cli/test-samples/integration.groovy b/spring-boot-cli/test-samples/integration.groovy index 1870183d1b..2b992a4bc8 100644 --- a/spring-boot-cli/test-samples/integration.groovy +++ b/spring-boot-cli/test-samples/integration.groovy @@ -1,5 +1,4 @@ -@SpringApplicationConfiguration(Application) -@IntegrationTest +@SpringBootTest(classes=Application) class BookTests { @Autowired Book book diff --git a/spring-boot-cli/test-samples/integration_auto.groovy b/spring-boot-cli/test-samples/integration_auto.groovy index a09cab57ae..b6a7d2ba8a 100644 --- a/spring-boot-cli/test-samples/integration_auto.groovy +++ b/spring-boot-cli/test-samples/integration_auto.groovy @@ -1,15 +1,15 @@ -@SpringApplicationConfiguration(Application) -@IntegrationTest('server.port:0') -@WebAppConfiguration -@DirtiesContext +package com.example + +@SpringBootApplication +@SpringBootTest(classes=RestTests, webEnvironment=WebEnvironment.RANDOM_PORT) class RestTests { - @Value('${local.server.port}') - int port + @Autowired + TestRestTemplate testRestTemplate; @Test void testHome() { - assertEquals('Hello', new TestRestTemplate().getForObject('http://localhost:' + port, String)) + assertEquals('Hello', testRestTemplate.getForObject('/', String)) } @RestController @@ -17,4 +17,5 @@ class RestTests { @RequestMapping('/') String hello() { 'Hello' } } + } diff --git a/spring-boot-cli/test-samples/integration_auto_test.groovy b/spring-boot-cli/test-samples/integration_auto_test.groovy index 4da6c670b3..a90e979fa4 100644 --- a/spring-boot-cli/test-samples/integration_auto_test.groovy +++ b/spring-boot-cli/test-samples/integration_auto_test.groovy @@ -1,5 +1,4 @@ -@SpringApplicationConfiguration(ReactorApplication) -@IntegrationTest('server.port:0') +@SpringBootTest(classes=ReactorApplication, webEnvironment=WebEnvironment.RANDOM_PORT) class RestTests { @Autowired