Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions grails-profiles-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gradle
.idea
build
*.iml
.DS_Store
demo
.project
.settings
23 changes: 23 additions & 0 deletions grails-profiles-tests/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
jdk:
- oraclejdk8
addons:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use travis. Can you please convert this project to a subproject of grails-core?

chrome: stable
firefox: latest
install: ./profiles-install.sh
script:
- ./vue.sh
- ./react.sh
- ./web.sh
- ./rest-api.sh
# - ./profile.sh
# - ./rest-api-plugin.sh
# - ./web-plugin.sh
# - ./web-jboss7.sh
# - ./plugin.sh
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
131 changes: 131 additions & 0 deletions grails-profiles-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Grails Profiles Tests

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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

https://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.
-->

This module contains comprehensive tests for Grails profiles functionality, replacing the old shell script-based tests that were removed in commit 9b8fa17d40.

## Purpose

These tests verify that Grails profiles work correctly by:
- Testing application generation with different profiles (web, plugin, rest-api, etc.)
- Verifying profile-specific commands and features
- Ensuring generated applications can be built and run successfully
- Performing functional testing of generated applications

## Test Structure

The tests are organized into several categories:

### Unit/Integration Tests
- `WebProfileTests.groovy` - Tests for the web profile
- `PluginProfileTests.groovy` - Tests for the plugin profile
- `RestApiProfileTests.groovy` - Tests for the REST API profile (to be implemented)

### Functional Tests
- `FunctionalProfileTests.groovy` - End-to-end testing of generated applications using Geb/Selenium

## Running the Tests

### Run all profile tests:
```bash
./gradlew profileTest
```

### Run functional tests specifically:
```bash
./gradlew functionalProfileTest
```

### Run with specific browser:
```bash
./gradlew profileTest -Dgeb.env=chrome
./gradlew profileTest -Dgeb.env=firefox
```

### Run in headless mode (CI friendly):
```bash
./gradlew profileTest -Dgeb.env=chromeHeadless
```

## Test Coverage

The tests cover:

### Application Generation
- Creating applications with different profiles
- Verifying correct directory structure
- Checking build files are generated properly

### Profile Commands
- `create-domain-class` - Domain class creation
- `create-controller` - Controller creation
- `create-service` - Service creation
- `create-taglib` - Tag library creation
- `create-unit-test` - Unit test creation

### Build Verification
- Gradle compilation
- Application packaging
- Plugin JAR creation

### Functional Testing
- Application startup
- Web page accessibility
- Controller functionality
- Basic UI interactions

## Dependencies

The tests depend on:
- Grails Forge for application generation
- Geb and Selenium for functional testing
- Spock testing framework
- Chrome/Firefox drivers for browser automation

## Configuration

The `GebConfig.groovy` file configures different browser environments:
- Chrome Headless (default for CI)
- Chrome with GUI (for debugging)
- Firefox Headless
- Firefox with GUI

## Future Enhancements

Planned additions:
- REST API profile tests
- Web Plugin profile tests
- More comprehensive functional test scenarios
- Performance testing of profile operations
- Cross-version compatibility testing

## Migration from Old Tests

This replaces the shell script-based testing approach that was:
- Platform-dependent (Unix/Linux only)
- Hard to maintain and debug
- Not integrated with Gradle build system
- Difficult to run in CI environments

The new Gradle-based approach provides:
- Cross-platform compatibility
- Better integration with existing test infrastructure
- Easier maintenance and extension
- Seamless CI/CD integration
122 changes: 122 additions & 0 deletions grails-profiles-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* https://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.
*/

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* https://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.
*/

plugins {
id 'groovy'
id 'java-library'
id 'org.apache.grails.buildsrc.properties'
id 'org.apache.grails.buildsrc.compile'
id 'org.apache.grails.gradle.grails-code-style'
}

version = projectVersion
group = 'org.apache.grails.testing'

dependencies {
implementation platform(project(':grails-bom'))

// Core dependencies for profile testing
implementation project(':grails-core')
implementation project(':grails-bootstrap')

// Testing dependencies
testImplementation project(':grails-test-core')
testImplementation project(':grails-testing-support-core')

// Spock testing framework
testImplementation 'org.spockframework:spock-core'
testRuntimeOnly 'net.bytebuddy:byte-buddy'
testImplementation 'org.objenesis:objenesis'

// JUnit platform
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// Logging for tests
testImplementation 'org.slf4j:slf4j-simple'
}

// Configure test tasks
test {
useJUnitPlatform()

// Enable Geb environment configuration
systemProperty 'geb.env', System.getProperty('geb.env', 'chrome')
systemProperty 'webdriver.chrome.driver', System.getProperty('webdriver.chrome.driver', '')
systemProperty 'webdriver.gecko.driver', System.getProperty('webdriver.gecko.driver', '')

// Test reporting configuration
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
showStandardStreams = true
}

// Fork settings for isolation
maxParallelForks = 1
forkEvery = 5

// Include only profile test classes
include '**/*Profile*Test*'
include '**/*Profile*Spec*'
}

// Custom task to run profile tests with specific configurations
tasks.register('profileTest', Test) {
useJUnitPlatform()
systemProperty 'geb.env', 'chromeHeadless'
include '**/*Profile*Test*'
include '**/*Profile*Spec*'

testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
}

// Task to run functional profile tests separately
tasks.register('functionalProfileTest', Test) {
useJUnitPlatform()
systemProperty 'geb.env', 'chromeHeadless'
include '**/*Functional*Profile*Test*'
include '**/*Functional*Profile*Spec*'

testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
}
41 changes: 41 additions & 0 deletions grails-profiles-tests/functional-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id "com.energizedwork.webdriver-binaries" version "1.4"
id 'groovy'
}

ext {
spockVersion = '1.2-groovy-2.4'
gebVersion = '2.3'
seleniumVersion = '3.14.0'
seleniumSafariDriverVersion='3.14.0'
chromeDriverVersion='2.44'
geckodriverVersion='0.23.0'
}

repositories {
jcenter()
}

dependencies {
testCompile "org.spockframework:spock-core:$spockVersion"

compile "org.gebish:geb-spock:$gebVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"

testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
testRuntime "org.seleniumhq.selenium:selenium-safari-driver:$seleniumSafariDriverVersion"
}

webdriverBinaries {
chromedriver "$chromeDriverVersion"
geckodriver "$geckodriverVersion"
}

tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
testLogging {
events "passed", "skipped", "failed"
exceptionFormat 'full'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package example.grails

import geb.Page

class HomePage extends Page {

static url = '/#/'

static at = { title.contains('Grails') }

static content = {
controllers(wait: true) { $('#controllers li') }
}

List<String> controllerNames() {
controllers.collect { it.text() } as List<String>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package example.grails

import geb.Browser
import geb.spock.GebSpec
import spock.lang.Requires

class HomeSpec extends GebSpec {

//@Requires({ Utils.available('http://localhost:8080') && Utils.available('http://localhost:3000') })
def "homage shows a list of available controllers"() {
given:
Browser browser = new Browser()
List<String> expectedControllerNames = ['demo.ApplicationController']

when:
HomePage homePage = browser.to(HomePage)
List<String> controllerNames = homePage.controllerNames()

then:
expectedControllerNames == controllerNames
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package example.grails

import groovy.transform.Memoized

class Utils {
@Memoized
static boolean available(String url) {
try {
url.toURL().openConnection().with {
connectTimeout = 1000
connect()
}
true
} catch (IOException e) {
false
}
}
}
Loading
Loading