3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.plugins.ws;
22 import com.google.common.base.Optional;
24 import org.junit.Before;
25 import org.sonar.api.server.ws.Request;
26 import org.sonar.api.utils.DateUtils;
27 import org.sonar.server.plugins.UpdateCenterMatrixFactory;
28 import org.sonar.server.ws.WsTester;
29 import org.sonar.updatecenter.common.Plugin;
30 import org.sonar.updatecenter.common.PluginUpdate;
31 import org.sonar.updatecenter.common.Release;
32 import org.sonar.updatecenter.common.UpdateCenter;
33 import org.sonar.updatecenter.common.Version;
35 import static org.mockito.Matchers.anyBoolean;
36 import static org.mockito.Mockito.mock;
37 import static org.mockito.Mockito.when;
38 import static org.sonar.updatecenter.common.PluginUpdate.Status.COMPATIBLE;
39 import static org.sonar.updatecenter.common.Version.create;
41 public abstract class AbstractUpdateCenterBasedPluginsWsActionTest {
42 protected static final String DUMMY_CONTROLLER_KEY = "dummy";
43 protected static final String JSON_EMPTY_PLUGIN_LIST =
45 " \"plugins\":" + "[]" +
47 protected static final Plugin PLUGIN_1 = Plugin.factory("pkey1").setName("p_name_1");
48 protected static final Plugin PLUGIN_2 = Plugin.factory("pkey2").setName("p_name_2").setDescription("p_desc_2");
50 protected UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
51 protected UpdateCenter updateCenter = mock(UpdateCenter.class);
52 protected Request request = mock(Request.class);
53 protected WsTester.TestResponse response = new WsTester.TestResponse();
55 protected static Release release(Plugin plugin1, String version) {
56 return new Release(plugin1, create(version));
59 protected static PluginUpdate pluginUpdate(Release pluginRelease, PluginUpdate.Status compatible) {
60 return PluginUpdate.createWithStatus(pluginRelease, compatible);
63 protected static URL resource(String s) {
64 Class<AvailableActionTest> clazz = AvailableActionTest.class;
65 return clazz.getResource(clazz.getSimpleName() + "/" + s);
68 protected static PluginUpdate pluginUpdate(String key, String name) {
69 return PluginUpdate.createWithStatus(
70 new Release(Plugin.factory(key).setName(name), Version.create("1.0")),
76 public void wireMocksTogether() {
77 when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter));
78 when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200"));