"<ol>" +
"<li>Line number</li>" +
"<li>Is the line covered?</li>" +
+ "<li>Number of tests covering this line</li>" +
"<li>Number of branches</li>" +
"<li>Number of branches covered</li>" +
"</ol>")
*/
package org.sonar.wsclient;
+import org.sonar.wsclient.duplication.DuplicationClient;
+import org.sonar.wsclient.duplication.internal.DefaultDuplicationClient;
import org.sonar.wsclient.internal.HttpRequestFactory;
import org.sonar.wsclient.issue.ActionPlanClient;
import org.sonar.wsclient.issue.IssueClient;
import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
import org.sonar.wsclient.rule.RuleClient;
import org.sonar.wsclient.rule.internal.DefaultRuleClient;
+import org.sonar.wsclient.source.SourceClient;
+import org.sonar.wsclient.source.internal.DefaultSourceClient;
import org.sonar.wsclient.system.SystemClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
+import org.sonar.wsclient.test.CoverageClient;
+import org.sonar.wsclient.test.internal.DefaultCoverageClient;
import org.sonar.wsclient.user.UserClient;
import org.sonar.wsclient.user.internal.DefaultUserClient;
return new DefaultQProfileClient(requestFactory);
}
+ /**
+ * New client to interact with web services related to source
+ */
+ public SourceClient sourceClient() {
+ return new DefaultSourceClient(requestFactory);
+ }
+
+ /**
+ * New client to interact with web services related to coverage
+ */
+ public CoverageClient coverageClient() {
+ return new DefaultCoverageClient(requestFactory);
+ }
+
+ /**
+ * New client to interact with web services related to duplication
+ */
+ public DuplicationClient duplicationClient() {
+ return new DefaultDuplicationClient(requestFactory);
+ }
public SystemClient systemClient() {
return new DefaultSystemClient(requestFactory);
--- /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.wsclient.duplication;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 4.4
+ */
+public interface Block {
+
+ @CheckForNull
+ String fileRef();
+
+ @CheckForNull
+ Integer from();
+
+ @CheckForNull
+ Integer size();
+
+}
--- /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.wsclient.duplication;
+
+import java.util.List;
+
+/**
+ * @since 4.4
+ */
+public interface Duplication {
+
+ List<Block> blocks();
+
+}
--- /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.wsclient.duplication;
+
+/**
+ * Display duplication information
+ *
+ * @since 4.4
+ */
+public interface DuplicationClient {
+
+ Duplications show(String componentKey);
+
+}
--- /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.wsclient.duplication;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+/**
+ * @since 4.4
+ */
+public interface Duplications {
+
+ List<Duplication> duplications();
+
+ List<File> files();
+
+ @CheckForNull
+ File fileByRef(String ref);
+
+}
--- /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.wsclient.duplication;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 4.4
+ */
+public interface File {
+
+ @CheckForNull
+ String key();
+
+ @CheckForNull
+ String name();
+
+ @CheckForNull
+ String projectName();
+
+}
--- /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.wsclient.duplication.internal;
+
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.duplication.*;
+import org.sonar.wsclient.internal.EncodingUtils;
+import org.sonar.wsclient.internal.HttpRequestFactory;
+import org.sonar.wsclient.unmarshallers.JsonUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultDuplicationClient implements DuplicationClient {
+
+ private final HttpRequestFactory requestFactory;
+
+ public DefaultDuplicationClient(HttpRequestFactory requestFactory) {
+ this.requestFactory = requestFactory;
+ }
+
+ @Override
+ public Duplications show(String componentKey) {
+ Map<String, Object> params = EncodingUtils.toMap("key", componentKey);
+ String jsonResult = requestFactory.get("/api/duplications/show", params);
+
+ DefaultDuplications duplications = new DefaultDuplications();
+ Map jRoot = (Map) JSONValue.parse(jsonResult);
+ parseDuplications(duplications, jRoot);
+ parseFiles(duplications, jRoot);
+ return duplications;
+ }
+
+ private void parseDuplications(DefaultDuplications duplications, Map jRoot) {
+ List<Map> jsonDuplications = (List<Map>) jRoot.get("duplications");
+ if (jsonDuplications != null) {
+ for (Map jsonDuplication : jsonDuplications) {
+ final List<Block> blockList = new ArrayList<Block>();
+
+ List<Map> blocks = (List<Map>) jsonDuplication.get("blocks");
+ if (blocks != null) {
+ for (final Map block : blocks) {
+
+ blockList.add((new Block() {
+ @Override
+ public String fileRef() {
+ return JsonUtils.getString(block, "_ref");
+ }
+
+ @Override
+ public Integer from() {
+ return JsonUtils.getInteger(block, "from");
+ }
+
+ @Override
+ public Integer size() {
+ return JsonUtils.getInteger(block, "size");
+ }
+ }));
+ }
+ }
+
+ Duplication duplication = new Duplication() {
+ @Override
+ public List<Block> blocks() {
+ return blockList;
+ }
+ };
+
+ duplications.addDuplication(duplication);
+ }
+ }
+ }
+
+ private void parseFiles(DefaultDuplications duplications, Map jRoot) {
+ Map<String, Map> jsonFiles = (Map) jRoot.get("files");
+ if (jsonFiles != null) {
+ for (Map.Entry<String, Map> entry : jsonFiles.entrySet()) {
+ String ref = entry.getKey();
+ final Map file = entry.getValue();
+ if (ref != null && file != null) {
+
+ duplications.addFile(ref, new File() {
+ @Override
+ public String key () {
+ return JsonUtils.getString(file, "key");
+ }
+
+ @Override
+ public String name () {
+ return JsonUtils.getString(file, "name");
+ }
+
+ @Override
+ public String projectName () {
+ return JsonUtils.getString(file, "projectName");
+ }
+ });
+
+ }
+ }
+ }
+ }
+}
--- /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.wsclient.duplication.internal;
+
+import org.sonar.wsclient.duplication.Duplication;
+import org.sonar.wsclient.duplication.Duplications;
+import org.sonar.wsclient.duplication.File;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultDuplications implements Duplications {
+
+ private final List<Duplication> duplications = new ArrayList<Duplication>();
+ private final Map<String, File> files = new HashMap<String, File>();
+
+ @Override
+ public List<Duplication> duplications() {
+ return duplications;
+ }
+
+ @Override
+ public List<File> files() {
+ return new ArrayList<File>(files.values());
+ }
+
+ @Override
+ public File fileByRef(String ref) {
+ return files.get(ref);
+ }
+
+ DefaultDuplications addDuplication(Duplication duplication) {
+ duplications.add(duplication);
+ return this;
+ }
+
+ DefaultDuplications addFile(String ref, File file) {
+ files.put(ref, file);
+ return this;
+ }
+
+}
--- /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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.wsclient.duplication.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.wsclient.duplication;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /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.wsclient.test;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 4.4
+ */
+public interface Coverage {
+
+ @CheckForNull
+ Integer lineIndex();
+
+ @CheckForNull
+ Boolean isCovered();
+
+ @CheckForNull
+ Integer tests();
+
+ @CheckForNull
+ Integer branches();
+
+ @CheckForNull
+ Integer coveredBranches();
+
+}
--- /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.wsclient.test;
+
+import java.util.List;
+
+/**
+ * Display coverage information
+ *
+ * @since 4.4
+ */
+public interface CoverageClient {
+
+ List<Coverage> show(CoverageShowQuery query);
+
+}
--- /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.wsclient.test;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class CoverageShowQuery {
+
+ private String key;
+ private String from;
+ private String to;
+ private String type;
+
+ private CoverageShowQuery() {
+ // Nothing here
+ }
+
+ public String key() {
+ return key;
+ }
+
+ public CoverageShowQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @CheckForNull
+ public String from() {
+ return from;
+ }
+
+ public CoverageShowQuery setFrom(@Nullable String from) {
+ this.from = from;
+ return this;
+ }
+
+ @CheckForNull
+ public String to() {
+ return to;
+ }
+
+ public CoverageShowQuery setTo(@Nullable String to) {
+ this.to = to;
+ return this;
+ }
+
+ @CheckForNull
+ public String type() {
+ return type;
+ }
+
+ public CoverageShowQuery setType(@Nullable String type) {
+ this.type = type;
+ return this;
+ }
+
+ public static CoverageShowQuery create(){
+ return new CoverageShowQuery();
+ }
+
+}
--- /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.wsclient.test.internal;
+
+import org.sonar.wsclient.test.Coverage;
+
+import java.util.List;
+
+public class DefaultCoverage implements Coverage {
+
+ private final List json;
+
+ public DefaultCoverage(List json) {
+ this.json = json;
+ }
+
+ @Override
+ public Integer lineIndex() {
+ Object value = json.get(0);
+ return value != null ? ((Long) value).intValue() : null;
+ }
+
+ @Override
+ public Boolean isCovered() {
+ Object value = json.get(1);
+ return value != null ? (Boolean) value : null;
+ }
+
+ @Override
+ public Integer tests() {
+ Object value = json.get(2);
+ return value != null ? ((Long) value).intValue() : null;
+ }
+
+ @Override
+ public Integer branches() {
+ Object value = json.get(3);
+ return value != null ? ((Long) value).intValue() : null;
+ }
+
+ @Override
+ public Integer coveredBranches() {
+ Object value = json.get(4);
+ return value != null ? ((Long) value).intValue() : null;
+ }
+}
--- /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.wsclient.test.internal;
+
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.internal.EncodingUtils;
+import org.sonar.wsclient.internal.HttpRequestFactory;
+import org.sonar.wsclient.test.Coverage;
+import org.sonar.wsclient.test.CoverageClient;
+import org.sonar.wsclient.test.CoverageShowQuery;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultCoverageClient implements CoverageClient {
+
+ private final HttpRequestFactory requestFactory;
+
+ public DefaultCoverageClient(HttpRequestFactory requestFactory) {
+ this.requestFactory = requestFactory;
+ }
+
+ @Override
+ public List<Coverage> show(CoverageShowQuery query) {
+ Map<String, Object> params = EncodingUtils.toMap("key", query.key(), "from", query.from(), "to", query.to(), "type", query.type());
+ String jsonResult = requestFactory.get("/api/coverage/show", params);
+
+ List<Coverage> coverages = new ArrayList<Coverage>();
+ Map jRoot = (Map) JSONValue.parse(jsonResult);
+ List<List> jsonList = (List) jRoot.get("coverage");
+ if (jsonList != null) {
+ for (List json : jsonList) {
+ coverages.add(new DefaultCoverage(json));
+ }
+ }
+ return coverages;
+ }
+
+}
--- /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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.wsclient.test.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.wsclient.test;
+
+import javax.annotation.ParametersAreNonnullByDefault;
package org.sonar.wsclient;
import org.junit.Test;
+import org.sonar.wsclient.duplication.internal.DefaultDuplicationClient;
import org.sonar.wsclient.issue.internal.DefaultActionPlanClient;
import org.sonar.wsclient.issue.internal.DefaultIssueClient;
import org.sonar.wsclient.permissions.internal.DefaultPermissionClient;
import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
import org.sonar.wsclient.rule.internal.DefaultRuleClient;
+import org.sonar.wsclient.source.internal.DefaultSourceClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
+import org.sonar.wsclient.test.internal.DefaultCoverageClient;
import org.sonar.wsclient.user.internal.DefaultUserClient;
import static org.fest.assertions.Assertions.assertThat;
assertThat(client.ruleClient()).isNotNull().isInstanceOf(DefaultRuleClient.class);
assertThat(client.qualityGateClient()).isNotNull().isInstanceOf(DefaultQualityGateClient.class);
assertThat(client.qProfileClient()).isNotNull().isInstanceOf(DefaultQProfileClient.class);
+ assertThat(client.sourceClient()).isNotNull().isInstanceOf(DefaultSourceClient.class);
+ assertThat(client.coverageClient()).isNotNull().isInstanceOf(DefaultCoverageClient.class);
+ assertThat(client.duplicationClient()).isNotNull().isInstanceOf(DefaultDuplicationClient.class);
assertThat(client.systemClient()).isNotNull().isInstanceOf(DefaultSystemClient.class);
}
--- /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.wsclient.duplication.internal;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.wsclient.MockHttpServerInterceptor;
+import org.sonar.wsclient.duplication.*;
+import org.sonar.wsclient.internal.HttpRequestFactory;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultDuplicationClientTest {
+
+ @Rule
+ public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
+
+ @Test
+ public void show_duplications() throws IOException {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+ httpServer.stubResponseBody(Resources.toString(Resources.getResource(this.getClass(), "DefaultDuplicationClientTest/show_duplications.json"), Charsets.UTF_8));
+
+ DuplicationClient client = new DefaultDuplicationClient(requestFactory);
+ Duplications result = client.show("MyFile");
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/duplications/show?key=MyFile");
+
+ List<Duplication> duplications = result.duplications();
+ assertThat(duplications).hasSize(1);
+
+ Duplication duplication = duplications.get(0);
+ assertThat(duplication.blocks()).hasSize(2);
+
+ Block block = duplication.blocks().get(0);
+ assertThat(block.fileRef()).isEqualTo("1");
+ assertThat(block.from()).isEqualTo(94);
+ assertThat(block.size()).isEqualTo(101);
+
+ List<File> files = result.files();
+ assertThat(files).hasSize(2);
+
+ File file = result.fileByRef("1");
+ assertThat(file.key()).isEqualTo("org.codehaus.sonar:sonar-plugin-api:src/main/java/org/sonar/api/utils/command/CommandExecutor.java");
+ assertThat(file.name()).isEqualTo("CommandExecutor");
+ assertThat(file.projectName()).isEqualTo("SonarQube");
+ }
+
+}
--- /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.wsclient.test.internal;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.wsclient.MockHttpServerInterceptor;
+import org.sonar.wsclient.internal.HttpRequestFactory;
+import org.sonar.wsclient.test.Coverage;
+import org.sonar.wsclient.test.CoverageClient;
+import org.sonar.wsclient.test.CoverageShowQuery;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultCoverageClientTest {
+
+ @Rule
+ public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
+
+ @Test
+ public void show_coverage() throws IOException {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+ httpServer.stubResponseBody(Resources.toString(Resources.getResource(this.getClass(), "DefaultCoverageClientTest/show_coverage.json"), Charsets.UTF_8));
+
+ CoverageClient client = new DefaultCoverageClient(requestFactory);
+ List<Coverage> coverage = client.show(CoverageShowQuery.create().setKey("MyFile").setFrom("20").setTo("25").setType("UT"));
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/coverage/show?key=MyFile&from=20&to=25&type=UT");
+ assertThat(coverage).hasSize(3);
+ assertThat(coverage.get(0).lineIndex()).isEqualTo(49);
+ assertThat(coverage.get(0).isCovered()).isTrue();
+ assertThat(coverage.get(0).tests()).isEqualTo(14);
+ assertThat(coverage.get(0).branches()).isEqualTo(3);
+ assertThat(coverage.get(0).coveredBranches()).isEqualTo(2);
+ }
+
+}
--- /dev/null
+{
+ "duplications": [
+ {
+ "blocks": [
+ {
+ "from": 94,
+ "size": 101,
+ "_ref": "1"
+ },
+ {
+ "from": 83,
+ "size": 101,
+ "_ref": "2"
+ }
+ ]
+ }
+ ],
+ "files": {
+ "1": {
+ "key": "org.codehaus.sonar:sonar-plugin-api:src/main/java/org/sonar/api/utils/command/CommandExecutor.java",
+ "name": "CommandExecutor",
+ "projectName": "SonarQube"
+ },
+ "2": {
+ "key": "com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java",
+ "name": "CommandExecutor",
+ "projectName": "SonarSource :: Orchestrator"
+ }
+ }
+}
--- /dev/null
+{
+ "coverage": [
+ [49, true, 14, 3, 2],
+ [52, false, null, null, null],
+ [72, true, 4, 2, 1]
+ ]
+}