Results 1 to 5 of 5

Thread: Accessing properties of externalized config file

  1. #1

    Default Accessing properties of externalized config file

    I am trying to access the properties that are in an externalized config file, from my integration service tests file and did not succeed.

    I have tried...

    def propValue = grailsApplication.config.setting

    and

    def myData = ConfigurationHolder.config.setting


    No success.

    Appreciate help.

    Thanks

  2. #2
    Join Date
    Jun 2006
    Location
    Roma (Italy)
    Posts
    9

    Default

    have you added the external files in the Config.groovy?

    Below the example code i have in mine Confiog.groovy,

    Code:
    grails.config.locations = ["file:pathToYourFile"]
    I use external config file when i'm in production environment and worked always in this manner.

    And in classes:
    def configHolder = ConfigurationHolder.config
    then you can use configHolder object :
    configHolder.maxAttemptLogin to access the property maxAttemptLogin and so on.

    Hope this help.

  3. #3

    Default

    Yes. I am able to read all props well from a Controller. The Controller actions are able to read the props. No problem there.

    I am getting problem only to read props, in the Tests written for Controller and service.

    Thanks

  4. #4

    Default

    In unit tests you'll need to mock the config required in your code.

    Code:
    setUp(){
            ConfigurationHolder.config = ["defaultContactNumber": '123456789']
    }
    testSomething(){
            assertEquals '123456789', ConfigurationHolder.config.defaultContactNumber
    }
    Or you can move your tests to the integration context.

  5. #5

    Default

    I am running tests from Integration only. Not using unit as the service and controller references are spring injected.

    Did not work for me even from Integration tests.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •