BAEL-3059: Update Play Framework (#7674)
* Implementation of Introduction to Play Framework in Java * Implementation of Introduction to Play Framework in Java * Implementation of Introduction to Play Framework in Java * Implementation of the tutorial for Introduction to Play Framework. * Updated code for Play Routing to 2.7.3 * Updated code for Play Routing to 2.7.3 * Initial Commit * Added request object to create end point * Finished implementing student-api * Finished implementing student-api * Implementation of the tutorial for Introduction to Play Framework. * Updated test names * Removed Lombok dependency * Corrected isSuccessful spelling and removed the +1 on student ids
This commit is contained in:
committed by
KevinGilmore
parent
0d648321dc
commit
5bce8b22a1
@@ -0,0 +1,97 @@
|
||||
package controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import play.Application;
|
||||
import play.inject.guice.GuiceApplicationBuilder;
|
||||
import play.mvc.Http;
|
||||
import play.mvc.Result;
|
||||
import play.test.WithApplication;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static play.mvc.Http.Status.*;
|
||||
import static play.test.Helpers.GET;
|
||||
import static play.test.Helpers.route;
|
||||
|
||||
public class HomeControllerUnitTest extends WithApplication {
|
||||
|
||||
@Override
|
||||
protected Application provideApplication() {
|
||||
return new GuiceApplicationBuilder().build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenRootPath_ThenStatusOkay() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(OK, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenHtmlPath_ThenStatusOkay() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/html");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(OK, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenBadRequest_ThenStatusBadRequest() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/bad-req");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(BAD_REQUEST, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenNotFound_ThenStatusNotFound() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/not-found");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(NOT_FOUND, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenCustomContentTypePath_ThenContextTypeTextHtml() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/custom-content-type");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertTrue(result.contentType().isPresent());
|
||||
assertEquals("text/html", result.contentType().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenAsyncPath_ThenStatusOkay() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/async");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(OK, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenHeadersPath_ThenCustomHeaderFieldSet() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/headers");
|
||||
|
||||
Result result = route(app, request);
|
||||
final Optional<String> headerOptional = result.header("Header-Key");
|
||||
assertTrue(headerOptional.isPresent());
|
||||
assertEquals("Some value", headerOptional.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user