Doing a post request in java ninja test?

183 views Asked by At

I am using the ninjaframework and documentation is quite limited. There is no documentation on making a post request with ninja test? I see the method:

ninjatestbrowser.makePostRequestWithFormParameters();

But nothing explaining how to use it. Parameters, yes there is: String, Map, Map.

An example would be very beneficial!

1

There are 1 answers

0
Fritz Seitz On

It isn't documented well but, I looked into the source code and found the method signature. The parameters are as follows: url, header, parameters. You can easily test a controller post like this:

@Test
public void test() {

    Map<String, String> headers = new HashMap<String, String>();
    Map<String, String> parameters = new HashMap<String, String>();
    headers.put("TESTHEADER", "value");
    parameters.put("email", "[email protected]");
    parameters.put("username", "tester");
    parameters.put("secret", "pass123");

    String result = ninjaTestBrowser
    .makePostRequestWithFormParameters(getServerAddress() + "/", headers, parameters);

    assertTrue(result.contains("true"));
}