summaryrefslogtreecommitdiffstats
path: root/it/it-tests/src/test/java/administation/suite/PropertySetsTest.java
blob: 6b1b7f938308563605455ebfae88e0d46a24640f (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * 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 administation.suite;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.selenium.Selenese;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.services.PropertyQuery;
import org.sonar.wsclient.services.PropertyUpdateQuery;

import static org.assertj.core.api.Assertions.assertThat;

public class PropertySetsTest {

  @ClassRule
  public static Orchestrator orchestrator = AdministrationTestSuite.ORCHESTRATOR;

  @Test
  public void should_support_property_sets() {
    Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("property-sets",
      "/administration/property-sets/create.html",
      "/administration/property-sets/delete.html",
      "/administration/property-sets/reference.html",
      "/administration/property-sets/all_types.html"
      ).build();
    orchestrator.executeSelenese(selenese);

    // SSF-25 Check that the password has well be setted as now it does not appears in the html source code
    String sonarDemoValue = getProperty("sonar.demo");
    assertThat(getProperty("sonar.demo." + sonarDemoValue + ".password")).isEqualTo("abcde");
  }

  @Test
  public void should_edit_properties() {
    setProperty("sonar.test.jira.servers", "jira1,jira2");
    setProperty("sonar.test.jira.servers.jira1.url", "http://jira1");
    setProperty("sonar.test.jira.servers.jira2.url", "http://jira2");
    setProperty("sonar.test.jira.servers.jira1.port", "12345");
    setProperty("sonar.test.jira.servers.jira2.port", "66666");

    assertThat(getProperty("sonar.test.jira.servers")).isEqualTo("jira1,jira2");
    assertThat(getProperty("sonar.test.jira.servers.jira1.url")).isEqualTo("http://jira1");
    assertThat(getProperty("sonar.test.jira.servers.jira2.url")).isEqualTo("http://jira2");
    assertThat(getProperty("sonar.test.jira.servers.jira1.port")).isEqualTo("12345");
    assertThat(getProperty("sonar.test.jira.servers.jira2.port")).isEqualTo("66666");
  }

  @Test
  public void should_support_property_sets_with_auto_generated_keys() {
    orchestrator.executeSelenese(Selenese.builder().setHtmlTestsInClasspath("create-auto-generated",
      "/administration/auto-generated/create.html"
      ).build());

    String[] keys = getProperty("sonar.autogenerated").split("[,]");
    assertThat(getProperty("sonar.autogenerated." + keys[0] + ".value")).isEqualTo("FIRST");
    assertThat(getProperty("sonar.autogenerated." + keys[1] + ".value")).isEqualTo("SECOND");
    assertThat(getProperty("sonar.autogenerated." + keys[2] + ".value")).isEqualTo("THIRD");

    orchestrator.executeSelenese(Selenese.builder().setHtmlTestsInClasspath("update-auto-generated",
      "/administration/auto-generated/update.html"
      ).build());

    keys = getProperty("sonar.autogenerated").split("[,]");
    assertThat(getProperty("sonar.autogenerated." + keys[0] + ".value")).isEqualTo("FIRST");
    assertThat(getProperty("sonar.autogenerated." + keys[1] + ".value")).isEqualTo("THIRD");
  }

  static void setProperty(String key, String value) {
    orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery(key, value));
  }

  static String getProperty(String key) {
    return orchestrator.getServer().getAdminWsClient().find(new PropertyQuery().setKey(key)).getValue();
  }
}