Grails change Environment from Development to Test - grails

Is there any way to change current environment from DEVELOPMENT to TEST?
I have tried,
if(Environment.getCurrent().equals(Environment.DEVELOPMENT)){
Environment.currentEnvironment = Environment.TEST
println("Current Environment : "+Environment.getCurrent())
}
But it is showing error like :
Error There was an error loading the BuildConfig: Cannot set readonly property: currentEnvironment for class: grails.util.Environment
How can I change this ENVIRONMENT property?
I need to change my development environment into TEST for some AES encryption algorithms, as it is not working in Development environment.
Now am using grails test run-app command for running app in test environment, How can I fix it in TEST environment permanently?

Related

grails custom development environment

I would like to create a custom grails environment which combines the on-the-fly recompilation feature of the 'development' environment with the persistent database feature of the 'production' environment. However, I do not wish to alter either the development or production environment configurations.
I've tried using the -reloading command line parameter, however, it doesn't appear to have any effect.
It would be great if there were a flag that lived in the conf directory somewhere...
You can create a new environment in the DataSource.groovy file under the section
environment {
developemnt { ...
}
production { ...}
test { ... }
custom{ .. //your code here}
}
with your custom configuration, then
you can run a custom configuration with: grails -Dgrails.env=customEnvironment run-app
https://grails.org/Environments
BTW, if you want your DB to be persistent you only have to change dbCreate to update:
dbCreate = "update"
in the DataSource file in the environment you want to be persistent.

Change rake test environment

In my job we have a development, test and production environments. Development is the local environment use for development, test is a shared environment use for general purpose testing (QA) and production is well for production.
We are starting to development is Rails, in this framework the 'test' environment is use for running the specs. How do we specify the new environment to run the unit tests?
I have try to change the value of RAILS_ENV on "test_helper" but when running "rake test" it still try to connect to the test database.

Loading testing environment in rails

I am trying to load the test environment for unit testing and used several commands like
1. RAILS_ENV = test
2. rails console test
3. RAILS_ENV=test rails console
I am getting the same error each time(undefined method 'symbolize keys').
Can someone let me know what to do to load the test environment ?
If you are using automated testing, your test environment will be loaded automatically.
If you want to switch to the test environment in your console:
rails console test
The error you get is telling me there is something wrong in your code.

how can i manually set GrailsUtil.environment variable in Bootstrap.groovy

At the time bootstrap.groovy is running GrailsUtil.environment is automatically switch to development.
Can any one explain,How can i manually change that variable before bootstrap starts..??
Where it is setting as default to development in grails framework..??
Thanks.
Your grails environment is specified on the command line when you type run-app, for example. I don't believe you can switch the environment setting within Bootstrap.groovy--or any file--at runtime. Instead, you can change it by how you execute the grails commands:
-Dgrails.env=production run-app-- you can create your own environments to run, just change the value for -Dgrails.env to your custom environment.
Some of the grails tasks will run in a given environment by default; you don't need to set it explicitly.
run-app -- defaults to run in the development environment
test-app -- defaults to test environment
war -- defaults to production environment
More info here: http://www.grails.org/Environments

Customise behaviour of a Grails environment

I was wanting to run a custom environment called "local"...as in a local dev. I would use the config (eg DB connections) of this before a war would be deployed to the "shared" development server. But I noticed that it lacks the behavior of the standard Grails "development" Environment, such as Changes to a GSP were not available when you refresh the browser.
So this led me to wonder how do you change the behaviours of a custom environment? How can you copy all the settings for "development" to another environment?
You can enable reloading of modified gsp in a custom environment specifying the run-app flag:
-Dgrails.gsp.enable.reload=true
I don't think the automatic reloading is environment dependent. If you execute grails run-app, reloading will happen regardless of which environment you run under. In other words, automatic reloading will happen for all of
grails dev run-app
grails prod run-app
grails test run-app
On the other hand, reloading will not happen if you build a war using grails war, then deploy it. So reloading depends on how you run the app, not the environment. The easiest way to define a custom environment that is similar to dev, is to define a set of default configuration, then selectively override the settings for each environemnt, e.g.
//default config
myApp {
userRoleName = 'ROLE_USER'
adminRoleName = 'ROLE_ADMIN'
dateFormat = 'yyyy-MM-dd'
}
environments {
// config overrides for dev
development {
myApp.dateFormat = 'yyyy/MM/dd'
}
// config overrides for local
local {
myApp.dateFormat = 'MM/yy/dd'
}
}

Resources