@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 get_parent_by_id() {
    dbTester.prepareDbUnit(getClass(), "inheritance.xml");

    QualityProfileDto dto = underTest.selectParentById(1);
    assertThat(dto.getId()).isEqualTo(3);
  }
  @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 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 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");
  }
  @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();
  }
  @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");
  }
  @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);
  }