mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Improve ProjectGenerator tests
This commit is contained in:
@@ -23,7 +23,7 @@ apply plugin: 'war'
|
||||
|
||||
<% if (packaging=='war') { %>war<% } else { %>jar<% } %> {
|
||||
baseName = '${artifactId}'
|
||||
version = '${version}'
|
||||
version = '${version}'
|
||||
}
|
||||
sourceCompatibility = ${javaVersion}
|
||||
targetCompatibility = ${javaVersion}
|
||||
|
@@ -16,16 +16,23 @@
|
||||
|
||||
package io.spring.initializr
|
||||
|
||||
import io.spring.initializr.support.GradleBuildAssert
|
||||
import io.spring.initializr.support.InitializrMetadataBuilder
|
||||
import io.spring.initializr.support.PomAssert
|
||||
import io.spring.initializr.support.ProjectAssert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class ProjectGeneratorTests {
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder folder = new TemporaryFolder()
|
||||
|
||||
private final ProjectGenerator projectGenerator = new ProjectGenerator()
|
||||
|
||||
@Before
|
||||
@@ -33,6 +40,7 @@ class ProjectGeneratorTests {
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder.withDefaults()
|
||||
.addDependencyGroup('test', 'web', 'security', 'data-jpa', 'aop', 'batch', 'integration').validateAndGet()
|
||||
projectGenerator.metadata = metadata
|
||||
projectGenerator.tmpdir = folder.newFolder().getAbsolutePath()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,6 +50,19 @@ class ProjectGeneratorTests {
|
||||
.hasNoRepository().hasSpringBootStarterDependency('web')
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultGradleBuild() {
|
||||
ProjectRequest request = createProjectRequest('web')
|
||||
generateGradleBuild(request)
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultProject() {
|
||||
ProjectRequest request = createProjectRequest('web')
|
||||
generateProject(request).isJavaProject().isMavenProject().pomAssert()
|
||||
.hasStartClass('demo.Application').hasNoRepository().hasSpringBootStarterDependency('web')
|
||||
}
|
||||
|
||||
@Test
|
||||
void mavenPomWithBootSnapshot() {
|
||||
ProjectRequest request = createProjectRequest('web')
|
||||
@@ -106,7 +127,17 @@ class ProjectGeneratorTests {
|
||||
|
||||
PomAssert generateMavenPom(ProjectRequest request) {
|
||||
String content = new String(projectGenerator.generateMavenPom(request))
|
||||
return new PomAssert(content).validateProjectRequest(request)
|
||||
new PomAssert(content).validateProjectRequest(request)
|
||||
}
|
||||
|
||||
GradleBuildAssert generateGradleBuild(ProjectRequest request) {
|
||||
String content = new String(projectGenerator.generateGradleBuild(request))
|
||||
new GradleBuildAssert(content).validateProjectRequest(request)
|
||||
}
|
||||
|
||||
ProjectAssert generateProject(ProjectRequest request) {
|
||||
File dir = projectGenerator.generateProjectStructure(request)
|
||||
new ProjectAssert(dir)
|
||||
}
|
||||
|
||||
ProjectRequest createProjectRequest(String... styles) {
|
||||
|
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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 io.spring.initializr.support
|
||||
|
||||
import io.spring.initializr.ProjectRequest
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
/**
|
||||
* Very simple assertions for the gradle build.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.0
|
||||
*/
|
||||
class GradleBuildAssert {
|
||||
|
||||
private final String content
|
||||
|
||||
GradleBuildAssert(String content) {
|
||||
this.content = content
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that this generated gradle build validates against its request.
|
||||
*/
|
||||
GradleBuildAssert validateProjectRequest(ProjectRequest request) {
|
||||
hasArtifactId(request.artifactId).hasVersion(request.version).
|
||||
hasBootVersion(request.bootVersion).hasJavaVersion(request.javaVersion)
|
||||
|
||||
}
|
||||
|
||||
GradleBuildAssert hasArtifactId(String artifactId) {
|
||||
contains('baseName = \'' + artifactId + '\'')
|
||||
}
|
||||
|
||||
GradleBuildAssert hasVersion(String version) {
|
||||
contains('version = \'' + version + '\'')
|
||||
}
|
||||
|
||||
GradleBuildAssert hasBootVersion(String bootVersion) {
|
||||
contains('springBootVersion = \'' + bootVersion + '\'')
|
||||
}
|
||||
|
||||
GradleBuildAssert hasJavaVersion(String javaVersion) {
|
||||
contains('sourceCompatibility = ' + javaVersion + '')
|
||||
contains('targetCompatibility = ' + javaVersion + '')
|
||||
}
|
||||
|
||||
GradleBuildAssert contains(String expression) {
|
||||
assertTrue expression + ' has not been found in gradle build', content.contains(expression)
|
||||
this
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user