Question

I am working on Play Framework 1.2.x with Java. In one of my unit test I want to send cookie information as part of my functional test case. I have tried below code but it is not working. In the controller once I read the cookie it is returning null.

Any idea what I am missing here?

Cookie cookie = new Cookie();
cookie.name = "testTimeZone";
cookie.value = "-330";
cookie.maxAge = 30000;
request.cookies.put(cookie.name, cookie); 
response = ApplicationTest.POST(request, url, null, null);  
Was it helpful?

Solution

Ok. Here is how solved it. I found it is a bug in Play 1.2.x. So, I have implemented the FunctionalTest class provided by the framework by extending it and overridden the POST method.

In overridden POST method added this code

if (savedCookies != null) { // savedCookies  is there in FunctionalTest class
            if (request.cookies != null) {
                request.cookies.putAll(savedCookies);
            } else {
                request.cookies = savedCookies;
            }
        }

And then use this extended class in my testcases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top