]> source.dussan.org Git - sonarqube.git/commitdiff
Improve DuplicationDaoTest
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 1 Nov 2011 17:23:29 +0000 (21:23 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 1 Nov 2011 17:37:45 +0000 (21:37 +0400)
plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java [deleted file]
plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml [deleted file]
plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml [deleted file]
plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml [deleted file]
sonar-core/src/test/java/org/sonar/persistence/dao/DuplicationDaoTest.java
sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldGetByHash.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldInsert-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldInsert.xml [new file with mode: 0644]

diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java
deleted file mode 100644 (file)
index 543adf4..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.cpd.index;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.commons.io.IOUtils;
-import org.dbunit.Assertion;
-import org.dbunit.DataSourceDatabaseTester;
-import org.dbunit.DatabaseUnitException;
-import org.dbunit.IDatabaseTester;
-import org.dbunit.database.IDatabaseConnection;
-import org.dbunit.dataset.*;
-import org.dbunit.dataset.filter.DefaultColumnFilter;
-import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.dbunit.operation.DatabaseOperation;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.Resource;
-import org.sonar.duplications.block.Block;
-import org.sonar.duplications.block.ByteArray;
-import org.sonar.persistence.InMemoryDatabase;
-import org.sonar.persistence.MyBatis;
-import org.sonar.persistence.dao.DuplicationDao;
-
-/**
- * TODO Godin: would be better to split this test on two - one for DAO and one for DbDuplicationsIndex
- */
-public class DbDuplicationsIndexTest {
-
-  private static IDatabaseTester databaseTester;
-  private static InMemoryDatabase database;
-  private static DuplicationDao dao;
-
-  private DbDuplicationsIndex index;
-
-  @Before
-  public void startDatabase() throws Exception {
-    database = new InMemoryDatabase();
-    MyBatis myBatis = new MyBatis(database);
-
-    database.start();
-    myBatis.start();
-
-    dao = new DuplicationDao(myBatis);
-    databaseTester = new DataSourceDatabaseTester(database.getDataSource());
-  }
-
-  @After
-  public void stopDatabase() throws Exception {
-    if (databaseTester != null) {
-      databaseTester.onTearDown();
-    }
-    database.stop();
-  }
-
-  @Test
-  public void shouldGetByHash() throws Exception {
-    Resource resource = new JavaFile("foo");
-    index = spy(new DbDuplicationsIndex(dao, null, 9, 7));
-    doReturn(10).when(index).getSnapshotIdFor(resource);
-    setupData("shouldGetByHash");
-
-    index.prepareCache(resource);
-    Collection<Block> blocks = index.getByHash(new ByteArray("aa"));
-    Iterator<Block> blocksIterator = blocks.iterator();
-
-    assertThat(blocks.size(), is(1));
-
-    Block block = blocksIterator.next();
-    assertThat("block resourceId", block.getResourceId(), is("bar-last"));
-    assertThat("block hash", block.getBlockHash(), is(new ByteArray("aa")));
-    assertThat("block index in file", block.getIndexInFile(), is(0));
-    assertThat("block start line", block.getFirstLineNumber(), is(1));
-    assertThat("block end line", block.getLastLineNumber(), is(2));
-
-    // check null for lastSnapshotId
-    index = spy(new DbDuplicationsIndex(dao, null, 9, null));
-    doReturn(10).when(index).getSnapshotIdFor(resource);
-
-    index.prepareCache(resource);
-  }
-
-  @Test
-  public void shouldInsert() throws Exception {
-    Resource resource = new JavaFile("foo");
-    index = spy(new DbDuplicationsIndex(dao, null, 1, null));
-    doReturn(2).when(index).getSnapshotIdFor(resource);
-    setupData("shouldInsert");
-
-    index.insert(resource, Arrays.asList(new Block("foo", new ByteArray("bb"), 0, 1, 2)));
-
-    checkTables("shouldInsert", "duplications_index");
-  }
-
-  // ============================================================
-  // TODO Godin: a kind of copy-paste from AbstractDbUnitTestCase
-
-  private final void setupData(String... testNames) {
-    InputStream[] streams = new InputStream[testNames.length];
-    try {
-      for (int i = 0; i < testNames.length; i++) {
-        String className = getClass().getName();
-        className = String.format("/%s/%s.xml", className.replace(".", "/"), testNames[i]);
-        streams[i] = getClass().getResourceAsStream(className);
-        if (streams[i] == null) {
-          throw new RuntimeException("Test not found :" + className);
-        }
-      }
-
-      setupData(streams);
-
-    } finally {
-      for (InputStream stream : streams) {
-        IOUtils.closeQuietly(stream);
-      }
-    }
-  }
-
-  private final void setupData(InputStream... dataSetStream) {
-    try {
-      IDataSet[] dataSets = new IDataSet[dataSetStream.length];
-      for (int i = 0; i < dataSetStream.length; i++) {
-        ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(dataSetStream[i]));
-        dataSet.addReplacementObject("[null]", null);
-        dataSets[i] = dataSet;
-      }
-      CompositeDataSet compositeDataSet = new CompositeDataSet(dataSets);
-
-      databaseTester.setDataSet(compositeDataSet);
-      IDatabaseConnection connection = databaseTester.getConnection();
-
-      DatabaseOperation.CLEAN_INSERT.execute(connection, databaseTester.getDataSet());
-
-      connection.getConnection().commit();
-      connection.close();
-    } catch (Exception e) {
-      throw translateException("Could not setup DBUnit data", e);
-    }
-  }
-
-  private final void checkTables(String testName, String... tables) {
-    checkTables(testName, new String[] {}, tables);
-  }
-
-  private final void checkTables(String testName, String[] excludedColumnNames, String... tables) {
-    // getSession().commit();
-    try {
-      IDataSet dataSet = getCurrentDataSet();
-      IDataSet expectedDataSet = getExpectedData(testName);
-      for (String table : tables) {
-        ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
-        Assertion.assertEquals(expectedDataSet.getTable(table), filteredTable);
-      }
-    } catch (DataSetException e) {
-      throw translateException("Error while checking results", e);
-    } catch (DatabaseUnitException e) {
-      fail(e.getMessage());
-    }
-  }
-
-  private final IDataSet getExpectedData(String testName) {
-    String className = getClass().getName();
-    className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName);
-
-    InputStream in = getClass().getResourceAsStream(className);
-    try {
-      return getData(in);
-    } finally {
-      IOUtils.closeQuietly(in);
-    }
-  }
-
-  private final IDataSet getData(InputStream stream) {
-    try {
-      ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
-      dataSet.addReplacementObject("[null]", null);
-      return dataSet;
-    } catch (Exception e) {
-      throw translateException("Could not read the dataset stream", e);
-    }
-  }
-
-  private final IDataSet getCurrentDataSet() {
-    try {
-      IDatabaseConnection connection = databaseTester.getConnection();
-      return connection.createDataSet();
-    } catch (Exception e) {
-      throw translateException("Could not create the current dataset", e);
-    }
-  }
-
-  private static RuntimeException translateException(String msg, Exception cause) {
-    RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
-    runtimeException.setStackTrace(cause.getStackTrace());
-    return runtimeException;
-  }
-}
diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml
deleted file mode 100644 (file)
index 8edbe99..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<dataset>
-
-  <snapshots id="1" status="P" islast="0" project_id="0" />
-  <snapshots id="2" status="P" islast="0" project_id="1" />
-  <projects id="1" kee="bar-old" enabled="1" scope="FIL" qualifier="CLA" />
-
-  <snapshots id="3" status="P" islast="1" project_id="2" />
-  <snapshots id="4" status="P" islast="1" project_id="2" />
-  <projects id="2" kee="bar-last" enabled="1" scope="FIL" qualifier="CLA" />
-
-  <snapshots id="5" status="P" islast="0" project_id="3" />
-  <snapshots id="6" status="P" islast="0" project_id="3" />
-  <projects id="3" kee="foo-old" enabled="1" scope="FIL" qualifier="CLA" />
-
-  <snapshots id="7" status="P" islast="1" project_id="4" />
-  <snapshots id="8" status="P" islast="1" project_id="4" />
-  <projects id="4" kee="foo-last" enabled="1" scope="FIL" qualifier="CLA" />
-
-  <snapshots id="9" status="U" islast="0" project_id="5" />
-  <snapshots id="10" status="U" islast="0" project_id="5" />
-  <projects id="5" kee="foo" enabled="1" scope="FIL" qualifier="CLA" />
-
-  <!-- Old snapshot of another project -->
-  <!-- bar-old -->
-  <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="0" end_line="0" />
-
-  <!-- Last snapshot of another project -->
-  <!-- bar-last -->
-  <duplications_index id="2" project_snapshot_id="3" snapshot_id="4" hash="aa" index_in_file="0" start_line="1" end_line="2" />
-
-  <!-- Old snapshot of current project -->
-  <!-- foo-old -->
-  <duplications_index id="3" project_snapshot_id="5" snapshot_id="6" hash="bb" index_in_file="0" start_line="0" end_line="0" />
-
-  <!-- Last snapshot of current project -->
-  <!-- foo-last -->
-  <duplications_index id="4" project_snapshot_id="7" snapshot_id="8" hash="aa" index_in_file="0" start_line="0" end_line="0" />
-
-  <!-- New snapshot of current project -->
-  <!-- foo -->
-  <duplications_index id="5" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="0" start_line="0" end_line="0" />
-
-  <!-- Note that there is two blocks with same hash for current analysis to verify that we use "SELECT DISTINCT", -->
-  <!-- without "DISTINCT" we will select block from "bar-last" two times. -->
-  <duplications_index id="6" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="1" start_line="1" end_line="1" />
-
-</dataset>
diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml
deleted file mode 100644 (file)
index 619646c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-
-  <snapshots id="1" status="U" islast="0" project_id="0" />
-  <snapshots id="2" status="U" islast="0" project_id="1" />
-  <projects id="1" kee="foo" enabled="1" scope="FIL" qualifier="CLA" />
-
-  <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="1" end_line="2" />
-
-</dataset>
diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml
deleted file mode 100644 (file)
index e0efcf1..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-
-  <snapshots id="1" status="U" islast="0" project_id="0" />
-  <snapshots id="2" status="U" islast="0" project_id="1" />
-  <projects id="1" kee="foo" enabled="1" scope="FIL" qualifier="CLA" />
-
-</dataset>
index 6beea0d47422751b19533abf33119cf53a84b687..0c2126f72bb7fc44958819bf6206f786556909c7 100644 (file)
  */
 package org.sonar.persistence.dao;
 
