@Test public void select_line_hashes() { dbTester.prepareDbUnit(getClass(), "shared.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI"); }
@Test public void testSelectById() { dbTester.prepareDbUnit(getClass(), "selectForQualityGate.xml"); QualityGateConditionDto selectById = underTest.selectById(1L, dbSession); assertThat(selectById).isNotNull(); assertThat(selectById.getId()).isNotNull().isNotEqualTo(0L); assertThat(selectById.getMetricId()).isEqualTo(2L); assertThat(selectById.getOperator()).isEqualTo("<"); assertThat(selectById.getQualityGateId()).isEqualTo(1L); assertThat(selectById.getErrorThreshold()).isEqualTo("20"); assertThat(underTest.selectById(42L, dbSession)).isNull(); }
@Test public void getByKey_find_enabled_Metrics() { dbTester.prepareDbUnit(getClass(), "shared.xml"); underTest.start(); assertThat(underTest.getByKey("ncloc").getId()).isEqualTo(1); assertThat(underTest.getByKey("coverage").getId()).isEqualTo(2); }
@Test public void iterator_over_issue_from_project() { dbTester.prepareDbUnit(getClass(), "many_projects.xml"); Map<String, IssueDoc> issuesByKey = issuesByKey(factory -> factory.createForProject("THE_PROJECT_1")); assertThat(issuesByKey).hasSize(2); }
@Test public void selectLastSnapshotByRootComponentUuid_returns_absent_if_only_unprocessed_snapshots() { db.prepareDbUnit(getClass(), "snapshots.xml"); Optional<SnapshotDto> snapshot = underTest.selectLastAnalysisByRootComponentUuid(db.getSession(), "uuid_5"); assertThat(snapshot).isNotPresent(); }
@Test public void no_line_hashes_when_only_test_data() { dbTester.prepareDbUnit(getClass(), "no_line_hashes_when_only_test_data.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); assertThat(fn.result).isNull(); }
@Test public void testSelectForQualityGate() { dbTester.prepareDbUnit(getClass(), "selectForQualityGate.xml"); assertThat(underTest.selectForQualityGate(dbSession, 1L)).hasSize(3); assertThat(underTest.selectForQualityGate(dbSession, 2L)).hasSize(2); }
@Test public void shouldBulkUpdateKey() { db.prepareDbUnit(getClass(), "shared.xml"); underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource()); dbSession.commit(); db.assertDbUnit(getClass(), "shouldBulkUpdateKey-result.xml", "projects"); }
@Test public void shouldBulkUpdateKeyOnOnlyOneSubmodule() { db.prepareDbUnit(getClass(), "shared.xml"); underTest.bulkUpdateKey(dbSession, "A", "struts-ui", "struts-web", doNotReturnAnyRekeyedResource()); dbSession.commit(); db.assertDbUnit(getClass(), "shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml", "projects"); }
@Test public void shouldDeleteAnalyses() { dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml"); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deleteAnalyses("uuid_1"); assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("snapshots")).isZero(); assertThat(dbTester.countRowsOfTable("analysis_properties")).isZero(); assertThat(dbTester.countRowsOfTable("events")).isZero(); assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1); }
@Test public void shouldCleanConditions() { dbTester.prepareDbUnit(getClass(), "shouldCleanConditions.xml"); underTest.deleteConditionsWithInvalidMetrics(dbTester.getSession()); dbTester.commit(); dbTester.assertDbUnit(getClass(), "shouldCleanConditions-result.xml", new String[] {"created_at", "updated_at"}, "quality_gate_conditions"); } }
@Test public void delete_view_sub_view_and_tech_project() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); // view underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); }
@Test public void check_component_keys() { db.prepareDbUnit(getClass(), "shared.xml"); Map<String, Boolean> result = underTest.checkComponentKeys(dbSession, newArrayList("foo:struts", "foo:struts-core", "foo:struts-ui")); assertThat(result) .hasSize(3) .containsOnly(entry("foo:struts", false), entry("foo:struts-core", true), entry("foo:struts-ui", false)); }
@Test public void delete_view_and_child() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); assertThat(db.countRowsOfTable("projects")).isZero(); }
@Test public void purge_history_of_project() { db.prepareDbUnit(getClass(), "shouldPurgeProject.xml"); underTest.purge(dbSession, newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler()); dbSession.commit(); db.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots"); }
@Test public void simulate_bulk_update_key() { db.prepareDbUnit(getClass(), "shared.xml"); Map<String, String> result = underTest.simulateBulkUpdateKey(dbSession, "A", "org.struts", "foo"); assertThat(result) .hasSize(3) .containsOnly(entry("org.struts:struts", "foo:struts"), entry("org.struts:struts-core", "foo:struts-core"), entry("org.struts:struts-ui", "foo:struts-ui")); }
@Test public void delete_project_and_associated_data() { db.prepareDbUnit(getClass(), "shouldDeleteProject.xml"); underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countRowsOfTable("projects")).isZero(); assertThat(db.countRowsOfTable("snapshots")).isZero(); assertThat(db.countRowsOfTable("issues")).isZero(); assertThat(db.countRowsOfTable("issue_changes")).isZero(); assertThat(db.countRowsOfTable("file_sources")).isZero(); }
@Test public void select_snapshots_by_query() { db.prepareDbUnit(getClass(), "select_snapshots_by_query.xml"); assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery())).hasSize(6); assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, ASC)).get(0).getId()).isEqualTo(1L); assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L); assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD"))).hasSize(3); assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("UNKOWN"))).isEmpty(); assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("GHIJ"))).isEmpty(); }
@Test public void shouldFailBulkUpdateKeyIfKeyAlreadyExist() { db.prepareDbUnit(getClass(), "shared.xml"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Impossible to update key: a component with key \"foo:struts-core\" already exists."); underTest.bulkUpdateKey(dbSession, "A", "org.struts", "foo", doNotReturnAnyRekeyedResource()); dbSession.commit(); }
@Test public void testUpdate() { dbTester.prepareDbUnit(getClass(), "selectForQualityGate.xml"); underTest.update(new QualityGateConditionDto().setId(1L).setMetricId(7L).setOperator(">").setErrorThreshold("80"), dbSession); dbSession.commit(); dbTester.assertDbUnitTable(getClass(), "update-result.xml", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS); }