private void loadProjectDatabaseSettings(DatabaseSession session, Project project) {
    addConfiguration(new ResourceDatabaseConfiguration(session, project.getKey()));

    Project parent = project.getParent();
    while (parent != null && parent.getKey() != null) {
      addConfiguration(new ResourceDatabaseConfiguration(session, parent.getKey()));
      parent = parent.getParent();
    }
  }
  @Before
  public void initialise() {
    // create mock db objects
    databaseSession = new MockDatabaseSession();
    databaseSession.setEntities(entities);

    // create quality profile hierarchy
    int numberOfProfiles = 4;
    int numberOfRules = 100;
    rulesProfiles = createRuleProfileHierarchy("qp", numberOfProfiles, numberOfRules);

    // create test project DTO
    Integer projectId = new Integer(123);
    testProject = new Project("test.project.key");
    testProject.setId(projectId);
    testProject.setName("testProject");
    testProject.setLanguage(Java.INSTANCE);

    // create test project entity
    testProjectModel = new ResourceModel();
    testProjectModel.setId(projectId);
    testProjectModel.setKey(testProject.getKey());
    testProjectModel.setEnabled(Boolean.TRUE);
    testProjectModel.setRootId(projectId);
    testProjectModel.setLanguageKey(Java.KEY);
    testProjectModel.setRulesProfile(createRulesProfile("testProjectProfile", numberOfRules));

    // add project to db objects
    MockDatabaseSession.EntityKey projectKey =
        databaseSession.new EntityKey(ResourceModel.class, projectId);
    entities.put(projectKey, testProjectModel);
    databaseSession.addMockQueryResults(ResourceModel.class, Arrays.asList(testProjectModel));

    // define test threshold
    int violationThreshold = 10;

    // create violations
    List<ActiveRule> rules = rulesProfiles[0].getActiveRules();
    int numberOfViolationsToBUnderThreshold = ((numberOfRules / 100) * violationThreshold) - 1;
    for (int i = 0; i < numberOfViolationsToBUnderThreshold; i++) {
      violations.add(Violation.create(rules.get(i), testProject));
    }

    // create context
    decoratorContext = new MockDecoratorContext(testProject, testProject, violations);

    // define default settings
    settings = new Settings();
    settings.setProperty(
        ProfileProgressionPlugin.GLOBAL_QUALITY_PROFILE_CHANGE_ENABLED_KEY, "true");
    settings.setProperty(
        ProfileProgressionPlugin.PROJECT_QUALITY_PROFILE_CHANGE_ENABLED_KEY, "true");
    settings.setProperty(
        ProfileProgressionPlugin.QUALITY_PROFILE_CHANGE_THRESHOLD_KEY,
        String.valueOf(violationThreshold));
    settings.setProperty(
        ProfileProgressionPlugin.GLOBAL_TARGET_LANGUAGE_QUALITY_PROFILE_KEY,
        rulesProfiles[numberOfProfiles - 1].getName());
  }
Esempio n. 3
0
 static String createUID(Project project, Resource resource) {
   String uid = resource.getKey();
   if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
     // not a project nor a library
     uid =
         new StringBuilder(ResourceModel.KEY_SIZE)
             .append(project.getKey())
             .append(':')
             .append(resource.getKey())
             .toString();
   }
   return uid;
 }
  @Test
  public void shouldSaveNewProject() {
    setupData("shared");

    ResourcePersister persister =
        new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
    persister.saveProject(singleProject, null);

    checkTables(
        "shouldSaveNewProject", new String[] {"build_date", "created_at"}, "projects", "snapshots");

    // SONAR-3636 : created_at must be fed when inserting a new entry in the 'projects' table
    ResourceModel model =
        getSession().getSingleResult(ResourceModel.class, "key", singleProject.getKey());
    assertThat(model.getCreatedAt()).isNotNull();
  }
Esempio n. 5
0
 public void start() {
   Project rootProject = projectTree.getRootProject();
   if (StringUtils.isNotBlank(rootProject.getKey())) {
     doStart(rootProject);
   }
 }