Esempio n. 1
0
  @Test
  public void search_my_projects_by_exact_match_on_key() {
    ComponentDto sonarqube = componentDb.insertComponent(newProjectDto().setKey("MY_PROJECT_KEY"));
    ComponentDto ruby =
        componentDb.insertComponent(newProjectDto().setKey("MY_PROJECT_KEY_OR_ELSE"));
    dbClient.snapshotDao().insert(dbSession, newAnalysis(sonarqube), newAnalysis(ruby));
    componentDb.indexAllComponents();
    db.commit();

    insertUserPermission(UserRole.ADMIN, user.getId(), sonarqube.getId());
    insertUserPermission(UserRole.ADMIN, user.getId(), ruby.getId());

    SearchMyProjectsWsResponse result =
        call_ws(ws.newRequest().setParam(TEXT_QUERY, "MY_PROJECT_KEY"));

    assertThat(result.getProjectsCount()).isEqualTo(1);
    assertThat(result.getProjectsList())
        .extracting(Project::getId)
        .containsOnlyOnce(sonarqube.uuid())
        .doesNotContain(ruby.uuid());
  }
Esempio n. 2
0
  @Test
  public void search_my_projects_by_name() {
    ComponentDto sonarqube =
        componentDb.insertComponent(newProjectDto().setName("ONE_PROJECT_NAME"));
    ComponentDto jdk8 = componentDb.insertComponent(newProjectDto().setName("TWO_PROJECT_NAME"));
    ComponentDto ruby = componentDb.insertComponent(newProjectDto().setName("ANOTHER_42"));
    dbClient
        .snapshotDao()
        .insert(dbSession, newAnalysis(sonarqube), newAnalysis(jdk8), newAnalysis(ruby));
    componentDb.indexAllComponents();
    db.commit();

    insertUserPermission(UserRole.ADMIN, user.getId(), sonarqube.getId());
    insertUserPermission(UserRole.ADMIN, user.getId(), jdk8.getId());
    insertUserPermission(UserRole.ADMIN, user.getId(), ruby.getId());

    SearchMyProjectsWsResponse result = call_ws(ws.newRequest().setParam(TEXT_QUERY, "_project_"));

    assertThat(result.getProjectsCount()).isEqualTo(2);
    assertThat(result.getProjectsList())
        .extracting(Project::getId)
        .containsOnlyOnce(sonarqube.uuid(), jdk8.uuid())
        .doesNotContain(ruby.uuid());
  }