Esempio n. 1
0
  @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();
  }
Esempio n. 2
0
  @Test
  public void detachLabel() {
    // Given
    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");

    Label label1 = new Label("OS", "linux");
    label1.save();
    project.labels.add(label1);
    project.update();
    Long labelId = label1.id;

    assertThat(project.labels.contains(label1)).isTrue();

    Map<String, String> data = new HashMap<>();
    data.put("_method", "DELETE");
    User admin = User.findByLoginId("admin");

    String user = "******";
    String projectName = "projectYobi";

    // When
    Result result =
        callAction(
            controllers.routes.ref.ProjectApp.detachLabel(user, projectName, labelId),
            fakeRequest(POST, routes.ProjectApp.detachLabel(user, projectName, labelId).url())
                .withFormUrlEncodedBody(data)
                .withHeader("Accept", "application/json")
                .withSession(UserApp.SESSION_USERID, admin.id.toString()));

    // Then
    assertThat(status(result)).isEqualTo(204);
    assertThat(Project.findByOwnerAndProjectName("yobi", "projectYobi").labels.contains(label1))
        .isFalse();
  }
Esempio n. 3
0
  @Test
  public void labels() {
    // Given
    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");

    Label label1 = new Label("OS", "yobi-linux");
    label1.save();
    project.labels.add(label1);
    project.update();

    String user = "******";
    String projectName = "projectYobi";

    // If null is given as the first parameter, "Label" is chosen as the category.
    Label label2 = new Label(null, "foo");
    label2.save();
    project.labels.add(label2);
    project.update();

    // When
    Result result =
        callAction(
            controllers.routes.ref.ProjectApp.labels(user, projectName),
            fakeRequest(GET, routes.ProjectApp.labels(user, projectName).url())
                .withHeader("Accept", "application/json"));

    // Then
    assertThat(status(result)).isEqualTo(OK);
    JsonNode json = Json.parse(contentAsString(result));

    String id1 = label1.id.toString();
    String id2 = label2.id.toString();

    assertThat(json.has(id1)).isTrue();
    assertThat(json.has(id2)).isTrue();
    assertThat(json.get(id1).get("category").asText()).isEqualTo("OS");
    assertThat(json.get(id1).get("name").asText()).isEqualTo("yobi-linux");
    assertThat(json.get(id2).get("category").asText()).isEqualTo("Label");
    assertThat(json.get(id2).get("name").asText()).isEqualTo("foo");
  }