コード例 #1
0
ファイル: AppActionTest.java プロジェクト: hutea/sonarqube
  @Test
  public void app() throws Exception {
    userSessionRule
        .login("john")
        .addComponentPermission(UserRole.USER, SUB_PROJECT_KEY, COMPONENT_KEY);
    ComponentDto project = newProject();

    ComponentDto file =
        ComponentTesting.newFileDto(project)
            .setId(10L)
            .setKey(COMPONENT_KEY)
            .setUuid(COMPONENT_UUID)
            .setName("Plugin.java")
            .setProjectUuid("THE_PROJECT")
            .setLongName("src/main/java/org/sonar/api/Plugin.java")
            .setPath("src/main/java/org/sonar/api/Plugin.java")
            .setParentProjectId(5L);
    when(componentDao.selectByUuid(session, COMPONENT_UUID)).thenReturn(Optional.of(file));
    when(componentDao.selectOrFailById(session, 5L))
        .thenReturn(
            new ComponentDto()
                .setId(5L)
                .setLongName("SonarQube :: Plugin API")
                .setKey(SUB_PROJECT_KEY));
    when(componentDao.selectOrFailByUuid(session, project.uuid())).thenReturn(project);
    when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session)))
        .thenReturn(newArrayList(new PropertyDto()));

    WsTester.TestRequest request =
        tester.newGetRequest("api/components", "app").setParam("uuid", COMPONENT_UUID);
    request.execute().assertJson(getClass(), "app.json");
  }
コード例 #2
0
  @Test(expected = ForbiddenException.class)
  public void check_component_uuid_permission_ko() {
    UserSession session = newServerUserSession().setLogin("marius").setUserId(1);

    ComponentDto project = ComponentTesting.newProjectDto();
    ComponentDto file = ComponentTesting.newFileDto(project, "file-uuid");
    when(resourceDao.selectResource("file-uuid"))
        .thenReturn(new ResourceDto().setProjectUuid(project.uuid()));
    when(authorizationDao.selectAuthorizedRootProjectsUuids(1, UserRole.USER))
        .thenReturn(newArrayList(project.uuid()));

    session.checkComponentUuidPermission(UserRole.USER, "another-uuid");
  }
コード例 #3
0
ファイル: AppActionTest.java プロジェクト: hutea/sonarqube
 private ComponentDto newComponent(ComponentDto project) {
   ComponentDto file =
       ComponentTesting.newFileDto(project)
           .setId(10L)
           .setQualifier("FIL")
           .setKey(COMPONENT_KEY)
           .setUuid(COMPONENT_UUID)
           .setProjectUuid(PROJECT_UUID)
           .setName("Plugin.java")
           .setLongName("src/main/java/org/sonar/api/Plugin.java")
           .setPath("src/main/java/org/sonar/api/Plugin.java")
           .setParentProjectId(5L);
   when(componentDao.selectByUuid(session, COMPONENT_UUID)).thenReturn(Optional.of(file));
   when(componentDao.selectOrFailById(session, 5L))
       .thenReturn(
           new ComponentDto()
               .setId(5L)
               .setLongName("SonarQube :: Plugin API")
               .setKey(SUB_PROJECT_KEY));
   when(componentDao.selectOrFailByUuid(session, project.uuid())).thenReturn(project);
   return file;
 }