Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves Java REST tests: unique Strings, negative assertions #49

Merged
merged 4 commits into from
Sep 25, 2019

Conversation

ignasi35
Copy link
Member

This PR introduces multiple changes:

  1. each test case uses a unique title and body on the data it creates. This is necessary because this is a stateful tests and assertions were being mixed up
  2. assertions are more strict. Previous implementation would treat the response as a plain String and assert that contained the body substring. This assertion is wrong since the Play failure page (an HTML indicating the requested URI is missing) can be converted to a String and it also contains the substring body.
  3. Adds a test case to ensure GET /v1/posts/ works. Equivalent to Small fixes for Play REST samples #48 but for the java sample.

This PR is currently not passing all the tests (tested in 2.8.0-M3 and 2.7.3). The reason is a test expecting GET /v1/posts/ (the requests includes a trailing slash) fails.

This is related to playframework/playframework#8850, #47 and #48

@ignasi35
Copy link
Member Author

After discussing with @marcospereira, the behavior of Play is correct and the failing test here is wrong: the test expects GET /v1/posts/ to return a list of values but that's the wrong expectation.

Note that in play-scala-rest-example there's a similar test which does the exact same assertion and passes the test. The reason is that play-scala-rest-example sneakily includes support for trailing slashes but that's not a vanilla Play feature.

