コード例 #1
0
ファイル: AppAction.java プロジェクト: CodeLeague/sonarqube
  private void appendComponent(
      JsonWriter json, ComponentDto component, UserSession userSession, DbSession session) {
    List<PropertyDto> propertyDtos =
        dbClient
            .propertiesDao()
            .selectByQuery(
                PropertyQuery.builder()
                    .setKey("favourite")
                    .setComponentId(component.getId())
                    .setUserId(userSession.getUserId())
                    .build(),
                session);
    boolean isFavourite = propertyDtos.size() == 1;

    json.prop("key", component.key());
    json.prop("uuid", component.uuid());
    json.prop("path", component.path());
    json.prop("name", component.name());
    json.prop("longName", component.longName());
    json.prop("q", component.qualifier());

    ComponentDto parentProject = retrieveRootIfNotCurrentComponent(component, session);
    ComponentDto project =
        dbClient.componentDao().selectOrFailByUuid(session, component.projectUuid());

    // Do not display parent project if parent project and project are the same
    boolean displayParentProject =
        parentProject != null && !parentProject.uuid().equals(project.uuid());
    json.prop("subProject", displayParentProject ? parentProject.key() : null);
    json.prop("subProjectName", displayParentProject ? parentProject.longName() : null);
    json.prop("project", project.key());
    json.prop("projectName", project.longName());

    json.prop("fav", isFavourite);
  }
コード例 #2
0
  @Test
  public void hasProjectSubscribersForType() {
    setUpMocks();

    PropertiesDao dao = mock(PropertiesDao.class);
    when(dbClient.propertiesDao()).thenReturn(dao);

    // no subscribers
    when(dao.hasProjectNotificationSubscribersForDispatchers(
            "PROJECT_UUID",
            Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe")))
        .thenReturn(false);
    assertThat(
            service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes")))
        .isFalse();

    // has subscribers on one dispatcher (among the two)
    when(dao.hasProjectNotificationSubscribersForDispatchers(
            "PROJECT_UUID",
            Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe")))
        .thenReturn(true);
    assertThat(
            service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes")))
        .isTrue();
  }
コード例 #3
0
ファイル: AppActionTest.java プロジェクト: hutea/sonarqube
  @Before
  public void setUp() {
    DbClient dbClient = mock(DbClient.class);
    when(dbClient.openSession(false)).thenReturn(session);
    when(dbClient.componentDao()).thenReturn(componentDao);
    when(dbClient.propertiesDao()).thenReturn(propertiesDao);
    when(dbClient.measureDao()).thenReturn(measureDao);

    when(measureDao.selectByComponentKeyAndMetricKeys(
            eq(session), anyString(), anyListOf(String.class)))
        .thenReturn(measures);

    tester =
        new WsTester(
            new ComponentsWs(
                new AppAction(
                    dbClient, durations, i18n, userSessionRule, new ComponentFinder(dbClient)),
                mock(SearchAction.class)));
  }