mirror of
https://gitee.com/dcren/initializr.git
synced 2025-05-10 07:38:03 +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)
|
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) {
|
ProjectAssert isJavaWarProject(String expectedApplicationName) {
|
||||||
isJavaProject(expectedApplicationName).hasStaticAndTemplatesResources(true)
|
isJavaProject(expectedApplicationName).hasStaticAndTemplatesResources(true)
|
||||||
.hasFile('src/main/java/demo/ServletInitializer.java')
|
.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.WebRequest
|
||||||
import com.gargoylesoftware.htmlunit.WebResponse
|
import com.gargoylesoftware.htmlunit.WebResponse
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage
|
import com.gargoylesoftware.htmlunit.html.HtmlPage
|
||||||
|
import io.spring.initializr.support.PomAssert
|
||||||
import io.spring.initializr.support.ProjectAssert
|
import io.spring.initializr.support.ProjectAssert
|
||||||
import io.spring.initializr.web.support.HomePage
|
import io.spring.initializr.web.support.HomePage
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
@ -64,7 +65,7 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createDefaultProject() {
|
void createDefaultJavaProject() {
|
||||||
def page = home()
|
def page = home()
|
||||||
def projectAssert = zipProjectAssert(page.generateProject().contentAsStream.bytes)
|
def projectAssert = zipProjectAssert(page.generateProject().contentAsStream.bytes)
|
||||||
projectAssert.isMavenProject().isJavaProject().hasStaticAndTemplatesResources(false)
|
projectAssert.isMavenProject().isJavaProject().hasStaticAndTemplatesResources(false)
|
||||||
@ -73,13 +74,19 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createProjectWithCustomDefaults() {
|
void createDefaultGroovyProject() {
|
||||||
def page = home()
|
def page = home()
|
||||||
page.groupId = 'com.acme'
|
page.language = 'groovy'
|
||||||
page.artifactId = 'foo-bar'
|
def projectAssert = zipProjectAssert(page.generateProject().contentAsStream.bytes)
|
||||||
page.name = 'My project'
|
projectAssert.isMavenProject().isGroovyProject().hasStaticAndTemplatesResources(false)
|
||||||
page.description = 'A description for my project'
|
.pomAssert().hasDependenciesCount(3)
|
||||||
page.dependencies << 'web' << 'data-jpa'
|
.hasSpringBootStarterRootDependency().hasSpringBootStarterDependency('test')
|
||||||
|
.hasDependency('org.codehaus.groovy', 'groovy')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createJavaProjectWithCustomDefaults() {
|
||||||
|
def page = createCustomPage()
|
||||||
|
|
||||||
WebResponse webResponse = page.generateProject()
|
WebResponse webResponse = page.generateProject()
|
||||||
String value = webResponse.getResponseHeaderValue('Content-Disposition')
|
String value = webResponse.getResponseHeaderValue('Content-Disposition')
|
||||||
@ -89,7 +96,38 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
|
|||||||
projectAssert.isMavenProject().isJavaProject('MyProjectApplication')
|
projectAssert.isMavenProject().isJavaProject('MyProjectApplication')
|
||||||
.hasStaticAndTemplatesResources(true)
|
.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')
|
.hasName('My project').hasDescription('A description for my project')
|
||||||
.hasSpringBootStarterDependency('web')
|
.hasSpringBootStarterDependency('web')
|
||||||
.hasSpringBootStarterDependency('data-jpa')
|
.hasSpringBootStarterDependency('data-jpa')
|
||||||
|
@ -37,7 +37,8 @@ class DefaultHomePage extends HomePage {
|
|||||||
select('packaging', packaging)
|
select('packaging', packaging)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select(String selectId, String value) {
|
@Override
|
||||||
|
protected void select(String selectId, String value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
def input = page.getHtmlElementById(selectId)
|
def input = page.getHtmlElementById(selectId)
|
||||||
input.setSelectedAttribute(value, true)
|
input.setSelectedAttribute(value, true)
|
||||||
|
@ -33,6 +33,7 @@ abstract class HomePage {
|
|||||||
String packageName
|
String packageName
|
||||||
String type
|
String type
|
||||||
String packaging
|
String packaging
|
||||||
|
String language
|
||||||
List<String> dependencies = []
|
List<String> dependencies = []
|
||||||
|
|
||||||
protected final HtmlPage page
|
protected final HtmlPage page
|
||||||
@ -63,6 +64,7 @@ abstract class HomePage {
|
|||||||
setTextValue('name', name)
|
setTextValue('name', name)
|
||||||
setTextValue('description', description)
|
setTextValue('description', description)
|
||||||
setTextValue('packageName', packageName)
|
setTextValue('packageName', packageName)
|
||||||
|
select('language', language)
|
||||||
selectDependencies(dependencies)
|
selectDependencies(dependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +75,8 @@ abstract class HomePage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void select(String selectId, String value)
|
||||||
|
|
||||||
protected void selectDependencies(List<String> dependencies) {
|
protected void selectDependencies(List<String> dependencies) {
|
||||||
def styles = page.getElementsByName("style")
|
def styles = page.getElementsByName("style")
|
||||||
def allStyles = [:]
|
def allStyles = [:]
|
||||||
|
@ -36,7 +36,8 @@ class StsHomePage extends HomePage {
|
|||||||
select('packaging', packaging)
|
select('packaging', packaging)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select(String selectId, String value) {
|
@Override
|
||||||
|
protected void select(String selectId, String value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
page.getElementsByIdAndOrName(selectId).each {
|
page.getElementsByIdAndOrName(selectId).each {
|
||||||
it.checked = value.equals(it.defaultValue)
|
it.checked = value.equals(it.defaultValue)
|
||||||
|
Loading…
Reference in New Issue
Block a user