Package org.sonar.server.qualityprofile.db

Examples of org.sonar.server.qualityprofile.db.ActiveRuleDao


  @Test
  public void facade() throws Exception {
    MyBatis myBatis = db.myBatis();
    RuleDao ruleDao = new RuleDao(System2.INSTANCE);
    QualityProfileDao qualityProfileDao = new QualityProfileDao(myBatis, System2.INSTANCE);
    ActiveRuleDao activeRuleDao = new ActiveRuleDao(qualityProfileDao, ruleDao, System2.INSTANCE);

    DbClient client = new DbClient(db.database(), myBatis, ruleDao, activeRuleDao, qualityProfileDao);

    assertThat(client.database()).isSameAs(db.database());
    DbSession dbSession = client.openSession(true);
View Full Code Here


  @Before
  public void before() {
    system = mock(System2.class);
    when(system.now()).thenReturn(DATE1.getTime());
    RuleDao ruleDao = new RuleDao(system);
    ActiveRuleDao activeRuleDao = new ActiveRuleDao(new QualityProfileDao(getMyBatis(), system), ruleDao, system);
    dbClient = new DbClient(getDatabase(), getMyBatis(), ruleDao, activeRuleDao,
      new QualityProfileDao(getMyBatis(), system), new CharacteristicDao(getMyBatis()));
    dbSession = dbClient.openSession(false);
  }
View Full Code Here

    ActiveRuleDto activeRule = null;
    if (change.getType() == ActiveRuleChange.Type.ACTIVATED) {
      activeRule = doInsert(change, context, dbSession);

    } else if (change.getType() == ActiveRuleChange.Type.DEACTIVATED) {
      ActiveRuleDao dao = db.activeRuleDao();
      dao.deleteByKey(dbSession, change.getKey());

    } else if (change.getType() == ActiveRuleChange.Type.UPDATED) {
      activeRule = doUpdate(change, context, dbSession);
    }
    log.write(dbSession, Activity.Type.QPROFILE, change);
View Full Code Here

    return activeRule;
  }

  private ActiveRuleDto doInsert(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
    ActiveRuleDto activeRule;
    ActiveRuleDao dao = db.activeRuleDao();
    activeRule = ActiveRuleDto.createFor(context.profile(), context.rule());
    String severity = change.getSeverity();
    if (severity != null) {
      activeRule.setSeverity(severity);
    }
    ActiveRule.Inheritance inheritance = change.getInheritance();
    if (inheritance != null) {
      activeRule.setInheritance(inheritance.name());
    }
    dao.insert(dbSession, activeRule);
    for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
      if (param.getValue() != null) {
        ActiveRuleParamDto paramDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey()));
        paramDto.setValue(param.getValue());
        dao.addParam(dbSession, activeRule, paramDto);
      }
    }
    return activeRule;
  }
View Full Code Here

    }
    return activeRule;
  }

  private ActiveRuleDto doUpdate(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
    ActiveRuleDao dao = db.activeRuleDao();
    ActiveRuleDto activeRule = context.activeRule();
    String severity = change.getSeverity();
    if (severity != null) {
      activeRule.setSeverity(severity);
    }
    ActiveRule.Inheritance inheritance = change.getInheritance();
    if (inheritance != null) {
      activeRule.setInheritance(inheritance.name());
    }
    dao.update(dbSession, activeRule);

    for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
      ActiveRuleParamDto activeRuleParamDto = context.activeRuleParamsAsMap().get(param.getKey());
      if (activeRuleParamDto == null) {
        // did not exist
        if (param.getValue() != null) {
          activeRuleParamDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey()));
          activeRuleParamDto.setValue(param.getValue());
          dao.addParam(dbSession, activeRule, activeRuleParamDto);
        }
      } else {
        if (param.getValue() != null) {
          activeRuleParamDto.setValue(param.getValue());
          dao.updateParam(dbSession, activeRule, activeRuleParamDto);
        } else {
          dao.deleteParam(dbSession, activeRule, activeRuleParamDto);
        }
      }
    }
    return activeRule;
  }
View Full Code Here

    assertThat(qualityProfileDao.findAll(dbSession)).hasSize(1);
    QualityProfileDto profile = qualityProfileDao.getByNameAndLanguage("Basic", "xoo", dbSession);
    assertThat(profile).isNotNull();

    // Check ActiveRules in DB
    ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
    assertThat(activeRuleDao.findByProfileKey(dbSession, profile.getKey())).hasSize(2);
    RuleKey ruleKey = RuleKey.of("xoo", "x1");
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);

    // 0. Check and clear ES
    assertThat(tester.get(ActiveRuleIndex.class).getNullableByKey(activeRuleKey)).isNotNull();
    tester.clearIndexes();
    assertThat(tester.get(ActiveRuleIndex.class).getNullableByKey(activeRuleKey)).isNull();
    tester.get(Platform.class).restart();
    assertThat(tester.get(ActiveRuleIndex.class).getNullableByKey(activeRuleKey)).isNotNull();

    // Check ActiveRules in ES
    org.sonar.server.qualityprofile.ActiveRule activeRule = tester.get(ActiveRuleIndex.class).getNullableByKey(activeRuleKey);
    assertThat(activeRule.key().qProfile()).isEqualTo(profile.getKee());
    assertThat(activeRule.key().ruleKey()).isEqualTo(ruleKey);
    assertThat(activeRule.severity()).isEqualTo(Severity.CRITICAL);

    // TODO
    // Check ActiveRuleParameters in DB
    Map<String, ActiveRuleParamDto> params =
      ActiveRuleParamDto.groupByKey(activeRuleDao.findParamsByActiveRuleKey(dbSession, activeRule.key()));
    assertThat(params).hasSize(2);
    // set by profile
    assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
    // default value
    assertThat(params.get("max").getValue()).isEqualTo("10");
View Full Code Here

    // Check Default Profile
    verifyProperty("sonar.profile.xoo", "Basic");

    // Check ActiveRules in DB
    ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
    assertThat(activeRuleDao.findByProfileKey(dbSession, profile.getKey())).hasSize(2);
    RuleKey ruleKey = RuleKey.of("xoo", "x1");

    ActiveRuleDto activeRule = activeRuleDao.getNullableByKey(dbSession, ActiveRuleKey.of(profile.getKey(), ruleKey));
    assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKey());
    assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
    assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);

    // Check ActiveRuleParameters in DB
    Map<String, ActiveRuleParamDto> params =
      ActiveRuleParamDto.groupByKey(activeRuleDao.findParamsByActiveRuleKey(dbSession, activeRule.getKey()));
    assertThat(params).hasSize(2);
    // set by profile
    assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
    // default value
    assertThat(params.get("max").getValue()).isEqualTo("10");
View Full Code Here

TOP

Related Classes of org.sonar.server.qualityprofile.db.ActiveRuleDao

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.