Skip to content

Commit

Permalink
Separate dev and test env config to support running functional tests …
Browse files Browse the repository at this point in the history
…without modifying config #2942
  • Loading branch information
chrisala committed Jul 25, 2023
1 parent 4234e16 commit 125d7c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
16 changes: 4 additions & 12 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import grails.util.Environment
\******************************************************************************/
def appName = 'fieldcapture'
def ENV_NAME = "${appName.toUpperCase()}_CONFIG"
environments.dev.config.locatations = "~/data/${appName}/config/${appName}-config.properties"
default_config = "/data/${appName}/config/${appName}-config.properties"
if(!grails.config.locations || !(grails.config.locations instanceof List)) {
grails.config.locations = []
Expand Down Expand Up @@ -204,7 +205,6 @@ abn.abnLookupToken = "Insert abn Token here"
abn.abnUrl= "https://abr.business.gov.au/json/AbnDetails.aspx?abn="

esp.activities.admin = 'ESP Annual Report Submission'
reports.filterableActivityTypes = ['RLP Output Report', 'Wildlife Recovery Progress Report - WRR']
reports.initialScrollPositionDelay = 1000
risks.scheduleCheckingPeriod = 7
grails.mail.poolSize = 1
Expand All @@ -217,6 +217,7 @@ grails {
}
}
}
ehcache.directory = '/data/fieldcapture/ehcache'

auth.baseUrl = 'https://auth-test.ala.org.au'
userDetails.url = "${auth.baseUrl}/userdetails/"
Expand Down Expand Up @@ -273,6 +274,7 @@ environments {
logging.dir = '.'
ecodata.service.url = 'http://localhost:8080/ws'
espSupportEmail='[email protected]'
ehcache.directory = './ehcache'
}
test {
server.port = "8087"
Expand All @@ -281,12 +283,11 @@ environments {
grails.serverURL = serverName
layout.skin = "nrm"
app.default.hub='merit'
runWithNoExternalConfig = true
wiremock.port = 8018
security.oidc.discoveryUri = "http://localhost:${wiremock.port}/cas/oidc/.well-known"
security.oidc.allowUnsignedIdTokens = true
def casBaseUrl = "http://localhost:${wiremock.port}"

ehcache.directory = './ehcache'
security.cas.appServerName=serverName
security.cas.contextPath=
security.cas.casServerName="${casBaseUrl}"
Expand All @@ -305,17 +306,8 @@ environments {
abn.abnUrl= "http://localhost:${wiremock.port}/json/AbnDetails.aspx?abn="
abn.abnLookupToken = "123456"
api_key='testapikey'
grails.cache.config = {
diskStore {
path '/tmp'
}
defaultCache {
overflowToDisk false
}
}
spatial.baseUrl = "http://localhost:${wiremock.port}"
spatial.layersUrl = spatial.baseUrl + "/ws"
reports.filterableActivityTypes = ['RLP Output Report', 'Wildlife Recovery Progress Report - WRR', 'Progress Report']
grails.mail.port = 3025 // com.icegreen.greenmail.util.ServerSetupTest.SMTP.port
}
production {
Expand Down
2 changes: 1 addition & 1 deletion grails-app/conf/merit-ehcache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns='http://www.ehcache.org/v3'
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'>

<persistence directory="/data/fieldcapture/ehcache"/>
<persistence directory="${ehcache.directory}"/>

<cache alias="homePageImages">
<expiry>
Expand Down
25 changes: 25 additions & 0 deletions grails-app/init/au/org/ala/fieldcapture/Application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import asset.pipeline.AssetPipelineConfigHolder
import au.org.ala.ecodata.forms.TemplateFileAssetResolver
import au.org.ala.merit.SessionLogger
import grails.boot.GrailsApp
import grails.boot.config.GrailsApplicationPostProcessor
import grails.boot.config.GrailsAutoConfiguration
import grails.converters.JSON
import grails.core.GrailsApplication
import grails.util.BuildSettings
import grails.util.Environment
import groovy.util.logging.Slf4j
Expand All @@ -14,16 +16,21 @@ import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean
import org.springframework.context.annotation.Bean

@Slf4j
class Application extends GrailsAutoConfiguration {

private static final String EHCACHE_DIRECTORY_CONFIG_ITEM = "ehcache.directory"
private static final String DEFAULT_EHCACHE_DIRECTORY = "./ehcache"

static void main(String[] args) {
GrailsApp.run(Application, args)
}

@Override
Closure doWithSpring() {

return {
log.info("doWithSpring....")
sessionLogger(new ServletListenerRegistrationBean(new SessionLogger()))
Expand Down Expand Up @@ -54,4 +61,22 @@ class Application extends GrailsAutoConfiguration {
log.info("Shutting down - destroying the cache manager")
applicationContext.grailsCacheManager.destroy()
}

@Bean
GrailsApplicationPostProcessor grailsApplicationPostProcessor() {

// We are overriding the GrailsApplicationPostProcessor because we need a lifecycle hook after
// the configuration has been read, but before the plugin lifecycle bean initialisation has started.
// This is because the grails ehcache plugin only supports configuration via XML files and the
// cache directory store can only be configured via an environment variable.
// To keep the configuration in one place, we are reading the config, and setting the system property
// so it can be read during cache initialisation.
return new GrailsApplicationPostProcessor( this, applicationContext, classes() as Class[]) {
@Override
protected void customizeGrailsApplication(GrailsApplication grailsApplication) {
System.setProperty(EHCACHE_DIRECTORY_CONFIG_ITEM, grailsApplication.config.getProperty(EHCACHE_DIRECTORY_CONFIG_ITEM, DEFAULT_EHCACHE_DIRECTORY))
}

}
}
}
1 change: 0 additions & 1 deletion src/test/groovy/au/org/ala/merit/ProjectServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest<Projec
au.org.ala.merit.ActivityService realService = new au.org.ala.merit.ActivityService()
activityService.defaultDescription(_ as Map) >> {Map activity -> realService.defaultDescription(activity) }
grailsApplication.config.ecodata.baseUrl = ''
grailsApplication.config.reports.filterableActivityTypes = ['output']
service.reportService = reportService
service.userService = userService
service.metadataService = metadataService
Expand Down

0 comments on commit 125d7c9

Please sign in to comment.