Search in sources :

Example 6 with Response

use of play.mvc.Http.Response in project play-cookbook by spinscale.

the class UserRightTest method testSecretsAreDeniedForUnknownUser.

@Test
public void testSecretsAreDeniedForUnknownUser() {
    Response response = GET("/secret");
    assertStatus(404, response);
}
Also used : Response(play.mvc.Http.Response) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 7 with Response

use of play.mvc.Http.Response in project play-cookbook by spinscale.

the class JsonRenderTest method testThatJsonRenderingWorks.

@Test
public void testThatJsonRenderingWorks() {
    Response response = GET("/user/1");
    assertIsOk(response);
    User user = new Gson().fromJson(getContent(response), User.class);
    assertNotNull(user);
    assertNull(user.password);
    assertNull(user.secrets);
    assertEquals(user.login, "alex");
    assertEquals(user.address.city, "Munich");
    assertContentMatch("\"uri\":\"/user/1\"", response);
}
Also used : Response(play.mvc.Http.Response) User(models.User) Gson(com.google.gson.Gson) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 8 with Response

use of play.mvc.Http.Response in project play-cookbook by spinscale.

the class FeedTest method testThatRss10Works.

@Test
public void testThatRss10Works() throws Exception {
    Response response = GET("/feed/posts.rss");
    assertIsOk(response);
    assertContentType("application/rss+xml", response);
    assertCharset("utf-8", response);
    SyndFeed feed = getFeed(response);
    assertEquals("rss_1.0", feed.getFeedType());
}
Also used : Response(play.mvc.Http.Response) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 9 with Response

use of play.mvc.Http.Response in project play-cookbook by spinscale.

the class CachingTest method testThatCachingWholePageWorks.

@Test
public void testThatCachingWholePageWorks() throws Exception {
    Response response = GET("/cacheFor");
    String content = getContent(response);
    response = GET("/cacheFor");
    assertEquals(content, getContent(response));
    Thread.sleep(6000);
    response = GET("/cacheFor");
    assertNotSame(content, getContent(response));
}
Also used : Response(play.mvc.Http.Response) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 10 with Response

use of play.mvc.Http.Response in project play-cookbook by spinscale.

the class CachingTest method testThatEtagCachingWorks.

@Test
public void testThatEtagCachingWorks() {
    Response response = GET("/etagCache/123");
    assertIsOk(response);
    assertContentEquals("Learn to use etags, dumbass!", response);
    Request request = newRequest();
    String etag = String.valueOf("123".hashCode());
    Header noneMatchHeader = new Header("if-none-match", etag);
    request.headers.put("if-none-match", noneMatchHeader);
    DateTime ago = new DateTime().minusHours(12);
    String agoStr = Utils.getHttpDateFormatter().format(ago.toDate());
    Header modifiedHeader = new Header("if-modified-since", agoStr);
    request.headers.put("if-modified-since", modifiedHeader);
    response = GET(request, "/etagCache/123");
    assertStatus(304, response);
}
Also used : Response(play.mvc.Http.Response) Header(play.mvc.Http.Header) Request(play.mvc.Http.Request) DateTime(org.joda.time.DateTime) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Aggregations

Response (play.mvc.Http.Response)13 Test (org.junit.Test)12 FunctionalTest (play.test.FunctionalTest)12 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)3 Gson (com.google.gson.Gson)1 User (models.User)1 DateTime (org.joda.time.DateTime)1 Header (play.mvc.Http.Header)1 Request (play.mvc.Http.Request)1