+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.computation.db.AnalysisReportDto;
-import org.sonar.server.computation.AnalysisReportQueue;
-
-import java.util.List;
-
-/**
- * @since 5.0
- */
-public class ActiveAnalysisReportsAction implements RequestHandler {
- private final AnalysisReportQueue queue;
-
- public ActiveAnalysisReportsAction(AnalysisReportQueue queue) {
- this.queue = queue;
- }
-
- @Override
- public void handle(Request request, Response response) throws Exception {
- List<AnalysisReportDto> reports = queue.all();
-
- JsonWriter json = response.newJsonWriter().beginObject();
- writeReports(reports, json);
- json.endObject();
- json.close();
- }
-
- private void writeReports(List<AnalysisReportDto> reports, JsonWriter json) {
- json.name("reports").beginArray();
- for (AnalysisReportDto report : reports) {
- json.beginObject();
- json.prop("id", report.getId());
- json.prop("project", report.getProjectKey());
- json.prop("projectName", report.getProjectKey());
- json.propDateTime("startedAt", report.getStartedAt());
- json.propDateTime("finishedAt", report.getFinishedAt());
- json.propDateTime("submittedAt", report.getCreatedAt());
- json.prop("status", report.getStatus().toString());
- json.endObject();
- }
- json.endArray();
- }
-
- void define(WebService.NewController controller) {
- controller
- .createAction("active")
- .setDescription("List all the active analysis reports")
- .setSince("5.0")
- .setInternal(true)
- .setHandler(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.
- */
-
-package org.sonar.server.computation.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.activity.Activity;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.server.activity.ActivityService;
-import org.sonar.server.activity.index.ActivityQuery;
-import org.sonar.server.activity.ws.ActivityMapping;
-import org.sonar.server.search.QueryContext;
-import org.sonar.server.search.Result;
-import org.sonar.server.search.ws.SearchOptions;
-import org.sonar.server.user.UserSession;
-
-import java.util.Arrays;
-import java.util.Map;
-
-public class AnalysisReportHistorySearchAction implements RequestHandler {
-
- public static final String PARAM_TYPE = "type";
-
- public static final String SEARCH_ACTION = "history";
-
- private final ActivityService logService;
- private final ActivityMapping mapping;
-
- public AnalysisReportHistorySearchAction(ActivityService logService, ActivityMapping mapping) {
- this.logService = logService;
- this.mapping = mapping;
- }
-
- void define(WebService.NewController controller) {
- WebService.NewAction action = controller
- .createAction(SEARCH_ACTION)
- .setDescription("Search for activities")
- .setSince("5.0")
- .setInternal(true)
- .setHandler(this);
-
- // Generic search parameters
- SearchOptions.defineFieldsParam(action, mapping.supportedFields());
- SearchOptions.definePageParams(action);
- }
-
- @Override
- public void handle(Request request, Response response) {
- checkUserRights();
-
- ActivityQuery query = logService.newActivityQuery();
- query.setTypes(Arrays.asList(Activity.Type.ANALYSIS_REPORT));
-
- SearchOptions searchOptions = SearchOptions.create(request);
- QueryContext queryContext = mapping.newQueryOptions(searchOptions);
-
- Result<Activity> results = logService.search(query, queryContext);
-
- JsonWriter json = response.newJsonWriter().beginObject();
- searchOptions.writeStatistics(json, results);
- writeReports(results, json);
- json.endObject().close();
- }
-
- private void checkUserRights() {
- UserSession.get().checkGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
- }
-
- private void writeReports(Result<Activity> result, JsonWriter json) {
- json.name("reports").beginArray();
- for (Activity reportActivity : result.getHits()) {
- json.beginObject();
- for (Map.Entry<String, String> detail : reportActivity.details().entrySet()) {
- json.prop(detail.getKey(), detail.getValue());
- }
- json.endObject();
- }
- json.endArray();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.ws;
-
-import org.sonar.api.server.ws.WebService;
-
-public class AnalysisReportWebService implements WebService {
- public static final String API_ENDPOINT = "api/analysis_reports";
-
- private final ActiveAnalysisReportsAction activeAnalysisReportsAction;
- private final IsAnalysisReportQueueEmptyAction isAnalysisReportQueueEmptyAction;
- private final AnalysisReportHistorySearchAction historySearchAction;
-
- public AnalysisReportWebService(ActiveAnalysisReportsAction activeReports, IsAnalysisReportQueueEmptyAction isAnalysisReportQueueEmptyAction,
- AnalysisReportHistorySearchAction historySearchAction) {
- this.activeAnalysisReportsAction = activeReports;
- this.isAnalysisReportQueueEmptyAction = isAnalysisReportQueueEmptyAction;
- this.historySearchAction = historySearchAction;
- }
-
- @Override
- public void define(Context context) {
- NewController controller = context
- .createController(API_ENDPOINT)
- .setDescription("Analysis reports processed");
-
- activeAnalysisReportsAction.define(controller);
- isAnalysisReportQueueEmptyAction.define(controller);
- historySearchAction.define(controller);
-
- controller.done();
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+/**
+ * Web service to interact with the "computation" stack :
+ * <ul>
+ * <li>queue of analysis reports to be integrated</li>
+ * <li>consolidation and aggregation of analysis measures</li>
+ * <li>persistence in datastores (database/elasticsearch)</li>
+ * </ul>
+ */
+public class ComputationWebService implements WebService {
+ public static final String API_ENDPOINT = "api/analysis_reports";
+
+ private final ComputationWsAction[] actions;
+
+ public ComputationWebService(ComputationWsAction... actions) {
+ this.actions = actions;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context
+ .createController(API_ENDPOINT)
+ .setDescription("Analysis reports processed");
+ for (ComputationWsAction action : actions) {
+ action.define(controller);
+ }
+ controller.done();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.computation.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+/**
+ * Used by {@link ComputationWebService} to
+ * loop over all its actions
+ */
+interface ComputationWsAction {
+ void define(WebService.NewController controller);
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.activity.Activity;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.server.activity.ActivityService;
+import org.sonar.server.activity.index.ActivityQuery;
+import org.sonar.server.activity.ws.ActivityMapping;
+import org.sonar.server.search.QueryContext;
+import org.sonar.server.search.Result;
+import org.sonar.server.search.ws.SearchOptions;
+import org.sonar.server.user.UserSession;
+
+import java.util.Arrays;
+import java.util.Map;
+
+public class HistoryWsAction implements ComputationWsAction, RequestHandler {
+
+ public static final String PARAM_TYPE = "type";
+
+ public static final String SEARCH_ACTION = "history";
+
+ private final ActivityService logService;
+ private final ActivityMapping mapping;
+
+ public HistoryWsAction(ActivityService logService, ActivityMapping mapping) {
+ this.logService = logService;
+ this.mapping = mapping;
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ WebService.NewAction action = controller
+ .createAction(SEARCH_ACTION)
+ .setDescription("Search for activities")
+ .setSince("5.0")
+ .setInternal(true)
+ .setHandler(this);
+
+ // Generic search parameters
+ SearchOptions.defineFieldsParam(action, mapping.supportedFields());
+ SearchOptions.definePageParams(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) {
+ checkUserRights();
+
+ ActivityQuery query = logService.newActivityQuery();
+ query.setTypes(Arrays.asList(Activity.Type.ANALYSIS_REPORT));
+
+ SearchOptions searchOptions = SearchOptions.create(request);
+ QueryContext queryContext = mapping.newQueryOptions(searchOptions);
+
+ Result<Activity> results = logService.search(query, queryContext);
+
+ JsonWriter json = response.newJsonWriter().beginObject();
+ searchOptions.writeStatistics(json, results);
+ writeReports(results, json);
+ json.endObject().close();
+ }
+
+ private void checkUserRights() {
+ UserSession.get().checkGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
+ }
+
+ private void writeReports(Result<Activity> result, JsonWriter json) {
+ json.name("reports").beginArray();
+ for (Activity reportActivity : result.getHits()) {
+ json.beginObject();
+ for (Map.Entry<String, String> detail : reportActivity.details().entrySet()) {
+ json.prop(detail.getKey(), detail.getValue());
+ }
+ json.endObject();
+ }
+ json.endArray();
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.ws;
-
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.core.computation.db.AnalysisReportDto;
-import org.sonar.server.computation.AnalysisReportQueue;
-
-import java.util.List;
-
-public class IsAnalysisReportQueueEmptyAction implements RequestHandler {
- private final AnalysisReportQueue queue;
-
- public IsAnalysisReportQueueEmptyAction(AnalysisReportQueue queue) {
- this.queue = queue;
- }
-
- void define(WebService.NewController controller) {
- controller
- .createAction("is_queue_empty")
- .setDescription("Check is the analysis report queue is empty")
- .setInternal(true)
- .setHandler(this);
- }
-
- @Override
- public void handle(Request request, Response response) throws Exception {
- List<AnalysisReportDto> reports = queue.all();
- boolean isQueueEmpty = reports.isEmpty();
-
- IOUtils.write(String.valueOf(isQueueEmpty), response.stream().output());
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.server.computation.AnalysisReportQueue;
+
+import java.util.List;
+
+public class IsQueueEmptyWsAction implements ComputationWsAction, RequestHandler {
+ private final AnalysisReportQueue queue;
+
+ public IsQueueEmptyWsAction(AnalysisReportQueue queue) {
+ this.queue = queue;
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ controller
+ .createAction("is_queue_empty")
+ .setDescription("Check if the analysis report queue is empty")
+ .setInternal(true)
+ .setHandler(this);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ List<AnalysisReportDto> reports = queue.all();
+ boolean isQueueEmpty = reports.isEmpty();
+
+ IOUtils.write(String.valueOf(isQueueEmpty), response.stream().output());
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.server.computation.AnalysisReportQueue;
+
+import java.util.List;
+
+/**
+ * @since 5.0
+ */
+public class QueueWsAction implements ComputationWsAction, RequestHandler {
+ private final AnalysisReportQueue queue;
+
+ public QueueWsAction(AnalysisReportQueue queue) {
+ this.queue = queue;
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ controller
+ .createAction("active")
+ .setDescription("List all the active analysis reports")
+ .setSince("5.0")
+ .setInternal(true)
+ .setHandler(this);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ List<AnalysisReportDto> reports = queue.all();
+
+ JsonWriter json = response.newJsonWriter().beginObject();
+ writeReports(reports, json);
+ json.endObject();
+ json.close();
+ }
+
+ private void writeReports(List<AnalysisReportDto> reports, JsonWriter json) {
+ json.name("reports").beginArray();
+ for (AnalysisReportDto report : reports) {
+ json.beginObject();
+ // TODO naming consistency -> rename id to key
+ json.prop("id", report.getId());
+ // TODO rename to projectKey
+ json.prop("project", report.getProjectKey());
+ json.prop("projectName", report.getProjectKey());
+ json.propDateTime("startedAt", report.getStartedAt());
+ json.propDateTime("finishedAt", report.getFinishedAt());
+ json.propDateTime("submittedAt", report.getCreatedAt());
+ json.prop("status", report.getStatus().toString());
+ json.endObject();
+ }
+ json.endArray();
+ }
+
+}
package org.sonar.server.computation.ws;
import javax.annotation.ParametersAreNonnullByDefault;
+
import org.sonar.server.computation.*;
import org.sonar.server.computation.db.AnalysisReportDao;
import org.sonar.server.computation.step.*;
-import org.sonar.server.computation.ws.ActiveAnalysisReportsAction;
-import org.sonar.server.computation.ws.AnalysisReportHistorySearchAction;
-import org.sonar.server.computation.ws.AnalysisReportWebService;
-import org.sonar.server.computation.ws.IsAnalysisReportQueueEmptyAction;
+import org.sonar.server.computation.ws.QueueWsAction;
+import org.sonar.server.computation.ws.HistoryWsAction;
+import org.sonar.server.computation.ws.ComputationWebService;
+import org.sonar.server.computation.ws.IsQueueEmptyWsAction;
import org.sonar.server.config.ws.PropertiesWs;
import org.sonar.server.dashboard.db.DashboardDao;
import org.sonar.server.dashboard.db.WidgetDao;
pico.addSingleton(AnalysisReportService.class);
pico.addSingleton(AnalysisReportQueue.class);
pico.addSingleton(AnalysisReportTaskLauncher.class);
- pico.addSingleton(AnalysisReportWebService.class);
- pico.addSingleton(ActiveAnalysisReportsAction.class);
- pico.addSingleton(IsAnalysisReportQueueEmptyAction.class);
- pico.addSingleton(AnalysisReportHistorySearchAction.class);
+ pico.addSingleton(ComputationWebService.class);
+ pico.addSingleton(QueueWsAction.class);
+ pico.addSingleton(IsQueueEmptyWsAction.class);
+ pico.addSingleton(HistoryWsAction.class);
pico.addSingleton(DefaultPeriodCleaner.class);
pico.addSingleton(DefaultPurgeTask.class);
pico.addSingleton(ProjectCleaner.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.server.computation.ws;
-
-import com.google.common.collect.Lists;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.core.computation.db.AnalysisReportDto;
-import org.sonar.server.computation.AnalysisReportQueue;
-import org.sonar.server.ws.WsTester;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
-
-public class ActiveAnalysisReportsActionTest {
-
- WsTester tester;
- private AnalysisReportQueue queue;
-
- @Before
- public void setup() throws Exception {
- queue = mock(AnalysisReportQueue.class);
- tester = new WsTester(new AnalysisReportWebService(new ActiveAnalysisReportsAction(queue), new IsAnalysisReportQueueEmptyAction(queue),
- mock(AnalysisReportHistorySearchAction.class)));
- }
-
- @Test
- public void list_active_reports() throws Exception {
- AnalysisReportDto report = AnalysisReportDto
- .newForTests(1L)
- .setProjectKey("project-name")
- .setStatus(PENDING)
- .setData(null)
- .setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
- .setStartedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
- .setFinishedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"));
- List<AnalysisReportDto> reports = Lists.newArrayList(report);
- when(queue.all()).thenReturn(reports);
-
- WsTester.TestRequest request = tester.newGetRequest(AnalysisReportWebService.API_ENDPOINT, "active");
- request.execute().assertJson(getClass(), "list_active_reports.json", false);
- }
-
- @Test
- public void define() throws Exception {
- assertThat(tester.controller(AnalysisReportWebService.API_ENDPOINT).action("active")).isNotNull();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.ws;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.web.UserRole;
-import org.sonar.core.activity.Activity;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.core.computation.db.AnalysisReportDto;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.permission.PermissionFacade;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.user.UserDto;
-import org.sonar.server.activity.ActivityService;
-import org.sonar.server.component.ComponentTesting;
-import org.sonar.server.computation.AnalysisReportLog;
-import org.sonar.server.computation.AnalysisReportQueue;
-import org.sonar.server.computation.ComputationService;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.tester.ServerTester;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.ws.WsTester;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class AnalysisReportHistorySearchActionMediumTest {
- private static final String DEFAULT_PROJECT_KEY = "DefaultProjectKey";
- private static final String DEFAULT_PROJECT_NAME = "DefaultProjectName";
- private static final String DEFAULT_REPORT_DATA = "default-project";
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- private DbClient dbClient;
- private DbSession session;
- private WsTester wsTester;
- private AnalysisReportQueue queue;
- private MockUserSession userSession;
- private ComputationService computationService;
- private ActivityService activityService;
-
- @Before
- public void before() {
- tester.clearDbAndIndexes();
- dbClient = tester.get(DbClient.class);
- wsTester = tester.get(WsTester.class);
- session = dbClient.openSession(false);
- queue = tester.get(AnalysisReportQueue.class);
- activityService = tester.get(ActivityService.class);
-
- UserDto connectedUser = new UserDto().setLogin("gandalf").setName("Gandalf");
- dbClient.userDao().insert(session, connectedUser);
-
- userSession = MockUserSession.set()
- .setLogin(connectedUser.getLogin())
- .setUserId(connectedUser.getId().intValue())
- .setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
- }
-
- @After
- public void after() {
- MyBatis.closeQuietly(session);
- }
-
- @Test
- public void add_and_try_to_retrieve_activities() throws Exception {
- insertPermissionsForProject(DEFAULT_PROJECT_KEY);
- queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
- queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
- queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
-
- List<AnalysisReportDto> reports = queue.all();
- ComponentDto project = ComponentTesting.newProjectDto()
- .setName(DEFAULT_PROJECT_NAME)
- .setKey(DEFAULT_PROJECT_KEY);
- for (AnalysisReportDto report : reports) {
- report.succeed();
- activityService.write(session, Activity.Type.ANALYSIS_REPORT, new AnalysisReportLog(report, project));
- }
-
- session.commit();
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
-
- WsTester.TestRequest request = wsTester.newGetRequest(AnalysisReportWebService.API_ENDPOINT, AnalysisReportHistorySearchAction.SEARCH_ACTION);
- WsTester.Result result = request.execute();
-
- assertThat(result).isNotNull();
- result.assertJson(getClass(), "list_history_reports.json", false);
- }
-
- private ComponentDto insertPermissionsForProject(String projectKey) {
- ComponentDto project = new ComponentDto().setKey(projectKey).setId(1L);
- dbClient.componentDao().insert(session, project);
-
- tester.get(PermissionFacade.class).insertGroupPermission(project.getId(), DefaultGroups.ANYONE, UserRole.USER, session);
- userSession.addProjectPermissions(UserRole.ADMIN, project.key());
- userSession.addProjectPermissions(UserRole.USER, project.key());
-
- session.commit();
-
- return project;
- }
-
- @Test(expected = ForbiddenException.class)
- public void user_rights_is_not_enough_throw_ForbiddenException() throws Exception {
- insertPermissionsForProject(DEFAULT_PROJECT_KEY);
- queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
-
- AnalysisReportDto report = queue.all().get(0);
- report.succeed();
- queue.remove(report);
- userSession.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
-
- WsTester.TestRequest sut = wsTester.newGetRequest(AnalysisReportWebService.API_ENDPOINT, AnalysisReportHistorySearchAction.SEARCH_ACTION);
- sut.execute();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.ws;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.activity.ActivityService;
-import org.sonar.server.activity.ws.ActivityMapping;
-import org.sonar.server.computation.AnalysisReportQueue;
-import org.sonar.server.ws.WsTester;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class AnalysisReportWebServiceTest {
-
- private WsTester tester;
-
- @Before
- public void setUp() throws Exception {
- this.tester = new WsTester(new AnalysisReportWebService(new ActiveAnalysisReportsAction(mock(AnalysisReportQueue.class)), new IsAnalysisReportQueueEmptyAction(
- mock(AnalysisReportQueue.class)), new AnalysisReportHistorySearchAction(mock(ActivityService.class), mock(ActivityMapping.class))));
- }
-
- @Test
- public void define() throws Exception {
- WebService.Controller controller = tester.controller(AnalysisReportWebService.API_ENDPOINT);
-
- assertThat(controller).isNotNull();
- assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(3);
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.WebService;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class ComputationWebServiceTest {
+
+ @Test
+ public void define() throws Exception {
+ ComputationWebService ws = new ComputationWebService(new ComputationWsAction() {
+ @Override
+ public void define(WebService.NewController controller) {
+ WebService.NewAction upload = controller.createAction("upload");
+ upload.setHandler(mock(RequestHandler.class));
+ }
+ });
+ WebService.Context context = new WebService.Context();
+ ws.define(context);
+
+ WebService.Controller controller = context.controller("api/analysis_reports");
+ assertThat(controller).isNotNull();
+ assertThat(controller.description()).isNotEmpty();
+ assertThat(controller.actions()).hasSize(1);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.security.DefaultGroups;
+import org.sonar.api.web.UserRole;
+import org.sonar.core.activity.Activity;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.permission.PermissionFacade;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.user.UserDto;
+import org.sonar.server.activity.ActivityService;
+import org.sonar.server.component.ComponentTesting;
+import org.sonar.server.computation.AnalysisReportLog;
+import org.sonar.server.computation.AnalysisReportQueue;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.tester.ServerTester;
+import org.sonar.server.user.MockUserSession;
+import org.sonar.server.ws.WsTester;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+/**
+ * TODO replace this medium test by a small test
+ */
+public class HistoryWsActionMediumTest {
+ private static final String DEFAULT_PROJECT_KEY = "DefaultProjectKey";
+ private static final String DEFAULT_PROJECT_NAME = "DefaultProjectName";
+ private static final String DEFAULT_REPORT_DATA = "default-project";
+
+ @ClassRule
+ public static ServerTester tester = new ServerTester();
+
+ private DbClient dbClient;
+ private DbSession session;
+ private WsTester wsTester;
+ private AnalysisReportQueue queue;
+ private MockUserSession userSession;
+ private ActivityService activityService;
+
+ @Before
+ public void before() {
+ tester.clearDbAndIndexes();
+ dbClient = tester.get(DbClient.class);
+ wsTester = tester.get(WsTester.class);
+ session = dbClient.openSession(false);
+ queue = tester.get(AnalysisReportQueue.class);
+ activityService = tester.get(ActivityService.class);
+
+ UserDto connectedUser = new UserDto().setLogin("gandalf").setName("Gandalf");
+ dbClient.userDao().insert(session, connectedUser);
+
+ userSession = MockUserSession.set()
+ .setLogin(connectedUser.getLogin())
+ .setUserId(connectedUser.getId().intValue())
+ .setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ }
+
+ @After
+ public void after() {
+ MyBatis.closeQuietly(session);
+ }
+
+ @Test
+ public void add_and_try_to_retrieve_activities() throws Exception {
+ insertPermissionsForProject(DEFAULT_PROJECT_KEY);
+ queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
+ queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
+ queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
+
+ List<AnalysisReportDto> reports = queue.all();
+ ComponentDto project = ComponentTesting.newProjectDto()
+ .setName(DEFAULT_PROJECT_NAME)
+ .setKey(DEFAULT_PROJECT_KEY);
+ for (AnalysisReportDto report : reports) {
+ report.succeed();
+ activityService.write(session, Activity.Type.ANALYSIS_REPORT, new AnalysisReportLog(report, project));
+ }
+
+ session.commit();
+ userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+
+ WsTester.TestRequest request = wsTester.newGetRequest(ComputationWebService.API_ENDPOINT, HistoryWsAction.SEARCH_ACTION);
+ WsTester.Result result = request.execute();
+
+ assertThat(result).isNotNull();
+ result.assertJson(getClass(), "list_history_reports.json", false);
+ }
+
+ private ComponentDto insertPermissionsForProject(String projectKey) {
+ ComponentDto project = new ComponentDto().setKey(projectKey).setId(1L);
+ dbClient.componentDao().insert(session, project);
+
+ tester.get(PermissionFacade.class).insertGroupPermission(project.getId(), DefaultGroups.ANYONE, UserRole.USER, session);
+ userSession.addProjectPermissions(UserRole.ADMIN, project.key());
+ userSession.addProjectPermissions(UserRole.USER, project.key());
+
+ session.commit();
+
+ return project;
+ }
+
+ @Test(expected = ForbiddenException.class)
+ public void user_rights_is_not_enough_throw_ForbiddenException() throws Exception {
+ insertPermissionsForProject(DEFAULT_PROJECT_KEY);
+ queue.add(DEFAULT_PROJECT_KEY, 123L, IOUtils.toInputStream(DEFAULT_REPORT_DATA));
+
+ AnalysisReportDto report = queue.all().get(0);
+ report.succeed();
+ queue.remove(report);
+ userSession.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+
+ WsTester.TestRequest sut = wsTester.newGetRequest(ComputationWebService.API_ENDPOINT, HistoryWsAction.SEARCH_ACTION);
+ sut.execute();
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.ws;
-
-import com.google.common.collect.Lists;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.core.computation.db.AnalysisReportDto;
-import org.sonar.server.computation.AnalysisReportQueue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class IsAnalysisReportQueueEmptyActionTest {
-
- IsAnalysisReportQueueEmptyAction sut;
- AnalysisReportQueue queue;
- Response response;
-
- @Before
- public void before() throws Exception {
- queue = mock(AnalysisReportQueue.class);
- sut = new IsAnalysisReportQueueEmptyAction(queue);
-
- response = mock(Response.class);
- when(response.stream()).thenReturn(new FakeStream());
- }
-
- @Test
- public void send_true_when_queue_is_empty() throws Exception {
- when(queue.all()).thenReturn(new ArrayList<AnalysisReportDto>());
-
- sut.handle(mock(Request.class), response);
-
- assertThat(response.stream().toString()).isEqualTo("true");
- }
-
- @Test
- public void send_false_when_queue_is_not_empty() throws Exception {
- when(queue.all()).thenReturn(Lists.newArrayList(AnalysisReportDto.newForTests(1L)));
-
- sut.handle(mock(Request.class), response);
-
- assertThat(response.stream().toString()).isEqualTo("false");
- }
-
- private class FakeStream implements Response.Stream {
- private ByteArrayOutputStream stream;
-
- private FakeStream() {
- this.stream = new ByteArrayOutputStream();
- }
-
- public String toString() {
- return stream.toString();
- }
-
- @Override
- public Response.Stream setMediaType(String s) {
- return null;
- }
-
- @Override
- public Response.Stream setStatus(int httpStatus) {
- return null;
- }
-
- @Override
- public OutputStream output() {
- return stream;
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import com.google.common.collect.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.server.computation.AnalysisReportQueue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class IsQueueEmptyWsActionTest {
+
+ IsQueueEmptyWsAction sut;
+ AnalysisReportQueue queue;
+ Response response;
+
+ @Before
+ public void before() throws Exception {
+ queue = mock(AnalysisReportQueue.class);
+ sut = new IsQueueEmptyWsAction(queue);
+
+ response = mock(Response.class);
+ when(response.stream()).thenReturn(new FakeStream());
+ }
+
+ @Test
+ public void send_true_when_queue_is_empty() throws Exception {
+ when(queue.all()).thenReturn(new ArrayList<AnalysisReportDto>());
+
+ sut.handle(mock(Request.class), response);
+
+ assertThat(response.stream().toString()).isEqualTo("true");
+ }
+
+ @Test
+ public void send_false_when_queue_is_not_empty() throws Exception {
+ when(queue.all()).thenReturn(Lists.newArrayList(AnalysisReportDto.newForTests(1L)));
+
+ sut.handle(mock(Request.class), response);
+
+ assertThat(response.stream().toString()).isEqualTo("false");
+ }
+
+ private class FakeStream implements Response.Stream {
+ private ByteArrayOutputStream stream;
+
+ private FakeStream() {
+ this.stream = new ByteArrayOutputStream();
+ }
+
+ public String toString() {
+ return stream.toString();
+ }
+
+ @Override
+ public Response.Stream setMediaType(String s) {
+ return null;
+ }
+
+ @Override
+ public Response.Stream setStatus(int httpStatus) {
+ return null;
+ }
+
+ @Override
+ public OutputStream output() {
+ return stream;
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.ws;
+
+import com.google.common.collect.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.server.computation.AnalysisReportQueue;
+import org.sonar.server.ws.WsTester;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
+
+public class QueueWsActionTest {
+
+ WsTester tester;
+ private AnalysisReportQueue queue;
+
+ @Before
+ public void setup() throws Exception {
+ queue = mock(AnalysisReportQueue.class);
+ tester = new WsTester(new ComputationWebService(new QueueWsAction(queue)));
+ }
+
+ @Test
+ public void list_active_reports() throws Exception {
+ AnalysisReportDto report = AnalysisReportDto
+ .newForTests(1L)
+ .setProjectKey("project-name")
+ .setStatus(PENDING)
+ .setData(null)
+ .setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
+ .setStartedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
+ .setFinishedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"));
+ List<AnalysisReportDto> reports = Lists.newArrayList(report);
+ when(queue.all()).thenReturn(reports);
+
+ WsTester.TestRequest request = tester.newGetRequest(ComputationWebService.API_ENDPOINT, "active");
+ request.execute().assertJson(getClass(), "list_active_reports.json", false);
+ }
+
+ @Test
+ public void define() throws Exception {
+ assertThat(tester.controller(ComputationWebService.API_ENDPOINT).action("active")).isNotNull();
+ }
+}
+++ /dev/null
-{
- "reports": [
- {
- "id": 1,
- "status": "PENDING",
- "projectName": "project-name",
- "project": "project-name",
- "submittedAt": "2014-10-13T00:00:00+0200",
- "startedAt": "2014-10-13T00:00:00+0200",
- "finishedAt": "2014-10-13T00:00:00+0200"
- }
- ]
-}
\ No newline at end of file
+++ /dev/null
-{
- "reports": [
- {
- "status": "SUCCESS",
- "projectName": "DefaultProjectName",
- "projectKey": "DefaultProjectKey"
- },
- {
- "status": "SUCCESS",
- "projectName": "DefaultProjectName",
- "projectKey": "DefaultProjectKey"
- },
- {
- "status": "SUCCESS",
- "projectName": "DefaultProjectName",
- "projectKey": "DefaultProjectKey"
- }
- ]
-}
\ No newline at end of file
--- /dev/null
+{
+ "reports": [
+ {
+ "status": "SUCCESS",
+ "projectName": "DefaultProjectName",
+ "projectKey": "DefaultProjectKey"
+ },
+ {
+ "status": "SUCCESS",
+ "projectName": "DefaultProjectName",
+ "projectKey": "DefaultProjectKey"
+ },
+ {
+ "status": "SUCCESS",
+ "projectName": "DefaultProjectName",
+ "projectKey": "DefaultProjectKey"
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+{
+ "reports": [
+ {
+ "id": 1,
+ "status": "PENDING",
+ "projectName": "project-name",
+ "project": "project-name",
+ "submittedAt": "2014-10-13T00:00:00+0200",
+ "startedAt": "2014-10-13T00:00:00+0200",
+ "finishedAt": "2014-10-13T00:00:00+0200"
+ }
+ ]
+}
\ No newline at end of file