mirror of
https://gitee.com/dcren/initializr.git
synced 2025-05-09 15:18:02 +08:00
Add tests for Groovy-based projects
Closes gh-61
This commit is contained in:
parent
fd85022ef6
commit
5092e32a26
@ -65,6 +65,16 @@ class ProjectAssert {
|
||||
isJavaProject(DEFAULT_APPLICATION_NAME)
|
||||
}
|
||||
|
||||
ProjectAssert isGroovyProject(String expectedApplicationName) {
|
||||
hasFile("src/main/groovy/demo/${expectedApplicationName}.groovy",
|
||||
"src/test/groovy/demo/${expectedApplicationName}Tests.groovy",
|
||||
'src/main/resources/application.properties')
|
||||
}
|
||||
|
||||
ProjectAssert isGroovyProject() {
|
||||
isGroovyProject(DEFAULT_APPLICATION_NAME)
|
||||
}
|
||||
|
||||
ProjectAssert isJavaWarProject(String expectedApplicationName) {
|
||||
isJavaProject(expectedApplicationName).hasStaticAndTemplatesResources(true)
|
||||
.hasFile('src/main/java/demo/ServletInitializer.java')
|
||||
|
@ -20,6 +20,7 @@ import com.gargoylesoftware.htmlunit.WebClient
|
||||
import com.gargoylesoftware.htmlunit.WebRequest
|
||||
import com.gargoylesoftware.htmlunit.WebResponse
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage
|
||||
import io.spring.initializr.support.PomAssert
|
||||
import io.spring.initializr.support.ProjectAssert
|
||||
import io.spring.initializr.web.support.HomePage
|
||||
import org.junit.After
|
||||
@ -64,7 +65,7 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDefaultProject() {
|
||||
void createDefaultJavaProject() {
|
||||
def page = home()
|
||||
def projectAssert = zipProjectAssert(page.generateProject().contentAsStream.bytes)
|
||||
projectAssert.isMavenProject().isJavaProject().hasStaticAndTemplatesResources(false)
|
||||
@ -73,13 +74,19 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
|
||||
}
|
||||
|
||||
@Test
|
||||
void createProjectWithCustomDefaults() {
|
||||
void createDefaultGroovyProject() {
|
||||
def page = home()
|
||||
page.groupId = 'com.acme'
|
||||
page.artifactId = 'foo-bar'
|
||||
page.name = 'My project'
|
||||
page.description = 'A description for my project'
|
||||
page.dependencies << 'web' << 'data-jpa'
|
||||
page.language = 'groovy'
|
||||
def projectAssert = zipProjectAssert(page.generateProject().contentAsStream.bytes)
|
||||
projectAssert.isMavenProject().isGroovyProject().hasStaticAndTemplatesResources(false)
|
||||
.pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterDependency('test')
|
||||
.hasDependency('org.codehaus.groovy', 'groovy')
|
||||
}
|
||||
|
||||
@Test
|
||||
void createJavaProjectWithCustomDefaults() {
|
||||
def page = createCustomPage()
|
||||
|
||||
WebResponse webResponse = page.generateProject()
|
||||
String value = webResponse.getResponseHeaderValue('Content-Disposition')
|
||||
@ -89,7 +96,38 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
|
||||
projectAssert.isMavenProject().isJavaProject('MyProjectApplication')
|
||||
.hasStaticAndTemplatesResources(true)
|
||||
|
||||
projectAssert.pomAssert().hasGroupId('com.acme').hasArtifactId('foo-bar')
|
||||
assertMavenProject(projectAssert.pomAssert())
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroovyProjectWithCustomDefaults() {
|
||||
def page = createCustomPage()
|
||||
page.language = 'groovy'
|
||||
|
||||
WebResponse webResponse = page.generateProject()
|
||||
String value = webResponse.getResponseHeaderValue('Content-Disposition')
|
||||
assertEquals 'attachment; filename="foo-bar.zip"', value
|
||||
|
||||
def projectAssert = zipProjectAssert(webResponse)
|
||||
projectAssert.isMavenProject().isGroovyProject('MyProjectApplication')
|
||||
.hasStaticAndTemplatesResources(true)
|
||||
|
||||
assertMavenProject(projectAssert.pomAssert())
|
||||
.hasDependency('org.codehaus.groovy', 'groovy')
|
||||
}
|
||||
|
||||
private def createCustomPage() {
|
||||
def page = home()
|
||||
page.groupId = 'com.acme'
|
||||
page.artifactId = 'foo-bar'
|
||||
page.name = 'My project'
|
||||
page.description = 'A description for my project'
|
||||
page.dependencies << 'web' << 'data-jpa'
|
||||
page
|
||||
}
|
||||
|
||||
private PomAssert assertMavenProject(PomAssert pomAssert) {
|
||||
pomAssert.hasGroupId('com.acme').hasArtifactId('foo-bar')
|
||||
.hasName('My project').hasDescription('A description for my project')
|
||||
.hasSpringBootStarterDependency('web')
|
||||
.hasSpringBootStarterDependency('data-jpa')
|
||||
|
@ -37,7 +37,8 @@ class DefaultHomePage extends HomePage {
|
||||
select('packaging', packaging)
|
||||
}
|
||||
|
||||
private void select(String selectId, String value) {
|
||||
@Override
|
||||
protected void select(String selectId, String value) {
|
||||
if (value) {
|
||||
def input = page.getHtmlElementById(selectId)
|
||||
input.setSelectedAttribute(value, true)
|
||||
|
@ -33,6 +33,7 @@ abstract class HomePage {
|
||||
String packageName
|
||||
String type
|
||||
String packaging
|
||||
String language
|
||||
List<String> dependencies = []
|
||||
|
||||
protected final HtmlPage page
|
||||
@ -63,6 +64,7 @@ abstract class HomePage {
|
||||
setTextValue('name', name)
|
||||
setTextValue('description', description)
|
||||
setTextValue('packageName', packageName)
|
||||
select('language', language)
|
||||
selectDependencies(dependencies)
|
||||
}
|
||||
|
||||
@ -73,6 +75,8 @@ abstract class HomePage {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void select(String selectId, String value)
|
||||
|
||||
protected void selectDependencies(List<String> dependencies) {
|
||||
def styles = page.getElementsByName("style")
|
||||
def allStyles = [:]
|
||||
|
@ -36,7 +36,8 @@ class StsHomePage extends HomePage {
|
||||
select('packaging', packaging)
|
||||
}
|
||||
|
||||
private void select(String selectId, String value) {
|
||||
@Override
|
||||
protected void select(String selectId, String value) {
|
||||
if (value) {
|
||||
page.getElementsByIdAndOrName(selectId).each {
|
||||
it.checked = value.equals(it.defaultValue)
|
||||
|
Loading…
Reference in New Issue
Block a user