Package org.sonar.core.technicaldebt.db

Examples of org.sonar.core.technicaldebt.db.CharacteristicDto


      .setInheritance(null)
      .setSeverity("BLOCKER");
  }

  private void insertDebtCharacteristics(DbSession dbSession) {
    CharacteristicDto reliability = DebtTesting.newCharacteristicDto("RELIABILITY").setName("Reliability");
    db.debtCharacteristicDao().insert(reliability, dbSession);

    CharacteristicDto softReliability = DebtTesting.newCharacteristicDto("SOFT_RELIABILITY").setName("Soft Reliability")
      .setParentId(reliability.getId());
    db.debtCharacteristicDao().insert(softReliability, dbSession);
    softReliabilityId = softReliability.getId();

    CharacteristicDto hardReliability = DebtTesting.newCharacteristicDto("HARD_RELIABILITY").setName("Hard Reliability")
      .setParentId(reliability.getId());
    db.debtCharacteristicDao().insert(hardReliability, dbSession);
    hardReliabilityId = hardReliability.getId();
  }
View Full Code Here


  }

  @Test
  public void search_by_has_debt_characteristic() throws InterruptedException {
    CharacteristicDto char1 = DebtTesting.newCharacteristicDto("c1")
      .setEnabled(true)
      .setName("char1");
    db.debtCharacteristicDao().insert(char1, dbSession);
    dbSession.commit();

    CharacteristicDto char11 = DebtTesting.newCharacteristicDto("c11")
      .setEnabled(true)
      .setName("char11")
      .setParentId(char1.getId());
    db.debtCharacteristicDao().insert(char11, dbSession);

    // Rule with default characteristic
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("findbugs", "S001"))
      .setSubCharacteristicId(null)
      .setRemediationFunction(null)
      .setDefaultSubCharacteristicId(char11.getId())
      .setDefaultRemediationFunction("LINEAR").setDefaultRemediationCoefficient("2h"));
    // Rule with overridden characteristic
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("pmd", "S002"))
      .setSubCharacteristicId(char11.getId())
      .setRemediationFunction("LINEAR").setRemediationCoefficient("2h")
      .setDefaultSubCharacteristicId(null)
      .setDefaultRemediationFunction(null));
    dbSession.commit();
View Full Code Here

    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(2);
  }

  @Test
  public void search_by_characteristics() throws InterruptedException {
    CharacteristicDto char1 = DebtTesting.newCharacteristicDto("RELIABILITY");
    db.debtCharacteristicDao().insert(char1, dbSession);

    CharacteristicDto char11 = DebtTesting.newCharacteristicDto("SOFT_RELIABILITY")
      .setParentId(char1.getId());
    db.debtCharacteristicDao().insert(char11, dbSession);
    dbSession.commit();

    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S001"))
      .setSubCharacteristicId(char11.getId()));

    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("javascript", "S002")));

    dbSession.commit();
    dbSession.clearCache();

    RuleQuery query;
    Result<Rule> results;

    // 0. we have 2 rules in index
    results = index.search(new RuleQuery(), new QueryContext());
    assertThat(results.getHits()).hasSize(2);

    // filter by non-subChar
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of("toto"));
    assertThat(index.search(query, new QueryContext()).getHits()).isEmpty();

    // filter by subChar
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char11.getKey()));
    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);

    // filter by Char
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char1.getKey()));
    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);

    // filter by Char and SubChar
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char11.getKey(), char1.getKey()));
    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);

    // match by Char
    query = new RuleQuery().setQueryText(char1.getKey());
    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);

    // match by SubChar
    query = new RuleQuery().setQueryText(char11.getKey());
    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);

    // match by SubChar & Char
    query = new RuleQuery().setQueryText(char11.getKey() + " " + char1.getKey());
    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);
  }