@ignasi35 ignasi35 requested review from marcospereira and removed request for marcospereira and wsargent September 25, 2019 15:51
private Optional<PostResource> findPostByTitle(JsonNode listOfPosts, String postTitle) {
Iterator<JsonNode> elements = listOfPosts.elements();
// spliterator dance to build a Stream from an Iterator
return StreamSupport.stream(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... this is API is so nice. /s

@@ -1,5 +1,8 @@
#!/usr/bin/env bash

set -e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ignasi35 ignasi35 merged commit ab63776 into playframework:2.8.x Sep 25, 2019
@ignasi35 ignasi35 deleted the improves-java-rest-tests branch September 25, 2019 17:16
octonato added a commit to octonato/play-samples that referenced this pull request Dec 4, 2019
…2.6.x

Upgrade branch 2.6.x using TemplateControl
octonato added a commit to octonato/play-samples that referenced this pull request Dec 4, 2019
…2.6.x

Upgrade branch 2.6.x using TemplateControl
octonato pushed a commit to octonato/play-samples that referenced this pull request Dec 4, 2019
…o 2.6.x

* play-java-fileupload-example/2.6.x: (47 commits)
  Nest play-java-fileupload-example
  Updated with template-control on 2019-02-13T20:25:39.476Z (playframework#76)
  Upgrade branch 2.6.x using TemplateControl (playframework#74)
  Upgrade branch 2.6.x using TemplateControl (playframework#73)
  Upgrade branch 2.6.x using TemplateControl (playframework#72)
  Updated with template-control on 2019-01-08T14:44:42.021Z (playframework#70)
  Updated with template-control on 2019-01-04T17:13:23.621Z (playframework#65)
  Upgrade branch 2.6.x using TemplateControl (playframework#64)
  Upgrade branch 2.6.x using TemplateControl (playframework#61)
  Updated with template-control on 2018-09-11T20:14:49.858Z (playframework#60)
  Updated with template-control on 2018-08-20T20:37:13.644Z (playframework#59)
  Updated with template-control on 2018-07-19T01:58:54.727Z (playframework#57)
  Updated with template-control on 2018-07-16T18:38:45.481Z (playframework#56)
  Upgrade branch 2.6.x using TemplateControl (playframework#55)
  Updated with template-control on 2018-05-27T23:54:09.370Z (playframework#54)
  Updated with template-control on 2018-04-06T19:34:57.877Z (playframework#52)
  Add explicit note on upload limit (playframework#51)
  Updated with template-control on 2018-03-02T18:56:28.047Z (playframework#49)
  Upgrade branch 2.6.x using TemplateControl (playframework#48)
  Fix cross build to sbt 1.1.0 (playframework#47)
  ...
octonato pushed a commit to octonato/play-samples that referenced this pull request Dec 4, 2019
…2.6.x

* play-java-rest-api-example/2.6.x: (61 commits)
  Nest play-java-rest-api-example
  Updated with template-control on 2019-02-13T20:25:39.721Z (playframework#81)
  Upgrade branch 2.6.x using TemplateControl (playframework#79)
  Updated with template-control on 2019-01-17T15:10:58.259Z   /.mergify.yml:     wrote /.mergify.yml
  Updated with template-control on 2019-01-16T12:08:46.124Z   /LICENSE:     wrote /LICENSE   /NOTICE:     wrote /NOTICE   /.mergify.yml:     wrote /.mergify.yml   **build.sbt:     scalaVersion := "2.12.8"   **build.gradle:         playTest "io.gatling.highcharts:gatling-charts-highcharts:$gatlingVersion"   **build.gradle:         playTest "io.gatling:gatling-test-framework:$gatlingVersion"
  Upgrade branch 2.6.x using TemplateControl (playframework#74)
  Upgrade branch 2.6.x using TemplateControl (playframework#65)
  fixing wrong template-ctrl replacement
  Updated with template-control on 2018-11-29T16:03:57.787Z   /.mergify.yml:     wrote /.mergify.yml   **build.sbt:     scalaVersion := "2.12.7"   **/build.properties:     sbt.version=1.2.6
  removed jdk 9 and 10
  removed misterious GatlingSpec
  fixed build.sbt
  Updated with template-control on 2018-11-16T14:25:15.563Z   **build.sbt:     scalaVersion := "2.12.6"   **/plugins.sbt:     addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.20")   **build.gradle:     def playVersion = "2.6.20"
  Upgrade branch 2.6.x using TemplateControl (playframework#55)
  Upgrade branch 2.6.x using TemplateControl (playframework#54)
  Upgrade branch 2.6.x using TemplateControl (playframework#51)
  Upgrade branch 2.6.x using TemplateControl (playframework#50)
  Upgrade branch 2.6.x using TemplateControl (playframework#49)
  Correct scalaVersion setting
  Revert gatling version changes
  ...
octonato pushed a commit to octonato/play-samples that referenced this pull request Dec 4, 2019
… 2.6.x

* play-scala-chatroom-example/2.6.x: (52 commits)
  Nest play-scala-chatroom-example
  Updated with template-control on 2019-02-13T20:25:39.259Z (playframework#76)
  Upgrade branch 2.6.x using TemplateControl (playframework#74)
  Upgrade branch 2.6.x using TemplateControl (playframework#73)
  Upgrade branch 2.6.x using TemplateControl (playframework#72)
  Updated with template-control on 2019-01-08T14:44:41.803Z (playframework#70)
  Updated with template-control on 2019-01-04T17:13:23.812Z (playframework#65)
  Upgrade branch 2.6.x using TemplateControl (playframework#64)
  Upgrade branch 2.6.x using TemplateControl (playframework#61)
  Updated with template-control on 2018-09-11T20:14:50.057Z (playframework#60)
  Updated with template-control on 2018-08-20T20:37:13.669Z (playframework#59)
  Updated with template-control on 2018-07-19T01:58:55.835Z (playframework#57)
  Updated with template-control on 2018-07-16T18:38:45.034Z (playframework#56)
  Upgrade branch 2.6.x using TemplateControl (playframework#55)
  Updated with template-control on 2018-05-27T23:54:09.446Z (playframework#53)
  Updated with template-control on 2018-04-06T19:34:57.975Z (playframework#51)
  Updated with template-control on 2018-03-02T18:56:28.165Z (playframework#50)
  Upgrade branch 2.6.x using TemplateControl (playframework#49)
  Fix cross build to sbt 1.1.0 (playframework#48)
  Upgrade branch 2.6.x using TemplateControl (playframework#47)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants