mardi 9 juin 2015

Faking Ajax Request Form for testing

In my Playframework 2.4 project I have methods like this:

public static Result resetValue(int client) {
    String receivedName= form().bindFromRequest().get("username");
    User user = User.findByName(receivedName);
    if( user == null ) {
        return badRequest("No user logged in");
    }
    user.setValue(0);
    user.saveUsertoDB();
    return ok("Value set to zero");
}

I want to write JUnit Tests for those methods and ran into the problem that I don`t know how to recreate the Ajax Requests which would normally call those methods in my application.

I am looking for a way to fake the ajax requests and integrate the needed fields into the request so that I can successfully test those methods.

Aucun commentaire:

Enregistrer un commentaire