use of org.doctester.testbrowser.Response in project ninja by ninjaframework.
the class ApiControllerDocTesterTest method testGetAndPostArticleViaJson.
@Test
public void testGetAndPostArticleViaJson() {
// /////////////////////////////////////////////////////////////////////
// Test initial data:
// /////////////////////////////////////////////////////////////////////
sayNextSection("Retrieving articles for a user (Json)");
say("Retrieving all articles of a user is a GET request to " + GET_ARTICLES_URL);
Response response = sayAndMakeRequest(Request.GET().url(testServerUrl().path(GET_ARTICLES_URL.replace("{username}", "bob@gmail.com"))));
ArticlesDto articlesDto = getGsonWithLongToDateParsing().fromJson(response.payload, ArticlesDto.class);
sayAndAssertThat("We get back all 3 articles of that user", articlesDto.articles.size(), CoreMatchers.is(3));
// /////////////////////////////////////////////////////////////////////
// Post new article:
// /////////////////////////////////////////////////////////////////////
sayNextSection("Posting new article (Json)");
say("Posting a new article is a post request to " + POST_ARTICLE_URL);
say("Please note that you have to be authenticated in order to be allowed to post.");
ArticleDto articleDto = new ArticleDto();
articleDto.content = "contentcontent";
articleDto.title = "new title new title";
response = sayAndMakeRequest(Request.POST().url(testServerUrl().path(POST_ARTICLE_URL.replace("{username}", USER))).payload(articleDto));
sayAndAssertThat("You have to be authenticated in order to post articles", response.httpStatus, CoreMatchers.is(403));
doLogin();
say("Now we are authenticated and expect the post to succeed...");
response = sayAndMakeRequest(Request.POST().url(testServerUrl().path(POST_ARTICLE_URL.replace("{username}", USER))).contentTypeApplicationJson().payload(articleDto));
sayAndAssertThat("After successful login we are able to post articles", response.httpStatus, CoreMatchers.is(200));
// /////////////////////////////////////////////////////////////////////
// Fetch articles again => assert we got a new one ...
// /////////////////////////////////////////////////////////////////////
say("If we now fetch the articles again we are getting a new article (the one we have posted successfully");
response = sayAndMakeRequest(Request.GET().url(testServerUrl().path(GET_ARTICLES_URL.replace("{username}", "bob@gmail.com"))));
articlesDto = getGsonWithLongToDateParsing().fromJson(response.payload, ArticlesDto.class);
// one new result:
sayAndAssertThat("We are now getting 4 articles.", articlesDto.articles.size(), CoreMatchers.is(4));
// /////////////////////////////////////////////////////////////////////
// Fetch single article
// /////////////////////////////////////////////////////////////////////
say("We can also fetch an individual article via the Json Api.");
say("That's a GET request to: " + GET_ARTICLE_URL);
response = sayAndMakeRequest(Request.GET().url(testServerUrl().path(GET_ARTICLE_URL.replace("{username}", "bob@gmail.com").replace("{id}", "1"))));
Article article = getGsonWithLongToDateParsing().fromJson(response.payload, Article.class);
// one new result:
sayAndAssertThat("And we got back the first article", article.id, CoreMatchers.is(1L));
}
use of org.doctester.testbrowser.Response in project ninja by ninjaframework.
the class NotFoundTest method testThatNotFoundWorksHtml.
@Test
public void testThatNotFoundWorksHtml() {
Response response = makeRequest(Request.GET().url(testServerUrl().path("/_non_existing_url")));
assertEquals(404, response.httpStatus);
assertTrue(response.payload.contains("The requested route cannot be found."));
}
use of org.doctester.testbrowser.Response in project ninja by ninjaframework.
the class NotFoundTest method testThatNotFoundWorksXml.
@Test
public void testThatNotFoundWorksXml() {
Response response = makeRequest(Request.GET().url(testServerUrl().path("/_non_existing_url")).addHeader(HttpConstants.HEADER_ACCEPT, HttpConstants.APPLICATION_XML));
assertEquals(404, response.httpStatus);
Message message = response.payloadXmlAs(Message.class);
Assert.assertThat(message.text, CoreMatchers.equalTo(NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_TEXT_DEFAULT));
}
use of org.doctester.testbrowser.Response in project ninja by ninjaframework.
the class ApplicationControllerTest method testDevModeIndexMissing012.
@Test
public void testDevModeIndexMissing012() {
// Server runs in Test mode making pure "dev" routes unavailable
Response response = makeRequest(Request.GET().url(testServerUrl().path("/0/1/2/mode/dev")));
Assert.assertThat(response.httpStatus, CoreMatchers.equalTo(Result.SC_404_NOT_FOUND));
}
use of org.doctester.testbrowser.Response in project ninja by ninjaframework.
the class ApplicationControllerTest method testTestModeIndex012.
@Test
public void testTestModeIndex012() {
Response response = makeRequest(Request.GET().url(testServerUrl().path("/0/1/2/mode/test")));
Assert.assertThat(response.payload, CoreMatchers.equalTo("test mode works."));
}
Aggregations