-import com.google.common.collect.Lists;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.dbunit.Assertion;
 import org.dbunit.DataSourceDatabaseTester;
+import org.dbunit.DatabaseUnitException;
 import org.dbunit.IDatabaseTester;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.dbunit.database.IDatabaseConnection;
+import org.dbunit.dataset.*;
+import org.dbunit.dataset.filter.DefaultColumnFilter;
+import org.dbunit.dataset.xml.FlatXmlDataSet;
+import org.dbunit.operation.DatabaseOperation;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.sonar.persistence.InMemoryDatabase;
 import org.sonar.persistence.MyBatis;
 import org.sonar.persistence.model.DuplicationUnit;
 
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
+import com.google.common.collect.Lists;
 
 public class DuplicationDaoTest {
-  protected static IDatabaseTester databaseTester;
+
+  private static IDatabaseTester databaseTester;
   private static InMemoryDatabase database;
   private static DuplicationDao dao;
 
-  @BeforeClass
-  public static void startDatabase() throws Exception {
+  @Before
+  public void startDatabase() throws Exception {
     database = new InMemoryDatabase();
     MyBatis myBatis = new MyBatis(database);
 
@@ -51,14 +65,42 @@ public class DuplicationDaoTest {
     databaseTester = new DataSourceDatabaseTester(database.getDataSource());
   }
 
-  @AfterClass
-  public static void stopDatabase() throws Exception {
+  @After
+  public void stopDatabase() throws Exception {
     if (databaseTester != null) {
       databaseTester.onTearDown();
     }
     database.stop();
   }
 
+  @Test
+  public void shouldGetByHash() throws Exception {
+    setupData("shouldGetByHash");
+
+    List<DuplicationUnit> blocks = dao.selectCandidates(10, 7);
+    assertThat(blocks.size(), is(1));
+
+    DuplicationUnit block = blocks.get(0);
+    assertThat("block resourceId", block.getResourceKey(), is("bar-last"));
+    assertThat("block hash", block.getHash(), is("aa"));
+    assertThat("block index in file", block.getIndexInFile(), is(0));
+    assertThat("block start line", block.getStartLine(), is(1));
+    assertThat("block end line", block.getEndLine(), is(2));
+
+    // check null for lastSnapshotId
+    blocks = dao.selectCandidates(10, null);
+    assertThat(blocks.size(), is(2));
+  }
+
+  @Test
+  public void shouldInsert() throws Exception {
+    setupData("shouldInsert");
+
+    dao.insert(Arrays.asList(new DuplicationUnit(1, 2, "bb", 0, 1, 2)));
+
+    checkTables("shouldInsert", "duplications_index");
+  }
+
   @Test
   public void testBatchInsert() {
     List<DuplicationUnit> duplications = Lists.newArrayList();
@@ -72,4 +114,107 @@ public class DuplicationDaoTest {
       assertThat(duplication.getId(), nullValue());
     }
   }
+
+  // ============================================================
+  // TODO Godin: a kind of copy-paste from AbstractDbUnitTestCase
+
+  private final void setupData(String... testNames) {
+    InputStream[] streams = new InputStream[testNames.length];
+    try {
+      for (int i = 0; i < testNames.length; i++) {
+        String className = getClass().getName();
+        className = String.format("/%s/%s.xml", className.replace(".", "/"), testNames[i]);
+        streams[i] = getClass().getResourceAsStream(className);
+        if (streams[i] == null) {
+          throw new RuntimeException("Test not found :" + className);
+        }
+      }
+
+      setupData(streams);
+
+    } finally {
+      for (InputStream stream : streams) {
+        IOUtils.closeQuietly(stream);
+      }
+    }
+  }
+
+  private final void setupData(InputStream... dataSetStream) {
+    try {
+      IDataSet[] dataSets = new IDataSet[dataSetStream.length];
+      for (int i = 0; i < dataSetStream.length; i++) {
+        ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(dataSetStream[i]));
+        dataSet.addReplacementObject("[null]", null);
+        dataSets[i] = dataSet;
+      }
+      CompositeDataSet compositeDataSet = new CompositeDataSet(dataSets);
+
+      databaseTester.setDataSet(compositeDataSet);
+      IDatabaseConnection connection = databaseTester.getConnection();
+
+      DatabaseOperation.CLEAN_INSERT.execute(connection, databaseTester.getDataSet());
+
+      connection.getConnection().commit();
+      connection.close();
+    } catch (Exception e) {
+      throw translateException("Could not setup DBUnit data", e);
+    }
+  }
+
+  private final void checkTables(String testName, String... tables) {
+    checkTables(testName, new String[] {}, tables);
+  }
+
+  private final void checkTables(String testName, String[] excludedColumnNames, String... tables) {
+    // getSession().commit();
+    try {
+      IDataSet dataSet = getCurrentDataSet();
+      IDataSet expectedDataSet = getExpectedData(testName);
+      for (String table : tables) {
+        ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
+        Assertion.assertEquals(expectedDataSet.getTable(table), filteredTable);
+      }
+    } catch (DataSetException e) {
+      throw translateException("Error while checking results", e);
+    } catch (DatabaseUnitException e) {
+      fail(e.getMessage());
+    }
+  }
+
+  private final IDataSet getExpectedData(String testName) {
+    String className = getClass().getName();
+    className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName);
+
+    InputStream in = getClass().getResourceAsStream(className);
+    try {
+      return getData(in);
+    } finally {
+      IOUtils.closeQuietly(in);
+    }
+  }
+
+  private final IDataSet getData(InputStream stream) {
+    try {
+      ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
+      dataSet.addReplacementObject("[null]", null);
+      return dataSet;
+    } catch (Exception e) {
+      throw translateException("Could not read the dataset stream", e);
+    }
+  }
+
+  private final IDataSet getCurrentDataSet() {
+    try {
+      IDatabaseConnection connection = databaseTester.getConnection();
+      return connection.createDataSet();
+    } catch (Exception e) {
+      throw translateException("Could not create the current dataset", e);
+    }
+  }
+
+  private static RuntimeException translateException(String msg, Exception cause) {
+    RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
+    runtimeException.setStackTrace(cause.getStackTrace());
+    return runtimeException;
+  }
 }
diff --git a/sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldGetByHash.xml b/sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldGetByHash.xml
new file mode 100644 (file)
index 0000000..8edbe99
--- /dev/null
@@ -0,0 +1,47 @@
+<dataset>
+
+  <snapshots id="1" status="P" islast="0" project_id="0" />
+  <snapshots id="2" status="P" islast="0" project_id="1" />
+  <projects id="1" kee="bar-old" enabled="1" scope="FIL" qualifier="CLA" />
+
+  <snapshots id="3" status="P" islast="1" project_id="2" />
+  <snapshots id="4" status="P" islast="1" project_id="2" />
+  <projects id="2" kee="bar-last" enabled="1" scope="FIL" qualifier="CLA" />
+
+  <snapshots id="5" status="P" islast="0" project_id="3" />
+  <snapshots id="6" status="P" islast="0" project_id="3" />
+  <projects id="3" kee="foo-old" enabled="1" scope="FIL" qualifier="CLA" />
+
+  <snapshots id="7" status="P" islast="1" project_id="4" />
+  <snapshots id="8" status="P" islast="1" project_id="4" />
+  <projects id="4" kee="foo-last" enabled="1" scope="FIL" qualifier="CLA" />
+
+  <snapshots id="9" status="U" islast="0" project_id="5" />
+  <snapshots id="10" status="U" islast="0" project_id="5" />
+  <projects id="5" kee="foo" enabled="1" scope="FIL" qualifier="CLA" />
+
+  <!-- Old snapshot of another project -->
+  <!-- bar-old -->
+  <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+
+  <!-- Last snapshot of another project -->
+  <!-- bar-last -->
+  <duplications_index id="2" project_snapshot_id="3" snapshot_id="4" hash="aa" index_in_file="0" start_line="1" end_line="2" />
+
+  <!-- Old snapshot of current project -->
+  <!-- foo-old -->
+  <duplications_index id="3" project_snapshot_id="5" snapshot_id="6" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+
+  <!-- Last snapshot of current project -->
+  <!-- foo-last -->
+  <duplications_index id="4" project_snapshot_id="7" snapshot_id="8" hash="aa" index_in_file="0" start_line="0" end_line="0" />
+
+  <!-- New snapshot of current project -->
+  <!-- foo -->
+  <duplications_index id="5" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="0" start_line="0" end_line="0" />
+
+  <!-- Note that there is two blocks with same hash for current analysis to verify that we use "SELECT DISTINCT", -->
+  <!-- without "DISTINCT" we will select block from "bar-last" two times. -->
+  <duplications_index id="6" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="1" start_line="1" end_line="1" />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldInsert-result.xml
new file mode 100644 (file)
index 0000000..619646c
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+
+  <snapshots id="1" status="U" islast="0" project_id="0" />
+  <snapshots id="2" status="U" islast="0" project_id="1" />
+  <projects id="1" kee="foo" enabled="1" scope="FIL" qualifier="CLA" />
+
+  <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="1" end_line="2" />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldInsert.xml b/sonar-core/src/test/resources/org/sonar/persistence/dao/DuplicationDaoTest/shouldInsert.xml
new file mode 100644 (file)
index 0000000..e0efcf1
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <snapshots id="1" status="U" islast="0" project_id="0" />
+  <snapshots id="2" status="U" islast="0" project_id="1" />
+  <projects id="1" kee="foo" enabled="1" scope="FIL" qualifier="CLA" />
+
+</dataset>