import org.sonar.core.qualityprofile.db.QualityProfileKey;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
+import org.sonar.server.activity.ActivityService;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.log.ActivityService;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.rule.Rule;
import org.sonar.server.rule.index.RuleIndex;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log;
-
-
-import com.google.common.collect.ImmutableMap;
-import org.elasticsearch.common.collect.Iterables;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.core.log.Log;
-import org.sonar.core.log.Loggable;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.log.db.LogDao;
-import org.sonar.server.log.index.LogIndex;
-import org.sonar.server.log.index.LogQuery;
-import org.sonar.server.search.QueryOptions;
-import org.sonar.server.tester.ServerTester;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LogBackendMediumTest {
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- LogService service = tester.get(LogService.class);
- LogDao dao = tester.get(LogDao.class);
- LogIndex index = tester.get(LogIndex.class);
- DbClient db;
- DbSession dbSession;
-
- @Before
- public void before() {
- tester.clearDbAndIndexes();
- db = tester.get(DbClient.class);
- dbSession = tester.get(DbClient.class).openSession(false);
- }
-
- @After
- public void after() {
- dbSession.close();
- }
-
- @Test
- public void insert_find_text_log() throws InterruptedException {
- final String testValue = "hello world";
- service.write(dbSession, Log.Type.ACTIVE_RULE, testValue);
- dbSession.commit();
- assertThat(index.findAll().getTotal()).isEqualTo(1);
-
- Log log = Iterables.getFirst(index.findAll().getHits(), null);
- assertThat(log).isNotNull();
- assertThat(log.message()).isEqualTo(testValue);
- }
-
- @Test
- public void insert_find_loggable_log() {
- final String testKey = "message";
- final String testValue = "hello world";
- service.write(dbSession, Log.Type.ACTIVE_RULE, new Loggable() {
-
- @Override
- public Map<String, String> getDetails() {
- return ImmutableMap.of(testKey, testValue);
- }
-
- @Override
- public int getExecutionTime() {
- return 12;
- }
- });
- dbSession.commit();
-
- assertThat(index.findAll().getTotal()).isEqualTo(1);
-
- Log log = Iterables.getFirst(index.findAll().getHits(), null);
- assertThat(log).isNotNull();
- assertThat(log.details().get(testKey)).isEqualTo(testValue);
- assertThat(log.executionTime()).isEqualTo(12);
- }
-
- @Test
- public void massive_insert() {
-
- // 0 Assert no logs in DB
- assertThat(dao.findAll(dbSession)).hasSize(0);
- int max = 200;
- final String testValue = "hello world";
- for (int i = 0; i < max; i++) {
- service.write(dbSession, Log.Type.ACTIVE_RULE, testValue + "_" + i);
- }
- dbSession.commit();
-
- // 1. assert both backends have all logs
- assertThat(dao.findAll(dbSession)).hasSize(max);
- assertThat(index.findAll().getHits()).hasSize(max);
-
- // 2. assert scrollable
- int count = 0;
- Iterator<Log> logs = index.search(new LogQuery(), new QueryOptions().setScroll(true)).scroll();
- while (logs.hasNext()) {
- logs.next();
- count++;
- }
- assertThat(count).isEqualTo(max);
-
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log;
-
-import org.elasticsearch.common.collect.Iterables;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.sonar.core.log.Log;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.log.db.LogDao;
-import org.sonar.server.log.index.LogIndex;
-import org.sonar.server.log.index.LogQuery;
-import org.sonar.server.search.QueryOptions;
-import org.sonar.server.search.Result;
-import org.sonar.server.tester.ServerTester;
-
-import java.util.Iterator;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LogServiceMediumTest {
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- LogService service = tester.get(LogService.class);
- LogDao dao = tester.get(LogDao.class);
- LogIndex index = tester.get(LogIndex.class);
- DbClient db;
- DbSession dbSession;
-
- @Before
- public void before() {
- tester.clearDbAndIndexes();
- db = tester.get(DbClient.class);
- dbSession = tester.get(DbClient.class).openSession(false);
- }
-
- @After
- public void after() {
- dbSession.close();
- }
-
- @Test
- public void find_all() throws InterruptedException {
- final String testValue = "hello world";
- service.write(dbSession, Log.Type.ACTIVE_RULE, testValue);
- dbSession.commit();
- assertThat(index.findAll().getTotal()).isEqualTo(1);
-
- Log log = Iterables.getFirst(index.findAll().getHits(), null);
- assertThat(log).isNotNull();
- assertThat(log.message()).isEqualTo(testValue);
- }
-
- @Test
- public void search_all() throws InterruptedException {
- final String testValue = "hello world";
- service.write(dbSession, Log.Type.ACTIVE_RULE, testValue);
- dbSession.commit();
- assertThat(index.findAll().getTotal()).isEqualTo(1);
-
- Result<Log> result = index.search(new LogQuery(), new QueryOptions());
- assertThat(result.getTotal()).isEqualTo(1L);
- }
-
- @Test
- @Ignore
- // TODO fix missing logs in ES.
- public void iterate_all() throws InterruptedException {
- int max = QueryOptions.DEFAULT_LIMIT + 3;
- final String testValue = "hello world";
- for (int i = 0; i < max; i++) {
- service.write(dbSession, Log.Type.ACTIVE_RULE, testValue + "_" + i);
- }
- dbSession.commit();
-
- // 0. assert Base case
- assertThat(dao.findAll(dbSession)).hasSize(max);
-
- Result<Log> result = index.search(new LogQuery(), new QueryOptions().setScroll(true));
- assertThat(result.getTotal()).isEqualTo(max);
- assertThat(result.getHits()).hasSize(0);
- int count = 0;
- Iterator<Log> logIterator = result.scroll();
- while (logIterator.hasNext()) {
- count++;
- logIterator.next();
- }
- assertThat(count).isEqualTo(max);
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log.db;
-
-
-import com.google.common.collect.ImmutableMap;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.api.utils.System2;
-import org.sonar.core.log.Log;
-import org.sonar.core.log.Loggable;
-import org.sonar.core.log.db.LogDto;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.persistence.DbSession;
-
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class LogDaoTest extends AbstractDaoTestCase {
-
-
- private LogDao dao;
- private DbSession session;
- private System2 system2;
-
- @Before
- public void before() throws Exception {
- this.session = getMyBatis().openSession(false);
- this.system2 = mock(System2.class);
- this.dao = new LogDao(system2);
- }
-
- @After
- public void after() {
- session.close();
- }
-
- @Test
- public void fail_insert_missing_type() {
- String testValue = "hello world";
- LogDto log = LogDto.createFor(testValue);
- try {
- dao.insert(session, log);
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage()).isEqualTo("Type must be set");
- }
- }
-
- @Test
- public void fail_insert_missing_author() {
- String testValue = "hello world";
- LogDto log = LogDto.createFor(testValue)
- .setType(Log.Type.ACTIVE_RULE);
- try {
- dao.insert(session, log);
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage()).isEqualTo("Type must be set");
- }
- }
-
- @Test
- public void insert_text_log() {
- String testValue = "hello world";
- LogDto log = LogDto.createFor(testValue)
- .setType(Log.Type.ACTIVE_RULE)
- .setAuthor("jUnit");
- dao.insert(session, log);
-
- assertThat(dao.findAll(session)).hasSize(1);
- LogDto newDto = dao.getByKey(session, log.getKey());
- assertThat(newDto.getAuthor()).isEqualTo(log.getAuthor());
- assertThat(newDto.getMessage()).isEqualTo(testValue);
- }
-
- @Test
- public void insert_loggable_log() {
- final String testKey = "message";
- final String testValue = "hello world";
- LogDto log = LogDto.createFor(new Loggable() {
-
- @Override
- public Map<String, String> getDetails() {
- return ImmutableMap.of(testKey, testValue);
- }
-
- @Override
- public int getExecutionTime() {
- return 12;
- }
- })
- .setAuthor("jUnit")
- .setType(Log.Type.ACTIVE_RULE);
-
- dao.insert(session, log);
-
- assertThat(dao.findAll(session)).hasSize(1);
- LogDto newDto = dao.getByKey(session, log.getKey());
- assertThat(newDto.getAuthor()).isEqualTo(log.getAuthor());
- assertThat(newDto.getExecutionTime()).isEqualTo(12);
- assertThat(newDto.getData()).isNotNull();
- Map<String, String> details = KeyValueFormat.parse(newDto.getData());
- assertThat(details.get(testKey)).isEqualTo(testValue);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log.ws;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.core.log.Log;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.log.LogService;
-import org.sonar.server.tester.ServerTester;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.ws.WsTester;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LogsWebServiceMediumTest {
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- private LogsWebService ws;
- private LogService service;
- private DbSession session;
-
-
- @Before
- public void setUp() throws Exception {
- tester.clearDbAndIndexes();
- ws = tester.get(LogsWebService.class);
- service = tester.get(LogService.class);
- session = tester.get(DbClient.class).openSession(false);
- }
-
- @After
- public void after() {
- session.close();
- }
-
- @Test
- public void define() throws Exception {
- WebService.Context context = new WebService.Context();
- ws.define(context);
-
- WebService.Controller controller = context.controller(LogsWebService.API_ENDPOINT);
-
- assertThat(controller).isNotNull();
- assertThat(controller.actions()).hasSize(1);
- assertThat(controller.action(SearchAction.SEARCH_ACTION)).isNotNull();
- }
-
- @Test
- public void search_logs() throws Exception {
- service.write(session, Log.Type.ACTIVE_RULE, "Hello World");
- session.commit();
-
- MockUserSession.set();
-
- // 1. List single Text log
- WsTester.TestRequest request = tester.wsTester().newGetRequest(LogsWebService.API_ENDPOINT, SearchAction.SEARCH_ACTION);
- WsTester.Result result = request.execute();
- System.out.println("result = " + result.outputAsString());
- }
-
-
-}
package org.sonar.server.qualityprofile;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multimap;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
}
@Test
- public void count_all_by_index_field() {
+ public void count_all_by_index_field() {
QualityProfileDto profileDto1 = QualityProfileDto.createFor("p1", "java");
QualityProfileDto profileDto2 = QualityProfileDto.createFor("p2", "java");
db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);
ActiveRuleDto.createFor(profileDto2, ruleDto2)
.setInheritance(ActiveRule.Inheritance.INHERITED.name())
.setSeverity(Severity.BLOCKER)
- );
+ );
dbSession.commit();
// 0. Test base case
assertThat(index.countAll()).isEqualTo(4);
// 1. Assert by term aggregation;
- Collection<FacetValue> stats = index.getStatsByProfileKey(
+ Map<QualityProfileKey, Multimap<String, FacetValue>> stats = index.getStatsByProfileKey(
ImmutableList.of(profileDto1.getKey(),
profileDto2.getKey()));
dbSession.commit();
- Multimap<QualityProfileKey, FacetValue> stats = service.getAllProfileStats();
+ Map<QualityProfileKey, Multimap<String, FacetValue>> stats = service.getAllProfileStats();
assertThat(stats.size()).isEqualTo(2);
assertThat(stats.get(XOO_PROFILE_1).size()).isEqualTo(1);
}