Package org.sonar.core.resource

Examples of org.sonar.core.resource.ResourceDto


  public void get_source_as_html_with_to_param() throws Exception {
    String componentKey = "org.sonar.sample:Sample";
    String source = "line 1\nline 2\nline 3\n";
    String htmlSource = "<span>line 1</span>\n<span>line 2</span>\n<span>line 3</span>\n";

    when(resourceDao.getResource(any(ResourceQuery.class), eq(session))).thenReturn(new ResourceDto().setKey(componentKey).setLanguage("java"));
    when(snapshotSourceDao.selectSnapshotSourceByComponentKey(componentKey, session)).thenReturn(source);
    when(codeColorizers.toHtml(source, "java")).thenReturn(htmlSource);

    List<String> result = sourceDecorator.getSourceAsHtml(componentKey, null, 3);
    assertThat(result).containsExactly("<span>line 1</span>", "<span>line 2</span>", "<span>line 3</span>");
View Full Code Here


    AuthorizationDao authorizationDao = mock(AuthorizationDao.class);
    ResourceDao resourceDao = mock(ResourceDao.class);
    UserSession session = new SpyUserSession("marius", authorizationDao, resourceDao).setUserId(1);

    String componentKey = "com.foo:Bar:BarFile.xoo";
    when(resourceDao.getRootProjectByComponentKey(componentKey)).thenReturn(new ResourceDto().setKey(componentKey));
    when(authorizationDao.selectAuthorizedRootProjectsKeys(1, UserRole.USER)).thenReturn(newArrayList(componentKey));

    assertThat(session.hasComponentPermission(UserRole.USER, componentKey)).isTrue();
    assertThat(session.hasComponentPermission(UserRole.CODEVIEWER, componentKey)).isFalse();
    assertThat(session.hasComponentPermission(UserRole.ADMIN, componentKey)).isFalse();
View Full Code Here

  public void check_component_permission_ok() throws Exception {
    AuthorizationDao authorizationDao = mock(AuthorizationDao.class);
    ResourceDao resourceDao = mock(ResourceDao.class);
    UserSession session = new SpyUserSession("marius", authorizationDao, resourceDao).setUserId(1);

    when(resourceDao.getRootProjectByComponentKey("com.foo:Bar:BarFile.xoo")).thenReturn(new ResourceDto().setKey("com.foo:Bar"));
    when(authorizationDao.selectAuthorizedRootProjectsKeys(1, UserRole.USER)).thenReturn(newArrayList("com.foo:Bar"));

    session.checkComponentPermission(UserRole.USER, "com.foo:Bar:BarFile.xoo");
  }
View Full Code Here

  public void check_component_permission_ko() throws Exception {
    AuthorizationDao authorizationDao = mock(AuthorizationDao.class);
    ResourceDao resourceDao = mock(ResourceDao.class);
    UserSession session = new SpyUserSession("marius", authorizationDao, resourceDao).setUserId(1);

    when(resourceDao.getRootProjectByComponentKey("com.foo:Bar:BarFile.xoo")).thenReturn(new ResourceDto().setKey("com.foo:Bar2"));
    when(authorizationDao.selectAuthorizedRootProjectsKeys(1, UserRole.USER)).thenReturn(newArrayList("com.foo:Bar"));

    session.checkComponentPermission(UserRole.USER, "com.foo:Bar:BarFile.xoo");
  }
View Full Code Here

        return 0;
      }
      return Long.valueOf(dto.getValue());
    }
    // For modules look for root project last modification timestamp
    ResourceDto rootProject = resourceDao.getRootProjectByComponentId(projectId);
    if (rootProject == null) {
      throw new SonarException("Unable to find root project for project with [id=" + projectId + "]");
    }
    PropertyDto dto = propertiesDao.selectProjectProperty(rootProject.getId(), SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY);
    if (dto == null) {
      return 0;
    }
    return Long.valueOf(dto.getValue());
  }
View Full Code Here

    actionPlanService = new ActionPlanService(dbClient, actionPlanDao, actionPlanStatsDao, resourceDao, issueUpdater, issueStorage);
  }

  @Test
  public void create() {
    when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey(projectKey).setId(1l));
    ActionPlan actionPlan = DefaultActionPlan.create("Long term");

    actionPlanService.create(actionPlan, projectAdministratorUserSession);
    verify(actionPlanDao).save(any(ActionPlanDto.class));
  }
View Full Code Here

    verify(actionPlanDao).save(any(ActionPlanDto.class));
  }

  @Test
  public void create_required_admin_role() {
    when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey(projectKey).setId(1l));
    ActionPlan actionPlan = DefaultActionPlan.create("Long term");

    try {
      actionPlanService.create(actionPlan, unauthorizedUserSession);
      Fail.fail();
View Full Code Here

  public void reportGlobalModification(SqlSession session) {
    propertiesDao.setProperty(new PropertyDto().setKey(SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY).setValue(String.valueOf(System.currentTimeMillis())), session);
  }

  public void reportResourceModification(String resourceKey) {
    ResourceDto rootProject = resourceDao.getRootProjectByComponentKey(resourceKey);
    if (rootProject == null) {
      throw new SonarException("Unable to find root project for component with [key=" + resourceKey + "]");
    }
    propertiesDao.setProperty(new PropertyDto().setKey(SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY).setResourceId(rootProject.getId())
      .setValue(String.valueOf(System.currentTimeMillis())));
  }
View Full Code Here

  }

  @Test
  public void set_status() {
    when(actionPlanDao.findByKey("ABCD")).thenReturn(new ActionPlanDto().setKey("ABCD").setProjectKey_unit_test_only(projectKey));
    when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey(projectKey).setId(1l));

    ActionPlan result = actionPlanService.setStatus("ABCD", "CLOSED", projectAdministratorUserSession);
    verify(actionPlanDao).update(any(ActionPlanDto.class));

    assertThat(result).isNotNull();
View Full Code Here

    assertThat(result.status()).isEqualTo("CLOSED");
  }

  @Test
  public void update() {
    when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey(projectKey).setId(1l));
    ActionPlan actionPlan = DefaultActionPlan.create("Long term");

    actionPlanService.update(actionPlan, projectAdministratorUserSession);
    verify(actionPlanDao).update(any(ActionPlanDto.class));
  }
View Full Code Here

TOP

Related Classes of org.sonar.core.resource.ResourceDto

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.