title: how to access session in integration test in grails?
body: <p>In my project, i set session.loggedInUser in login controller. But during integration test , we dont use login controller. So i have set value for session.loggedInUser. But i couldn't use session in that place. How can i use session in integration Test. Give some solution for this. thank you in advance</p>
  
  <pre><code>class MaritalStatusIntegrationTests {
  
      @Test
      void testCategoryAudit() {
  
          RequestContextHolder.currentRequestAttributes().session.loggedInUser="Anantha"
              def category = new Category(name:"Single")
  
          category.save(flush:true)
          assert CategoryAudit.count() == 1
  
          category.name="Married"
          category.save(flush:true)
          assert CategoryAudit.count() == 2
      }
  }
  </code></pre>
  
  <p>Category.groovy:</p>
  
  <pre><code>class Category {
      static constraints = {
          name blank:false
      }
      String name
  
      //Auditing
      static auditable = false
      def onSave = {
          new CategoryAudit(this,'Insert').save(failOnError:true)
      }
  }
  </code></pre>
  
  <p>CategoryAudit.groovy:</p>
  
  <pre><code>import org.springframework.web.context.request.RequestContextHolder
  class CategoryAudit {
      String name
      String operation
      String doneBy
      Date txnDate
      def CategoryAudit(){}
      def CategoryAudit(Category category , String operation) {
          this.name = category.name
          this.operation = operation
          this.doneBy = RequestContextHolder.currentRequestAttributes().session.loggedInUser
          this.txnDate = new Date()
      }
  }
  </code></pre>