Skip to content

Instantly share code, notes, and snippets.

@kouphax
Created February 13, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouphax/c04b70e379ed8b549dcb086b6be6966c to your computer and use it in GitHub Desktop.
Save kouphax/c04b70e379ed8b549dcb086b6be6966c to your computer and use it in GitHub Desktop.
package parsers;
import com.fasterxml.jackson.databind.JsonNode;
import helpers.Assertions;
import org.junit.Test;
import play.http.HttpErrorHandler;
import play.libs.F;
import play.mvc.BodyParser;
import play.mvc.Http;
import play.mvc.Result;
import play.test.WithApplication;
import static com.google.common.collect.ImmutableMap.of;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static play.libs.Json.toJson;
public class SubmissionBodyParserTest extends WithApplication implements Assertions {
@Test
public void parseParsesValidBodies() throws Exception {
HttpErrorHandler errorHandler = mock(HttpErrorHandler.class, RETURNS_DEEP_STUBS);
JsonNode body = toJson(of("firstName", "James", "lastName", "Hughes"));
BodyParser.Json bodyParser = new BodyParser.Json(1024*1024, errorHandler);
Http.RequestHeader request = new Http.RequestBuilder().bodyJson(body).build();
F.Either<Result, JsonNode> run = bodyParser.apply(request).run(mat).toCompletableFuture().get();
assertTrue(run.right.isPresent());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment