*/
package org.sonar.server.component.ws;
+import com.google.common.base.Function;
import com.google.common.collect.Collections2;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.core.util.NonNullInputFunction;
-
import java.util.Arrays;
import java.util.Collection;
+import javax.annotation.Nonnull;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
public class LanguageParamUtils {
}
public static Collection<String> getLanguageKeys(Languages languages) {
- return Collections2.transform(Arrays.asList(languages.all()), new NonNullInputFunction<Language, String>() {
- @Override
- public String doApply(Language input) {
- return input.getKey();
- }
- });
+ return Collections2.transform(Arrays.asList(languages.all()), LanguageToKeyFunction.INSTANCE);
+ }
+
+ private enum LanguageToKeyFunction implements Function<Language, java.lang.String> {
+ INSTANCE;
+
+ @Override
+ public String apply(@Nonnull Language input) {
+ return input.getKey();
+ }
}
}
import org.sonar.api.server.ws.WebService;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.measure.custom.CustomMeasureDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.user.UserSession;
public class DeleteAction implements CustomMeasuresWsAction {
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.db.DbClient;
import org.sonar.server.metric.ws.MetricJsonWriter;
import org.sonar.server.user.UserSession;
DbSession dbSession = dbClient.openSession(false);
try {
- ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
+ ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY),
+ PROJECT_ID_AND_KEY);
checkPermissions(userSession, project);
List<MetricDto> metrics = searchMetrics(dbSession, project);
import org.sonar.api.user.User;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.user.UserSession;
import org.sonar.server.user.index.UserIndex;
this.resourceTypes = resourceTypes;
}
- @CheckForNull
ComponentTreeData load(ComponentTreeWsRequest wsRequest) {
DbSession dbSession = dbClient.openSession(false);
try {
private List<MetricDto> searchMetrics(DbSession dbSession, ComponentTreeWsRequest request) {
List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, request.getMetricKeys());
if (metrics.size() < request.getMetricKeys().size()) {
- List<String> foundMetricKeys = Lists.transform(metrics, new Function<MetricDto, String>() {
- @Override
- public String apply(@Nonnull MetricDto input) {
- return input.getKey();
- }
- });
+ List<String> foundMetricKeys = Lists.transform(metrics, MetricDtoFunctions.toKey());
Set<String> missingMetricKeys = Sets.difference(
new LinkedHashSet<>(request.getMetricKeys()),
new LinkedHashSet<>(foundMetricKeys));
static List<ComponentDtoWithSnapshotId> sortComponents(List<ComponentDtoWithSnapshotId> components, ComponentTreeWsRequest wsRequest, List<MetricDto> metrics,
Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric) {
+ List<String> sortParameters = wsRequest.getSort();
+ if (sortParameters == null || sortParameters.isEmpty()) {
+ return components;
+ }
boolean isAscending = wsRequest.getAsc();
Map<String, Ordering<ComponentDtoWithSnapshotId>> orderingsBySortField = ImmutableMap.<String, Ordering<ComponentDtoWithSnapshotId>>builder()
.put(NAME_SORT, componentNameOrdering(isAscending))
.put(METRIC_SORT, metricOrdering(wsRequest, metrics, measuresByComponentUuidAndMetric))
.build();
- List<String> sortParameters = wsRequest.getSort();
String firstSortParameter = sortParameters.get(0);
Ordering<ComponentDtoWithSnapshotId> primaryOrdering = orderingsBySortField.get(firstSortParameter);
if (sortParameters.size() > 1) {
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.WsMeasures;
-import static org.sonar.server.measure.ws.MeasureValueFormatter.formatDoubleValue;
+import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
import static org.sonar.server.measure.ws.MeasureValueFormatter.formatMeasureValue;
class MeasureDtoToWsMeasure {
measure.setValue(formatMeasureValue(measureDto, metricDto));
}
if (measureDto.getVariation(1) != null) {
- measure.setVariationValueP1(formatDoubleValue(measureDto.getVariation(1), metricDto));
+ measure.setVariationValueP1(formatNumericalValue(measureDto.getVariation(1), metricDto));
}
if (measureDto.getVariation(2) != null) {
- measure.setVariationValueP2(formatDoubleValue(measureDto.getVariation(2), metricDto));
+ measure.setVariationValueP2(formatNumericalValue(measureDto.getVariation(2), metricDto));
}
if (measureDto.getVariation(3) != null) {
- measure.setVariationValueP3(formatDoubleValue(measureDto.getVariation(3), metricDto));
+ measure.setVariationValueP3(formatNumericalValue(measureDto.getVariation(3), metricDto));
}
if (measureDto.getVariation(4) != null) {
- measure.setVariationValueP4(formatDoubleValue(measureDto.getVariation(4), metricDto));
+ measure.setVariationValueP4(formatNumericalValue(measureDto.getVariation(4), metricDto));
}
if (measureDto.getVariation(5) != null) {
- measure.setVariationValueP5(formatDoubleValue(measureDto.getVariation(5), metricDto));
+ measure.setVariationValueP5(formatNumericalValue(measureDto.getVariation(5), metricDto));
}
return measure.build();
}
}
- static String formatDoubleValue(Double value, MetricDto metric) {
+ static String formatNumericalValue(Double value, MetricDto metric) {
Metric.ValueType metricType = Metric.ValueType.valueOf(metric.getValueType());
switch (metricType) {
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.Common.Metric;
-import static org.sonar.server.measure.ws.MeasureValueFormatter.formatDoubleValue;
+import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
class MetricDtoToWsMetric {
private MetricDtoToWsMetric() {
metric.setDecimalScale(metricDto.getDecimalScale());
}
if (metricDto.getBestValue() != null) {
- metric.setBestValue(formatDoubleValue(metricDto.getBestValue(), metricDto));
+ metric.setBestValue(formatNumericalValue(metricDto.getBestValue(), metricDto));
}
if (metricDto.getWorstValue() != null) {
- metric.setWorstValue(formatDoubleValue(metricDto.getWorstValue(), metricDto));
+ metric.setWorstValue(formatNumericalValue(metricDto.getWorstValue(), metricDto));
}
return metric.build();
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.ruby.RubyBridge;
import org.sonar.server.user.UserSession;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.ruby.RubyBridge;
import org.sonar.server.user.UserSession;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.SearchOptions;
import static com.google.common.collect.Sets.newHashSet;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.ruby.RubyBridge;
import org.sonar.server.user.UserSession;
*/
package org.sonar.server.measure.custom.ws;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
-import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.custom.CustomMeasureDao;
-import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.component.ComponentTesting;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
public static final String ACTION = "delete";
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
+
WsTester ws;
- DbClient dbClient;
- DbSession dbSession;
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new CustomMeasureDao(), new ComponentDao());
- dbSession = dbClient.openSession(false);
ws = new WsTester(new CustomMeasuresWs(new DeleteAction(dbClient, userSessionRule)));
userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- db.truncateTables();
- }
-
- @After
- public void tearDown() {
- dbSession.close();
}
@Test
*/
package org.sonar.server.measure.custom.ws;
-import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.component.ComponentFinder;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.db.measure.custom.CustomMeasureDao;
-import org.sonar.db.metric.MetricDao;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.index.UserDoc;
import org.sonar.server.user.index.UserIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto;
+import static org.sonar.db.metric.MetricTesting.newMetricDto;
import static org.sonar.server.measure.custom.ws.CustomMeasuresWs.ENDPOINT;
import static org.sonar.server.measure.custom.ws.MetricsAction.ACTION;
-import static org.sonar.db.metric.MetricTesting.newMetricDto;
@Category(DbTests.class)
public class MetricsActionTest {
private static final String DEFAULT_PROJECT_UUID = "project-uuid";
private static final String DEFAULT_PROJECT_KEY = "project-key";
+ @ClassRule
+ public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
@Rule
public ExpectedException expectedException = ExpectedException.none();
-
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
-
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
-
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
- DbClient dbClient;
- DbSession dbSession;
WsTester ws;
ComponentDto defaultProject;
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao(), new ComponentDao(), new CustomMeasureDao());
- dbSession = dbClient.openSession(false);
- db.truncateTables();
ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, new ComponentFinder(dbClient))));
userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
defaultProject = insertDefaultProject();
}
- @After
- public void tearDown() {
- dbSession.close();
- }
-
@Test
public void list_metrics() throws Exception {
insertCustomMetric("metric-key-1");
*/
package org.sonar.server.measure.custom.ws;
-import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
-import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.custom.CustomMeasureDao;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.measure.custom.CustomMeasureDto;
-import org.sonar.db.metric.MetricDao;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.MetricTesting;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.ServerException;
public DbTester db = DbTester.create(System2.INSTANCE);
@ClassRule
public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
- DbClient dbClient;
- DbSession dbSession;
- System2 system;
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
+ System2 system = mock(System2.class);
WsTester ws;
@BeforeClass
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new CustomMeasureDao(), new ComponentDao(), new MetricDao());
- dbSession = dbClient.openSession(false);
- db.truncateTables();
- system = mock(System2.class);
CustomMeasureValidator validator = new CustomMeasureValidator(newFullTypeValidations());
+
ws = new WsTester(new CustomMeasuresWs(new UpdateAction(dbClient, userSessionRule, system, validator, new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule)),
new UserIndex(es.client()))));
userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
- @After
- public void tearDown() {
- dbSession.close();
- }
-
@Test
public void update_text_value_and_description_in_db() throws Exception {
MetricDto metric = insertNewMetric(ValueType.STRING);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.measure.ws;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.measures.Metric;
+import org.sonar.db.measure.MeasureDto;
+import org.sonar.db.metric.MetricDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.measures.Metric.ValueType.BOOL;
+import static org.sonar.api.measures.Metric.ValueType.DATA;
+import static org.sonar.api.measures.Metric.ValueType.FLOAT;
+import static org.sonar.api.measures.Metric.ValueType.INT;
+import static org.sonar.api.measures.Metric.ValueType.MILLISEC;
+import static org.sonar.api.measures.Metric.ValueType.PERCENT;
+import static org.sonar.api.measures.Metric.ValueType.WORK_DUR;
+import static org.sonar.db.metric.MetricTesting.newMetricDto;
+import static org.sonar.server.measure.ws.MeasureValueFormatter.formatMeasureValue;
+import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
+
+public class MeasureValueFormatterTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void test_formatNumericalValue() {
+ assertThat(formatNumericalValue(-1.0d, newMetric(BOOL))).isEqualTo("false");
+ assertThat(formatNumericalValue(1.0d, newMetric(BOOL))).isEqualTo("true");
+ assertThat(formatNumericalValue(1_000.123d, newMetric(FLOAT))).isEqualTo("1000.123");
+ assertThat(formatNumericalValue(1_000.0d, newMetric(INT))).isEqualTo("1000");
+ assertThat(formatNumericalValue(1_000.0d, newMetric(WORK_DUR))).isEqualTo("1000");
+ }
+
+ @Test
+ public void test_formatMeasureValue() {
+ assertThat(formatMeasureValue(newNumericMeasure(-1.0d), newMetric(BOOL))).isEqualTo("false");
+ assertThat(formatMeasureValue(newNumericMeasure(1.0d), newMetric(BOOL))).isEqualTo("true");
+ assertThat(formatMeasureValue(newNumericMeasure(1000.123d), newMetric(PERCENT))).isEqualTo("1000.123");
+ assertThat(formatMeasureValue(newNumericMeasure(1000d), newMetric(MILLISEC))).isEqualTo("1000");
+ assertThat(formatMeasureValue(newNumericMeasure(1000.0d), newMetric(WORK_DUR))).isEqualTo("1000");
+ assertThat(formatMeasureValue(newTextMeasure("text-value"), newMetric(DATA))).isEqualTo("text-value");
+ }
+
+ @Test
+ public void fail_if_text_value_type_for_numeric_formatter() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Unsupported metric type 'DATA' for numerical value");
+
+ formatNumericalValue(42.0d, newMetric(DATA));
+ }
+
+ private static MetricDto newMetric(Metric.ValueType valueType) {
+ return newMetricDto().setValueType(valueType.name());
+ }
+
+ private static MeasureDto newNumericMeasure(Double value) {
+ return new MeasureDto().setValue(value);
+ }
+
+ private static MeasureDto newTextMeasure(String data) {
+ return new MeasureDto().setData(data);
+ }
+}
*/
package org.sonar.server.metric.ws;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.measure.custom.CustomMeasureTesting;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.MetricTesting;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.ServerException;
-import org.sonar.db.measure.custom.CustomMeasureDao;
-import org.sonar.db.measure.custom.CustomMeasureTesting;
-import org.sonar.db.metric.MetricDao;
import org.sonar.server.ruby.RubyBridge;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
private static final String DEFAULT_DESCRIPTION = "custom-metric-description";
private static final String DEFAULT_TYPE = ValueType.INT.name();
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
+
WsTester ws;
- DbClient dbClient;
- DbSession dbSession;
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao(), new CustomMeasureDao());
- dbSession = dbClient.openSession(false);
- db.truncateTables();
-
ws = new WsTester(new MetricsWs(new CreateAction(dbClient, userSessionRule, mock(RubyBridge.class, RETURNS_DEEP_STUBS))));
userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
- @After
- public void tearDown() {
- dbSession.close();
- }
-
@Test
public void insert_new_minimalist_metric() throws Exception {
newRequest()
import java.util.Arrays;
import java.util.List;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.measure.custom.CustomMeasureDto;
-import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.db.measure.custom.CustomMeasureDao;
import org.sonar.db.measure.custom.CustomMeasureTesting;
import org.sonar.db.metric.MetricDao;
+import org.sonar.db.metric.MetricDto;
+import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.ruby.RubyBridge;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@Category(DbTests.class)
public class DeleteActionTest {
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = ExpectedException.none();
- DbClient dbClient;
- DbSession dbSession;
- WsTester ws;
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
MetricDao metricDao;
+ WsTester ws;
+
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao(), new CustomMeasureDao());
- dbSession = dbClient.openSession(false);
- db.truncateTables();
userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
ws = new WsTester(new MetricsWs(new DeleteAction(dbClient, userSessionRule, mock(RubyBridge.class, RETURNS_DEEP_STUBS))));
metricDao = dbClient.metricDao();
}
- @After
- public void tearDown() {
- dbSession.close();
- }
-
@Test
public void delete_by_keys() throws Exception {
insertCustomEnabledMetrics(1, 2, 3);
package org.sonar.server.metric.ws;
import org.apache.commons.lang.StringUtils;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
-import org.sonar.db.metric.MetricDao;
import org.sonar.server.ws.WsTester;
import org.sonar.test.DbTests;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- DbClient dbClient;
- DbSession dbSession;
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
WsTester ws;
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao());
- dbSession = dbClient.openSession(false);
ws = new WsTester(new MetricsWs(new SearchAction(dbClient)));
- db.truncateTables();
- }
-
- @After
- public void tearDown() {
- dbSession.close();
}
@Test
*/
package org.sonar.server.metric.ws;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.metric.MetricDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.ServerException;
-import org.sonar.db.measure.custom.CustomMeasureDao;
-import org.sonar.db.metric.MetricDao;
import org.sonar.server.ruby.RubyBridge;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
private static final String DEFAULT_DESCRIPTION = "custom-metric-description";
private static final String DEFAULT_TYPE = ValueType.INT.name();
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
+
WsTester ws;
- DbClient dbClient;
- DbSession dbSession;
@Before
public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao(), new CustomMeasureDao());
- dbSession = dbClient.openSession(false);
- db.truncateTables();
-
ws = new WsTester(new MetricsWs(new UpdateAction(dbClient, userSessionRule, mock(RubyBridge.class, RETURNS_DEEP_STUBS))));
userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
- @After
- public void tearDown() {
- dbSession.close();
- }
-
@Test
public void update_all_fields() throws Exception {
int id = insertMetric(newDefaultMetric());
*/
package org.sonarqube.ws.client.issue;
-import com.google.common.base.Joiner;
import org.sonarqube.ws.Issues.SearchWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.TAGS;
public class IssuesService extends BaseService {
- private static final Joiner LIST_TO_PARAMS_STRING = Joiner.on(",").skipNulls();
public IssuesService(WsConnector wsConnector) {
super(wsConnector, "api/issues");