diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-05 21:54:22 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-05 21:54:22 +0200 |
commit | b96df0defa1e12f9f679e4c6e8b451bde1a7a566 (patch) | |
tree | 8fcb6c8413b957f3fc0d3ac316842662d6d8aaca /sonar-batch/src/test/java/org/sonar/batch | |
parent | 40ef7ce47f9400d88d351db0bf7e6c8dd7abba68 (diff) | |
download | sonarqube-b96df0defa1e12f9f679e4c6e8b451bde1a7a566.tar.gz sonarqube-b96df0defa1e12f9f679e4c6e8b451bde1a7a566.zip |
SONAR-5381 SONAR-3350 replace mysql MEDIUMTEXT columns by LONGTEXT
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar/batch')
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java | 10 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java | 40 |
2 files changed, 27 insertions, 23 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java index 39f4095ccd2..451fa91f691 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java @@ -25,23 +25,25 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.DuplicatedSourceException; import org.sonar.api.resources.File; import org.sonar.api.resources.Resource; -import org.sonar.jpa.test.AbstractDbUnitTestCase; +import org.sonar.core.persistence.AbstractDaoTestCase; +import org.sonar.core.source.db.SnapshotSourceDao; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class SourcePersisterTest extends AbstractDbUnitTestCase { +public class SourcePersisterTest extends AbstractDaoTestCase { private SourcePersister sourcePersister; @Before public void before() { setupData("shared"); - Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000); ResourcePersister resourcePersister = mock(ResourcePersister.class); + Snapshot snapshot = new Snapshot(); + snapshot.setId(1000); when(resourcePersister.getSnapshotOrFail(any(Resource.class))).thenReturn(snapshot); - sourcePersister = new SourcePersister(getSession(), resourcePersister); + sourcePersister = new SourcePersister(resourcePersister, new SnapshotSourceDao(getMyBatis())); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java index d6cddb4447d..505b644d98e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java @@ -28,7 +28,8 @@ import org.sonar.api.resources.Project; import org.sonar.api.utils.HttpDownloader; import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.bootstrap.ServerClient; -import org.sonar.jpa.test.AbstractDbUnitTestCase; +import org.sonar.core.persistence.TestDatabase; +import org.sonar.core.source.db.SnapshotSourceDao; import java.net.URI; import java.net.URISyntaxException; @@ -36,15 +37,16 @@ import java.net.URISyntaxException; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; -public class LastSnapshotsTest extends AbstractDbUnitTestCase { +public class LastSnapshotsTest { @Rule public ExpectedException thrown = ExpectedException.none(); + + @Rule + public TestDatabase db = new TestDatabase(); + private AnalysisMode mode; @Before @@ -55,10 +57,10 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase { @Test public void should_get_source_of_last_snapshot() { - setupData("last_snapshot"); - ServerClient server = mock(ServerClient.class); + db.prepareDbUnit(getClass(), "last_snapshot.xml"); - LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server); + ServerClient server = mock(ServerClient.class); + LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server); assertThat(lastSnapshots.getSource(newFile())).isEqualTo("this is bar"); verifyZeroInteractions(server); @@ -66,10 +68,10 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase { @Test public void should_return_empty_source_if_no_last_snapshot() { - setupData("no_last_snapshot"); + db.prepareDbUnit(getClass(), "no_last_snapshot.xml"); ServerClient server = mock(ServerClient.class); - LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server); + LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server); assertThat(lastSnapshots.getSource(newFile())).isEqualTo(""); verifyZeroInteractions(server); @@ -77,12 +79,12 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase { @Test public void should_download_source_from_ws_if_preview_mode() { - setupData("last_snapshot"); + db.prepareDbUnit(getClass(), "last_snapshot.xml"); ServerClient server = mock(ServerClient.class); when(server.request(anyString(), eq(false), eq(30 * 1000))).thenReturn("downloaded source of Bar.c"); when(mode.isPreview()).thenReturn(true); - LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server); + LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server); String source = lastSnapshots.getSource(newFile()); assertThat(source).isEqualTo("downloaded source of Bar.c"); @@ -91,12 +93,12 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase { @Test public void should_fail_to_download_source_from_ws() throws URISyntaxException { - setupData("last_snapshot"); + db.prepareDbUnit(getClass(), "last_snapshot.xml"); ServerClient server = mock(ServerClient.class); when(server.request(anyString(), eq(false), eq(30 * 1000))).thenThrow(new HttpDownloader.HttpException(new URI(""), 500)); when(mode.isPreview()).thenReturn(true); - LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server); + LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server); thrown.expect(HttpDownloader.HttpException.class); lastSnapshots.getSource(newFile()); @@ -104,12 +106,12 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase { @Test public void should_return_empty_source_if_preview_mode_and_no_last_snapshot() throws URISyntaxException { - setupData("last_snapshot"); + db.prepareDbUnit(getClass(), "last_snapshot.xml"); ServerClient server = mock(ServerClient.class); when(server.request(anyString(), eq(false), eq(30 * 1000))).thenThrow(new HttpDownloader.HttpException(new URI(""), 404)); when(mode.isPreview()).thenReturn(true); - LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server); + LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server); String source = lastSnapshots.getSource(newFile()); assertThat(source).isEqualTo(""); @@ -118,10 +120,10 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase { @Test public void should_not_load_source_of_non_files() throws URISyntaxException { - setupData("last_snapshot"); + db.prepareDbUnit(getClass(), "last_snapshot.xml"); ServerClient server = mock(ServerClient.class); - LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server); + LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server); String source = lastSnapshots.getSource(new Project("my-project")); assertThat(source).isEqualTo(""); |