@Test public void label() { // Given Map<String, String> data = new HashMap<>(); data.put("category", "OS"); data.put("name", "linux"); User admin = User.findByLoginId("admin"); String user = "******"; String projectName = "projectYobi"; // When Result result = callAction( controllers.routes.ref.ProjectApp.attachLabel(user, projectName), fakeRequest(POST, routes.ProjectApp.attachLabel(user, projectName).url()) .withFormUrlEncodedBody(data) .withHeader("Accept", "application/json") .withSession(UserApp.SESSION_USERID, admin.id.toString())); // Then assertThat(status(result)).isEqualTo(CREATED); Iterator<Map.Entry<String, JsonNode>> fields = Json.parse(contentAsString(result)).getFields(); Map.Entry<String, JsonNode> field = fields.next(); Label expected = new Label(field.getValue().get("category").asText(), field.getValue().get("name").asText()); expected.id = Long.valueOf(field.getKey()); assertThat(expected.category).isEqualTo("OS"); assertThat(expected.name).isEqualTo("linux"); assertThat(Project.findByOwnerAndProjectName("yobi", "projectYobi").labels.contains(expected)) .isTrue(); }