{"id":3201,"date":"2011-03-03T21:12:49","date_gmt":"2011-03-03T15:42:49","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3201"},"modified":"2016-12-19T15:06:13","modified_gmt":"2016-12-19T09:36:13","slug":"grails-unit-test-case-with-cookies","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-unit-test-case-with-cookies\/","title":{"rendered":"Grails Unit test case for cookies"},"content":{"rendered":"<p>In one of my project we were reading the cookies so that we could do the processing accordingly. Now reading the cookie is easy but writing a unit test case for that action was little bit tricky for me because I wanted to test the behavior in case of when I find the cookie and when there is no desired cookie in the request. So the question was how to add cookie into the mocked request.<\/p>\n<p>To do this I did the following in my unit test setup<\/p>\n<p>[java]<br \/>\nCookie cookie = new Cookie(&quot;APPNAME&quot;, &quot;ABCD&quot;)<br \/>\nmockRequest.cookies = [cookie].toArray()<br \/>\n[\/java]<\/p>\n<p>Now I can test my action easily :).<br \/>\n<\/p>\n<p>Hope it helps<br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/author\/uday\/\">Uday Pratap Singh<\/a><br \/>\n<a href=\"mailto:uday@intelligrape.com\">uday@intelligrape.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my project we were reading the cookies so that we could do the processing accordingly. Now reading the cookie is easy but writing a unit test case for that action was little bit tricky for me because I wanted to test the behavior in case of when I find the cookie and [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[539,542,540,541],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3201"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3201"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3201\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}