I don’t understand why I have this error.
When I use newRequest, I have a RuntimeException when calling the
makeRequest(request); method.
The exception message is : “play.mvc.results.NotFound : POST /”
But what is odd, is that in the .url, I specify “/dashboard”, not
“/” (and of course, the url is well indicated in the routes file for POST requests!)
Thanks for your help.
Here is my test class :
public class DashboardTest extends FunctionalTest {
protected Request ajaxRequest;
@Before
public void _setUp() {
Fixtures.deleteDatabase();
Fixtures.loadModels("fixtures/accounts.yml");
ajaxRequest = newRequest();
//ajaxRequest.headers.put("X-Requested-With", new Header("X-
Requested-With", "XMLHttpRequest"));
ajaxRequest.method = "POST";
ajaxRequest.url = "/dashboard";
}
@Test
public void testAuthenticateWithValidDataAjax() {
ajaxRequest.params.put("email", "john.sm...@gmail.com");
Response response = makeRequest(ajaxRequest);
assertIsOk(response);
assertContentType("application/json", response);
}
}
Looking at the API documentation, the
.urlspecifies that it needs the Full URL. What I would suggest you do instead, is to use the.actioninstead.The Javadoc for the this is
or specify the full URL, which would include
Your final option, if you are still having problems, is to use the
createRequestmethod on theHttp.Requestobject, which gives you complete control over the Request object you are creating. The signature looks like this