View Full Code Here

    assertThat(index.search(query, new QueryContext()).getHits()).hasSize(1);
  }

  @Test
  public void search_by_characteristics_with_default_and_overridden_char() throws InterruptedException {
    CharacteristicDto char1 = DebtTesting.newCharacteristicDto("RELIABILITY");
    db.debtCharacteristicDao().insert(char1, dbSession);

    CharacteristicDto char11 = DebtTesting.newCharacteristicDto("SOFT_RELIABILITY")
      .setParentId(char1.getId());
    db.debtCharacteristicDao().insert(char11, dbSession);
    dbSession.commit();

    CharacteristicDto char2 = DebtTesting.newCharacteristicDto("TESTABILITY");
    db.debtCharacteristicDao().insert(char2, dbSession);

    CharacteristicDto char21 = DebtTesting.newCharacteristicDto("UNIT_TESTABILITY")
      .setParentId(char2.getId());
    db.debtCharacteristicDao().insert(char21, dbSession);
    dbSession.commit();

    // Rule with only default sub characteristic -> should be find by char11 and char1
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S001"))
      .setSubCharacteristicId(char11.getId())
      .setDefaultSubCharacteristicId(null));

    // Rule with only sub characteristic -> should be find by char11 and char1
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S002"))
      .setSubCharacteristicId(null)
      .setDefaultSubCharacteristicId(char11.getId()));

    // Rule with both default sub characteristic and overridden sub characteristic -> should only be find by char21 and char2
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S003"))
      .setSubCharacteristicId(char21.getId()))
      .setDefaultSubCharacteristicId(char11.getId());

    // Rule with both default sub characteristic and overridden sub characteristic and with same values -> should be find by char11 and char1
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S004"))
      .setSubCharacteristicId(char11.getId()))
      .setDefaultSubCharacteristicId(char11.getId());

    dbSession.commit();
    dbSession.clearCache();

    RuleQuery query;
    Result<Rule> results;

    // 0. we have 4 rules in index
    results = index.search(new RuleQuery(), new QueryContext());
    assertThat(results.getHits()).hasSize(4);

    // filter by subChar
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char11.getKey()));
    assertThat(ruleKeys(index.search(query, new QueryContext()).getHits())).containsOnly("S001", "S002", "S004");

    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char21.getKey()));
    assertThat(ruleKeys(index.search(query, new QueryContext()).getHits())).containsOnly("S003");

    // filter by Char
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char1.getKey()));
    assertThat(ruleKeys(index.search(query, new QueryContext()).getHits())).containsOnly("S001", "S002", "S004");

    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char2.getKey()));
    assertThat(ruleKeys(index.search(query, new QueryContext()).getHits())).containsOnly("S003");

    // filter by Char and SubChar
    query = new RuleQuery().setDebtCharacteristics(ImmutableSet.of(char11.getKey(), char1.getKey(), char2.getKey(), char21.getKey()));
    assertThat(ruleKeys(index.search(query, new QueryContext()).getHits())).containsOnly("S001", "S002", "S003", "S004");
  }
