@Test
  public void get_default_profile() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    QualityProfileDto java = underTest.selectDefaultProfile("java");
    assertThat(java).isNotNull();
    assertThat(java.getKey()).isEqualTo("java_sonar_way");

    assertThat(underTest.selectDefaultProfile("js")).isNull();
  }
  @Test
  public void get_by_id() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    QualityProfileDto dto = underTest.selectById(1);
    assertThat(dto.getId()).isEqualTo(1);
    assertThat(dto.getName()).isEqualTo("Sonar Way");
    assertThat(dto.getLanguage()).isEqualTo("java");
    assertThat(dto.getParentKee()).isNull();

    assertThat(underTest.selectById(555)).isNull();
  }
  @Test
  public void select_by_project_key_and_language() {
    dbTester.prepareDbUnit(getClass(), "projects.xml");

    QualityProfileDto dto =
        underTest.selectByProjectAndLanguage(
            dbTester.getSession(), "org.codehaus.sonar:sonar", "java");
    assertThat(dto.getId()).isEqualTo(1);

    assertThat(
            underTest.selectByProjectAndLanguage(
                dbTester.getSession(), "org.codehaus.sonar:sonar", "unkown"))
        .isNull();
    assertThat(underTest.selectByProjectAndLanguage(dbTester.getSession(), "unknown", "java"))
        .isNull();
  }
  @Test
  public void select_by_project_id_and_language() {
    dbTester.prepareDbUnit(getClass(), "projects.xml");

    QualityProfileDto dto = underTest.selectByProjectAndLanguage(1L, "java");
    assertThat(dto.getId()).isEqualTo(1);
  }
  @Test
  public void count_projects_by_profile() {
    dbTester.prepareDbUnit(getClass(), "projects.xml");

    assertThat(underTest.countProjectsByProfileKey())
        .containsOnly(MapEntry.entry("java_sonar_way", 2L), MapEntry.entry("js_sonar_way", 2L));
  }
  @Test
  public void get_parent_by_id() {
    dbTester.prepareDbUnit(getClass(), "inheritance.xml");

    QualityProfileDto dto = underTest.selectParentById(1);
    assertThat(dto.getId()).isEqualTo(3);
  }
  @Test
  public void get_by_name_and_language() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    QualityProfileDto dto =
        underTest.selectByNameAndLanguage("Sonar Way", "java", dbTester.getSession());
    assertThat(dto.getId()).isEqualTo(1);
    assertThat(dto.getName()).isEqualTo("Sonar Way");
    assertThat(dto.getLanguage()).isEqualTo("java");
    assertThat(dto.getParentKee()).isNull();

    assertThat(underTest.selectByNameAndLanguage("Sonar Way", "java", dbTester.getSession()))
        .isNotNull();
    assertThat(underTest.selectByNameAndLanguage("Sonar Way", "unknown", dbTester.getSession()))
        .isNull();
  }
  @Test
  public void selectByKeys() {
    qualityProfileDb.insertQualityProfiles(
        newQualityProfileDto().setKey("qp-key-1"),
        newQualityProfileDto().setKee("qp-key-2"),
        newQualityProfileDto().setKee("qp-key-3"));

    assertThat(underTest.selectOrFailByKey(dbSession, "qp-key-1")).isNotNull();
    assertThat(underTest.selectByKey(dbSession, "qp-key-1")).isNotNull();
    assertThat(underTest.selectByKey(dbSession, "qp-key-42")).isNull();
    assertThat(underTest.selectByKeys(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
        .hasSize(2)
        .extracting(QualityProfileDto::getKey)
        .containsOnlyOnce("qp-key-1", "qp-key-3");
    assertThat(underTest.selectByKeys(dbSession, emptyList())).isEmpty();
  }
  @Test
  public void get_default_profiles() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    List<QualityProfileDto> java =
        underTest.selectDefaultProfiles(dbTester.getSession(), singletonList("java"));
    assertThat(java).extracting("key").containsOnly("java_sonar_way");

    assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), singletonList("js")))
        .isEmpty();
    assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), of("java", "js")))
        .extracting("key")
        .containsOnly("java_sonar_way");
    assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), of("js", "java")))
        .extracting("key")
        .containsOnly("java_sonar_way");
  }
Exemplo n.º 10
0
  @Test
  public void delete() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    underTest.delete(1);

    dbTester.assertDbUnit(getClass(), "delete-result.xml", "rules_profiles");
  }
Exemplo n.º 11
0
  @Test
  public void find_by_language() {
    dbTester.prepareDbUnit(getClass(), "select_by_language.xml");

    List<QualityProfileDto> result = underTest.selectByLanguage("java");
    assertThat(result).hasSize(2);
    assertThat(result.get(0).getName()).isEqualTo("Sonar Way 1");
    assertThat(result.get(1).getName()).isEqualTo("Sonar Way 2");
  }
Exemplo n.º 12
0
  @Test
  public void find_all_is_sorted_by_profile_name() {
    dbTester.prepareDbUnit(getClass(), "select_all_is_sorted_by_profile_name.xml");

    List<QualityProfileDto> dtos = underTest.selectAll();

    assertThat(dtos).hasSize(3);
    assertThat(dtos.get(0).getName()).isEqualTo("First");
    assertThat(dtos.get(1).getName()).isEqualTo("Second");
    assertThat(dtos.get(2).getName()).isEqualTo("Third");
  }
