diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-07-24 16:20:04 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-07-24 16:20:12 +0200 |
commit | bcd12057b05d26ca3a782720060e75cc42177215 (patch) | |
tree | 9ad0c667c8cb7997ed21aeb52cbab4b82b3afd04 /sonar-db | |
parent | 3af4e48a629a4a74bf8b88a1de387a151231d879 (diff) | |
download | sonarqube-bcd12057b05d26ca3a782720060e75cc42177215.tar.gz sonarqube-bcd12057b05d26ca3a782720060e75cc42177215.zip |
Make the AnalysisReportDaoTest test stronger
Diffstat (limited to 'sonar-db')
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java b/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java index 6a1e740a7f3..d2851d99529 100644 --- a/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java @@ -21,11 +21,13 @@ package org.sonar.db.compute; import java.util.List; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.TemporaryFolder; import org.sonar.api.utils.System2; +import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.test.DbTests; @@ -49,6 +51,12 @@ public class AnalysisReportDaoTest { public DbTester db = DbTester.create(system2); AnalysisReportDao underTest = db.getDbClient().analysisReportDao(); + private DbSession session; + + @Before + public void setUp() { + session = db.getSession(); + } @Test public void insert_multiple_reports() { @@ -58,9 +66,9 @@ public class AnalysisReportDaoTest { AnalysisReportDto report1 = new AnalysisReportDto().setProjectKey("ProjectKey1").setProjectName("Project 1").setUuid("UUID_1").setStatus(PENDING); AnalysisReportDto report2 = new AnalysisReportDto().setProjectKey("ProjectKey2").setProjectName("Project 2").setUuid("UUID_2").setStatus(PENDING); - underTest.insert(db.getSession(), report1); - underTest.insert(db.getSession(), report2); - db.getSession().commit(); + underTest.insert(session, report1); + underTest.insert(session, report2); + session.commit(); db.assertDbUnit(getClass(), "insert-result.xml", "analysis_reports"); } @@ -69,8 +77,8 @@ public class AnalysisReportDaoTest { public void resetAllToPendingStatus() { db.prepareDbUnit(getClass(), "update-all-to-status-pending.xml"); - underTest.resetAllToPendingStatus(db.getSession()); - db.getSession().commit(); + underTest.resetAllToPendingStatus(session); + session.commit(); db.assertDbUnit(getClass(), "update-all-to-status-pending-result.xml", "analysis_reports"); } @@ -79,8 +87,8 @@ public class AnalysisReportDaoTest { public void truncate() { db.prepareDbUnit(getClass(), "any-analysis-reports.xml"); - underTest.truncate(db.getSession()); - db.getSession().commit(); + underTest.truncate(session); + session.commit(); db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports"); } @@ -90,7 +98,7 @@ public class AnalysisReportDaoTest { db.prepareDbUnit(getClass(), "select.xml"); final String projectKey = "123456789-987654321"; - List<AnalysisReportDto> reports = underTest.selectByProjectKey(db.getSession(), projectKey); + List<AnalysisReportDto> reports = underTest.selectByProjectKey(session, projectKey); AnalysisReportDto report = reports.get(0); assertThat(reports).hasSize(1); @@ -105,7 +113,7 @@ public class AnalysisReportDaoTest { db.prepareDbUnit(getClass(), "select.xml"); final String projectKey = "987654321-123456789"; - List<AnalysisReportDto> reports = underTest.selectByProjectKey(db.getSession(), projectKey); + List<AnalysisReportDto> reports = underTest.selectByProjectKey(session, projectKey); assertThat(reports).hasSize(2); } @@ -114,7 +122,7 @@ public class AnalysisReportDaoTest { public void pop_oldest_pending() { db.prepareDbUnit(getClass(), "pop_oldest_pending.xml"); - AnalysisReportDto nextAvailableReport = underTest.pop(db.getSession()); + AnalysisReportDto nextAvailableReport = underTest.pop(session); assertThat(nextAvailableReport.getId()).isEqualTo(3); assertThat(nextAvailableReport.getProjectKey()).isEqualTo("P2"); @@ -124,7 +132,7 @@ public class AnalysisReportDaoTest { public void pop_null_if_no_pending_reports() { db.prepareDbUnit(getClass(), "pop_null_if_no_pending_reports.xml"); - AnalysisReportDto nextAvailableReport = underTest.pop(db.getSession()); + AnalysisReportDto nextAvailableReport = underTest.pop(session); assertThat(nextAvailableReport).isNull(); } @@ -133,7 +141,7 @@ public class AnalysisReportDaoTest { public void getById_maps_all_the_fields_except_the_data() { db.prepareDbUnit(getClass(), "one_analysis_report.xml"); - AnalysisReportDto report = underTest.selectById(db.getSession(), 1L); + AnalysisReportDto report = underTest.selectById(session, 1L); assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY); assertThat(report.getCreatedAt()).isEqualTo(1_500_000_000_001L); @@ -147,7 +155,7 @@ public class AnalysisReportDaoTest { public void getById_returns_null_when_id_not_found() { db.prepareDbUnit(getClass(), "select.xml"); - AnalysisReportDto report = underTest.selectById(db.getSession(), 4L); + AnalysisReportDto report = underTest.selectById(session, 4L); assertThat(report).isNull(); } @@ -156,8 +164,8 @@ public class AnalysisReportDaoTest { public void delete_one_analysis_report() { db.prepareDbUnit(getClass(), "one_analysis_report.xml"); - underTest.delete(db.getSession(), 1); - db.getSession().commit(); + underTest.delete(session, 1); + session.commit(); db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports"); } @@ -166,7 +174,7 @@ public class AnalysisReportDaoTest { public void findAll_one_analysis_report() { db.prepareDbUnit(getClass(), "one_analysis_report.xml"); - List<AnalysisReportDto> reports = underTest.selectAll(db.getSession()); + List<AnalysisReportDto> reports = underTest.selectAll(session); assertThat(reports).hasSize(1); } @@ -175,7 +183,7 @@ public class AnalysisReportDaoTest { public void findAll_empty_table() { db.prepareDbUnit(getClass(), "empty.xml"); - List<AnalysisReportDto> reports = underTest.selectAll(db.getSession()); + List<AnalysisReportDto> reports = underTest.selectAll(session); assertThat(reports).isEmpty(); } @@ -184,7 +192,7 @@ public class AnalysisReportDaoTest { public void findAll_three_analysis_reports() { db.prepareDbUnit(getClass(), "three_analysis_reports.xml"); - List<AnalysisReportDto> reports = underTest.selectAll(db.getSession()); + List<AnalysisReportDto> reports = underTest.selectAll(session); assertThat(reports).hasSize(3); } |