Use reactor-spring idioms

This commit is contained in:
Dave Syer 2014-05-28 19:25:35 +01:00
parent 54561770cc
commit c62acf515e
4 changed files with 92 additions and 51 deletions

View File

@ -1,8 +1,10 @@
package app
@Grab("spring-boot-starter-actuator")
@Grab("org.codehaus.groovy:groovy-ant:2.1.6")
@Grab("org.codehaus.groovy:groovy-ant:2.3.2")
@Configuration
@EnableConfigurationProperties(Projects)
@Controller
@Log
class MainController {
@ -19,33 +21,16 @@ class MainController {
@Autowired
private Reactor reactor
@Autowired
private Projects projects
@RequestMapping("/")
@ResponseBody
String home() {
def model = [:]
model["styles"] = [[name:"Web", value:"web"]]
model["styles"] << [name:"Thymeleaf", value:"thymeleaf"]
model["styles"] << [name:"Actuator", value:"actuator"]
model["styles"] << [name:"Security", value:"security"]
model["styles"] << [name:"Batch", value:"batch"]
model["styles"] << [name:"JDBC", value:"jdbc"]
model["styles"] << [name:"Integration", value:"integration"]
// model["styles"] << [name:"JMS", value:"jms"]
model["styles"] << [name:"AMQP", value:"amqp"]
model["styles"] << [name:"AOP", value:"aop"]
model["styles"] << [name:"JPA", value:"data-jpa"]
model["styles"] << [name:"MongoDB", value:"data-mongodb"]
model["styles"] << [name:"Redis", value:"redis"]
model["styles"] << [name:"Rest Repositories", value:"data-rest"]
model["styles"] << [name:"Remote Shell", value:"remote-shell"]
model["styles"] << [name:"Mobile", value:"mobile"]
model["types"] = [[name:"Maven POM", value:"pom.xml", selected: false],
[name:"Maven Project", value:"starter.zip", selected: true],
[name:"Gradle Build", value:"build.gradle", selected: false]]
// sort lists
model["styles"] = model["styles"].sort { it.name }
model["types"] = model["types"].sort { it.name }
// sort lists
model["styles"] = projects.styles.sort { it.name }
model["types"] = projects.types.sort { it.name }
template "home.html", model
}
@ -210,31 +195,26 @@ class ReactorConfiguration {
}
@Component
@Consumer
@Log
class TemporaryFileCleaner {
@Autowired
Reactor reactor
@PostConstruct
void init() {
reactor.on(Selectors.$("tempfiles"), [
accept: { event ->
def tempFiles = event.data
log.info "Tempfiles: " + tempFiles
if (tempFiles) {
tempFiles.each {
File file = it as File
if (file.directory) {
file.deleteDir()
} else {
file.delete()
}
}
}
}
] as Consumer)
@Selector('tempfiles')
void clean(def tempFiles) {
log.info "Tempfiles: " + tempFiles
if (tempFiles) {
tempFiles.each {
File file = it as File
if (file.directory) {
file.deleteDir()
} else {
file.delete()
}
}
}
}
}
@ -256,3 +236,9 @@ class PomRequest {
packageName == null ? name.replace('-', '.') : packageName
}
}
@ConfigurationProperties(prefix='projects', ignoreUnknownFields=false)
class Projects {
List<Map<String,Object>> styles
List<Map<String,Object>> types
}

View File

@ -1,5 +0,0 @@
info.project.name: Spring Start
info.project.version: 0.0.1
# remember to update static/install.sh as well:
info.spring-boot.version: 1.0.2.RELEASE

50
application.yml Normal file
View File

@ -0,0 +1,50 @@
info:
project:
name: Spring Start
version: 0.1.0
# remember to update static/install.sh as well:
spring-boot:
version: 1.1.0.RELEASE
projects:
styles:
- name: Web
value: web
- name: Thymeleaf
value: thymeleaf
- name: Actuator
value: actuator
- name: Security
value: security
- name: Batch
value: batch
- name: JDBC
value: jdbc
- name: Integration
value: integration
- name: AMQP
value: amqp
- name: AOP
value: aop
- name: JPA
value: data-jpa
- name: MongoDB
value: data-mongodb
- name: Redis
value: redis
- name: Rest Repositories
value: data-rest
- name: Remote Shell
value: remote-shell
- name: Mobile
value: mobile
types:
- name: Maven POM
value: pom.xml
selected: false
- name: Maven Project
value: starter.zip
selected: true
- name: Gradle
value: build.gradle
selected: false

View File

@ -1,7 +1,5 @@
package test
@Grab("spring-boot-starter-test")
@SpringApplicationConfiguration(classes=app.MainController)
@WebAppConfiguration
@IntegrationTest('server.port:0')
@ -12,9 +10,21 @@ class IntegrationTests {
int port
@Test
void testHome() {
void homeIsZipForm() {
String body = new TestRestTemplate().getForObject('http://localhost:' + port, String)
assertTrue('Wrong body:\n' + body, body.contains('action="/starter.zip"'))
}
@Test
void infoHasExternalProperties() {
String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/info', String)
assertTrue('Wrong body:\n' + body, body.contains('"project"'))
}
@Test
void homeHasWebStyle() {
String body = new TestRestTemplate().getForObject('http://localhost:' + port, String)
assertTrue('Wrong body:\n' + body, body.contains('name="style" value="web"'))
}
}