3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact 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;
23 import org.junit.Before;
24 import org.sonar.api.server.ws.Request;
25 import org.sonar.api.utils.DateUtils;
26 import org.sonar.server.plugins.UpdateCenterMatrixFactory;
27 import org.sonar.server.ws.WsTester;
28 import org.sonar.updatecenter.common.Plugin;
29 import org.sonar.updatecenter.common.PluginUpdate;
30 import org.sonar.updatecenter.common.Release;
31 import org.sonar.updatecenter.common.UpdateCenter;
32 import org.sonar.updatecenter.common.Version;
36 import static org.mockito.Matchers.anyBoolean;
37 import static org.mockito.Mockito.mock;
38 import static org.mockito.Mockito.when;
39 import static org.sonar.updatecenter.common.PluginUpdate.Status.COMPATIBLE;
40 import static org.sonar.updatecenter.common.Version.create;
42 public abstract class AbstractUpdateCenterBasedPluginsWsActionTest {
43 protected static final String DUMMY_CONTROLLER_KEY = "dummy";
44 protected static final String JSON_EMPTY_PLUGIN_LIST =
46 " \"plugins\":" + "[]" +
48 protected static final Plugin PLUGIN_1 = new Plugin("p_key_1").setName("p_name_1");
49 protected static final Plugin PLUGIN_2 = new Plugin("p_key_2").setName("p_name_2").setDescription("p_desc_2");
51 protected UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
52 protected UpdateCenter updateCenter = mock(UpdateCenter.class);
53 protected Request request = mock(Request.class);
54 protected WsTester.TestResponse response = new WsTester.TestResponse();
56 protected static Release release(Plugin plugin1, String version) {
57 return new Release(plugin1, create(version));
60 protected static PluginUpdate pluginUpdate(Release pluginRelease, PluginUpdate.Status compatible) {
61 return PluginUpdate.createWithStatus(pluginRelease, compatible);
64 protected static URL resource(String s) {
65 Class<AvailableActionTest> clazz = AvailableActionTest.class;
66 return clazz.getResource(clazz.getSimpleName() + "/" + s);
69 protected static PluginUpdate pluginUpdate(String key, String name) {
70 return PluginUpdate.createWithStatus(
71 new Release(new Plugin(key).setName(name), Version.create("1.0")),
77 public void wireMocksTogether() {
78 when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter));
79 when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200"));