Exemplo n.º 13
0
  @Test
  public void select_by_project_key_and_languages() {
    dbTester.prepareDbUnit(getClass(), "projects.xml");

    List<QualityProfileDto> dto =
        underTest.selectByProjectAndLanguages(
            dbTester.getSession(), "org.codehaus.sonar:sonar", singletonList("java"));
    assertThat(dto).extracting("id").containsOnly(1);

    assertThat(
            underTest.selectByProjectAndLanguages(
                dbTester.getSession(), "org.codehaus.sonar:sonar", singletonList("unkown")))
        .isEmpty();
    assertThat(
            underTest.selectByProjectAndLanguages(
                dbTester.getSession(), "org.codehaus.sonar:sonar", of("java", "unkown")))
        .extracting("id")
        .containsOnly(1);
    assertThat(
            underTest.selectByProjectAndLanguages(
                dbTester.getSession(), "unknown", singletonList("java")))
        .isEmpty();
  }
Exemplo n.º 14
0
  @Test
  public void insert() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    QualityProfileDto dto =
        QualityProfileDto.createFor("abcde").setName("ABCDE").setLanguage("xoo");

    underTest.insert(dto);

    dbTester.assertDbUnit(
        getClass(),
        "insert-result.xml",
        new String[] {"created_at", "updated_at", "rules_updated_at"},
        "rules_profiles");
  }
Exemplo n.º 15
0
  @Test
  public void get_by_name_and_languages() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    List<QualityProfileDto> dtos =
        underTest.selectByNameAndLanguages(
            "Sonar Way", singletonList("java"), dbTester.getSession());
    assertThat(dtos).hasSize(1);
    QualityProfileDto dto = dtos.iterator().next();
    assertThat(dto.getId()).isEqualTo(1);
    assertThat(dto.getName()).isEqualTo("Sonar Way");
    assertThat(dto.getLanguage()).isEqualTo("java");
    assertThat(dto.getParentKee()).isNull();

    assertThat(
            underTest.selectByNameAndLanguages(
                "Sonar Way", singletonList("unknown"), dbTester.getSession()))
        .isEmpty();
    assertThat(
            underTest.selectByNameAndLanguages(
                "Sonar Way", of("java", "unknown"), dbTester.getSession()))
        .extracting("id")
        .containsOnly(1);
  }
Exemplo n.º 16
0
  @Test
  public void find_children() {
    dbTester.prepareDbUnit(getClass(), "inheritance.xml");

    List<QualityProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent");

    assertThat(dtos).hasSize(2);

    QualityProfileDto dto1 = dtos.get(0);
    assertThat(dto1.getId()).isEqualTo(1);
    assertThat(dto1.getName()).isEqualTo("Child1");
    assertThat(dto1.getLanguage()).isEqualTo("java");
    assertThat(dto1.getParentKee()).isEqualTo("java_parent");

    QualityProfileDto dto2 = dtos.get(1);
    assertThat(dto2.getId()).isEqualTo(2);
    assertThat(dto2.getName()).isEqualTo("Child2");
    assertThat(dto2.getLanguage()).isEqualTo("java");
    assertThat(dto2.getParentKee()).isEqualTo("java_parent");
  }
Exemplo n.º 17
0
  @Test
  public void find_all() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    List<QualityProfileDto> dtos = underTest.selectAll(dbTester.getSession());

    assertThat(dtos).hasSize(2);

    QualityProfileDto dto1 = dtos.get(0);
    assertThat(dto1.getId()).isEqualTo(1);
    assertThat(dto1.getName()).isEqualTo("Sonar Way");
    assertThat(dto1.getLanguage()).isEqualTo("java");
    assertThat(dto1.getParentKee()).isNull();

    QualityProfileDto dto2 = dtos.get(1);
    assertThat(dto2.getId()).isEqualTo(2);
    assertThat(dto2.getName()).isEqualTo("Sonar Way");
    assertThat(dto2.getLanguage()).isEqualTo("js");
    assertThat(dto2.getParentKee()).isNull();
  }
Exemplo n.º 18
0
  @Test
  public void update() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");

    QualityProfileDto dto =
        new QualityProfileDto()
            .setId(1)
            .setName("New Name")
            .setLanguage("js")
            .setParentKee("fghij")
            .setDefault(false);

    underTest.update(dto);

    dbTester.assertDbUnit(
        getClass(),
        "update-result.xml",
        new String[] {"created_at", "updated_at", "rules_updated_at"},
        "rules_profiles");
  }
Exemplo n.º 19
0
  @Test
  public void select_projects() {
    dbTester.prepareDbUnit(getClass(), "projects.xml");

    assertThat(underTest.selectProjects("Sonar Way", "java")).hasSize(2);
  }
Exemplo n.º 20
0
  @Test
  public void count_projects() {
    dbTester.prepareDbUnit(getClass(), "projects.xml");

    assertThat(underTest.countProjects("Sonar Way", "java")).isEqualTo(2);
  }