Announcement Announcement Module
Collapse
No announcement yet.
Accessing properties of externalized config file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment

          Working...
          X