Skip to content

Commit

Permalink
Grails 7: further work and get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoehm committed Nov 19, 2024
1 parent 1e03dd7 commit e58b742
Show file tree
Hide file tree
Showing 25 changed files with 269 additions and 506 deletions.
56 changes: 56 additions & 0 deletions .github/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Java CI
on:
push:
branches:
- '[5-9]+.[0-9]+.x'
pull_request:
branches:
- '[5-9]+.[0-9]+.x'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
env:
WORKSPACE: ${{ github.workspace }}
GRADLE_OPTS: -Xmx1500m -Dfile.encoding=UTF-8
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Run Tests
if: github.event_name == 'pull_request'
id: tests
uses: gradle/gradle-build-action@v2
with:
arguments: check -Dgeb.env=chromeHeadless
- name: Run Build
if: github.event_name == 'push'
id: build
uses: gradle/gradle-build-action@v2
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
with:
arguments: build -Dgeb.env=chromeHeadless
- name: Publish Test Report
if: steps.build.outcome == 'failure' || steps.tests.outcome == 'failure'
uses: scacap/action-surefire-report@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: '**/build/test-results/test/TEST-*.xml'
#- name: Publish to repo.grails.org
# id: publish
# uses: gradle/gradle-build-action@v2
# if: steps.build.outcome == 'success' && github.event_name == 'push'
# env:
# ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
# ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
# with:
# arguments: -Dorg.gradle.internal.publish.checksums.insecure=true publish
#- name: Build Documentation
# id: docs
# uses: gradle/gradle-build-action@v2
# with:
# arguments: docs
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![Build Status](https://travis-ci.org/grails-plugins/grails-spring-security-acl.svg?branch=master)

Grails Spring Security ACL Plugin
==================================

Expand Down
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
subprojects {
configurations.configureEach {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if ((details.requested.group == 'org.codehaus.groovy' || details.requested.group == 'org.apache.groovy') && details.requested.name != 'groovy-bom') {
String groovyVersion = findProperty('groovyVersion') ?: libs.versions.groovy.get()
details.useTarget(group: 'org.apache.groovy', name: details.requested.name, version: groovyVersion)
details.because "The dependency coordinates are changed in Apache Groovy 4, plus ensure version"
if (details.requested.group == 'org.seleniumhq.selenium') {
details.useVersion(seleniumVersion)
}
}
}
Expand Down
32 changes: 17 additions & 15 deletions functional-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:5.0.1"
classpath "org.grails.plugins:hibernate5:$gormVersion"
classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.7"
classpath "com.github.erdi:webdriver-binaries-gradle-plugin:3.2"
}
}

Expand Down Expand Up @@ -41,12 +41,11 @@ dependencies {
implementation "org.grails:grails-plugin-url-mappings"
implementation "org.grails:grails-plugin-interceptors"
implementation "org.grails:grails-web-boot"
implementation "org.grails.plugins:cache"
implementation "org.grails.plugins:async"
implementation "org.grails.plugins:scaffolding"
implementation "org.grails.plugins:events"
implementation "org.grails.plugins:hibernate5"
implementation "org.hibernate:hibernate-core:$hibernateCoreVersion"
implementation "org.hibernate:hibernate-core-jakarta:$hibernateCoreVersion"
implementation "org.grails.plugins:gsp"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
Expand All @@ -55,24 +54,27 @@ dependencies {
runtimeOnly "com.h2database:h2"
testImplementation "org.grails:grails-gorm-testing-support"
testImplementation "org.grails:grails-web-testing-support"
testImplementation "io.micronaut:micronaut-http-client:$micronautVersion"
testImplementation "org.grails.plugins:geb"
testRuntimeOnly "org.seleniumhq.selenium:selenium-chrome-driver:4.19.1"
testImplementation "org.seleniumhq.selenium:selenium-remote-driver:4.19.1"
testImplementation "org.seleniumhq.selenium:selenium-api:4.19.1"
implementation project(':spring-security-acl')
}
integrationTestImplementation testFixtures('org.grails.plugins:geb')

webdriverBinaries {
chromedriver '2.46.0'
geckodriver '0.29.1'
testRuntimeOnly "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
testRuntimeOnly "org.seleniumhq.selenium:selenium-safari-driver:$seleniumVersion"
testImplementation "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion"
testImplementation "org.seleniumhq.selenium:selenium-api:$seleniumVersion"
implementation project(':spring-security-acl')
}

tasks.withType(Test) {
useJUnitPlatform()
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
if (System.getenv('CHROMEWEBDRIVER')) {
systemProperty 'webdriver.chrome.driver', "${System.getenv('CHROMEWEBDRIVER')}/chromedriver"
}
if (System.getenv('GECKOWEBDRIVER')) {
systemProperty 'webdriver.gecko.driver', "${System.getenv('GECKOWEBDRIVER')}/geckodriver"
}

beforeTest { descriptor -> logger.quiet " -- $descriptor" }
testLogging {
events "passed", "skipped", "failed"
Expand Down
190 changes: 61 additions & 129 deletions functional-test-app/grails-app/conf/application.yml
Original file line number Diff line number Diff line change
@@ -1,137 +1,69 @@
---
grails:
profile: web
codegen:
defaultPackage: misc.functional.test.app
spring:
transactionManagement:
proxies: false
gorm:
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
info:
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
spring:
main:
banner-mode: "off"
groovy:
template:
check-template-location: false

# Spring Actuator Endpoints are Disabled by Default
endpoints:
enabled: false
jmx:
enabled: true
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
views:
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlet: html
taglib: none
staticparts: none
default:
codec: html
dataSource:
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
driverClassName: org.h2.Driver
username: sa
password: ''
pooled: true
jmxExport: true
dbCreate: update
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false

---
grails:
plugin:
springsecurity:
userLookup:
user-domain-class-name: com.testacl.User
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlets: html
taglib: none
staticparts: none
endpoints:
jmx:
unique-names: true

---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false

dataSource:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password: ''

environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: none
url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import groovy.transform.CompileStatic
@Secured('permitAll')
class ErrorsController {

def error403() {
// Line necessary due to: https://github.com/grails/grails-core/issues/10582
[view: 'error403']
}

def error404() {
String uri = 'request.forwardURI'
if (!uri.contains('favicon.ico')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UrlMappings {
"403"(controller: 'errors', action: 'error403')
"404"(controller: 'errors', action: 'error404')
"500"(controller: 'errors', action: 'error500')
"500"(controller: 'errors', action: 'error403', exception: AccessDeniedException)
"500"(controller: 'errors', action: 'error403', exception: NotFoundException)
"500"(view: 'errors/error403', exception: AccessDeniedException)
"500"(controller: 'errors', action: 'error404', exception: NotFoundException)
}
}
4 changes: 4 additions & 0 deletions functional-test-app/grails-app/domain/com/testacl/User.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ class User implements Serializable {
username blank: false, unique: true
password blank: false
}

static mapping = {
table name: '`user`'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.testacl

import grails.gorm.DetachedCriteria
import groovy.transform.ToString
import org.apache.commons.lang.builder.HashCodeBuilder
import org.apache.commons.lang3.builder.HashCodeBuilder
import org.hibernate.ObjectNotFoundException

@ToString(cache=true, includeNames=true, includePackage=false)
class UserRole implements Serializable {
Expand Down Expand Up @@ -86,7 +87,11 @@ class UserRole implements Serializable {
if (ur.user == null || ur.user.id == null) return
boolean existing = false
UserRole.withNewSession {
existing = UserRole.exists(ur.user.id, r.id)
try {
existing = UserRole.exists(ur.user.id, r.id)
} catch (ObjectNotFoundException ignored) {
// no-op
}
}
if (existing) {
return 'userRole.exists'
Expand Down
Loading

0 comments on commit e58b742

Please sign in to comment.