예제 #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();
  }
예제 #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();
  }
예제 #3
0
  @Test
  public void testAcceptTransferWithWrongKey()
      throws IOException, ServletException, ClientException {
    // Given
    GitRepository.setRepoPrefix("resources/test/repo/git/");

    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
    RepositoryService.createRepository(project);

    User sender = User.findByLoginId("yobi");
    User newOwner = User.findByLoginId("doortts");

    ProjectTransfer pt = ProjectTransfer.requestNewTransfer(project, sender, newOwner.loginId);
    assertThat(pt.confirmKey).isNotNull();

    // When
    Result result =
        callAction(
            controllers.routes.ref.ProjectApp.acceptTransfer(pt.id, "wrongKey"),
            fakeRequest(PUT, routes.ProjectApp.acceptTransfer(pt.id, "wrongKey").url())
                .withSession(UserApp.SESSION_USERID, newOwner.id.toString()));

    // Then
    assertThat(status(result)).isEqualTo(400);
    support.Files.rm_rf(new File(GitRepository.getRepoPrefix()));
  }
예제 #4
0
  @Test
  public void anonymousCanSearchPublicProjects() {
    // Given
    User anonymous = User.anonymous;
    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");

    // When
    // Then
    testProjectSearch(
        anonymous,
        project,
        acceptHtml,
        contains(routes.ProjectApp.project(project.owner, project.name).url()));
  }
예제 #5
0
  @Test
  public void anonymousCannotSearchPrivateProjects() {
    // Given
    User anonymous = User.anonymous;
    Project project = Project.findByOwnerAndProjectName("laziel", "Jindo");

    // When
    // Then
    testProjectSearch(
        anonymous,
        project,
        acceptHtml,
        doesNotContains(routes.ProjectApp.project(project.owner, project.name).url()));
  }
예제 #6
0
  @Test
  public void memberCanSearchPublicProjects() {
    // Given
    User member = User.find.byId(2L);
    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");

    // When
    // Then
    testProjectSearch(
        member,
        project,
        acceptHtml,
        contains(routes.ProjectApp.project(project.owner, project.name).url()));
  }
예제 #7
0
  @Test
  public void memberCannotSearchPrivateProjects() {
    // Given
    User member = User.find.byId(3L);
    Project project = Project.findByOwnerAndProjectName("laziel", "Jindo");

    // When
    // Then
    testProjectSearch(
        member,
        project,
        acceptHtml,
        doesNotContains(routes.ProjectApp.project(project.owner, project.name).url()));
  }
예제 #8
0
  @Test
  public void adminCanSearchPrivateProjects() {
    // Given
    User admin = User.find.byId(1L);
    Project project = Project.findByOwnerAndProjectName("laziel", "Jindo");

    // When
    // Then
    testProjectSearch(
        admin,
        project,
        acceptHtml,
        contains(routes.ProjectApp.project(project.owner, project.name).url()));
  }
예제 #9
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");
  }
예제 #10
0
  @Test
  public void testTransferProject() {
    // Given
    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
    User oldOwner = User.findByLoginId("yobi");
    User newOwner = User.findByLoginId("doortts");

    Map<String, String> data = new HashMap<>();
    data.put("owner", newOwner.loginId);

    // When
    Result result =
        callAction(
            controllers.routes.ref.ProjectApp.transferProject(project.owner, project.name),
            fakeRequest(
                    PUT,
                    routes.ProjectApp.transferProject(project.owner, project.name).url()
                        + "?owner="
                        + newOwner.loginId)
                .withSession(UserApp.SESSION_USERID, oldOwner.id.toString()));

    // Then
    assertThat(status(result)).isEqualTo(303); // redirection to project home
    assertThat(redirectLocation(result)).isEqualTo("/yobi/projectYobi");

    ProjectTransfer pt =
        ProjectTransfer.find
            .where()
            .eq("project", project)
            .eq("sender", oldOwner)
            .eq("destination", newOwner.loginId)
            .findUnique();

    assertThat(pt).isNotNull();
    assertThat(pt.confirmKey).isNotNull();
    assertThat(pt.accepted).isFalse();
  }
예제 #11
0
  @Test
  public void testTransferProjectToWrongUser() {
    // Given
    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
    User oldOwner = User.findByLoginId("yobi");
    User newOwner = User.findByLoginId("keesun");

    Map<String, String> data = new HashMap<>();
    data.put("owner", newOwner.loginId);

    // When
    Result result =
        callAction(
            controllers.routes.ref.ProjectApp.transferProject(project.owner, project.name),
            fakeRequest(
                    PUT,
                    routes.ProjectApp.transferProject(project.owner, project.name).url()
                        + "?owner="
                        + newOwner.loginId)
                .withSession(UserApp.SESSION_USERID, oldOwner.id.toString()));

    // Then
    assertThat(status(result)).isEqualTo(400); // bad request
  }