]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7345 Fix test on MsSQL
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Mar 2016 12:38:48 +0000 (13:38 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Mar 2016 12:55:50 +0000 (13:55 +0100)
sonar-db/src/test/java/org/sonar/db/issue/IssueMapperTest.java
sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testInsert-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testUpdate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testUpdate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/updateBeforeSelectedDate_with_conflict-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/updateBeforeSelectedDate_with_conflict.xml [deleted file]

index 4d3c379fea5b8b2995d480648e389433ed6deaeb..2bf9d9cb891ad5b74b5ad0958fd3d63c3d5ee733 100644 (file)
  */
 package org.sonar.db.issue;
 
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-
 public class IssueMapperTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  IssueMapper mapper = dbTester.getSession().getMapper(IssueMapper.class);
+  DbSession dbSession = dbTester.getSession();
+
+  IssueMapper underTest = dbSession.getMapper(IssueMapper.class);
+
+  ComponentDto project, file;
+  RuleDto rule;
+
+  @Before
+  public void setUp() throws Exception {
+    project = ComponentTesting.newProjectDto();
+    dbTester.getDbClient().componentDao().insert(dbSession, project);
+    file = ComponentTesting.newFileDto(project);
+    dbTester.getDbClient().componentDao().insert(dbSession, file);
+    rule = RuleTesting.newXooX1();
+    dbTester.getDbClient().ruleDao().insert(dbSession, rule);
+    dbSession.commit();
+  }
 
   @Test
   public void insert() {
-    IssueDto dto = new IssueDto();
-    dto.setComponentUuid("uuid-123");
-    dto.setProjectUuid("uuid-100");
-    dto.setRuleId(200);
-    dto.setType(2);
-    dto.setKee("ABCDE");
-    dto.setLine(500);
-    dto.setGap(3.14);
-    dto.setEffort(10L);
-    dto.setResolution("FIXED");
-    dto.setStatus("RESOLVED");
-    dto.setSeverity("BLOCKER");
-    dto.setReporter("emmerik");
-    dto.setAuthorLogin("morgan");
-    dto.setAssignee("karadoc");
-    dto.setActionPlanKey("current_sprint");
-    dto.setIssueAttributes("JIRA=FOO-1234");
-    dto.setChecksum("123456789");
-    dto.setMessage("the message");
-
-    dto.setIssueCreationTime(1_401_000_000_000L);
-    dto.setIssueUpdateTime(1_402_000_000_000L);
-    dto.setIssueCloseTime(1_403_000_000_000L);
-    dto.setCreatedAt(1_400_000_000_000L);
-    dto.setUpdatedAt(1_500_000_000_000L);
-
-    mapper.insert(dto);
+    underTest.insert(newIssue());
     dbTester.getSession().commit();
 
-    dbTester.assertDbUnit(getClass(), "testInsert-result.xml", new String[]{"id"}, "issues");
+    IssueDto result = underTest.selectByKey("ABCDE");
+    assertThat(result).isNotNull();
+    assertThat(result.getId()).isNotNull();
+    assertThat(result.getKey()).isEqualTo("ABCDE");
+    assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
+    assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
+    assertThat(result.getRuleId()).isEqualTo(rule.getId());
+    assertThat(result.getType()).isEqualTo(2);
+    assertThat(result.getLine()).isEqualTo(500);
+    assertThat(result.getGap()).isEqualTo(3.14d);
+    assertThat(result.getEffort()).isEqualTo(10L);
+    assertThat(result.getResolution()).isEqualTo("FIXED");
+    assertThat(result.getStatus()).isEqualTo("RESOLVED");
+    assertThat(result.getSeverity()).isEqualTo("BLOCKER");
+    assertThat(result.getReporter()).isEqualTo("emmerik");
+    assertThat(result.getAuthorLogin()).isEqualTo("morgan");
+    assertThat(result.getAssignee()).isEqualTo("karadoc");
+    assertThat(result.getActionPlanKey()).isEqualTo("current_sprint");
+    assertThat(result.getIssueAttributes()).isEqualTo("JIRA=FOO-1234");
+    assertThat(result.getChecksum()).isEqualTo("123456789");
+    assertThat(result.getMessage()).isEqualTo("the message");
+    assertThat(result.getIssueCreationTime()).isEqualTo(1_401_000_000_000L);
+    assertThat(result.getIssueUpdateTime()).isEqualTo(1_402_000_000_000L);
+    assertThat(result.getIssueCloseTime()).isEqualTo(1_403_000_000_000L);
+    assertThat(result.getCreatedAt()).isEqualTo(1_400_000_000_000L);
+    assertThat(result.getUpdatedAt()).isEqualTo(1_500_000_000_000L);
   }
 
   @Test
   public void update() {
-    dbTester.prepareDbUnit(getClass(), "testUpdate.xml");
-
-    IssueDto dto = new IssueDto();
-    dto.setComponentUuid("uuid-123");
-    dto.setProjectUuid("uuid-101");
-    dto.setRuleId(200);
-    dto.setType(3);
-    dto.setKee("ABCDE");
-    dto.setLine(500);
-    dto.setGap(3.14);
-    dto.setEffort(10L);
-    dto.setResolution("FIXED");
-    dto.setStatus("RESOLVED");
-    dto.setSeverity("BLOCKER");
-    dto.setReporter("emmerik");
-    dto.setAuthorLogin("morgan");
-    dto.setAssignee("karadoc");
-    dto.setActionPlanKey("current_sprint");
-    dto.setIssueAttributes("JIRA=FOO-1234");
-    dto.setChecksum("123456789");
-    dto.setMessage("the message");
-
-    dto.setIssueCreationTime(1_401_000_000_000L);
-    dto.setIssueUpdateTime(1_402_000_000_000L);
-    dto.setIssueCloseTime(1_403_000_000_000L);
-    dto.setCreatedAt(1_400_000_000_000L);
-    dto.setUpdatedAt(1_500_000_000_000L);
-
-    mapper.update(dto);
+    underTest.insert(newIssue());
+
     dbTester.getSession().commit();
 
-    dbTester.assertDbUnit(getClass(), "testUpdate-result.xml", new String[]{"id"}, "issues");
+    IssueDto update = new IssueDto();
+    update.setKee("ABCDE");
+    update.setComponentUuid(file.uuid());
+    update.setProjectUuid(project.uuid());
+    update.setRuleId(rule.getId());
+    update.setType(3);
+    update.setLine(500);
+    update.setGap(3.14);
+    update.setEffort(10L);
+    update.setResolution("FIXED");
+    update.setStatus("RESOLVED");
+    update.setSeverity("BLOCKER");
+    update.setReporter("emmerik");
+    update.setAuthorLogin("morgan");
+    update.setAssignee("karadoc");
+    update.setActionPlanKey("current_sprint");
+    update.setIssueAttributes("JIRA=FOO-1234");
+    update.setChecksum("123456789");
+    update.setMessage("the message");
+
+    update.setIssueCreationTime(1_550_000_000_000L);
+    update.setIssueUpdateTime(1_550_000_000_000L);
+    update.setIssueCloseTime(1_550_000_000_000L);
+    // Should not change
+    update.setCreatedAt(1_400_123_456_789L);
+    update.setUpdatedAt(1_550_000_000_000L);
+
+    underTest.update(update);
+    dbTester.getSession().commit();
+
+    IssueDto result = underTest.selectByKey("ABCDE");
+    assertThat(result).isNotNull();
+    assertThat(result.getId()).isNotNull();
+    assertThat(result.getKey()).isEqualTo("ABCDE");
+    assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
+    assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
+    assertThat(result.getRuleId()).isEqualTo(rule.getId());
+    assertThat(result.getType()).isEqualTo(3);
+    assertThat(result.getLine()).isEqualTo(500);
+    assertThat(result.getGap()).isEqualTo(3.14d);
+    assertThat(result.getEffort()).isEqualTo(10L);
+    assertThat(result.getResolution()).isEqualTo("FIXED");
+    assertThat(result.getStatus()).isEqualTo("RESOLVED");
+    assertThat(result.getSeverity()).isEqualTo("BLOCKER");
+    assertThat(result.getReporter()).isEqualTo("emmerik");
+    assertThat(result.getAuthorLogin()).isEqualTo("morgan");
+    assertThat(result.getAssignee()).isEqualTo("karadoc");
+    assertThat(result.getActionPlanKey()).isEqualTo("current_sprint");
+    assertThat(result.getIssueAttributes()).isEqualTo("JIRA=FOO-1234");
+    assertThat(result.getChecksum()).isEqualTo("123456789");
+    assertThat(result.getMessage()).isEqualTo("the message");
+    assertThat(result.getIssueCreationTime()).isEqualTo(1_550_000_000_000L);
+    assertThat(result.getIssueUpdateTime()).isEqualTo(1_550_000_000_000L);
+    assertThat(result.getIssueCloseTime()).isEqualTo(1_550_000_000_000L);
+    assertThat(result.getCreatedAt()).isEqualTo(1_400_000_000_000L);
+    assertThat(result.getUpdatedAt()).isEqualTo(1_550_000_000_000L);
   }
 
   @Test
   public void updateBeforeSelectedDate_without_conflict() {
-    dbTester.prepareDbUnit(getClass(), "testUpdate.xml");
-
-    IssueDto dto = new IssueDto();
-    dto.setComponentUuid("uuid-123");
-    dto.setProjectUuid("uuid-101");
-    dto.setRuleId(200);
-    dto.setType(3);
-    dto.setKee("ABCDE");
-    dto.setLine(500);
-    dto.setGap(3.14);
-    dto.setEffort(10L);
-    dto.setResolution("FIXED");
-    dto.setStatus("RESOLVED");
-    dto.setSeverity("BLOCKER");
-    dto.setReporter("emmerik");
-    dto.setAuthorLogin("morgan");
-    dto.setAssignee("karadoc");
-    dto.setActionPlanKey("current_sprint");
-    dto.setIssueAttributes("JIRA=FOO-1234");
-    dto.setChecksum("123456789");
-    dto.setMessage("the message");
-    dto.setIssueCreationTime(1_401_000_000_000L);
-    dto.setIssueUpdateTime(1_402_000_000_000L);
-    dto.setIssueCloseTime(1_403_000_000_000L);
-    dto.setCreatedAt(1_400_000_000_000L);
-    dto.setUpdatedAt(1_500_000_000_000L);
+    underTest.insert(newIssue());
+
+    IssueDto dto = newIssue()
+      .setType(3)
+      .setLine(600)
+      .setGap(1.12d)
+      .setEffort(50L)
+      .setIssueUpdateTime(1_600_000_000_000L)
+      .setUpdatedAt(1_600_000_000_000L);
 
     // selected after last update -> ok
     dto.setSelectedAt(1500000000000L);
 
-    int count = mapper.updateIfBeforeSelectedDate(dto);
+    int count = underTest.updateIfBeforeSelectedDate(dto);
     assertThat(count).isEqualTo(1);
     dbTester.getSession().commit();
 
-    dbTester.assertDbUnit(getClass(), "testUpdate-result.xml", new String[]{"id"}, "issues");
+    IssueDto result = underTest.selectByKey("ABCDE");
+    assertThat(result).isNotNull();
+    assertThat(result.getType()).isEqualTo(3);
+    assertThat(result.getLine()).isEqualTo(600);
+    assertThat(result.getGap()).isEqualTo(1.12d);
+    assertThat(result.getEffort()).isEqualTo(50L);
+    assertThat(result.getIssueUpdateTime()).isEqualTo(1_600_000_000_000L);
+    assertThat(result.getUpdatedAt()).isEqualTo(1_600_000_000_000L);
   }
 
   @Test
   public void updateBeforeSelectedDate_with_conflict() {
-    dbTester.prepareDbUnit(getClass(), "updateBeforeSelectedDate_with_conflict.xml");
-
-    IssueDto dto = new IssueDto();
-    dto.setComponentUuid("uuid-123");
-    dto.setProjectUuid("uuid-101");
-    dto.setRuleId(200);
-    dto.setKee("ABCDE");
-    dto.setLine(500);
-    dto.setGap(3.14);
-    dto.setEffort(10L);
-    dto.setResolution("FIXED");
-    dto.setStatus("RESOLVED");
-    dto.setSeverity("BLOCKER");
-    dto.setReporter("emmerik");
-    dto.setAuthorLogin("morgan");
-    dto.setAssignee("karadoc");
-    dto.setActionPlanKey("current_sprint");
-    dto.setIssueAttributes("JIRA=FOO-1234");
-    dto.setChecksum("123456789");
-    dto.setMessage("the message");
-    dto.setIssueCreationDate(DateUtils.parseDate("2013-05-18"));
-    dto.setIssueUpdateDate(DateUtils.parseDate("2013-05-19"));
-    dto.setIssueCloseDate(DateUtils.parseDate("2013-05-20"));
-    dto.setCreatedAt(1400000000000L);
-    dto.setUpdatedAt(1460000000000L);
+    underTest.insert(newIssue());
+
+    IssueDto dto = newIssue()
+      .setType(3)
+      .setLine(600)
+      .setGap(1.12d)
+      .setEffort(50L)
+      .setIssueUpdateTime(1_600_000_000_000L)
+      .setUpdatedAt(1_600_000_000_000L);
 
     // selected before last update -> ko
     dto.setSelectedAt(1400000000000L);
 
-    int count = mapper.updateIfBeforeSelectedDate(dto);
+    int count = underTest.updateIfBeforeSelectedDate(dto);
     assertThat(count).isEqualTo(0);
     dbTester.getSession().commit();
 
-    dbTester.assertDbUnit(getClass(), "updateBeforeSelectedDate_with_conflict-result.xml", new String[]{"id"}, "issues");
+    // No change
+    IssueDto result = underTest.selectByKey("ABCDE");
+    assertThat(result).isNotNull();
+    assertThat(result.getType()).isEqualTo(2);
+    assertThat(result.getLine()).isEqualTo(500);
+    assertThat(result.getGap()).isEqualTo(3.14d);
+    assertThat(result.getEffort()).isEqualTo(10L);
+    assertThat(result.getIssueUpdateTime()).isEqualTo(1_402_000_000_000L);
+    assertThat(result.getUpdatedAt()).isEqualTo(1_500_000_000_000L);
+  }
+
+  private IssueDto newIssue() {
+    return new IssueDto()
+      .setKee("ABCDE")
+      .setComponentUuid(file.uuid())
+      .setProjectUuid(project.uuid())
+      .setRuleId(rule.getId())
+      .setType(2)
+      .setLine(500)
+      .setGap(3.14)
+      .setEffort(10L)
+      .setResolution("FIXED")
+      .setStatus("RESOLVED")
+      .setSeverity("BLOCKER")
+      .setReporter("emmerik")
+      .setAuthorLogin("morgan")
+      .setAssignee("karadoc")
+      .setActionPlanKey("current_sprint")
+      .setIssueAttributes("JIRA=FOO-1234")
+      .setChecksum("123456789")
+      .setMessage("the message")
+      .setIssueCreationTime(1_401_000_000_000L)
+      .setIssueUpdateTime(1_402_000_000_000L)
+      .setIssueCloseTime(1_403_000_000_000L)
+      .setCreatedAt(1_400_000_000_000L)
+      .setUpdatedAt(1_500_000_000_000L);
   }
 }
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testInsert-result.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testInsert-result.xml
deleted file mode 100644 (file)
index 1d1e874..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-  <issues
-    id="100"
-    kee="ABCDE"
-    component_uuid="uuid-123"
-    project_uuid="uuid-100"
-    rule_id="200"
-    severity="BLOCKER"
-    manual_severity="[false]"
-    message="the message"
-    line="500"
-    gap="3.14"
-    effort="10"
-    status="RESOLVED"
-    resolution="FIXED"
-    checksum="123456789"
-    reporter="emmerik"
-    author_login="morgan"
-    assignee="karadoc"
-    issue_attributes="JIRA=FOO-1234"
-    tags="[null]"
-    issue_creation_date="1401000000000"
-    issue_update_date="1402000000000"
-    issue_close_date="1403000000000"
-    created_at="1400000000000"
-    updated_at="1500000000000"
-    action_plan_key="current_sprint"
-    locations="[null]"
-    issue_type="2"
-    />
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testUpdate-result.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testUpdate-result.xml
deleted file mode 100644 (file)
index 8e2a411..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-  <issues
-    id="100"
-    kee="ABCDE"
-    component_uuid="uuid-123"
-    project_uuid="uuid-101"
-    rule_id="200"
-    severity="BLOCKER"
-    manual_severity="[false]"
-    message="the message"
-    line="500"
-    gap="3.14"
-    effort="10"
-    status="RESOLVED"
-    resolution="FIXED"
-    checksum="123456789"
-    reporter="emmerik"
-    author_login="morgan"
-    assignee="karadoc"
-    issue_attributes="JIRA=FOO-1234"
-    tags="[null]"
-    issue_creation_date="1401000000000"
-    issue_update_date="1402000000000"
-    issue_close_date="1403000000000"
-    created_at="1400000000000"
-    updated_at="1500000000000"
-    action_plan_key="current_sprint"
-    locations="[null]"
-    issue_type="3"
-    />
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testUpdate.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/testUpdate.xml
deleted file mode 100644 (file)
index 6aed4c7..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<dataset>
-  <issues
-    id="100"
-    kee="ABCDE"
-    component_uuid="uuid-123"
-    project_uuid="uuid-100"
-    rule_id="200"
-    severity="INFO"
-    manual_severity="[false]"
-    message="old"
-    line="[null]"
-    gap="[null]"
-    effort="[null]"
-    status="OPEN"
-    resolution="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    author_login="[null]"
-    assignee="[null]"
-    issue_creation_date="1401000000000"
-    issue_update_date="1402000000000"
-    issue_close_date="1403000000000"
-    created_at="1400000000000"
-    updated_at="1500000000000"
-    action_plan_key="[null]"
-    locations="[null]"
-    issue_type="2"
-    />
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/updateBeforeSelectedDate_with_conflict-result.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/updateBeforeSelectedDate_with_conflict-result.xml
deleted file mode 100644 (file)
index 09140f4..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<dataset>
-  <!-- not updated -->
-  <issues
-    id="100"
-    kee="ABCDE"
-    component_uuid="uuid-123"
-    project_uuid="uuid-100"
-    rule_id="200"
-    severity="INFO"
-    manual_severity="[false]"
-    message="old"
-    line="[null]"
-    gap="[null]"
-    effort="[null]"
-    status="OPEN"
-    resolution="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    author_login="[null]"
-    assignee="[null]"
-    issue_attributes="[null]"
-    tags="[null]"
-    issue_creation_date="[null]"
-    issue_update_date="[null]"
-    issue_close_date="[null]"
-    created_at="1400000000000"
-    updated_at="1450000000000"
-    action_plan_key="[null]"
-    locations="[null]"
-    issue_type="[null]"
-    />
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/updateBeforeSelectedDate_with_conflict.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueMapperTest/updateBeforeSelectedDate_with_conflict.xml
deleted file mode 100644 (file)
index bd808bd..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<dataset>
-  <issues
-    id="100"
-    kee="ABCDE"
-    component_uuid="uuid-123"
-    project_uuid="uuid-100"
-    rule_id="200"
-    severity="INFO"
-    manual_severity="[false]"
-    message="old"
-    line="[null]"
-    gap="[null]"
-    effort="[null]"
-    status="OPEN"
-    resolution="[null]"
-    checksum="[null]"
-    reporter="[null]"
-    author_login="[null]"
-    assignee="[null]"
-    issue_attributes="[null]"
-    issue_creation_date="[null]"
-    issue_update_date="[null]"
-    issue_close_date="[null]"
-    created_at="1400000000000"
-    updated_at="1450000000000"
-    action_plan_key="[null]"
-    locations="[null]"
-    issue_type="[null]"
-    />
-</dataset>