2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.activity.index;
22 import org.apache.commons.dbutils.DbUtils;
23 import org.assertj.core.data.MapEntry;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.ClassRule;
27 import org.junit.Test;
28 import org.junit.experimental.categories.Category;
29 import org.sonar.api.utils.DateUtils;
30 import org.sonar.core.persistence.DbTester;
31 import org.sonar.server.db.DbClient;
32 import org.sonar.test.DbTests;
34 import java.sql.Connection;
36 import static org.assertj.core.api.Assertions.assertThat;
38 @Category(DbTests.class)
39 public class ActivityResultSetIteratorTest {
42 public static DbTester dbTester = new DbTester();
45 Connection connection;
48 public void setUp() throws Exception {
49 dbTester.truncateTables();
50 client = new DbClient(dbTester.database(), dbTester.myBatis());
51 connection = dbTester.openConnection();
55 public void tearDown() throws Exception {
56 DbUtils.closeQuietly(connection);
60 public void traverse() throws Exception {
61 dbTester.prepareDbUnit(getClass(), "traverse.xml");
62 ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, 0L);
63 assertThat(it.hasNext()).isTrue();
64 ActivityDoc doc = it.next();
65 assertThat(doc).isNotNull();
66 assertThat(doc.getKey()).isEqualTo("UUID1");
67 assertThat(doc.getAction()).isEqualTo("THE_ACTION");
68 assertThat(doc.getMessage()).isEqualTo("THE_MSG");
69 assertThat(doc.getDetails()).containsOnly(MapEntry.entry("foo", "bar"));
70 assertThat(doc.getLogin()).isEqualTo("THE_AUTHOR");
72 assertThat(it.hasNext()).isTrue();
73 assertThat(it.next()).isNotNull();
74 assertThat(it.hasNext()).isFalse();
79 public void traverse_after_date() throws Exception {
80 dbTester.prepareDbUnit(getClass(), "traverse.xml");
81 ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, DateUtils.parseDate("2014-12-01").getTime());
83 assertThat(it.hasNext()).isTrue();
84 ActivityDoc doc = it.next();
85 assertThat(doc).isNotNull();
86 assertThat(doc.getKey()).isEqualTo("UUID2");
88 assertThat(it.hasNext()).isFalse();