Package org.sonar.core.qualityprofile.db

Examples of org.sonar.core.qualityprofile.db.QualityProfileDto


    assertThat(exporters.export(profile.getKey(), "standard")).isEqualTo("standard -> P1 -> 1");
  }

  @Test
  public void fail_if_missing_exporter() {
    QualityProfileDto profile = tester.get(QProfileLoader.class).getByLangAndName("xoo", "P1");
    try {
      exporters.export(profile.getKey(), "unknown");
      fail();
    } catch (NotFoundException e) {
      assertThat(e).hasMessage("Unknown quality profile exporter: unknown");
    }
  }
View Full Code Here


    assertThat(exporters.findProfileImportersForLanguage("xoo")).hasSize(3);
  }

  @Test
  public void import_xml() throws Exception {
    QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor("xoo", "import_xml"), "import_xml");
    db.qualityProfileDao().insert(dbSession, profileDto);
    dbSession.commit();

    assertThat(loader.findActiveRulesByProfile(profileDto.getKey())).isEmpty();

    exporters.importXml(profileDto, "XooProfileImporter", "<xml/>", dbSession);
    dbSession.commit();

    List<ActiveRule> activeRules = loader.findActiveRulesByProfile(profileDto.getKey());
    assertThat(activeRules).hasSize(1);
    ActiveRule activeRule = activeRules.get(0);
    assertThat(activeRule.key().ruleKey()).isEqualTo(RuleKey.of("xoo", "R1"));
    assertThat(activeRule.severity()).isEqualTo(Severity.CRITICAL);
  }
View Full Code Here

    ruleDao.addRuleParam(dbSession, customRule, templateRuleParam1.setDefaultValue("a.*"));
    ruleDao.addRuleParam(dbSession, customRule, templateRuleParam2.setDefaultValue("txt"));
    ruleDao.addRuleParam(dbSession, customRule, templateRuleParam3);

    // Create a quality profile
    QualityProfileDto profileDto = QProfileTesting.newXooP1();
    db.qualityProfileDao().insert(dbSession, profileDto);
    dbSession.commit();

    // Activate the custom rule
    RuleActivation activation = new RuleActivation(customRule.getKey()).setSeverity(Severity.BLOCKER);
    tester.get(RuleActivator.class).activate(dbSession, activation, QProfileTesting.XOO_P1_NAME);
    dbSession.commit();
    dbSession.clearCache();

    // Update custom rule parameter 'regex', add 'message' and remove 'format'
    RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey())
      .setParameters(ImmutableMap.of("regex", "b.*", "message", "a message"));
    updater.update(update, UserSession.get());

    dbSession.clearCache();

    // Verify custom rule parameters has been updated
    Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
    assertThat(customRuleReloaded.params()).hasSize(3);
    assertThat(customRuleReloaded.param("regex")).isNotNull();
    assertThat(customRuleReloaded.param("regex").defaultValue()).isEqualTo("b.*");
    assertThat(customRuleReloaded.param("message")).isNotNull();
    assertThat(customRuleReloaded.param("message").defaultValue()).isEqualTo("a message");
    assertThat(customRuleReloaded.param("format")).isNotNull();
    assertThat(customRuleReloaded.param("format").defaultValue()).isNull();

    RuleParam param = customRuleReloaded.params().get(0);
    assertThat(param.defaultValue()).isEqualTo("b.*");

    // Verify active rule parameters has been updated
    ActiveRule activeRule = tester.get(ActiveRuleIndex.class).getByKey(ActiveRuleKey.of(profileDto.getKey(), customRule.getKey()));
    assertThat(activeRule.params()).hasSize(2);
    assertThat(activeRule.params().get("regex")).isEqualTo("b.*");
    assertThat(activeRule.params().get("message")).isEqualTo("a message");
    assertThat(activeRule.params().get("format")).isNull();

View Full Code Here

    dbSession.close();
  }

  @Test
  public void create() {
    QualityProfileDto dto = factory.create(dbSession, new QProfileName("xoo", "P1"));
    dbSession.commit();
    dbSession.clearCache();
    assertThat(dto.getKey()).startsWith("xoo-p1-");
    assertThat(dto.getName()).isEqualTo("P1");
    assertThat(dto.getLanguage()).isEqualTo("xoo");
    assertThat(dto.getId()).isNotNull();

    // reload the dto
    dto = db.qualityProfileDao().getByNameAndLanguage("P1", "xoo", dbSession);
    assertThat(dto.getLanguage()).isEqualTo("xoo");
    assertThat(dto.getName()).isEqualTo("P1");
    assertThat(dto.getKey()).startsWith("xoo-p1");
    assertThat(dto.getId()).isNotNull();
    assertThat(dto.getParentKee()).isNull();

    assertThat(db.qualityProfileDao().findAll(dbSession)).hasSize(1);
  }
View Full Code Here

    }
  }

  @Test
  public void rename() {
    QualityProfileDto dto = factory.create(dbSession, new QProfileName("xoo", "P1"));
    dbSession.commit();
    dbSession.clearCache();
    String key = dto.getKey();

    assertThat(factory.rename(key, "the new name")).isTrue();
    dbSession.clearCache();

    QualityProfileDto reloaded = db.qualityProfileDao().getByKey(dbSession, dto.getKee());
    assertThat(reloaded.getKey()).isEqualTo(key);
    assertThat(reloaded.getName()).isEqualTo("the new name");
  }
View Full Code Here

TOP

Related Classes of org.sonar.core.qualityprofile.db.QualityProfileDto

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.