View Full Code Here


  @Test
  public void insert_update_characteristics() throws Exception {

    CharacteristicDto char1 = DebtTesting.newCharacteristicDto("c1");
    db.debtCharacteristicDao().insert(char1, dbSession);
    dbSession.commit();

    CharacteristicDto char11 = DebtTesting.newCharacteristicDto("c11")
      .setParentId(char1.getId());
    db.debtCharacteristicDao().insert(char11, dbSession);

    dao.insert(dbSession,
      RuleTesting.newXooX1()
        .setDefaultSubCharacteristicId(char11.getId())
        .setRemediationFunction(null)
        .setRemediationCoefficient(null)
        .setRemediationOffset(null));
    dbSession.commit();


    // 0. assert chars in DB
    assertThat(db.debtCharacteristicDao().selectByKey("c1", dbSession)).isNotNull();
    assertThat(db.debtCharacteristicDao().selectByKey("c1", dbSession).getParentId()).isNull();
    assertThat(db.debtCharacteristicDao().selectByKey("c11", dbSession)).isNotNull();
    assertThat(db.debtCharacteristicDao().selectByKey("c11", dbSession).getParentId()).isEqualTo(char1.getId());

    // 1. find char and subChar from rule
    Rule rule = index.getByKey(RuleTesting.XOO_X1);
    assertThat(rule.debtCharacteristicKey()).isEqualTo(char1.getKey());
    assertThat(rule.debtSubCharacteristicKey()).isEqualTo(char11.getKey());
    assertThat(rule.debtOverloaded()).isFalse();


    // 3. set Non-default characteristics
    RuleDto ruleDto = db.ruleDao().getByKey(dbSession, RuleTesting.XOO_X1);
    CharacteristicDto char2 = DebtTesting.newCharacteristicDto("c2");
    db.debtCharacteristicDao().insert(char2, dbSession);

    CharacteristicDto char21 = DebtTesting.newCharacteristicDto("c21")
      .setParentId(char2.getId());
    db.debtCharacteristicDao().insert(char21, dbSession);

    ruleDto.setSubCharacteristicId(char21.getId());
    dao.update(dbSession, ruleDto);
    dbSession.commit();

    rule = index.getByKey(RuleTesting.XOO_X1);

    // Assert rule has debt Overloaded Char
    assertThat(rule.debtOverloaded()).isTrue();

    // 4. Get non-default chars from Rule
    assertThat(rule.debtCharacteristicKey()).isEqualTo(char2.getKey());
    assertThat(rule.debtSubCharacteristicKey()).isEqualTo(char21.getKey());

    //  5 Assert still get the default one
    assertThat(rule.debtOverloaded()).isTrue();
    assertThat(rule.defaultDebtCharacteristicKey()).isEqualTo(char1.getKey());
    assertThat(rule.defaultDebtSubCharacteristicKey()).isEqualTo(char11.getKey());
View Full Code Here

  public void show_rule_with_default_debt_infos() throws Exception {
    MockUserSession.set()
      .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN)
      .setLogin("me");

    CharacteristicDto characteristicDto = new CharacteristicDto().setKey("API").setName("Api").setEnabled(true);
    tester.get(CharacteristicDao.class).insert(characteristicDto, session);
    CharacteristicDto subCharacteristicDto = new CharacteristicDto().setKey("API_ABUSE").setName("API Abuse").setEnabled(true).setParentId(characteristicDto.getId());
    tester.get(CharacteristicDao.class).insert(subCharacteristicDto, session);

    RuleDto ruleDto = ruleDao.insert(session,
      RuleTesting.newDto(RuleKey.of("java", "S001"))
        .setName("Rule S001")
        .setDescription("Rule S001 <b>description</b>")
        .setSeverity(Severity.MINOR)
        .setStatus(RuleStatus.BETA)
        .setConfigKey("InternalKeyS001")
        .setLanguage("xoo")
        .setDefaultSubCharacteristicId(subCharacteristicDto.getId())
        .setDefaultRemediationFunction("LINEAR_OFFSET")
        .setDefaultRemediationCoefficient("5d")
        .setDefaultRemediationOffset("10h")
        .setSubCharacteristicId(null)
        .setRemediationFunction(null)
View Full Code Here

  public void show_rule_with_overridden_debt() throws Exception {
    MockUserSession.set()
      .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN)
      .setLogin("me");

    CharacteristicDto characteristicDto = new CharacteristicDto().setKey("API").setName("Api").setEnabled(true);
    tester.get(CharacteristicDao.class).insert(characteristicDto, session);
    CharacteristicDto subCharacteristicDto = new CharacteristicDto().setKey("API_ABUSE").setName("API Abuse").setEnabled(true).setParentId(characteristicDto.getId());
    tester.get(CharacteristicDao.class).insert(subCharacteristicDto, session);

    RuleDto ruleDto = ruleDao.insert(session,
      RuleTesting.newDto(RuleKey.of("java", "S001"))
        .setName("Rule S001")
        .setDescription("Rule S001 <b>description</b>")
        .setSeverity(Severity.MINOR)
        .setStatus(RuleStatus.BETA)
        .setConfigKey("InternalKeyS001")
        .setLanguage("xoo")
        .setDefaultSubCharacteristicId(null)
        .setDefaultRemediationFunction(null)
        .setDefaultRemediationCoefficient(null)
        .setDefaultRemediationOffset(null)
        .setSubCharacteristicId(subCharacteristicDto.getId())
        .setRemediationFunction("LINEAR_OFFSET")
        .setRemediationCoefficient("5d")
        .setRemediationOffset("10h")
    );
    session.commit();
View Full Code Here

  public void show_rule_with_default_and_overridden_debt_infos() throws Exception {
    MockUserSession.set()
      .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN)
      .setLogin("me");

    CharacteristicDto defaultCharacteristic = new CharacteristicDto().setKey("API").setName("Api").setEnabled(true);
    tester.get(CharacteristicDao.class).insert(defaultCharacteristic, session);
    CharacteristicDto defaultSubCharacteristic = new CharacteristicDto().setKey("API_ABUSE").setName("API Abuse").setEnabled(true).setParentId(defaultCharacteristic.getId());
    tester.get(CharacteristicDao.class).insert(defaultSubCharacteristic, session);

    CharacteristicDto characteristic = new CharacteristicDto().setKey("OS").setName("Os").setEnabled(true);
    tester.get(CharacteristicDao.class).insert(characteristic, session);
    CharacteristicDto subCharacteristic = new CharacteristicDto().setKey("OS_RELATED_PORTABILITY").setName("Portability").setEnabled(true).setParentId(characteristic.getId());
    tester.get(CharacteristicDao.class).insert(subCharacteristic, session);

    RuleDto ruleDto = ruleDao.insert(session,
      RuleTesting.newDto(RuleKey.of("java", "S001"))
        .setName("Rule S001")
        .setDescription("Rule S001 <b>description</b>")
        .setSeverity(Severity.MINOR)
        .setStatus(RuleStatus.BETA)
        .setConfigKey("InternalKeyS001")
        .setLanguage("xoo")
        .setDefaultSubCharacteristicId(defaultSubCharacteristic.getId())
        .setDefaultRemediationFunction("LINEAR")
        .setDefaultRemediationCoefficient("5min")
        .setDefaultRemediationOffset(null)
        .setSubCharacteristicId(subCharacteristic.getId())
        .setRemediationFunction("LINEAR_OFFSET")
        .setRemediationCoefficient("5d")
        .setRemediationOffset("10h")
    );
    session.commit();
View Full Code Here

  private DebtTesting() {
    // only static helpers
  }

  public static CharacteristicDto newCharacteristicDto(String key) {
    return new CharacteristicDto()
      .setKey(key)
      .setName(StringUtils.capitalize(key))
      .setEnabled(true);
  }
View Full Code Here

      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom or a manual rule");
    }
  }

  private void insertDebtCharacteristics(DbSession dbSession) {
    CharacteristicDto reliability = DebtTesting.newCharacteristicDto("RELIABILITY");
    db.debtCharacteristicDao().insert(reliability, dbSession);

    CharacteristicDto softReliability = DebtTesting.newCharacteristicDto("SOFT_RELIABILITY")
      .setParentId(reliability.getId());
    db.debtCharacteristicDao().insert(softReliability, dbSession);
    softReliabilityId = softReliability.getId();

    CharacteristicDto hardReliability = DebtTesting.newCharacteristicDto("HARD_RELIABILITY")
      .setParentId(reliability.getId());
    db.debtCharacteristicDao().insert(hardReliability, dbSession);
    hardReliabilityId = hardReliability.getId();
  }
View Full Code Here

TOP

Related Classes of org.sonar.core.technicaldebt.db.CharacteristicDto

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.