aboutsummaryrefslogtreecommitdiffstats
path: root/it/it-tests/src/test/java/updatecenter/UpdateCenterTest.java
blob: 790883b9e34e8c27f54699ade30373906203117a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (C) 2009-2014 SonarSource SA
 * All rights reserved
 * mailto:contact AT sonarsource DOT com
 */
package updatecenter;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.selenium.Selenese;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.services.Plugin;
import org.sonar.wsclient.services.UpdateCenterQuery;
import util.selenium.SeleneseTest;

import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.pluginArtifact;

public class UpdateCenterTest {

  @ClassRule
  public static Orchestrator orchestrator = Orchestrator.builderEnv()
    .setServerProperty("sonar.updatecenter.url", UpdateCenterTest.class.getResource("UpdateCenterTest/update-center.properties").toString())
    .addPlugin(pluginArtifact("sonar-fake-plugin"))
    .build();

  @Test
  public void web_service_should_return_installed_plugins() {
    List<Plugin> plugins = orchestrator.getServer().getAdminWsClient().findAll(UpdateCenterQuery.createForInstalledPlugins());
    assertThat(plugins.size()).isGreaterThan(0);

    Plugin installedPlugin = findPlugin(plugins, "fake");

    assertThat(installedPlugin).isNotNull();
    assertThat(installedPlugin.getName()).isEqualTo("Plugins :: Fake");
    assertThat(installedPlugin.getVersion()).isEqualTo("1.0-SNAPSHOT");
  }

  @Test
  public void test_console() {
    Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("server-update-center",
      "/updatecenter/installed-plugins.html")
      .build();
    new SeleneseTest(selenese).runOn(orchestrator);
  }

  private Plugin findPlugin(List<Plugin> plugins, String pluginKey) {
    for (Plugin plugin : plugins) {
      if (StringUtils.equals(pluginKey, plugin.getKey())) {
        return plugin;
      }
    }
    return null;
  }

}