import org.sonar.core.issue.db.IssueDto;
import java.util.Collection;
-import java.util.HashSet;
import java.util.IdentityHashMap;
+import java.util.Set;
class IssueTrackingResult {
- private final HashSet<IssueDto> unmatched = Sets.newHashSet();
+ private final Set<IssueDto> unmatched = Sets.newHashSet();
private final Multimap<RuleKey, IssueDto> unmatchedByRule = LinkedHashMultimap.create();
private final IdentityHashMap<DefaultIssue, IssueDto> matched = Maps.newIdentityHashMap();
@DryRunIncompatible
public class ApplyProjectRolesDecorator implements Decorator {
+ private static final Set<String> QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.SUBVIEW);
private final ResourcePermissions resourcePermissions;
- private final Set<String> QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.SUBVIEW);
public ApplyProjectRolesDecorator(ResourcePermissions resourcePermissions) {
this.resourcePermissions = resourcePermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-import org.sonar.api.Properties;
-import org.sonar.api.Property;
-import org.sonar.api.PropertyType;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.TimeUtils;
}
private PurgeConfiguration newConf(long resourceId) {
- String[] scopes = new String[] {Scopes.FILE};
+ String[] scopes = new String[]{Scopes.FILE};
if (settings.getBoolean(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY)) {
- scopes = new String[] {Scopes.DIRECTORY, Scopes.FILE};
+ scopes = new String[]{Scopes.DIRECTORY, Scopes.FILE};
}
return new PurgeConfiguration(resourceId, scopes, settings.getInt(DbCleanerConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES));
}
break;
case 4:
defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4;
- break; // NOSONAR false-positive: constant 4 is the same than 5 (empty string)
+ break;
case 5:
defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5;
- break; // NOSONAR false-positive: constant 5 is the same than 4 (empty string)
+ break;
}
return conf.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index, defaultValue);
}
import org.sonar.api.resources.Qualifiers;
import javax.persistence.Query;
-
import java.util.Date;
import java.util.List;
private DatabaseSession session;
public TimeMachineConfiguration(DatabaseSession session, Project project, Settings settings,
- PastSnapshotFinder pastSnapshotFinder) {
+ PastSnapshotFinder pastSnapshotFinder) {
this.session = session;
this.project = project;
this.settings = settings;
initPastSnapshots(pastSnapshotFinder, getRootProject(project).getQualifier());
}
- private Project getRootProject(Project project){
+ private Project getRootProject(Project project) {
if (!project.isRoot()) {
- return getRootProject(project.getRoot());
+ return getRootProject(project.getRoot());
}
return project;
}
private Snapshot buildProjectSnapshot() {
Query query = session
- .createNativeQuery("select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib and p.enabled=:enabled");
+ .createNativeQuery("select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib and p.enabled=:enabled");
query.setParameter("resourceKey", project.getKey());
query.setParameter("lib", Qualifiers.LIBRARY);
query.setParameter("enabled", Boolean.TRUE);
public String getStringData(String componentKey, String dataType) {
Data data = (Data) cache.get(componentKey, dataType);
- return data==null ? null : ((StringData)data).data();
- }
+ return data == null ? null : ((StringData) data).data();
+ }
public <D extends Data> Iterable<Cache.Entry<D>> entries(String componentKey) {
return cache.entries(componentKey);
package org.sonar.batch.index;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.core.persistence.BatchSession;
+import org.sonar.core.persistence.MyBatis;
import org.sonar.core.source.jdbc.SnapshotDataDao;
import org.sonar.core.source.jdbc.SnapshotDataDto;
private final ComponentDataCache data;
private final SnapshotCache snapshots;
private final SnapshotDataDao dao;
+ private final MyBatis mybatis;
- public ComponentDataPersister(ComponentDataCache data, SnapshotCache snapshots, SnapshotDataDao dao) {
+ public ComponentDataPersister(ComponentDataCache data, SnapshotCache snapshots,
+ SnapshotDataDao dao, MyBatis mybatis) {
this.data = data;
this.snapshots = snapshots;
this.dao = dao;
+ this.mybatis = mybatis;
}
@Override
public void persist() {
+ BatchSession session = mybatis.openBatchSession();
for (Map.Entry<String, Snapshot> componentEntry : snapshots.snapshots()) {
String componentKey = componentEntry.getKey();
Snapshot snapshot = componentEntry.getValue();
dto.setResourceId(snapshot.getResourceId());
dto.setDataType(dataEntry.key());
dto.setData(dataEntry.value().writeString());
-
- // TODO bulk insert
- dao.insert(dto);
+ dao.insert(session, dto);
}
}
}
+ session.commit();
}
}
import org.sonar.api.BatchComponent;
import org.sonar.api.database.model.Snapshot;
-import java.util.Collection;
import java.util.Map;
import java.util.Set;
data.setStringData("org/struts/Other.java", "SYMBOL", "unregistered component, should not be persisted");
SnapshotDataDao dataDao = new SnapshotDataDao(getMyBatis());
- ComponentDataPersister persister = new ComponentDataPersister(data, snapshots, dataDao);
+ ComponentDataPersister persister = new ComponentDataPersister(data, snapshots, dataDao, getMyBatis());
persister.persist();
checkTables("should_persist_component_data", new String[]{"id", "created_at", "updated_at"}, "snapshot_data");
import org.apache.ibatis.annotations.Param;
-import java.util.Collection;
import java.util.List;
/**
void delete(@Param("key") String key);
- List<ActionPlanDto> findByKeys(@Param("keys") List <List<String>> keys);
+ List<ActionPlanDto> findByKeys(@Param("keys") List<List<String>> keys);
ActionPlanDto findByKey(@Param("key") String key);
List<ActionPlanDto> findOpenByProjectId(@Param("projectId") Long projectId);
- List<ActionPlanDto> findByNameAndProjectId(@Param("name")String name, @Param("projectId") Long projectId);
+ List<ActionPlanDto> findByNameAndProjectId(@Param("name") String name, @Param("projectId") Long projectId);
}
public class PurgeConfiguration {
- private static final int ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
-
private final long rootProjectId;
private final String[] scopesWithoutHistoricalData;
private final int maxAgeInDaysOfClosedIssues;
}
public Collection<SnapshotDataDto> selectSnapshotData(long snapshotId, List<String> dataTypes) {
-
SqlSession session = mybatis.openSession();
-
try {
SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class);
return mapper.selectSnapshotData(snapshotId, dataTypes);
}
}
- public void insert(SnapshotDataDto snapshotData) {
-
- SqlSession session = mybatis.openBatchSession();
-
+ void insert(SnapshotDataDto snapshotData) {
+ SqlSession session = mybatis.openSession();
try {
- SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class);
- mapper.insert(snapshotData);
+ insert(session, snapshotData);
session.commit();
} finally {
MyBatis.closeQuietly(session);
}
}
+
+ public void insert(SqlSession session, SnapshotDataDto snapshotData) {
+ SnapshotDataMapper mapper = session.getMapper(SnapshotDataMapper.class);
+ mapper.insert(snapshotData);
+ }
}
issue.setMessage(null);
assertThat(issue.message()).isNull();
}
+
+ @Test
+ public void test_nullable_fields() throws Exception {
+ issue.setEffortToFix(null).setSeverity(null).setLine(null);
+ assertThat(issue.effortToFix()).isNull();
+ assertThat(issue.severity()).isNull();
+ assertThat(issue.line()).isNull();
+ }
+
+ @Test
+ public void test_equals_and_hashCode() throws Exception {
+ DefaultIssue a1 = new DefaultIssue().setKey("AAA");
+ DefaultIssue a2 = new DefaultIssue().setKey("AAA");
+ DefaultIssue b = new DefaultIssue().setKey("BBB");
+ assertThat(a1).isEqualTo(a1);
+ assertThat(a1).isEqualTo(a2);
+ assertThat(a1).isNotEqualTo(b);
+ assertThat(a1.hashCode()).isEqualTo(a1.hashCode());
+ }
}
public static class StringCodeLoader extends CodeLoader {
public static final String DEFAULT_NAME = "CODE_LOADED_FROM_STRING";
- private String source_code;
+ private String sourceCode;
private String name;
}
public StringCodeLoader(String code, String name) {
- this.source_code = code;
+ this.sourceCode = code;
this.name = name;
}
@Override
public Reader getReader() {
- return new StringReader(source_code);
+ return new StringReader(sourceCode);
}
@Override
*/
package org.sonar.api.component;
-public interface Component<CHILD extends Component> {
+public interface Component<C extends Component> {
String key();
+
String name();
+
String longName();
+
String qualifier();
}
* 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.api.issue;
import org.sonar.api.ServerComponent;
-import org.sonar.api.component.Component;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.utils.Paging;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Collection;
-import java.util.List;
/**
* Search for issues. This component can be used only by server-side extensions. Batch extensions should
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.Serializable;
-import java.util.HashMap;
import java.util.Map;
/**
* This class represents a notification that will be delivered to users. This is a general concept and it has no
* knowledge of the possible ways to be delivered (see {@link NotificationChannel}) or of the users who should
* receive it (see {@link NotificationDispatcher}).
- * </p>
+ * </p>
* <p>
- * When creating a new notification, it is strongly advised to give a default message that can be used by channels
- * that don't want to specifically format messages for different notification types. You can use
+ * When creating a new notification, it is strongly advised to give a default message that can be used by channels
+ * that don't want to specifically format messages for different notification types. You can use
* {@link Notification#setDefaultMessage(String)} for that purpose.
* </p>
- *
+ *
* @since 2.10
*/
public class Notification implements Serializable {
* Create a new {@link Notification} of the given type.
* </p>
* Example: type = "new-violations"
- *
+ *
* @param type the type of notification
*/
public Notification(String type) {
/**
* Returns the type of the notification
- *
+ *
* @return the type
*/
public String getType() {
/**
* <p>
- * When creating a new notification, it is strongly advised to give a default message that can be
+ * When creating a new notification, it is strongly advised to give a default message that can be
* used by channels that don't want to specifically format messages for different notification types.
* </p>
* <p>
- * This method is equivalent to setting a value for the field {@link #DEFAULT_MESSAGE_KEY} with
+ * This method is equivalent to setting a value for the field {@link #DEFAULT_MESSAGE_KEY} with
* {@link #setFieldValue(String, String)}.
- * </p>
- *
+ * </p>
+ *
* @since 3.5
*/
public Notification setDefaultMessage(String value) {
/**
* Adds a field (kind of property) to the notification
- *
+ *
* @param field the name of the field (= the key)
* @param value the value of the field
* @return the notification itself
/**
* Returns the value of a field.
- *
+ *
* @param field the field
* @return the value of the field
*/
private TimeUtils() {
}
+ /**
+ * Label for a duration, expressed in numbers of ms, seconds or minutes.
+ * <p/>
+ * Examples:
+ * <ul>
+ * <li>10 -> "10ms"</li>
+ * <li>100 -> "100ms"</li>
+ * <li>10000 -> "10s"</li>
+ * <li>100000 -> "1min 40s"</li>
+ * </ul>
+ */
public static String formatDuration(long durationInMs) {
if (durationInMs < 1000) {
return String.format("%sms", durationInMs);
- }
- else {
+ } else {
long sec = durationInMs / 1000;
if (sec < 60) {
return String.format("%ss", sec);
- }
- else {
+ } else {
long min = sec / 60;
long remainingSec = sec - (min * 60);
if (remainingSec > 0) {
return String.format("%smin %ss", min, remainingSec);
- }
- else {
+ } else {
return String.format("%smin", min);
}
}
}
}
-
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.api.utils;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class TimeUtilsTest {
+ @Test
+ public void formatDuration() throws Exception {
+ assertThat(TimeUtils.formatDuration(0)).isEqualTo("0ms");
+ assertThat(TimeUtils.formatDuration(100)).isEqualTo("100ms");
+ assertThat(TimeUtils.formatDuration(1000)).isEqualTo("1s");
+ assertThat(TimeUtils.formatDuration(10000)).isEqualTo("10s");
+ assertThat(TimeUtils.formatDuration(100000)).isEqualTo("1min 40s");
+ assertThat(TimeUtils.formatDuration(600000)).isEqualTo("10min");
+ assertThat(TimeUtils.formatDuration(1000000)).isEqualTo("16min 40s");
+ assertThat(TimeUtils.formatDuration(10000000)).isEqualTo("166min 40s");
+ }
+}
public class DefaultIssueClient implements IssueClient {
private final HttpRequestFactory requestFactory;
- private final IssueParser parser;
+ private final IssueJsonParser parser;
/**
* For internal use. Use {@link org.sonar.wsclient.SonarClient} to get an instance.
*/
public DefaultIssueClient(HttpRequestFactory requestFactory) {
this.requestFactory = requestFactory;
- this.parser = new IssueParser();
+ this.parser = new IssueJsonParser();
}
public Issues find(IssueQuery query) {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.wsclient.issue;
+
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.component.Component;
+import org.sonar.wsclient.rule.Rule;
+import org.sonar.wsclient.unmarshallers.JsonUtils;
+import org.sonar.wsclient.user.User;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @since 3.6
+ */
+class IssueJsonParser {
+
+ Issues parseIssues(String json) {
+ Issues result = new Issues();
+ Map jsonRoot = (Map) JSONValue.parse(json);
+ List<Map> jsonIssues = (List) jsonRoot.get("issues");
+ if (jsonIssues != null) {
+ for (Map jsonIssue : jsonIssues) {
+ result.add(new Issue(jsonIssue));
+ }
+ }
+ parseRules(result, jsonRoot);
+ parseUsers(result, jsonRoot);
+ parseComponents(result, jsonRoot);
+ parseProjects(result, jsonRoot);
+ parsePaging(result, jsonRoot);
+ return result;
+ }
+
+ private void parsePaging(Issues result, Map jsonRoot) {
+ Map paging = (Map) jsonRoot.get("paging");
+ result.setPaging(new Paging(paging));
+ result.setMaxResultsReached(JsonUtils.getBoolean(jsonRoot, "maxResultsReached"));
+ }
+
+ private void parseProjects(Issues result, Map jsonRoot) {
+ List<Map> jsonProjects = (List) jsonRoot.get("projects");
+ if (jsonProjects != null) {
+ for (Map jsonProject : jsonProjects) {
+ result.addProject(new Component(jsonProject));
+ }
+ }
+ }
+
+ private void parseComponents(Issues result, Map jsonRoot) {
+ List<Map> jsonComponents = (List) jsonRoot.get("components");
+ if (jsonComponents != null) {
+ for (Map jsonComponent : jsonComponents) {
+ result.addComponent(new Component(jsonComponent));
+ }
+ }
+ }
+
+ private void parseUsers(Issues result, Map jsonRoot) {
+ List<Map> jsonUsers = (List) jsonRoot.get("users");
+ if (jsonUsers != null) {
+ for (Map jsonUser : jsonUsers) {
+ result.add(new User(jsonUser));
+ }
+ }
+ }
+
+ private void parseRules(Issues result, Map jsonRoot) {
+ List<Map> jsonRules = (List) jsonRoot.get("rules");
+ if (jsonRules != null) {
+ for (Map jsonRule : jsonRules) {
+ result.add(new Rule(jsonRule));
+ }
+ }
+ }
+
+ List<String> parseTransitions(String json) {
+ List<String> transitions = new ArrayList<String>();
+ Map jRoot = (Map) JSONValue.parse(json);
+ List<String> jTransitions = (List) jRoot.get("transitions");
+ for (String jTransition : jTransitions) {
+ transitions.add(jTransition);
+ }
+ return transitions;
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.wsclient.issue;
-
-import org.json.simple.JSONValue;
-import org.sonar.wsclient.component.Component;
-import org.sonar.wsclient.rule.Rule;
-import org.sonar.wsclient.unmarshallers.JsonUtils;
-import org.sonar.wsclient.user.User;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @since 3.6
- */
-class IssueParser {
-
- Issues parseIssues(String json) {
- Issues result = new Issues();
- Map jsonRoot = (Map) JSONValue.parse(json);
- List<Map> jsonIssues = (List) jsonRoot.get("issues");
- if (jsonIssues != null) {
- for (Map jsonIssue : jsonIssues) {
- result.add(new Issue(jsonIssue));
- }
- }
-
- List<Map> jsonRules = (List) jsonRoot.get("rules");
- if (jsonRules != null) {
- for (Map jsonRule : jsonRules) {
- result.add(new Rule(jsonRule));
- }
- }
-
- List<Map> jsonUsers = (List) jsonRoot.get("users");
- if (jsonUsers != null) {
- for (Map jsonUser : jsonUsers) {
- result.add(new User(jsonUser));
- }
- }
-
- List<Map> jsonComponents = (List) jsonRoot.get("components");
- if (jsonComponents != null) {
- for (Map jsonComponent : jsonComponents) {
- result.addComponent(new Component(jsonComponent));
- }
- }
-
- List<Map> jsonProjects = (List) jsonRoot.get("projects");
- if (jsonProjects != null) {
- for (Map jsonProject : jsonProjects) {
- result.addProject(new Component(jsonProject));
- }
- }
-
- Map paging = (Map) jsonRoot.get("paging");
- result.setPaging(new Paging(paging));
- result.setMaxResultsReached(JsonUtils.getBoolean(jsonRoot, "maxResultsReached"));
- return result;
- }
-
- List<String> parseTransitions(String json) {
- List<String> transitions = new ArrayList<String>();
- Map jRoot = (Map) JSONValue.parse(json);
- List<String> jTransitions = (List) jRoot.get("transitions");
- for (String jTransition : jTransitions) {
- transitions.add(jTransition);
- }
- return transitions;
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.wsclient.issue;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.sonar.wsclient.component.Component;
+import org.sonar.wsclient.user.User;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueJsonParserTest {
+ @Test
+ public void test_GET_search() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/search.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+ assertThat(issues).isNotNull();
+ List<Issue> list = issues.list();
+ assertThat(list).hasSize(2);
+ Issue first = list.get(0);
+ assertThat(first.key()).isEqualTo("ABCDE");
+ assertThat(first.componentKey()).isEqualTo("Action.java");
+ assertThat(first.projectKey()).isEqualTo("struts");
+ assertThat(first.ruleKey()).isEqualTo("squid:CycleBetweenPackages");
+ assertThat(first.severity()).isEqualTo("CRITICAL");
+ assertThat(first.line()).isEqualTo(10);
+ assertThat(first.resolution()).isEqualTo("FIXED");
+ assertThat(first.status()).isEqualTo("OPEN");
+ assertThat(first.assignee()).isEqualTo("karadoc");
+ assertThat(first.message()).isEqualTo("the message");
+ assertThat(first.effortToFix()).isEqualTo(4.2);
+ assertThat(first.reporter()).isEqualTo("perceval");
+ assertThat(first.creationDate()).isNotNull();
+ assertThat(first.updateDate()).isNotNull();
+ assertThat(first.closeDate()).isNotNull();
+ assertThat(first.attribute("JIRA")).isEqualTo("FOO-1234");
+ assertThat(first.attribute("OTHER")).isNull();
+ assertThat(first.attributes()).hasSize(1);
+ assertThat(first.comments()).isEmpty();
+
+ Issue second = list.get(1);
+ assertThat(second.key()).isEqualTo("FGHIJ");
+ assertThat(second.line()).isNull();
+ assertThat(second.effortToFix()).isNull();
+ assertThat(second.reporter()).isNull();
+ assertThat(second.attribute("JIRA")).isNull();
+ assertThat(second.attributes()).isEmpty();
+ assertThat(second.comments()).isEmpty();
+
+ assertThat(issues.rules()).hasSize(2);
+ assertThat(issues.rule(first).key()).isEqualTo("squid:CycleBetweenPackages");
+ assertThat(issues.rule(first).name()).isEqualTo("Avoid cycle between java packages");
+ assertThat(issues.rule(first).description()).contains("When several packages");
+
+ assertThat(issues.paging()).isNotNull();
+ Paging paging = issues.paging();
+ assertThat(paging.pageIndex()).isEqualTo(1);
+ assertThat(paging.pageSize()).isEqualTo(100);
+ assertThat(paging.pages()).isEqualTo(1);
+ assertThat(paging.total()).isEqualTo(2);
+
+ assertThat(issues.maxResultsReached()).isTrue();
+ }
+
+ @Test
+ public void test_GET_empty_search() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/empty.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+ assertThat(issues).isNotNull();
+ assertThat(issues.list()).isEmpty();
+ assertThat(issues.rules()).isEmpty();
+ assertThat(issues.maxResultsReached()).isFalse();
+ }
+
+ @Test
+ public void test_GET_transitions() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/getTransitions.json"));
+ List<String> transitions = new IssueJsonParser().parseTransitions(json);
+
+ assertThat(transitions).isNotNull();
+ assertThat(transitions).hasSize(2);
+ assertThat(transitions).containsOnly("resolve", "falsepositive");
+ }
+
+ @Test
+ public void should_parse_comments() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-comments.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+ assertThat(issues.size()).isEqualTo(1);
+
+ Issue issue = issues.list().get(0);
+ assertThat(issue.comments()).hasSize(2);
+
+ IssueComment firstComment = issue.comments().get(0);
+ assertThat(firstComment.key()).isEqualTo("COMMENT-1");
+ assertThat(firstComment.login()).isEqualTo("morgan");
+ assertThat(firstComment.htmlText()).isEqualTo("the first comment");
+ assertThat(firstComment.createdAt().getDate()).isEqualTo(18);
+
+ IssueComment secondComment = issue.comments().get(1);
+ assertThat(secondComment.key()).isEqualTo("COMMENT-2");
+ assertThat(secondComment.login()).isEqualTo("arthur");
+ assertThat(secondComment.htmlText()).isEqualTo("the second comment");
+ assertThat(secondComment.createdAt().getDate()).isEqualTo(19);
+ }
+
+ @Test
+ public void should_parse_users() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-users.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+
+ assertThat(issues.users()).hasSize(2);
+
+ User morgan = issues.user("morgan");
+ assertThat(morgan.login()).isEqualTo("morgan");
+ assertThat(morgan.name()).isEqualTo("Morgan");
+ assertThat(morgan.active()).isTrue();
+ assertThat(morgan.email()).isEqualTo("mor@gan.bzh");
+
+ User arthur = issues.user("arthur");
+ assertThat(arthur.login()).isEqualTo("arthur");
+ assertThat(arthur.name()).isEqualTo("Arthur");
+ assertThat(arthur.active()).isFalse();
+ assertThat(arthur.email()).isEqualTo("ar@thur.bzh");
+ }
+
+ @Test
+ public void should_parse_components() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-components.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+
+ assertThat(issues.components()).hasSize(1);
+
+ Component component = issues.component(issues.list().get(0));
+ assertThat(component.key()).isEqualTo("struts:Action.java");
+ assertThat(component.qualifier()).isEqualTo("CLA");
+ assertThat(component.name()).isEqualTo("Action");
+ assertThat(component.longName()).isEqualTo("org.struts.Action");
+ }
+
+ @Test
+ public void should_parse_projects() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-projects.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+
+ assertThat(issues.projects()).hasSize(1);
+
+ Component component = issues.project(issues.list().get(0));
+ assertThat(component.key()).isEqualTo("struts");
+ assertThat(component.qualifier()).isEqualTo("TRK");
+ assertThat(component.name()).isEqualTo("Struts");
+ assertThat(component.longName()).isEqualTo("org.struts");
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.wsclient.issue;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.sonar.wsclient.component.Component;
-import org.sonar.wsclient.user.User;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class IssueParserTest {
- @Test
- public void test_GET_search() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/search.json"));
- Issues issues = new IssueParser().parseIssues(json);
- assertThat(issues).isNotNull();
- List<Issue> list = issues.list();
- assertThat(list).hasSize(2);
- Issue first = list.get(0);
- assertThat(first.key()).isEqualTo("ABCDE");
- assertThat(first.componentKey()).isEqualTo("Action.java");
- assertThat(first.projectKey()).isEqualTo("struts");
- assertThat(first.ruleKey()).isEqualTo("squid:CycleBetweenPackages");
- assertThat(first.severity()).isEqualTo("CRITICAL");
- assertThat(first.line()).isEqualTo(10);
- assertThat(first.resolution()).isEqualTo("FIXED");
- assertThat(first.status()).isEqualTo("OPEN");
- assertThat(first.assignee()).isEqualTo("karadoc");
- assertThat(first.message()).isEqualTo("the message");
- assertThat(first.effortToFix()).isEqualTo(4.2);
- assertThat(first.reporter()).isEqualTo("perceval");
- assertThat(first.creationDate()).isNotNull();
- assertThat(first.updateDate()).isNotNull();
- assertThat(first.closeDate()).isNotNull();
- assertThat(first.attribute("JIRA")).isEqualTo("FOO-1234");
- assertThat(first.attribute("OTHER")).isNull();
- assertThat(first.attributes()).hasSize(1);
- assertThat(first.comments()).isEmpty();
-
- Issue second = list.get(1);
- assertThat(second.key()).isEqualTo("FGHIJ");
- assertThat(second.line()).isNull();
- assertThat(second.effortToFix()).isNull();
- assertThat(second.reporter()).isNull();
- assertThat(second.attribute("JIRA")).isNull();
- assertThat(second.attributes()).isEmpty();
- assertThat(second.comments()).isEmpty();
-
- assertThat(issues.rules()).hasSize(2);
- assertThat(issues.rule(first).key()).isEqualTo("squid:CycleBetweenPackages");
- assertThat(issues.rule(first).name()).isEqualTo("Avoid cycle between java packages");
- assertThat(issues.rule(first).description()).contains("When several packages");
-
- assertThat(issues.paging()).isNotNull();
- Paging paging = issues.paging();
- assertThat(paging.pageIndex()).isEqualTo(1);
- assertThat(paging.pageSize()).isEqualTo(100);
- assertThat(paging.pages()).isEqualTo(1);
- assertThat(paging.total()).isEqualTo(2);
-
- assertThat(issues.maxResultsReached()).isTrue();
- }
-
- @Test
- public void test_GET_empty_search() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/empty.json"));
- Issues issues = new IssueParser().parseIssues(json);
- assertThat(issues).isNotNull();
- assertThat(issues.list()).isEmpty();
- assertThat(issues.rules()).isEmpty();
- assertThat(issues.maxResultsReached()).isFalse();
- }
-
- @Test
- public void test_GET_transitions() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/getTransitions.json"));
- List<String> transitions = new IssueParser().parseTransitions(json);
-
- assertThat(transitions).isNotNull();
- assertThat(transitions).hasSize(2);
- assertThat(transitions).containsOnly("resolve", "falsepositive");
- }
-
- @Test
- public void should_parse_comments() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-comments.json"));
- Issues issues = new IssueParser().parseIssues(json);
- assertThat(issues.size()).isEqualTo(1);
-
- Issue issue = issues.list().get(0);
- assertThat(issue.comments()).hasSize(2);
-
- IssueComment firstComment = issue.comments().get(0);
- assertThat(firstComment.key()).isEqualTo("COMMENT-1");
- assertThat(firstComment.login()).isEqualTo("morgan");
- assertThat(firstComment.htmlText()).isEqualTo("the first comment");
- assertThat(firstComment.createdAt().getDate()).isEqualTo(18);
-
- IssueComment secondComment = issue.comments().get(1);
- assertThat(secondComment.key()).isEqualTo("COMMENT-2");
- assertThat(secondComment.login()).isEqualTo("arthur");
- assertThat(secondComment.htmlText()).isEqualTo("the second comment");
- assertThat(secondComment.createdAt().getDate()).isEqualTo(19);
- }
-
- @Test
- public void should_parse_users() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-users.json"));
- Issues issues = new IssueParser().parseIssues(json);
-
- assertThat(issues.users()).hasSize(2);
-
- User morgan = issues.user("morgan");
- assertThat(morgan.login()).isEqualTo("morgan");
- assertThat(morgan.name()).isEqualTo("Morgan");
- assertThat(morgan.active()).isTrue();
- assertThat(morgan.email()).isEqualTo("mor@gan.bzh");
-
- User arthur = issues.user("arthur");
- assertThat(arthur.login()).isEqualTo("arthur");
- assertThat(arthur.name()).isEqualTo("Arthur");
- assertThat(arthur.active()).isFalse();
- assertThat(arthur.email()).isEqualTo("ar@thur.bzh");
- }
-
- @Test
- public void should_parse_components() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-components.json"));
- Issues issues = new IssueParser().parseIssues(json);
-
- assertThat(issues.components()).hasSize(1);
-
- Component component = issues.component(issues.list().get(0));
- assertThat(component.key()).isEqualTo("struts:Action.java");
- assertThat(component.qualifier()).isEqualTo("CLA");
- assertThat(component.name()).isEqualTo("Action");
- assertThat(component.longName()).isEqualTo("org.struts.Action");
- }
-
- @Test
- public void should_parse_projects() throws Exception {
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-projects.json"));
- Issues issues = new IssueParser().parseIssues(json);
-
- assertThat(issues.projects()).hasSize(1);
-
- Component component = issues.project(issues.list().get(0));
- assertThat(component.key()).isEqualTo("struts");
- assertThat(component.qualifier()).isEqualTo("TRK");
- assertThat(component.name()).isEqualTo("Struts");
- assertThat(component.longName()).isEqualTo("org.struts");
- }
-}
public void should_search_by_text() throws Exception {
UserQuery query = UserQuery.create().searchText("sim");
assertThat(query.urlParams().get("s")).isEqualTo("sim");
+
+ query = UserQuery.create().searchText("sim").searchText(null);
+ assertThat(query.urlParams().get("s")).isNull();
}
}