</properties>
<dependencies>
+ <dependency>
+ <groupId>org.sonarsource.sonarqube</groupId>
+ <artifactId>sonar-ws</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Helper to directly access Elasticsearch. It requires the HTTP port
+ * to be open.
+ */
+public class Elasticsearch {
+
+ private final int httpPort;
+
+ public Elasticsearch(int httpPort) {
+ this.httpPort = httpPort;
+ }
+
+ /**
+ * Forbid indexing requests on the specified index. Index becomes read-only.
+ */
+ public void lockWrites(String index) throws IOException {
+ putIndexSetting(httpPort, index, "blocks.write", "true");
+ }
+
+ /**
+ * Enable indexing requests on the specified index.
+ * @see #lockWrites(String)
+ */
+ public void unlockWrites(String index) throws IOException {
+ putIndexSetting(httpPort, index, "blocks.write", "false");
+ }
+
+ public void makeYellow() throws IOException {
+ putIndexSetting(httpPort, "issues", "number_of_replicas", "5");
+ }
+
+ public void makeGreen() throws IOException {
+ putIndexSetting(httpPort, "issues", "number_of_replicas", "0");
+ }
+
+ private static void putIndexSetting(int searchHttpPort, String index, String key, String value) throws IOException {
+ Request.Builder request = new Request.Builder()
+ .url(baseUrl(searchHttpPort) + index + "/_settings")
+ .put(RequestBody.create(MediaType.parse("application/json"), "{" +
+ " \"index\" : {" +
+ " \"" + key + "\" : \"" + value + "\"" +
+ " }" +
+ "}"));
+ OkHttpClient okClient = new OkHttpClient.Builder().build();
+ Response response = okClient.newCall(request.build()).execute();
+ assertThat(response.isSuccessful()).isTrue();
+ }
+
+ private static String baseUrl(int searchHttpPort) {
+ return "http://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + searchHttpPort + "/";
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsUserGroups;
+import org.sonarqube.ws.WsUsers;
+import org.sonarqube.ws.WsUsers.GroupsWsResponse.Group;
+import org.sonarqube.ws.client.user.GroupsRequest;
+import org.sonarqube.ws.client.usergroup.AddUserWsRequest;
+import org.sonarqube.ws.client.usergroup.CreateWsRequest;
+
+import static java.util.Arrays.stream;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GroupTester {
+
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
+
+ private final TesterSession session;
+
+ GroupTester(TesterSession session) {
+ this.session = session;
+ }
+
+ @SafeVarargs
+ public final WsUserGroups.Group generate(@Nullable Organizations.Organization organization, Consumer<CreateWsRequest.Builder>... populators) {
+ int id = ID_GENERATOR.getAndIncrement();
+ CreateWsRequest.Builder request = CreateWsRequest.builder()
+ .setName("Group" + id)
+ .setDescription("Description " + id)
+ .setOrganization(organization != null ? organization.getKey() : null);
+ stream(populators).forEach(p -> p.accept(request));
+ return session.wsClient().userGroups().create(request.build()).getGroup();
+ }
+
+ public List<Group> getGroupsOfUser(@Nullable Organizations.Organization organization, String userLogin) {
+ GroupsRequest request = GroupsRequest.builder()
+ .setOrganization(organization != null ? organization.getKey() : null)
+ .setLogin(userLogin)
+ .build();
+ WsUsers.GroupsWsResponse response = session.users().service().groups(request);
+ return response.getGroupsList();
+ }
+
+ public GroupTester addMemberToGroups(Organizations.Organization organization, String userLogin, String... groups) {
+ for (String group : groups) {
+ AddUserWsRequest request = AddUserWsRequest.builder()
+ .setLogin(userLogin)
+ .setOrganization(organization.getKey())
+ .setName(group)
+ .build();
+ session.wsClient().userGroups().addUser(request);
+ }
+ return this;
+ }
+
+ public GroupTester assertThatUserIsMemberOf(@Nullable Organizations.Organization organization, String userLogin, String expectedGroup, String... otherExpectedGroups) {
+ List<String> groups = getGroupsOfUser(organization, userLogin)
+ .stream()
+ .map(Group::getName)
+ .collect(Collectors.toList());
+
+ assertThat(groups).contains(expectedGroup);
+ if (otherExpectedGroups.length > 0) {
+ assertThat(groups).contains(otherExpectedGroups);
+ }
+ return this;
+ }
+
+ public GroupTester assertThatUserIsOnlyMemberOf(@Nullable Organizations.Organization organization, String userLogin, String... expectedGroups) {
+ Set<String> groups = getGroupsOfUser(organization, userLogin)
+ .stream()
+ .map(Group::getName)
+ .collect(Collectors.toSet());
+ assertThat(groups).containsExactlyInAnyOrder(expectedGroups);
+ return this;
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.apache.commons.io.input.Tailer;
+import org.apache.commons.io.input.TailerListenerAdapter;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Watch log files, usually server logs (see Orchestrator.getServer().get*Logs()).
+ * This class allows to not load the full content in memory.
+ */
+public class LogsTailer implements AutoCloseable {
+
+ private final List<Tailer> tailers;
+ private final LogConsumer logConsumer;
+
+ private LogsTailer(Builder builder) {
+ logConsumer = new LogConsumer(builder.consumers);
+ tailers = builder.files.stream()
+ .map(file -> Tailer.create(file, logConsumer, 500))
+ .collect(Collectors.toList());
+ }
+
+ public Watch watch(String text) {
+ return new Watch(text);
+ }
+
+ @Override
+ public void close() {
+ for (Tailer tailer : tailers) {
+ tailer.stop();
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private final List<File> files = new ArrayList<>();
+ private final List<Consumer<String>> consumers = new ArrayList<>();
+
+ public Builder addFile(File file) {
+ this.files.add(file);
+ return this;
+ }
+
+ public Builder addFiles(File file, File... otherFiles) {
+ this.files.add(file);
+ Collections.addAll(this.files, otherFiles);
+ return this;
+ }
+
+ /**
+ * Adds a consumer that is called on each new line appended
+ * to the files.
+ * Note that the consumer {@link Content} allows to keep
+ * all past logs in memory.
+ */
+ public Builder addConsumer(Consumer<String> consumer) {
+ this.consumers.add(consumer);
+ return this;
+ }
+
+ public LogsTailer build() {
+ return new LogsTailer(this);
+ }
+ }
+
+ private static class LogConsumer extends TailerListenerAdapter {
+ private final List<Consumer<String>> consumers = Collections.synchronizedList(new ArrayList<>());
+
+ private LogConsumer(List<Consumer<String>> consumers) {
+ this.consumers.addAll(consumers);
+ }
+
+ @Override
+ public void handle(String line) {
+ synchronized (consumers) {
+ for (Consumer<String> consumer : consumers) {
+ try {
+ consumer.accept(line);
+ } catch (Exception e) {
+ // do not prevent other consumers to handle the log
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void add(Consumer<String> consumer) {
+ this.consumers.add(consumer);
+ }
+
+ public void remove(Consumer<String> consumer) {
+ this.consumers.remove(consumer);
+ }
+ }
+
+ public class Watch implements AutoCloseable {
+ private final String expectedText;
+ private final CountDownLatch foundSignal = new CountDownLatch(1);
+ private String log = null;
+ private final Consumer<String> consumer;
+
+ private Watch(String expectedText) {
+ this.expectedText = requireNonNull(expectedText);
+ this.consumer = l -> {
+ if (l.contains(this.expectedText)) {
+ this.log = l;
+ foundSignal.countDown();
+ }
+ };
+ logConsumer.add(consumer);
+ }
+
+ /**
+ * Blocks until the expected log appears in watched files.
+ */
+ public void waitForLog() throws InterruptedException {
+ foundSignal.await();
+ }
+
+ /**
+ * Blocks until the expected log appears in watched files with timeout
+ */
+ public void waitForLog(long timeout, TimeUnit timeUnit) throws InterruptedException {
+ foundSignal.await(timeout, timeUnit);
+ }
+
+ public Optional<String> getLog() {
+ return Optional.ofNullable(log);
+ }
+
+ @Override
+ public void close() {
+ logConsumer.remove(consumer);
+ }
+ }
+
+ public static class Content implements Consumer<String> {
+ private final List<String> lines = Collections.synchronizedList(new ArrayList<>());
+
+ @Override
+ public void accept(String s) {
+ lines.add(s);
+ }
+
+ public boolean hasText(String text) {
+ synchronized (lines) {
+ for (String line : lines) {
+ if (line.contains(text)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public boolean hasLineMatching(Pattern pattern) {
+ synchronized (lines) {
+ for (String line : lines) {
+ if (pattern.matcher(line).matches()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.assertj.core.api.Assertions;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsUsers;
+import org.sonarqube.ws.client.HttpException;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.organization.CreateWsRequest;
+import org.sonarqube.ws.client.organization.OrganizationService;
+import org.sonarqube.ws.client.organization.SearchMembersWsRequest;
+import org.sonarqube.ws.client.organization.SearchWsRequest;
+import org.sonarqube.ws.client.user.GroupsRequest;
+
+import static java.util.Arrays.stream;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class OrganizationTester {
+
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
+
+ private final TesterSession session;
+
+ OrganizationTester(TesterSession session) {
+ this.session = session;
+ }
+
+ void enableSupport() {
+ session.wsClient().wsConnector().call(new PostRequest("api/organizations/enable_support"));
+ }
+
+ void deleteNonGuardedOrganizations() {
+ service().search(SearchWsRequest.builder().build()).getOrganizationsList()
+ .stream()
+ .filter(o -> !o.getKey().equals("default-organization"))
+ .forEach(organization -> service().delete(organization.getKey()));
+ }
+
+ @SafeVarargs
+ public final Organizations.Organization generate(Consumer<CreateWsRequest.Builder>... populators) {
+ int id = ID_GENERATOR.getAndIncrement();
+ CreateWsRequest.Builder request = new CreateWsRequest.Builder()
+ .setKey("org" + id)
+ .setName("Org " + id)
+ .setDescription("Description " + id)
+ .setUrl("http://test" + id);
+ stream(populators).forEach(p -> p.accept(request));
+ return service().create(request.build()).getOrganization();
+ }
+
+ public OrganizationTester addMember(Organizations.Organization organization, WsUsers.CreateWsResponse.User user) {
+ service().addMember(organization.getKey(), user.getLogin());
+ return this;
+ }
+
+ public Organizations.Organization getDefaultOrganization() {
+ return service().search(SearchWsRequest.builder().build()).getOrganizationsList()
+ .stream()
+ .filter(o -> o.getKey().equals("default-organization"))
+ .findFirst().orElseThrow(() -> new IllegalStateException("Can't find default organization"));
+ }
+
+ public OrganizationTester assertThatOrganizationDoesNotExist(String organizationKey) {
+ SearchWsRequest request = new SearchWsRequest.Builder().setOrganizations(organizationKey).build();
+ Organizations.SearchWsResponse searchWsResponse = service().search(request);
+ Assertions.assertThat(searchWsResponse.getOrganizationsList()).isEmpty();
+ return this;
+ }
+
+ public OrganizationTester assertThatMemberOf(Organizations.Organization organization, WsUsers.CreateWsResponse.User user) {
+ return assertThatMemberOf(organization, user.getLogin());
+ }
+
+ public OrganizationTester assertThatMemberOf(Organizations.Organization organization, String userLogin) {
+ verifyOrganizationMembership(organization, userLogin, true);
+ verifyMembersGroupMembership(userLogin, organization, true);
+ return this;
+ }
+
+ public OrganizationTester assertThatNotMemberOf(Organizations.Organization organization, WsUsers.CreateWsResponse.User user) {
+ return assertThatNotMemberOf(organization, user.getLogin());
+ }
+
+ public OrganizationTester assertThatNotMemberOf(Organizations.Organization organization, String userLogin) {
+ verifyOrganizationMembership(organization, userLogin, false);
+ try {
+ verifyMembersGroupMembership(userLogin, organization, false);
+ } catch (HttpException e) {
+ // do not fail if user does not exist
+ if (e.code() != 404) {
+ throw e;
+ }
+ }
+ return this;
+ }
+
+ private void verifyOrganizationMembership(@Nullable Organizations.Organization organization, String userLogin, boolean isMember) {
+ List<Organizations.User> users = service().searchMembers(new SearchMembersWsRequest()
+ .setQuery(userLogin)
+ .setSelected("selected")
+ .setOrganization(organization != null ? organization.getKey() : null))
+ .getUsersList();
+ Assertions.assertThat(users).hasSize(isMember ? 1 : 0);
+ }
+
+ private void verifyMembersGroupMembership(String userLogin, @Nullable Organizations.Organization organization, boolean isMember) {
+ List<WsUsers.GroupsWsResponse.Group> groups = session.wsClient().users().groups(GroupsRequest.builder()
+ .setLogin(userLogin)
+ .setOrganization(organization != null ? organization.getKey() : null)
+ .setQuery("Members")
+ .setSelected("selected")
+ .build())
+ .getGroupsList();
+ Assertions.assertThat(groups).hasSize(isMember ? 1 : 0);
+ }
+
+ public OrganizationService service() {
+ return session.wsClient().organizations();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsProjects;
+import org.sonarqube.ws.client.project.CreateRequest;
+import org.sonarqube.ws.client.project.DeleteRequest;
+import org.sonarqube.ws.client.project.ProjectsService;
+import org.sonarqube.ws.client.project.SearchWsRequest;
+
+import static java.util.Arrays.stream;
+import static java.util.Collections.singletonList;
+
+public class ProjectTester {
+
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
+
+ private final TesterSession session;
+
+ ProjectTester(TesterSession session) {
+ this.session = session;
+ }
+
+ void deleteAll() {
+ ProjectsService service = session.wsClient().projects();
+ service.search(SearchWsRequest.builder().setQualifiers(singletonList("TRK")).build()).getComponentsList().forEach(p ->
+ service.delete(DeleteRequest.builder().setKey(p.getKey()).build()));
+ }
+
+ @SafeVarargs
+ public final WsProjects.CreateWsResponse.Project generate(@Nullable Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
+ int id = ID_GENERATOR.getAndIncrement();
+ CreateRequest.Builder request = CreateRequest.builder()
+ .setKey("key" + id)
+ .setName("Name " + id)
+ .setOrganization(organization != null ? organization.getKey() : null);
+ stream(populators).forEach(p -> p.accept(request));
+
+ return session.wsClient().projects().create(request.build()).getProject();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import com.google.gson.Gson;
+import com.google.gson.annotations.SerializedName;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
+import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.qualitygate.QualityGatesService;
+import org.sonarqube.ws.client.qualitygate.SelectWsRequest;
+
+public class QGateTester {
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
+
+ private final TesterSession session;
+
+ QGateTester(TesterSession session) {
+ this.session = session;
+ }
+
+ public QualityGatesService service() {
+ return session.wsClient().qualityGates();
+ }
+
+ void deleteAll() {
+ String json = session.wsClient().wsConnector().call(new GetRequest("api/qualitygates/list")).failIfNotSuccessful().content();
+ ListResponse response = ListResponse.parse(json);
+ response.getQualityGates().stream()
+ .filter(qualityGate -> !qualityGate.getId().equals(response.getDefault()))
+ .forEach(qualityGate -> session.wsClient().wsConnector().call(new PostRequest("api/qualitygates/destroy").setParam("id", qualityGate.getId())).failIfNotSuccessful());
+ }
+
+ public CreateWsResponse generate() {
+ int id = ID_GENERATOR.getAndIncrement();
+ return session.wsClient().qualityGates().create("QualityGate" + id);
+ }
+
+ public void associateProject(CreateWsResponse qualityGate, Project project){
+ service().associateProject(new SelectWsRequest().setGateId(qualityGate.getId()).setProjectKey(project.getKey()));
+ }
+
+ public static class ListResponse {
+
+ @SerializedName("default")
+ private final String defaultQGate;
+ @SerializedName("qualitygates")
+ private final List<QGate> qualityGates = new ArrayList<>();
+
+ public ListResponse(String defaultQGate) {
+ this.defaultQGate = defaultQGate;
+ }
+
+ public List<QGate> getQualityGates() {
+ return qualityGates;
+ }
+
+ public String getDefault() {
+ return defaultQGate;
+ }
+
+ public static ListResponse parse(String json) {
+ Gson gson = new Gson();
+ return gson.fromJson(json, ListResponse.class);
+ }
+
+ public static class QGate {
+ @SerializedName("id")
+ private final String id;
+ @SerializedName("name")
+ private final String name;
+
+ public QGate(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.assertj.core.api.Assertions;
+import org.sonarqube.ws.Common;
+import org.sonarqube.ws.Organizations.Organization;
+import org.sonarqube.ws.QualityProfiles.CreateWsResponse.QualityProfile;
+import org.sonarqube.ws.Rules;
+import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
+import org.sonarqube.ws.client.HttpException;
+import org.sonarqube.ws.client.qualityprofile.ActivateRuleWsRequest;
+import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
+import org.sonarqube.ws.client.qualityprofile.CreateRequest;
+import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
+import org.sonarqube.ws.client.rule.SearchWsRequest;
+
+import static java.util.Arrays.asList;
+import static java.util.Arrays.stream;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class QProfileTester {
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
+
+ private final TesterSession session;
+
+ QProfileTester(TesterSession session) {
+ this.session = session;
+ }
+
+ public QualityProfilesService service() {
+ return session.wsClient().qualityProfiles();
+ }
+
+ @SafeVarargs
+ public final QualityProfile createXooProfile(Organization organization, Consumer<CreateRequest.Builder>... populators) {
+ int id = ID_GENERATOR.getAndIncrement();
+ CreateRequest.Builder request = CreateRequest.builder()
+ .setOrganizationKey(organization.getKey())
+ .setLanguage("xoo")
+ .setName("Profile" + id);
+ stream(populators).forEach(p -> p.accept(request));
+ return service().create(request.build()).getProfile();
+ }
+
+ public QProfileTester activateRule(QualityProfile profile, String ruleKey) {
+ return activateRule(profile.getKey(), ruleKey);
+ }
+
+ public QProfileTester activateRule(String profileKey, String ruleKey) {
+ ActivateRuleWsRequest request = ActivateRuleWsRequest.builder()
+ .setKey(profileKey)
+ .setRuleKey(ruleKey)
+ .build();
+ service().activateRule(request);
+ return this;
+ }
+
+ public QProfileTester deactivateRule(QualityProfile profile, String ruleKey) {
+ service().deactivateRule(profile.getKey(), ruleKey);
+ return this;
+ }
+
+ public QProfileTester assignQProfileToProject(QualityProfile profile, Project project) {
+ service().addProject(AddProjectRequest.builder()
+ .setProjectKey(project.getKey())
+ .setKey(profile.getKey())
+ .build());
+ return this;
+ }
+
+ public QProfileTester assertThatNumberOfActiveRulesEqualsTo(QualityProfile profile, int expectedActiveRules) {
+ return assertThatNumberOfActiveRulesEqualsTo(profile.getKey(), expectedActiveRules);
+ }
+
+ public QProfileTester assertThatNumberOfActiveRulesEqualsTo(String profileKey, int expectedActiveRules) {
+ try {
+ List<String> facetIds = asList("active_severities", "repositories", "languages", "severities", "statuses", "types");
+ SearchWsRequest request = new SearchWsRequest()
+ .setQProfile(profileKey)
+ .setActivation(true)
+ .setFacets(facetIds)
+ .setFields(singletonList("actives"));
+ Rules.SearchResponse response = session.wsClient().rules().search(request);
+
+ // assume that expectedActiveRules fits in first page of results
+ Assertions.assertThat(response.getRulesCount()).isEqualTo(expectedActiveRules);
+ Assertions.assertThat(response.getTotal()).isEqualTo(expectedActiveRules);
+ Assertions.assertThat(response.getActives().getActives()).as(response.toString()).hasSize(expectedActiveRules);
+
+ // verify facets
+ Assertions.assertThat(response.getFacets().getFacetsCount()).isEqualTo(facetIds.size());
+ response.getFacets().getFacetsList().forEach(facet -> {
+ long total = facet.getValuesList().stream()
+ .mapToLong(Common.FacetValue::getCount)
+ .sum();
+ assertThat(total).as("Facet " + facet.getProperty()).isEqualTo((long) expectedActiveRules);
+ });
+ } catch (HttpException e) {
+ if (expectedActiveRules == 0 && e.code() == 404) {
+ // profile does not exist, do nothing
+ return this;
+ }
+ throw e;
+ }
+ return this;
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
+import org.sonarqube.ws.Settings;
+import org.sonarqube.ws.client.setting.ListDefinitionsRequest;
+import org.sonarqube.ws.client.setting.ResetRequest;
+import org.sonarqube.ws.client.setting.SetRequest;
+import org.sonarqube.ws.client.setting.SettingsService;
+
+public class SettingTester {
+
+ private static final Set<String> EMAIL_SETTINGS = ImmutableSet.of("email.smtp_host.secured", "email.smtp_port.secured", "email.smtp_secure_connection.secured",
+ "email.smtp_username.secured", "email.smtp_password.secured", "email.from", "email.prefix");
+
+ private final TesterSession session;
+
+ SettingTester(TesterSession session) {
+ this.session = session;
+ }
+
+ public SettingsService service() {
+ return session.wsClient().settings();
+ }
+
+ void deleteAll() {
+ List<String> settingKeys = Stream.concat(
+ session.wsClient().settings().listDefinitions(ListDefinitionsRequest.builder().build()).getDefinitionsList()
+ .stream()
+ .filter(def -> def.getType() != Settings.Type.LICENSE)
+ .map(Settings.Definition::getKey),
+ EMAIL_SETTINGS.stream())
+ .collect(Collectors.toList());
+ session.wsClient().settings().reset(ResetRequest.builder().setKeys(settingKeys).build());
+ }
+
+ public void resetSettings(String... keys){
+ session.wsClient().settings().reset(ResetRequest.builder().setKeys(keys).build());
+ }
+
+ public void setGlobalSetting(String key, @Nullable String value) {
+ setSetting(null, key, value);
+ }
+
+ public void setGlobalSettings(String... properties) {
+ for (int i = 0; i < properties.length; i += 2) {
+ setSetting(null, properties[i], properties[i + 1]);
+ }
+ }
+
+ public void setProjectSetting(String componentKey, String key, @Nullable String value) {
+ setSetting(componentKey, key, value);
+ }
+
+ public void setProjectSettings(String componentKey, String... properties) {
+ for (int i = 0; i < properties.length; i += 2) {
+ setSetting(componentKey, properties[i], properties[i + 1]);
+ }
+ }
+
+ private void setSetting(@Nullable String componentKey, String key, @Nullable String value) {
+ if (value == null) {
+ session.wsClient().settings().reset(ResetRequest.builder().setKeys(key).setComponent(componentKey).build());
+ } else {
+ session.wsClient().settings().set(SetRequest.builder().setKey(key).setValue(value).setComponent(componentKey).build());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.container.Server;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.StringUtils;
+import org.junit.rules.ExternalResource;
+import org.sonarqube.qa.util.pageobjects.Navigation;
+import org.sonarqube.ws.client.HttpConnector;
+import org.sonarqube.ws.client.WsClient;
+import org.sonarqube.ws.client.WsClientFactories;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * This JUnit rule wraps an {@link Orchestrator} instance and provides :
+ * <ul>
+ * <li>enabling the organization feature by default</li>
+ * <li>clean-up of organizations between tests</li>
+ * <li>clean-up of users between tests</li>
+ * <li>clean-up of session when opening a browser (cookies, local storage)</li>
+ * <li>quick access to {@link WsClient} instances</li>
+ * <li>helpers to generate organizations and users</li>
+ * </ul>
+ * <p>
+ * Recommendation is to define a {@code @Rule} instance. If not possible, then
+ * {@code @ClassRule} must be used through a {@link org.junit.rules.RuleChain}
+ * around {@link Orchestrator}.
+ */
+public class Tester extends ExternalResource implements TesterSession {
+
+ private final Orchestrator orchestrator;
+
+ // configuration before startup
+ private boolean disableOrganizations = false;
+ private Elasticsearch elasticsearch = null;
+
+ // initialized in #before()
+ private boolean beforeCalled = false;
+ private TesterSession rootSession;
+
+ public Tester(Orchestrator orchestrator) {
+ this.orchestrator = orchestrator;
+ String elasticsearchHttpPort = orchestrator.getDistribution().getServerProperty("sonar.search.httpPort");
+ if (StringUtils.isNotBlank(elasticsearchHttpPort)) {
+ this.elasticsearch = new Elasticsearch(Integer.parseInt(elasticsearchHttpPort));
+ }
+ }
+
+ public Tester disableOrganizations() {
+ verifyNotStarted();
+ disableOrganizations = true;
+ return this;
+ }
+
+ /**
+ * Enables Elasticsearch debugging, see {@link #elasticsearch()}.
+ * <p>
+ * The property "sonar.search.httpPort" must be defined before
+ * starting SonarQube server.
+ */
+ public Tester setElasticsearchHttpPort(int port) {
+ verifyNotStarted();
+ elasticsearch = new Elasticsearch(port);
+ return this;
+ }
+
+ @Override
+ public void before() {
+ verifyNotStarted();
+ rootSession = new TesterSessionImpl(orchestrator, "admin", "admin");
+
+ if (!disableOrganizations) {
+ organizations().enableSupport();
+ }
+
+ beforeCalled = true;
+ }
+
+ @Override
+ public void after() {
+ if (!disableOrganizations) {
+ organizations().deleteNonGuardedOrganizations();
+ }
+ users().deleteAll();
+ projects().deleteAll();
+ settings().deleteAll();
+ qGates().deleteAll();
+ }
+
+ public TesterSession asAnonymous() {
+ return as(null, null);
+ }
+
+ public TesterSession as(String login) {
+ return as(login, login);
+ }
+
+ public TesterSession as(String login, String password) {
+ verifyStarted();
+ return new TesterSessionImpl(orchestrator, login, password);
+ }
+
+ public Elasticsearch elasticsearch() {
+ return requireNonNull(elasticsearch, "Elasticsearch HTTP port is not defined. See #setElasticsearchHttpPort()");
+ }
+
+ /**
+ * Open a new browser session. Cookies are deleted.
+ */
+ public Navigation openBrowser() {
+ verifyStarted();
+ return Navigation.create(orchestrator);
+ }
+
+ private void verifyNotStarted() {
+ if (beforeCalled) {
+ throw new IllegalStateException("Orchestrator should not be already started");
+ }
+ }
+
+ private void verifyStarted() {
+ if (!beforeCalled) {
+ throw new IllegalStateException("Orchestrator is not started yet");
+ }
+ }
+
+ /**
+ * Web service client configured with root access
+ */
+ @Override
+ public WsClient wsClient() {
+ verifyStarted();
+ return rootSession.wsClient();
+ }
+
+ @Override
+ public GroupTester groups() {
+ return rootSession.groups();
+ }
+
+ @Override
+ public OrganizationTester organizations() {
+ return rootSession.organizations();
+ }
+
+ @Override
+ public ProjectTester projects() {
+ return rootSession.projects();
+ }
+
+ @Override
+ public QProfileTester qProfiles() {
+ return rootSession.qProfiles();
+ }
+
+ @Override
+ public UserTester users() {
+ return rootSession.users();
+ }
+
+ @Override
+ public SettingTester settings() {
+ return rootSession.settings();
+ }
+
+ @Override
+ public QGateTester qGates() {
+ return rootSession.qGates();
+ }
+
+ private static class TesterSessionImpl implements TesterSession {
+ private final WsClient client;
+
+ private TesterSessionImpl(Orchestrator orchestrator, @Nullable String login, @Nullable String password) {
+ Server server = orchestrator.getServer();
+ this.client = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
+ .url(server.getUrl())
+ .credentials(login, password)
+ .build());
+ }
+
+ @Override
+ public WsClient wsClient() {
+ return client;
+ }
+
+ @Override
+ public GroupTester groups() {
+ return new GroupTester(this);
+ }
+
+ @Override
+ public OrganizationTester organizations() {
+ return new OrganizationTester(this);
+ }
+
+ @Override
+ public ProjectTester projects() {
+ return new ProjectTester(this);
+ }
+
+ @Override
+ public QProfileTester qProfiles() {
+ return new QProfileTester(this);
+ }
+
+ @Override
+ public UserTester users() {
+ return new UserTester(this);
+ }
+
+ @Override
+ public SettingTester settings() {
+ return new SettingTester(this);
+ }
+
+ @Override
+ public QGateTester qGates() {
+ return new QGateTester(this);
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import org.sonarqube.ws.client.WsClient;
+
+public interface TesterSession {
+
+ WsClient wsClient();
+
+ GroupTester groups();
+
+ OrganizationTester organizations();
+
+ ProjectTester projects();
+
+ QProfileTester qProfiles();
+
+ UserTester users();
+
+ SettingTester settings();
+
+ QGateTester qGates();
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.sonarqube.qa.util;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsUsers;
+import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.user.CreateRequest;
+import org.sonarqube.ws.client.user.SearchRequest;
+import org.sonarqube.ws.client.user.UsersService;
+import org.sonarqube.ws.client.usergroup.AddUserWsRequest;
+
+import static java.util.Arrays.stream;
+
+public class UserTester {
+
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
+
+ private final TesterSession session;
+
+ UserTester(TesterSession session) {
+ this.session = session;
+ }
+
+ void deleteAll() {
+ session.wsClient().users().search(SearchRequest.builder().build()).getUsersList()
+ .stream()
+ .filter(u -> !"admin".equals(u.getLogin()))
+ .forEach(u -> {
+ PostRequest request = new PostRequest("api/users/deactivate").setParam("login", u.getLogin());
+ session.wsClient().wsConnector().call(request);
+ });
+ }
+
+ @SafeVarargs
+ public final User generate(Consumer<CreateRequest.Builder>... populators) {
+ int id = ID_GENERATOR.getAndIncrement();
+ String login = "login" + id;
+ CreateRequest.Builder request = CreateRequest.builder()
+ .setLogin(login)
+ .setPassword(login)
+ .setName("name" + id)
+ .setEmail(id + "@test.com");
+ stream(populators).forEach(p -> p.accept(request));
+ return service().create(request.build()).getUser();
+ }
+
+ @SafeVarargs
+ public final User generateAdministrator(Consumer<CreateRequest.Builder>... populators) {
+ User user = generate(populators);
+ session.wsClient().permissions().addUser(new org.sonarqube.ws.client.permission.AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin"));
+ session.wsClient().userGroups().addUser(AddUserWsRequest.builder().setLogin(user.getLogin()).setName("sonar-administrators").build());
+ return user;
+ }
+
+ @SafeVarargs
+ public final User generateAdministrator(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
+ User user = generate(populators);
+ session.wsClient().organizations().addMember(organization.getKey(), user.getLogin());
+ session.wsClient().userGroups().addUser(AddUserWsRequest.builder()
+ .setOrganization(organization.getKey())
+ .setLogin(user.getLogin())
+ .setName("Owners")
+ .build());
+ return user;
+ }
+
+ @SafeVarargs
+ public final User generateMember(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
+ User user = generate(populators);
+ session.wsClient().organizations().addMember(organization.getKey(), user.getLogin());
+ return user;
+ }
+
+ public UsersService service() {
+ return session.wsClient().users();
+ }
+
+ public Optional<WsUsers.SearchWsResponse.User> getByLogin(String login) {
+ List<WsUsers.SearchWsResponse.User> users = session.wsClient().users().search(SearchRequest.builder().setQuery(login).build()).getUsersList();
+ if (users.size() == 1) {
+ return Optional.of(users.get(0));
+ }
+ return Optional.empty();
+ }
+}
}
public BackgroundTaskItem assertScannerContextContains(String text) {
- Selenide.$(".js-task-scanner-context").should(Condition.hasText(text));
+ Selenide.$(".js-task-scanner-context").should(Condition.text(text));
return this;
}
}
public BackgroundTaskItem assertErrorStacktraceContains(String text) {
- Selenide.$(".js-task-stacktrace").should(Condition.hasText(text));
+ Selenide.$(".js-task-stacktrace").should(Condition.text(text));
return this;
}
}
return Selenide.$(".process-spinner-failed");
}
- private <T> T submitCredentials(String login, String password, Class<T> expectedResultPage) {
+ private static <T> T submitCredentials(String login, String password, Class<T> expectedResultPage) {
Selenide.$("#login").val(login);
Selenide.$("#password").val(password);
Selenide.$(By.name("commit")).click();
return this;
}
- private SelenideElement getPlugin(String name) {
+ private static SelenideElement getPlugin(String name) {
return Selenide.$$(".js-plugin-name").findBy(Condition.text(name)).should(Condition.exist).parent().parent().parent();
}
}
}
public SettingsPage openSettings(@Nullable String projectKey) throws UnsupportedEncodingException {
- String url = projectKey != null ? "/project/settings?id=" + URLEncoder.encode(projectKey, "UTF-8") : "/settings";
+ String url = projectKey != null ? ("/project/settings?id=" + URLEncoder.encode(projectKey, "UTF-8")) : "/settings";
return open(url, SettingsPage.class);
}
return Selenide.$("#error");
}
- private SelenideElement logInLink() {
+ private static SelenideElement logInLink() {
return Selenide.$(By.linkText("Log in"));
}
- private SelenideElement loggedInDropdown() {
+ private static SelenideElement loggedInDropdown() {
return Selenide.$(".js-user-authenticated");
}
public class NotificationsPage extends Navigation {
- private final String EMAIL = "EmailNotificationChannel";
+ private static final String EMAIL = "EmailNotificationChannel";
public NotificationsPage() {
Selenide.$("#account-page").shouldHave(Condition.text("Overall notifications"));
return this;
}
- private String globalCheckboxSelector(String type, String channel) {
+ private static String globalCheckboxSelector(String type, String channel) {
return "#global-notification-" + type + "-" + channel;
}
- private String projectCheckboxSelector(String project, String type, String channel) {
+ private static String projectCheckboxSelector(String project, String type, String channel) {
return "#project-notification-" + project + "-" + type + "-" + channel;
}
return this;
}
- private void toggleCheckbox(String selector) {
+ private static void toggleCheckbox(String selector) {
Selenide.$(selector).click();
}
}
Selenide.$("#project-activity")
.find(".project-activity-day[data-day=\"" + day + "\"]")
.find(".project-activity-analysis")
- .should(Condition.hasText(text));
+ .should(Condition.text(text));
return this;
}
}
public class ProjectCodePage {
- public ProjectCodePage() {
- }
-
public ProjectCodePage openFirstComponent() {
Selenide.$$(".code-name-cell a").first().click();
return this;
public SelenideElement getOverviewMeasure(String measure) {
ElementsCollection measures = Selenide.$$(".overview-domain-measure");
- SelenideElement element = measures.find(Condition.text(measure)).shouldBe(Condition.visible);
- return element;
+ return measures.find(Condition.text(measure)).shouldBe(Condition.visible);
}
- private SelenideElement getTagsMeta() {
+ private static SelenideElement getTagsMeta() {
SelenideElement element = Selenide.$(".overview-meta-tags");
element.shouldBe(Condition.visible);
return element;
public ProjectDashboardPage shouldHaveTags(String... tags) {
String tagsList = String.join(", ", Arrays.asList(tags));
- this.getTagsMeta().$(".tags-list > span").should(Condition.hasText(tagsList));
+ getTagsMeta().$(".tags-list > span").should(Condition.text(tagsList));
return this;
}
public ProjectDashboardPage shouldNotBeEditable() {
- SelenideElement tagsElem = this.getTagsMeta();
+ SelenideElement tagsElem = getTagsMeta();
tagsElem.$("button").shouldNot(Condition.exist);
tagsElem.$("div.multi-select").shouldNot(Condition.exist);
return this;
}
public ProjectDashboardPage shouldBeEditable() {
- SelenideElement tagsElem = this.getTagsMeta();
+ SelenideElement tagsElem = getTagsMeta();
tagsElem.$("button").shouldBe(Condition.visible);
return this;
}
public ProjectDashboardPage openTagEditor() {
- SelenideElement tagsElem = this.getTagsMeta();
+ SelenideElement tagsElem = getTagsMeta();
tagsElem.$("button").shouldBe(Condition.visible).click();
tagsElem.$("div.multi-select").shouldBe(Condition.visible);
return this;
}
public SelenideElement getTagAtIdx(Integer idx) {
- SelenideElement tagsElem = this.getTagsMeta();
+ SelenideElement tagsElem = getTagsMeta();
tagsElem.$("div.multi-select").shouldBe(Condition.visible);
return tagsElem.$$("ul.menu a").get(idx);
}
public ProjectDashboardPage sendKeysToTagsInput(CharSequence... charSequences) {
- SelenideElement tagsInput = this.getTagsMeta().find("input");
+ SelenideElement tagsInput = getTagsMeta().find("input");
tagsInput.sendKeys(charSequences);
return this;
}
public ProjectKeyPage assertBulkChangeSimulationResult(String oldKey, String newKey) {
SelenideElement row = Selenide.$("#bulk-update-results").$("[data-key=\"" + oldKey + "\"]");
- row.$(".js-old-key").should(Condition.hasText(oldKey));
- row.$(".js-new-key").should(Condition.hasText(newKey));
+ row.$(".js-old-key").should(Condition.text(oldKey));
+ row.$(".js-new-key").should(Condition.text(newKey));
return this;
}
private final SelenideElement elt;
public SystemInfoPageItem(SelenideElement elt) {
- this.elt = elt;
- }
+ this.elt = elt;
+ }
public SystemInfoPageItem shouldHaveHealth() {
elt.$(".system-info-health-info .status-indicator").should(Condition.exist);
}
public SystemInfoPageItem ensureOpen() {
- if(!isOpen()) {
+ if (!isOpen()) {
elt.click();
elt.$(".boxed-group-inner").should(Condition.exist);
}
Selenide.$(".issues").should(Condition.exist);
}
- private ElementsCollection getIssuesElements() {
- return Selenide.$$(".issues .issue");
- }
-
- private ElementsCollection getIssuesPathComponents() {
- return Selenide.$$(".issues-workspace-list-component");
- }
-
public List<Issue> getIssues() {
return getIssuesElements()
.stream()
}
public IssuesPage issuesCount(Integer count) {
- this.getIssuesElements().shouldHaveSize(count);
+ getIssuesElements().shouldHaveSize(count);
return this;
}
}
public IssuesPage componentsShouldContain(String path) {
- this.getIssuesPathComponents().forEach(element -> element.shouldHave(Condition.text(path)));
+ getIssuesPathComponents().forEach(element -> element.shouldHave(Condition.text(path)));
return this;
}
public IssuesPage componentsShouldNotContain(String path) {
- this.getIssuesPathComponents().forEach(element -> element.shouldNotHave(Condition.text(path)));
+ getIssuesPathComponents().forEach(element -> element.shouldNotHave(Condition.text(path)));
return this;
}
Selenide.$("#issues-bulk-change-assignee .Select-input input").pressEscape();
return this;
}
+
+ private static ElementsCollection getIssuesElements() {
+ return Selenide.$$(".issues .issue");
+ }
+
+ private static ElementsCollection getIssuesPathComponents() {
+ return Selenide.$$(".issues-workspace-list-component");
+ }
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.qa.util.pageobjects.issues;
+
+import javax.annotation.ParametersAreNonnullByDefault;
}
public MeasuresPage measureHasValue(String measure, Integer value) {
- SelenideElement sidebar = this.getSideBar();
+ SelenideElement sidebar = getSideBar();
sidebar.$("#measure-" + measure + "-name").should(Condition.exist);
sidebar.$("#measure-" + measure + "-value").should(Condition.exist).shouldHave(Condition.text(value.toString()));
return this;
}
public MeasuresPage measureHasLeak(String measure, Integer value) {
- SelenideElement sidebar = this.getSideBar();
+ SelenideElement sidebar = getSideBar();
sidebar.$("#measure-" + measure + "-name").should(Condition.exist);
sidebar.$("#measure-" + measure + "-leak").should(Condition.exist).shouldHave(Condition.text(value.toString()));
return this;
}
public MeasureContent openMeasureContent(String measure) {
- SelenideElement sidebar = this.getSideBar();
+ SelenideElement sidebar = getSideBar();
SelenideElement facetItem = sidebar.$("#measure-" + measure + "-name");
facetItem.click();
MeasureContent content = new MeasureContent(Selenide.$("#component-measures .measure-details-content").should(Condition.exist));
return content;
}
- private SelenideElement getSideBar() {
+ private static SelenideElement getSideBar() {
return Selenide.$("#component-measures .layout-page-side").should(Condition.exist);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.qa.util.pageobjects.measures;
+
+import javax.annotation.ParametersAreNonnullByDefault;
return this;
}
- private SelenideElement getModal(String title) {
+ private static SelenideElement getModal(String title) {
Selenide.$(".modal-head").should(Condition.exist).shouldHave(Condition.text(title));
SelenideElement form = Selenide.$(".ReactModalPortal form");
form.should(Condition.exist);
this.canAddMember();
Selenide.$(".page-actions button").click();
- SelenideElement modal = this.getModal("Add user");
+ SelenideElement modal = getModal("Add user");
SelenideElement input = modal.$(".Select-input input");
input.val(login);
modal.$("div.Select-option.is-focused").should(Condition.exist);
return this;
}
- private SelenideElement getModal(String title) {
+ private static SelenideElement getModal(String title) {
Selenide.$(".modal-head").should(Condition.exist).shouldHave(Condition.text(title));
SelenideElement form = Selenide.$(".ReactModalPortal form");
form.should(Condition.exist);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.qa.util.pageobjects.organization;
+
+import javax.annotation.ParametersAreNonnullByDefault;
return this;
}
- private SelenideElement getOpenTopBar() {
+ private static SelenideElement getOpenTopBar() {
return Selenide.$(".projects-topbar-items").should(Condition.exist);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.qa.util.pageobjects.projects;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.qa.util.pageobjects.settings;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.net.InetAddress;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Helper to directly access Elasticsearch. It requires the HTTP port
- * to be open.
- */
-public class Elasticsearch {
-
- private final int httpPort;
-
- public Elasticsearch(int httpPort) {
- this.httpPort = httpPort;
- }
-
- /**
- * Forbid indexing requests on the specified index. Index becomes read-only.
- */
- public void lockWrites(String index) throws Exception {
- putIndexSetting(httpPort, index, "blocks.write", "true");
- }
-
- /**
- * Enable indexing requests on the specified index.
- * @see #lockWrites(String)
- */
- public void unlockWrites(String index) throws Exception {
- putIndexSetting(httpPort, index, "blocks.write", "false");
- }
-
- public void makeYellow() throws Exception {
- putIndexSetting(httpPort, "issues", "number_of_replicas", "5");
- }
-
- public void makeGreen() throws Exception {
- putIndexSetting(httpPort, "issues", "number_of_replicas", "0");
- }
-
- private void putIndexSetting(int searchHttpPort, String index, String key, String value) throws Exception {
- Request.Builder request = new Request.Builder()
- .url(baseUrl(searchHttpPort) + index + "/_settings")
- .put(RequestBody.create(MediaType.parse("application/json"), "{" +
- " \"index\" : {" +
- " \"" + key + "\" : \"" + value + "\"" +
- " }" +
- "}"));
- OkHttpClient okClient = new OkHttpClient.Builder().build();
- Response response = okClient.newCall(request.build()).execute();
- assertThat(response.isSuccessful()).isTrue();
- }
-
- private String baseUrl(int searchHttpPort) {
- return "http://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + searchHttpPort + "/";
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.sonarqube.ws.Organizations;
-import org.sonarqube.ws.WsUserGroups;
-import org.sonarqube.ws.WsUsers;
-import org.sonarqube.ws.WsUsers.GroupsWsResponse.Group;
-import org.sonarqube.ws.client.user.GroupsRequest;
-import org.sonarqube.ws.client.usergroup.AddUserWsRequest;
-import org.sonarqube.ws.client.usergroup.CreateWsRequest;
-
-import static java.util.Arrays.stream;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class GroupTester {
-
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- private final Session session;
-
- GroupTester(Session session) {
- this.session = session;
- }
-
- @SafeVarargs
- public final WsUserGroups.Group generate(@Nullable Organizations.Organization organization, Consumer<CreateWsRequest.Builder>... populators) {
- int id = ID_GENERATOR.getAndIncrement();
- CreateWsRequest.Builder request = CreateWsRequest.builder()
- .setName("Group" + id)
- .setDescription("Description " + id)
- .setOrganization(organization != null ? organization.getKey() : null);
- stream(populators).forEach(p -> p.accept(request));
- return session.wsClient().userGroups().create(request.build()).getGroup();
- }
-
- public List<Group> getGroupsOfUser(@Nullable Organizations.Organization organization, String userLogin) {
- GroupsRequest request = GroupsRequest.builder()
- .setOrganization(organization != null ? organization.getKey() : null)
- .setLogin(userLogin)
- .build();
- WsUsers.GroupsWsResponse response = session.users().service().groups(request);
- return response.getGroupsList();
- }
-
- public GroupTester addMemberToGroups(Organizations.Organization organization, String userLogin, String... groups) {
- for (String group : groups) {
- AddUserWsRequest request = AddUserWsRequest.builder()
- .setLogin(userLogin)
- .setOrganization(organization.getKey())
- .setName(group)
- .build();
- session.wsClient().userGroups().addUser(request);
- }
- return this;
- }
-
- public GroupTester assertThatUserIsMemberOf(@Nullable Organizations.Organization organization, String userLogin, String expectedGroup, String... otherExpectedGroups) {
- List<String> groups = getGroupsOfUser(organization, userLogin)
- .stream()
- .map(Group::getName)
- .collect(Collectors.toList());
-
- assertThat(groups).contains(expectedGroup);
- if (otherExpectedGroups.length > 0) {
- assertThat(groups).contains(otherExpectedGroups);
- }
- return this;
- }
-
- public GroupTester assertThatUserIsOnlyMemberOf(@Nullable Organizations.Organization organization, String userLogin, String... expectedGroups) {
- Set<String> groups = getGroupsOfUser(organization, userLogin)
- .stream()
- .map(Group::getName)
- .collect(Collectors.toSet());
- assertThat(groups).containsExactlyInAnyOrder(expectedGroups);
- return this;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import org.apache.commons.io.input.Tailer;
-import org.apache.commons.io.input.TailerListenerAdapter;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Watch log files, usually server logs (see Orchestrator.getServer().get*Logs()).
- * This class allows to not load the full content in memory.
- */
-public class LogsTailer implements AutoCloseable {
-
- private final List<Tailer> tailers;
- private final LogConsumer logConsumer;
-
- private LogsTailer(Builder builder) {
- logConsumer = new LogConsumer(builder.consumers);
- tailers = builder.files.stream()
- .map(file -> Tailer.create(file, logConsumer, 500))
- .collect(Collectors.toList());
- }
-
- public Watch watch(String text) {
- return new Watch(text);
- }
-
- @Override
- public void close() {
- for (Tailer tailer : tailers) {
- tailer.stop();
- }
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private final List<File> files = new ArrayList<>();
- private final List<Consumer<String>> consumers = new ArrayList<>();
-
- public Builder addFile(File file) {
- this.files.add(file);
- return this;
- }
-
- public Builder addFiles(File file, File... otherFiles) {
- this.files.add(file);
- Collections.addAll(this.files, otherFiles);
- return this;
- }
-
- /**
- * Adds a consumer that is called on each new line appended
- * to the files.
- * Note that the consumer {@link Content} allows to keep
- * all past logs in memory.
- */
- public Builder addConsumer(Consumer<String> consumer) {
- this.consumers.add(consumer);
- return this;
- }
-
- public LogsTailer build() {
- return new LogsTailer(this);
- }
- }
-
- private static class LogConsumer extends TailerListenerAdapter {
- private final List<Consumer<String>> consumers = Collections.synchronizedList(new ArrayList<>());
-
- private LogConsumer(List<Consumer<String>> consumers) {
- this.consumers.addAll(consumers);
- }
-
- @Override
- public void handle(String line) {
- synchronized (consumers) {
- for (Consumer<String> consumer : consumers) {
- try {
- consumer.accept(line);
- } catch (Exception e) {
- // do not prevent other consumers to handle the log
- e.printStackTrace();
- }
- }
- }
- }
-
- public void add(Consumer<String> consumer) {
- this.consumers.add(consumer);
- }
-
- public void remove(Consumer<String> consumer) {
- this.consumers.remove(consumer);
- }
- }
-
- public class Watch implements AutoCloseable {
- private final String expectedText;
- private final CountDownLatch foundSignal = new CountDownLatch(1);
- private String log = null;
- private final Consumer<String> consumer;
-
- private Watch(String expectedText) {
- this.expectedText = requireNonNull(expectedText);
- this.consumer = log -> {
- if (log.contains(this.expectedText)) {
- this.log = log;
- foundSignal.countDown();
- }
- };
- logConsumer.add(consumer);
- }
-
- /**
- * Blocks until the expected log appears in watched files.
- */
- public void waitForLog() throws InterruptedException {
- foundSignal.await();
- }
-
- /**
- * Blocks until the expected log appears in watched files with timeout
- */
- public void waitForLog(long timeout, TimeUnit timeUnit) throws InterruptedException {
- foundSignal.await(timeout, timeUnit);
- }
-
- public Optional<String> getLog() {
- return Optional.ofNullable(log);
- }
-
- @Override
- public void close() {
- logConsumer.remove(consumer);
- }
- }
-
- public static class Content implements Consumer<String> {
- private final List<String> lines = Collections.synchronizedList(new ArrayList<>());
-
- @Override
- public void accept(String s) {
- lines.add(s);
- }
-
- public boolean hasText(String text) {
- synchronized (lines) {
- for (String line : lines) {
- if (line.contains(text)) {
- return true;
- }
- }
- }
- return false;
- }
-
- public boolean hasLineMatching(Pattern pattern) {
- synchronized (lines) {
- for (String line : lines) {
- if (pattern.matcher(line).matches()) {
- return true;
- }
- }
- }
- return false;
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-import javax.annotation.Nullable;
-import org.sonarqube.ws.Organizations;
-import org.sonarqube.ws.WsUsers;
-import org.sonarqube.ws.client.HttpException;
-import org.sonarqube.ws.client.PostRequest;
-import org.sonarqube.ws.client.organization.CreateWsRequest;
-import org.sonarqube.ws.client.organization.OrganizationService;
-import org.sonarqube.ws.client.organization.SearchMembersWsRequest;
-import org.sonarqube.ws.client.organization.SearchWsRequest;
-import org.sonarqube.ws.client.user.GroupsRequest;
-
-import static java.util.Arrays.stream;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class OrganizationTester {
-
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- private final Session session;
-
- OrganizationTester(Session session) {
- this.session = session;
- }
-
- void enableSupport() {
- session.wsClient().wsConnector().call(new PostRequest("api/organizations/enable_support"));
- }
-
- void deleteNonGuardedOrganizations() {
- service().search(SearchWsRequest.builder().build()).getOrganizationsList()
- .stream()
- .filter(o -> !o.getKey().equals("default-organization"))
- .forEach(organization -> service().delete(organization.getKey()));
- }
-
- @SafeVarargs
- public final Organizations.Organization generate(Consumer<CreateWsRequest.Builder>... populators) {
- int id = ID_GENERATOR.getAndIncrement();
- CreateWsRequest.Builder request = new CreateWsRequest.Builder()
- .setKey("org" + id)
- .setName("Org " + id)
- .setDescription("Description " + id)
- .setUrl("http://test" + id);
- stream(populators).forEach(p -> p.accept(request));
- return service().create(request.build()).getOrganization();
- }
-
- public OrganizationTester addMember(Organizations.Organization organization, WsUsers.CreateWsResponse.User user) {
- service().addMember(organization.getKey(), user.getLogin());
- return this;
- }
-
- public Organizations.Organization getDefaultOrganization() {
- return service().search(SearchWsRequest.builder().build()).getOrganizationsList()
- .stream()
- .filter(o -> o.getKey().equals("default-organization"))
- .findFirst().orElseThrow(() -> new IllegalStateException("Can't find default organization"));
- }
-
- public OrganizationTester assertThatOrganizationDoesNotExist(String organizationKey) {
- SearchWsRequest request = new SearchWsRequest.Builder().setOrganizations(organizationKey).build();
- Organizations.SearchWsResponse searchWsResponse = service().search(request);
- assertThat(searchWsResponse.getOrganizationsList()).isEmpty();
- return this;
- }
-
- public OrganizationTester assertThatMemberOf(Organizations.Organization organization, WsUsers.CreateWsResponse.User user) {
- return assertThatMemberOf(organization, user.getLogin());
- }
-
- public OrganizationTester assertThatMemberOf(Organizations.Organization organization, String userLogin) {
- verifyOrganizationMembership(organization, userLogin, true);
- verifyMembersGroupMembership(userLogin, organization, true);
- return this;
- }
-
- public OrganizationTester assertThatNotMemberOf(Organizations.Organization organization, WsUsers.CreateWsResponse.User user) {
- return assertThatNotMemberOf(organization, user.getLogin());
- }
-
- public OrganizationTester assertThatNotMemberOf(Organizations.Organization organization, String userLogin) {
- verifyOrganizationMembership(organization, userLogin, false);
- try {
- verifyMembersGroupMembership(userLogin, organization, false);
- } catch (HttpException e) {
- // do not fail if user does not exist
- if (e.code() != 404) {
- throw e;
- }
- }
- return this;
- }
-
- private void verifyOrganizationMembership(@Nullable Organizations.Organization organization, String userLogin, boolean isMember) {
- List<Organizations.User> users = service().searchMembers(new SearchMembersWsRequest()
- .setQuery(userLogin)
- .setSelected("selected")
- .setOrganization(organization != null ? organization.getKey() : null))
- .getUsersList();
- assertThat(users).hasSize(isMember ? 1 : 0);
- }
-
- private void verifyMembersGroupMembership(String userLogin, @Nullable Organizations.Organization organization, boolean isMember) {
- List<WsUsers.GroupsWsResponse.Group> groups = session.wsClient().users().groups(GroupsRequest.builder()
- .setLogin(userLogin)
- .setOrganization(organization != null ? organization.getKey() : null)
- .setQuery("Members")
- .setSelected("selected")
- .build())
- .getGroupsList();
- assertThat(groups).hasSize(isMember ? 1 : 0);
- }
-
- public OrganizationService service() {
- return session.wsClient().organizations();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-import javax.annotation.Nullable;
-import org.sonarqube.ws.Organizations;
-import org.sonarqube.ws.WsProjects;
-import org.sonarqube.ws.client.project.CreateRequest;
-import org.sonarqube.ws.client.project.DeleteRequest;
-import org.sonarqube.ws.client.project.ProjectsService;
-import org.sonarqube.ws.client.project.SearchWsRequest;
-
-import static java.util.Arrays.stream;
-import static java.util.Collections.singletonList;
-
-public class ProjectTester {
-
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- private final Session session;
-
- ProjectTester(Session session) {
- this.session = session;
- }
-
- void deleteAll() {
- ProjectsService service = session.wsClient().projects();
- service.search(SearchWsRequest.builder().setQualifiers(singletonList("TRK")).build()).getComponentsList().forEach(p -> {
- service.delete(DeleteRequest.builder().setKey(p.getKey()).build());
- });
- }
-
- @SafeVarargs
- public final WsProjects.CreateWsResponse.Project generate(@Nullable Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
- int id = ID_GENERATOR.getAndIncrement();
- CreateRequest.Builder request = CreateRequest.builder()
- .setKey("key" + id)
- .setName("Name " + id)
- .setOrganization(organization != null ? organization.getKey() : null);
- stream(populators).forEach(p -> p.accept(request));
-
- return session.wsClient().projects().create(request.build()).getProject();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import com.google.gson.Gson;
-import com.google.gson.annotations.SerializedName;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
-import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.PostRequest;
-import org.sonarqube.ws.client.qualitygate.QualityGatesService;
-import org.sonarqube.ws.client.qualitygate.SelectWsRequest;
-
-public class QGateTester {
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- private final Session session;
-
- QGateTester(Session session) {
- this.session = session;
- }
-
- public QualityGatesService service() {
- return session.wsClient().qualityGates();
- }
-
- void deleteAll() {
- String json = session.wsClient().wsConnector().call(new GetRequest("api/qualitygates/list")).failIfNotSuccessful().content();
- ListResponse response = ListResponse.parse(json);
- response.getQualityGates().stream()
- .filter(qualityGate -> !qualityGate.getId().equals(response.getDefault()))
- .forEach(qualityGate -> session.wsClient().wsConnector().call(new PostRequest("api/qualitygates/destroy").setParam("id", qualityGate.getId())).failIfNotSuccessful());
- }
-
- public CreateWsResponse generate() {
- int id = ID_GENERATOR.getAndIncrement();
- return session.wsClient().qualityGates().create("QualityGate" + id);
- }
-
- public void associateProject(CreateWsResponse qualityGate, Project project){
- service().associateProject(new SelectWsRequest().setGateId(qualityGate.getId()).setProjectKey(project.getKey()));
- }
-
- public static class ListResponse {
-
- @SerializedName("default")
- private final String defaultQGate;
- @SerializedName("qualitygates")
- private final List<QGate> qualityGates = new ArrayList<>();
-
- public ListResponse(String defaultQGate) {
- this.defaultQGate = defaultQGate;
- }
-
- public List<QGate> getQualityGates() {
- return qualityGates;
- }
-
- public String getDefault() {
- return defaultQGate;
- }
-
- public static ListResponse parse(String json) {
- Gson gson = new Gson();
- return gson.fromJson(json, ListResponse.class);
- }
-
- public static class QGate {
- @SerializedName("id")
- private final String id;
- @SerializedName("name")
- private final String name;
-
- public QGate(String id, String name) {
- this.id = id;
- this.name = name;
- }
-
- public String getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-import org.sonarqube.ws.Common;
-import org.sonarqube.ws.Organizations.Organization;
-import org.sonarqube.ws.QualityProfiles.CreateWsResponse.QualityProfile;
-import org.sonarqube.ws.Rules;
-import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
-import org.sonarqube.ws.client.HttpException;
-import org.sonarqube.ws.client.qualityprofile.ActivateRuleWsRequest;
-import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
-import org.sonarqube.ws.client.qualityprofile.CreateRequest;
-import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
-import org.sonarqube.ws.client.rule.SearchWsRequest;
-
-import static java.util.Arrays.asList;
-import static java.util.Arrays.stream;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class QProfileTester {
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- private final Session session;
-
- QProfileTester(Session session) {
- this.session = session;
- }
-
- public QualityProfilesService service() {
- return session.wsClient().qualityProfiles();
- }
-
- @SafeVarargs
- public final QualityProfile createXooProfile(Organization organization, Consumer<CreateRequest.Builder>... populators) {
- int id = ID_GENERATOR.getAndIncrement();
- CreateRequest.Builder request = CreateRequest.builder()
- .setOrganizationKey(organization.getKey())
- .setLanguage("xoo")
- .setName("Profile" + id);
- stream(populators).forEach(p -> p.accept(request));
- return service().create(request.build()).getProfile();
- }
-
- public QProfileTester activateRule(QualityProfile profile, String ruleKey) {
- return activateRule(profile.getKey(), ruleKey);
- }
-
- public QProfileTester activateRule(String profileKey, String ruleKey) {
- ActivateRuleWsRequest request = ActivateRuleWsRequest.builder()
- .setKey(profileKey)
- .setRuleKey(ruleKey)
- .build();
- service().activateRule(request);
- return this;
- }
-
- public QProfileTester deactivateRule(QualityProfile profile, String ruleKey) {
- service().deactivateRule(profile.getKey(), ruleKey);
- return this;
- }
-
- public QProfileTester assignQProfileToProject(QualityProfile profile, Project project) {
- service().addProject(AddProjectRequest.builder()
- .setProjectKey(project.getKey())
- .setKey(profile.getKey())
- .build());
- return this;
- }
-
- public QProfileTester assertThatNumberOfActiveRulesEqualsTo(QualityProfile profile, int expectedActiveRules) {
- return assertThatNumberOfActiveRulesEqualsTo(profile.getKey(), expectedActiveRules);
- }
-
- public QProfileTester assertThatNumberOfActiveRulesEqualsTo(String profileKey, int expectedActiveRules) {
- try {
- List<String> facetIds = asList("active_severities", "repositories", "languages", "severities", "statuses", "types");
- SearchWsRequest request = new SearchWsRequest()
- .setQProfile(profileKey)
- .setActivation(true)
- .setFacets(facetIds)
- .setFields(singletonList("actives"));
- Rules.SearchResponse response = session.wsClient().rules().search(request);
-
- // assume that expectedActiveRules fits in first page of results
- assertThat(response.getRulesCount()).isEqualTo(expectedActiveRules);
- assertThat(response.getTotal()).isEqualTo(expectedActiveRules);
- assertThat(response.getActives().getActives()).as(response.toString()).hasSize(expectedActiveRules);
-
- // verify facets
- assertThat(response.getFacets().getFacetsCount()).isEqualTo(facetIds.size());
- response.getFacets().getFacetsList().forEach(facet -> {
- long total = facet.getValuesList().stream()
- .mapToLong(Common.FacetValue::getCount)
- .sum();
- assertThat(total).as("Facet " + facet.getProperty()).isEqualTo((long) expectedActiveRules);
- });
- } catch (HttpException e) {
- if (expectedActiveRules == 0 && e.code() == 404) {
- // profile does not exist, do nothing
- return this;
- }
- throw e;
- }
- return this;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import org.sonarqube.ws.client.WsClient;
-
-public interface Session {
-
- WsClient wsClient();
-
- GroupTester groups();
-
- OrganizationTester organizations();
-
- ProjectTester projects();
-
- QProfileTester qProfiles();
-
- UserTester users();
-
- SettingTester settings();
-
- QGateTester qGates();
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import javax.annotation.Nullable;
-import org.sonarqube.ws.Settings;
-import org.sonarqube.ws.client.setting.ListDefinitionsRequest;
-import org.sonarqube.ws.client.setting.ResetRequest;
-import org.sonarqube.ws.client.setting.SetRequest;
-import org.sonarqube.ws.client.setting.SettingsService;
-
-import static org.sonarqube.ws.Settings.Type.LICENSE;
-
-public class SettingTester {
-
- private static final Set<String> EMAIL_SETTINGS = ImmutableSet.of("email.smtp_host.secured", "email.smtp_port.secured", "email.smtp_secure_connection.secured",
- "email.smtp_username.secured", "email.smtp_password.secured", "email.from", "email.prefix");
-
- private final Session session;
-
- SettingTester(Session session) {
- this.session = session;
- }
-
- public SettingsService service() {
- return session.wsClient().settings();
- }
-
- void deleteAll() {
- List<String> settingKeys = Stream.concat(
- session.wsClient().settings().listDefinitions(ListDefinitionsRequest.builder().build()).getDefinitionsList()
- .stream()
- .filter(def -> def.getType() != LICENSE)
- .map(Settings.Definition::getKey),
- EMAIL_SETTINGS.stream())
- .collect(Collectors.toList());
- session.wsClient().settings().reset(ResetRequest.builder().setKeys(settingKeys).build());
- }
-
- public void resetSettings(String... keys){
- session.wsClient().settings().reset(ResetRequest.builder().setKeys(keys).build());
- }
-
- public void setGlobalSetting(String key, @Nullable String value) {
- setSetting(null, key, value);
- }
-
- public void setGlobalSettings(String... properties) {
- for (int i = 0; i < properties.length; i += 2) {
- setSetting(null, properties[i], properties[i + 1]);
- }
- }
-
- public void setProjectSetting(String componentKey, String key, @Nullable String value) {
- setSetting(componentKey, key, value);
- }
-
- public void setProjectSettings(String componentKey, String... properties) {
- for (int i = 0; i < properties.length; i += 2) {
- setSetting(componentKey, properties[i], properties[i + 1]);
- }
- }
-
- private void setSetting(@Nullable String componentKey, String key, @Nullable String value) {
- if (value == null) {
- session.wsClient().settings().reset(ResetRequest.builder().setKeys(key).setComponent(componentKey).build());
- } else {
- session.wsClient().settings().set(SetRequest.builder().setKey(key).setValue(value).setComponent(componentKey).build());
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import com.sonar.orchestrator.Orchestrator;
-import javax.annotation.Nullable;
-import org.apache.commons.lang.StringUtils;
-import org.junit.rules.ExternalResource;
-import org.sonarqube.qa.util.pageobjects.Navigation;
-import org.sonarqube.ws.client.WsClient;
-import util.selenium.Selenese;
-
-import static java.util.Objects.requireNonNull;
-import static util.ItUtils.newUserWsClient;
-
-/**
- * This JUnit rule wraps an {@link Orchestrator} instance and provides :
- * <ul>
- * <li>enabling the organization feature by default</li>
- * <li>clean-up of organizations between tests</li>
- * <li>clean-up of users between tests</li>
- * <li>clean-up of session when opening a browser (cookies, local storage)</li>
- * <li>quick access to {@link WsClient} instances</li>
- * <li>helpers to generate organizations and users</li>
- * </ul>
- * <p>
- * Recommendation is to define a {@code @Rule} instance. If not possible, then
- * {@code @ClassRule} must be used through a {@link org.junit.rules.RuleChain}
- * around {@link Orchestrator}.
- */
-public class Tester extends ExternalResource implements Session {
-
- private final Orchestrator orchestrator;
-
- // configuration before startup
- private boolean disableOrganizations = false;
- private Elasticsearch elasticsearch = null;
-
- // initialized in #before()
- private boolean beforeCalled = false;
- private Session rootSession;
-
- public Tester(Orchestrator orchestrator) {
- this.orchestrator = orchestrator;
- String elasticsearchHttpPort = orchestrator.getDistribution().getServerProperty("sonar.search.httpPort");
- if (StringUtils.isNotBlank(elasticsearchHttpPort)) {
- this.elasticsearch = new Elasticsearch(Integer.parseInt(elasticsearchHttpPort));
- }
- }
-
- public Tester disableOrganizations() {
- verifyNotStarted();
- disableOrganizations = true;
- return this;
- }
-
- /**
- * Enables Elasticsearch debugging, see {@link #elasticsearch()}.
- *
- * The property "sonar.search.httpPort" must be defined before
- * starting SonarQube server.
- */
- public Tester setElasticsearchHttpPort(int port) {
- verifyNotStarted();
- elasticsearch = new Elasticsearch(port);
- return this;
- }
-
- @Override
- public void before() {
- verifyNotStarted();
- rootSession = new SessionImpl(orchestrator, "admin", "admin");
-
- if (!disableOrganizations) {
- organizations().enableSupport();
- }
-
- beforeCalled = true;
- }
-
- @Override
- public void after() {
- if (!disableOrganizations) {
- organizations().deleteNonGuardedOrganizations();
- }
- users().deleteAll();
- projects().deleteAll();
- settings().deleteAll();
- qGates().deleteAll();
- }
-
- public Session asAnonymous() {
- return as(null, null);
- }
-
- public Session as(String login) {
- return as(login, login);
- }
-
- public Session as(String login, String password) {
- verifyStarted();
- return new SessionImpl(orchestrator, login, password);
- }
-
- public Elasticsearch elasticsearch() {
- return requireNonNull(elasticsearch, "Elasticsearch HTTP port is not defined. See #setElasticsearchHttpPort()");
- }
-
- /**
- * Open a new browser session. Cookies are deleted.
- */
- public Navigation openBrowser() {
- verifyStarted();
- return Navigation.create(orchestrator);
- }
-
- /**
- * @deprecated use Selenide tests with {@link #openBrowser()}
- */
- @Deprecated
- public Tester runHtmlTests(String... htmlTests) {
- Selenese.runSelenese(orchestrator, htmlTests);
- return this;
- }
-
- private void verifyNotStarted() {
- if (beforeCalled) {
- throw new IllegalStateException("Orchestrator should not be already started");
- }
- }
-
- private void verifyStarted() {
- if (!beforeCalled) {
- throw new IllegalStateException("Orchestrator is not started yet");
- }
- }
-
- /**
- * Web service client configured with root access
- */
- @Override
- public WsClient wsClient() {
- verifyStarted();
- return rootSession.wsClient();
- }
-
- @Override
- public GroupTester groups() {
- return rootSession.groups();
- }
-
- @Override
- public OrganizationTester organizations() {
- return rootSession.organizations();
- }
-
- @Override
- public ProjectTester projects() {
- return rootSession.projects();
- }
-
- @Override
- public QProfileTester qProfiles() {
- return rootSession.qProfiles();
- }
-
- @Override
- public UserTester users() {
- return rootSession.users();
- }
-
- @Override
- public SettingTester settings() {
- return rootSession.settings();
- }
-
- @Override
- public QGateTester qGates() {
- return rootSession.qGates();
- }
-
- private static class SessionImpl implements Session {
- private final WsClient client;
-
- private SessionImpl(Orchestrator orchestrator, @Nullable String login, @Nullable String password) {
- this.client = newUserWsClient(orchestrator, login, password);
- }
-
- @Override
- public WsClient wsClient() {
- return client;
- }
-
- @Override
- public GroupTester groups() {
- return new GroupTester(this);
- }
-
- @Override
- public OrganizationTester organizations() {
- return new OrganizationTester(this);
- }
-
- @Override
- public ProjectTester projects() {
- return new ProjectTester(this);
- }
-
- @Override
- public QProfileTester qProfiles() {
- return new QProfileTester(this);
- }
-
- @Override
- public UserTester users() {
- return new UserTester(this);
- }
-
- @Override
- public SettingTester settings() {
- return new SettingTester(this);
- }
-
- @Override
- public QGateTester qGates() {
- return new QGateTester(this);
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-import org.sonarqube.ws.Organizations;
-import org.sonarqube.ws.WsUsers;
-import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
-import org.sonarqube.ws.client.PostRequest;
-import org.sonarqube.ws.client.user.CreateRequest;
-import org.sonarqube.ws.client.user.SearchRequest;
-import org.sonarqube.ws.client.user.UsersService;
-import org.sonarqube.ws.client.usergroup.AddUserWsRequest;
-
-import static java.util.Arrays.stream;
-
-public class UserTester {
-
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- private final Session session;
-
- UserTester(Session session) {
- this.session = session;
- }
-
- void deleteAll() {
- session.wsClient().users().search(SearchRequest.builder().build()).getUsersList()
- .stream()
- .filter(u -> !"admin".equals(u.getLogin()))
- .forEach(u -> {
- PostRequest request = new PostRequest("api/users/deactivate").setParam("login", u.getLogin());
- session.wsClient().wsConnector().call(request);
- });
- }
-
- @SafeVarargs
- public final User generate(Consumer<CreateRequest.Builder>... populators) {
- int id = ID_GENERATOR.getAndIncrement();
- String login = "login" + id;
- CreateRequest.Builder request = CreateRequest.builder()
- .setLogin(login)
- .setPassword(login)
- .setName("name" + id)
- .setEmail(id + "@test.com");
- stream(populators).forEach(p -> p.accept(request));
- return service().create(request.build()).getUser();
- }
-
- @SafeVarargs
- public final User generateAdministrator(Consumer<CreateRequest.Builder>... populators) {
- User user = generate(populators);
- session.wsClient().permissions().addUser(new org.sonarqube.ws.client.permission.AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin"));
- session.wsClient().userGroups().addUser(org.sonarqube.ws.client.usergroup.AddUserWsRequest.builder().setLogin(user.getLogin()).setName("sonar-administrators").build());
- return user;
- }
-
- @SafeVarargs
- public final User generateAdministrator(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
- User user = generate(populators);
- session.wsClient().organizations().addMember(organization.getKey(), user.getLogin());
- session.wsClient().userGroups().addUser(AddUserWsRequest.builder()
- .setOrganization(organization.getKey())
- .setLogin(user.getLogin())
- .setName("Owners")
- .build());
- return user;
- }
-
- @SafeVarargs
- public final User generateMember(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
- User user = generate(populators);
- session.wsClient().organizations().addMember(organization.getKey(), user.getLogin());
- return user;
- }
-
- public UsersService service() {
- return session.wsClient().users();
- }
-
- public Optional<WsUsers.SearchWsResponse.User> getByLogin(String login) {
- List<WsUsers.SearchWsResponse.User> users = session.wsClient().users().search(SearchRequest.builder().setQuery(login).build()).getUsersList();
- if (users.size() == 1) {
- return Optional.of(users.get(0));
- }
- return Optional.empty();
- }
-}
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Byteman;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Common;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Organizations.Organization;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.sonarqube.tests.Category3Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsPermissions;
import org.sonarqube.ws.WsPermissions.CreateTemplateWsResponse;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.permission.AddUserWsRequest;
import org.sonarqube.ws.client.qualityprofile.CreateRequest;
+import util.selenium.Selenese;
import static util.ItUtils.runProjectAnalysis;
tester.wsClient().permissions().addUser(new AddUserWsRequest().setLogin("profileadm").setPermission("profileadmin"));
createProfile("xoo", "foo");
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
// Verify normal user is not allowed to do any modification
"/authorisation/QualityProfileAdminPermissionTest/normal-user.html",
// Verify profile admin is allowed to do modifications
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsRequest;
import org.sonarqube.ws.client.WsResponse;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category2Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Common;
import org.sonarqube.ws.WsBranches;
import org.sonarqube.ws.client.GetRequest;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
-import org.sonarqube.tests.LogsTailer;
+import org.sonarqube.qa.util.LogsTailer;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.ce.ActivityStatusWsRequest;
import util.ItUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsProjects;
import org.sonarqube.ws.WsUsers;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.ProjectAnalyses;
import org.sonarqube.ws.WsMeasures;
import org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueQuery;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsClient;
import org.subethamail.wiser.Wiser;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Issues.Issue;
import org.sonarqube.ws.Issues.SearchWsResponse;
import org.sonarqube.ws.Organizations.Organization;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.issue.SearchWsRequest;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Issues.Issue;
import org.sonarqube.ws.Organizations;
import org.junit.Test;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsUsers;
import util.issue.IssueRule;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.RuleChain;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsMeasures;
import org.sonarqube.qa.util.pageobjects.measures.MeasureContent;
import org.sonarqube.qa.util.pageobjects.measures.MeasuresPage;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.HttpException;
import org.junit.Test;
import org.sonarqube.qa.util.pageobjects.organization.MembersPage;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonarqube.tests.OrganizationTester;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.OrganizationTester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.Rules;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsUsers;
import org.sonarqube.ws.client.organization.SearchWsRequest;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Session;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.TesterSession;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsRoot;
import org.sonarqube.ws.WsUsers;
import util.user.UserRule;
public void root_can_be_set_and_unset_via_web_services() {
WsUsers.CreateWsResponse.User user1 = tester.users().generate();
WsUsers.CreateWsResponse.User user2 = tester.users().generate();
- Session user1Session = tester.as(user1.getLogin());
- Session user2Session = tester.as(user2.getLogin());
+ TesterSession user1Session = tester.as(user1.getLogin());
+ TesterSession user2Session = tester.as(user2.getLogin());
// non root can not set or unset root another user not itself
expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user2.getLogin()));
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import static util.ItUtils.expectForbiddenError;
import org.sonarqube.qa.util.pageobjects.ProjectsManagementPage;
import org.sonarqube.qa.util.pageobjects.settings.SettingsPage;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsPermissions;
import org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest;
import org.sonarqube.ws.client.permission.CreateTemplateWsRequest;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsProjects.CreateWsResponse;
import org.sonarqube.ws.WsProjects.SearchWsResponse.Component;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.client.component.SearchProjectsRequest;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsProjects;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsProjects;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsProjects;
try {
ProjectQualityGatePage page = openPage();
SelenideElement selectedQualityGate = page.getSelectedQualityGate();
- selectedQualityGate.should(Condition.hasText("Default"));
- selectedQualityGate.should(Condition.hasText(customQualityGate.name()));
+ selectedQualityGate.should(Condition.text("Default"));
+ selectedQualityGate.should(Condition.text(customQualityGate.name()));
} finally {
qualityGateClient().unsetDefault();
qualityGateClient().destroy(customQualityGate.id());
ProjectQualityGatePage page = openPage();
SelenideElement selectedQualityGate = page.getSelectedQualityGate();
- selectedQualityGate.shouldNot(Condition.hasText("Default"));
- selectedQualityGate.should(Condition.hasText(customQualityGate.name()));
+ selectedQualityGate.shouldNot(Condition.text("Default"));
+ selectedQualityGate.should(Condition.text(customQualityGate.name()));
}
@Test
page.setQualityGate(customQualityGate.name());
SelenideElement selectedQualityGate = page.getSelectedQualityGate();
- selectedQualityGate.should(Condition.hasText(customQualityGate.name()));
+ selectedQualityGate.should(Condition.text(customQualityGate.name()));
}
@Test
page.setQualityGate(customQualityGate.name());
SelenideElement selectedQualityGate = page.getSelectedQualityGate();
- selectedQualityGate.should(Condition.hasText("Default"));
- selectedQualityGate.should(Condition.hasText(customQualityGate.name()));
+ selectedQualityGate.should(Condition.text("Default"));
+ selectedQualityGate.should(Condition.text(customQualityGate.name()));
} finally {
qualityGateClient().unsetDefault();
qualityGateClient().destroy(customQualityGate.id());
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsProjects.CreateWsResponse;
import org.sonarqube.ws.WsProjects.SearchWsResponse;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.qa.util.pageobjects.projects.ProjectsPage;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.qa.util.pageobjects.projects.ProjectsPage;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUsers;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsClient;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Common;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsComponents.Component;
import org.sonarqube.qa.util.pageobjects.ProjectDashboardPage;
import org.sonarqube.qa.util.pageobjects.QualityGatePage;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsUsers;
import util.issue.IssueRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsCe;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates;
import org.sonarqube.ws.client.PostRequest;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsMeasures;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates;
import org.sonar.wsclient.qualitygate.QualityGate;
import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Session;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.TesterSession;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsCe;
Organization organization = tester.organizations().getDefaultOrganization();
WsUsers.CreateWsResponse.User user = tester.users().generateMember(organization);
tester.wsClient().permissions().addUser(new AddUserWsRequest().setLogin(user.getLogin()).setPermission("gateadmin").setOrganization(organization.getKey()));
- Session qGateAdminTester = tester.as(user.getLogin());
+ TesterSession qGateAdminTester = tester.as(user.getLogin());
QualityGatesService qGateService = qGateAdminTester.qGates().service();
// perform administration operations
WsQualityGates.CreateWsResponse qualityGate = qGateAdminTester.qGates().generate();
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.qa.util.pageobjects.ProjectActivityPage;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates;
import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Byteman;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.client.rule.SearchWsRequest;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Session;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.TesterSession;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.QualityProfiles.CreateWsResponse;
Organization org = tester.organizations().generate();
User administrator = tester.users().generateAdministrator(org);
QualityProfile builtInProfile = getProfile(org, p -> p.getIsBuiltIn() && "Basic".equals(p.getName()) && "xoo".equals(p.getLanguage()));
- Session adminSession = tester.as(administrator.getLogin());
+ TesterSession adminSession = tester.as(administrator.getLogin());
QualityProfiles.CopyWsResponse copyResponse = adminSession.qProfiles().service().copy(new CopyRequest(builtInProfile.getKey(), "My copy"));
Organization org = tester.organizations().generate();
User administrator = tester.users().generateAdministrator(org);
QualityProfile builtInProfile = getProfile(org, p -> p.getIsBuiltIn() && "Basic".equals(p.getName()) && "xoo".equals(p.getLanguage()));
- Session adminSession = tester.as(administrator.getLogin());
+ TesterSession adminSession = tester.as(administrator.getLogin());
QualityProfiles.CopyWsResponse copyResponse = adminSession.qProfiles().service().copy(new CopyRequest(builtInProfile.getKey(), "My copy"));
adminSession.qProfiles().service().changeParent(
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.QProfileTester;
-import org.sonarqube.tests.Session;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.QProfileTester;
+import org.sonarqube.qa.util.TesterSession;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.QualityProfiles.CreateWsResponse.QualityProfile;
Organization org = tester.organizations().generate();
QualityProfile profile = tester.qProfiles().createXooProfile(org);
- Session anonymousSession = tester.asAnonymous();
+ TesterSession anonymousSession = tester.asAnonymous();
expectUnauthorizedError(() -> anonymousSession.qProfiles().createXooProfile(org));
expectUnauthorizedError(() -> anonymousSession.qProfiles().service().delete(profile.getKey()));
Organization org = tester.organizations().generate();
User orgAdmin = tester.users().generateAdministrator(org);
- Session adminSession = tester.as(orgAdmin.getLogin());
+ TesterSession adminSession = tester.as(orgAdmin.getLogin());
QualityProfile profile = adminSession.qProfiles().createXooProfile(org);
// root can activate rule and delete the profile
Organization org = tester.organizations().generate();
User user = tester.users().generateAdministrator(org);
- Session adminSession = tester.as(user.getLogin());
+ TesterSession adminSession = tester.as(user.getLogin());
QualityProfile parentProfile = adminSession.qProfiles().createXooProfile(org);
QualityProfile inheritedProfile = adminSession.qProfiles().service().create(
CreateRequest.builder()
Organization org = tester.organizations().generate();
User admin = tester.users().generateAdministrator(org);
- Session adminSession = tester.as(admin.getLogin());
+ TesterSession adminSession = tester.as(admin.getLogin());
String projectKey = randomAlphanumeric(10);
String projectName = randomAlphanumeric(10);
User admin = tester.users().generateAdministrator(org);
String projectKey = randomAlphanumeric(10);
String projectName = randomAlphanumeric(10);
- Session adminSession = tester.as(admin.getLogin());
+ TesterSession adminSession = tester.as(admin.getLogin());
QualityProfile newXooProfile = adminSession.qProfiles().createXooProfile(org);
adminSession.wsClient().wsConnector().call(new PostRequest("api/projects/create")
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.qa.util.pageobjects.QualityProfilePage;
import org.sonarqube.qa.util.pageobjects.RulesPage;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
import org.sonarqube.ws.client.qualityprofile.ChangeParentRequest;
+import util.selenium.Selenese;
import static com.codeborne.selenide.Selenide.$;
import static util.ItUtils.projectDir;
@Test
public void testHomePage() {
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/organization/OrganizationQualityProfilesUiTest/should_display_list.html",
"/organization/OrganizationQualityProfilesUiTest/should_open_from_list.html",
"/organization/OrganizationQualityProfilesUiTest/should_filter_by_language.html");
@Test
public void testProfilePage() {
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/organization/OrganizationQualityProfilesUiTest/should_display_profile_rules.html",
"/organization/OrganizationQualityProfilesUiTest/should_display_profile_inheritance.html",
"/organization/OrganizationQualityProfilesUiTest/should_display_profile_exporters.html");
@Test
public void testProfileChangelog() {
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/organization/OrganizationQualityProfilesUiTest/should_display_changelog.html");
}
@Ignore("to be replaced by selenide test in order to inject profile key")
@Test
public void testComparison() {
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_compare.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_compare.html");
}
@Test
public void testCreation() {
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_create.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_create.html");
}
@Test
public void testDeletion() {
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_delete.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_delete.html");
}
@Test
public void testCopying() {
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_copy.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_copy.html");
}
@Test
public void testRenaming() {
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_rename.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_rename.html");
}
@Test
public void testSettingDefault() {
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_set_default.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_set_default.html");
}
@Test
public void testRestoration() {
deleteProfile("xoo", "empty");
- tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_restore.html");
+ Selenese.runSelenese(orchestrator, "/organization/OrganizationQualityProfilesUiTest/should_restore.html");
}
@Test
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Common;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles.CreateWsResponse;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
import org.sonarqube.ws.client.qualityprofile.ChangeParentRequest;
import org.sonarqube.ws.client.qualityprofile.CreateRequest;
+import util.selenium.Selenese;
import util.user.UserRule;
import static com.codeborne.selenide.Selenide.$;
@Test
public void testHomePage() {
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/qualityProfile/QualityProfilesUiTest/should_display_list.html",
"/qualityProfile/QualityProfilesUiTest/should_open_from_list.html",
"/qualityProfile/QualityProfilesUiTest/should_filter_by_language.html");
@Test
public void testProfilePage() {
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/qualityProfile/QualityProfilesUiTest/should_display_profile_rules.html",
"/qualityProfile/QualityProfilesUiTest/should_display_profile_inheritance.html",
"/qualityProfile/QualityProfilesUiTest/should_display_profile_projects.html",
@Test
public void testProfileChangelog() {
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/qualityProfile/QualityProfilesUiTest/should_display_changelog.html");
}
@Ignore("find a way to know profile key inside selenium tests")
@Test
public void testComparison() {
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_compare.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_compare.html");
}
@Test
public void testCreation() {
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_create.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_create.html");
}
@Test
public void testDeletion() {
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_delete.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_delete.html");
}
@Test
public void testCopying() {
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_copy.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_copy.html");
}
@Test
public void testRenaming() {
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_rename.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_rename.html");
}
@Test
public void testSettingDefault() {
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_set_default.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_set_default.html");
}
@Test
public void testRestore() {
deleteProfile("xoo", "empty");
- tester.runHtmlTests("/qualityProfile/QualityProfilesUiTest/should_restore.html");
+ Selenese.runSelenese(orchestrator, "/qualityProfile/QualityProfilesUiTest/should_restore.html");
}
private void createProfile(String language, String name) {
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles.CreateWsResponse;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Byteman;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.rule.CreateWsRequest;
import org.sonarqube.ws.client.rule.SearchWsRequest;
import util.ItUtils;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.client.PostRequest;
import util.ItUtils;
import org.junit.Test;
import org.sonarqube.qa.util.pageobjects.RulesPage;
import org.sonarqube.tests.Category2Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
public class RulesPageTest {
@ClassRule
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.QualityProfiles.CreateWsResponse;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsSystem;
import util.ItUtils;
+import util.selenium.Selenese;
import static org.apache.commons.lang.StringUtils.startsWithAny;
import static org.assertj.core.api.Assertions.assertThat;
public void display_warnings_when_using_h2() {
String dialect = orchestrator.getConfiguration().getString("sonar.jdbc.dialect");
if (dialect == null || dialect.equals("h2") || dialect.equals("embedded")) {
- tester.runHtmlTests("/serverSystem/ServerSystemTest/derby-warning.html");
+ Selenese.runSelenese(orchestrator, "/serverSystem/ServerSystemTest/derby-warning.html");
}
}
*/
@Test
public void hide_jdbc_settings_to_non_admin() {
- tester.runHtmlTests("/serverSystem/ServerSystemTest/hide-jdbc-settings.html");
+ Selenese.runSelenese(orchestrator, "/serverSystem/ServerSystemTest/hide-jdbc-settings.html");
}
@Test
orchestrator.executeBuild(SonarScanner.create(ItUtils.projectDir("shared/xoo-sample"))
.setProperty("sonar.projectKey", "myproject.jsp"));
// Access dashboard
- tester.runHtmlTests("/serverSystem/ServerSystemTest/url_ending_by_jsp.html");
+ Selenese.runSelenese(orchestrator, "/serverSystem/ServerSystemTest/url_ending_by_jsp.html");
}
/**
import org.junit.Test;
import org.sonarqube.qa.util.pageobjects.SystemInfoPage;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsResponse;
import util.ItUtils;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
-import org.sonarqube.tests.Elasticsearch;
+import org.sonarqube.qa.util.Elasticsearch;
import org.sonarqube.ws.WsSystem;
import org.sonarqube.ws.client.WsClient;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Settings;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.setting.ValuesRequest;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
+import util.selenium.Selenese;
import static util.ItUtils.runProjectAnalysis;
public void support_japanese_charset() {
runProjectAnalysis(orchestrator, "sourceCode/japanese-charset", "sonar.sourceEncoding", "Shift_JIS");
- tester.runHtmlTests("/sourceCode/EncodingTest/japanese_sources.html");
+ Selenese.runSelenese(orchestrator, "/sourceCode/EncodingTest/japanese_sources.html");
}
}
package org.sonarqube.tests.sourceCode;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category1Suite;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.tests.Category1Suite;
+import util.selenium.Selenese;
import static util.ItUtils.runProjectAnalysis;
runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v2");
// SONAR-3893 & SONAR-4247
- tester.runHtmlTests("/sourceCode/HighlightingTest/syntax-highlighting.html");
+ Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting.html");
// SONAR-4249 & SONAR-4250
- tester.runHtmlTests("/sourceCode/HighlightingTest/symbol-usages-highlighting.html");
+ Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/symbol-usages-highlighting.html");
}
// Check that E/S index is updated when file content is unchanged but plugin generates different syntax/symbol highlighting
public void update_highlighting_even_when_code_unchanged() {
runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v1");
- tester.runHtmlTests("/sourceCode/HighlightingTest/syntax-highlighting-v1.html");
+ Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting-v1.html");
runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v2");
- tester.runHtmlTests("/sourceCode/HighlightingTest/syntax-highlighting-v2.html");
- tester.runHtmlTests("/sourceCode/HighlightingTest/symbol-usages-highlighting.html");
+ Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting-v2.html");
+ Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/symbol-usages-highlighting.html");
}
}
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import static util.ItUtils.projectDir;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
-import org.sonarqube.tests.LogsTailer;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.LogsTailer;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUsers;
import org.sonarqube.ws.client.user.SearchRequest;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.RuleChain;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.GetRequest;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
import org.junit.Rule;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import static util.ItUtils.projectDir;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsProjects;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.project.CreateRequest;
import util.ItUtils;
+import util.selenium.Selenese;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
@Test
public void test_static_files() {
- tester.runHtmlTests("/ui/UiExtensionsTest/static-files.html");
+ Selenese.runSelenese(orchestrator, "/ui/UiExtensionsTest/static-files.html");
}
@Test
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.pageobjects.LoginPage;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
import org.sonarqube.ws.WsUserTokens;
import org.sonarqube.ws.WsUsers;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.usertoken.RevokeWsRequest;
import org.sonarqube.ws.client.usertoken.SearchWsRequest;
import org.sonarqube.ws.client.usertoken.UserTokensService;
+import util.selenium.Selenese;
import static java.lang.String.format;
import static java.util.Arrays.asList;
public void test_authentication_in_ui() {
tester.users().generate(u -> u.setLogin("simple-user").setPassword("password"));
tester.users().generateAdministrator(u -> u.setLogin("admin-user").setPassword("admin-user"));
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
"/user/LocalAuthenticationTest/login_successful.html",
"/user/LocalAuthenticationTest/login_wrong_password.html",
"/user/LocalAuthenticationTest/should_not_be_unlogged_when_going_to_login_page.html");
public void test_authentication_redirects_in_ui() {
tester.users().generate(u -> u.setLogin("simple-user").setPassword("password"));
tester.users().generateAdministrator(u -> u.setLogin("admin-user").setPassword("admin-user"));
- tester.runHtmlTests(
- "/user/LocalAuthenticationTest/redirect_to_login_when_not_enough_privilege.html",
+ Selenese.runSelenese(orchestrator,
+ "/user/LocalAuthenticationTest/redirect_to_login_when_not_enough_privilege.html",
// SONAR-2132
"/user/LocalAuthenticationTest/redirect_to_original_url_after_direct_login.html",
"/user/LocalAuthenticationTest/redirect_to_original_url_with_parameters_after_direct_login.html",
tester.users().generateAdministrator(u -> u.setLogin("admin-user").setPassword("admin-user"));
setServerProperty(orchestrator, "sonar.forceAuthentication", "true");
- tester.runHtmlTests(
+ Selenese.runSelenese(orchestrator,
// SONAR-3473
"/user/LocalAuthenticationTest/force-authentication.html");
}
import org.junit.Test;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.PostRequest;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.tests.Category4Suite;
-import org.sonarqube.tests.Tester;
import org.sonarqube.ws.WsUsers.SearchWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsResponse;
import org.sonarqube.ws.client.permission.AddUserWsRequest;
import org.sonarqube.ws.client.user.CreateRequest;
+import util.selenium.Selenese;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
// As this property is null, the plugin will throw an exception
tester.settings().setGlobalSettings("sonar.auth.fake-oauth2-id-provider.user", null);
- tester.runHtmlTests("/user/OAuth2IdentityProviderTest/display_unauthorized_page_when_authentication_failed.html");
+ Selenese.runSelenese(orchestrator, "/user/OAuth2IdentityProviderTest/display_unauthorized_page_when_authentication_failed.html");
assertThatUserDoesNotExist(USER_LOGIN);
}
enablePlugin();
tester.settings().setGlobalSettings("sonar.auth.fake-oauth2-id-provider.allowsUsersToSignUp", "false");
- tester.runHtmlTests("/user/OAuth2IdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html");
+ Selenese.runSelenese(orchestrator, "/user/OAuth2IdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html");
assertThatUserDoesNotExist(USER_LOGIN);
}
enablePlugin();
tester.settings().setGlobalSettings("sonar.auth.fake-oauth2-id-provider.throwUnauthorizedMessage", "true");
- tester.runHtmlTests("/user/OAuth2IdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html");
+ Selenese.runSelenese(orchestrator, "/user/OAuth2IdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html");
File logFile = orchestrator.getServer().getWebLogs();
assertThat(FileUtils.readFileToString(logFile)).doesNotContain("A functional error has happened");
enablePlugin();
tester.users().generate(u -> u.setLogin("another").setName("Another").setEmail(USER_EMAIL).setPassword("another"));
- tester.runHtmlTests("/user/OAuth2IdentityProviderTest/fail_when_email_already_exists.html");
+ Selenese.runSelenese(orchestrator, "/user/OAuth2IdentityProviderTest/fail_when_email_already_exists.html");
File logFile = orchestrator.getServer().getWebLogs();
assertThat(FileUtils.readFileToString(logFile))
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.WsClient;
import util.ItUtils;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUserGroups.Group;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
import org.sonar.wsclient.services.AuthenticationQuery;
import org.sonar.wsclient.user.UserParameters;
import org.sonarqube.qa.util.pageobjects.SystemInfoPage;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsResponse;
import org.sonarqube.ws.client.user.CreateRequest;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.sonarqube.tests.Byteman;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.user.SearchRequest;
import org.sonarqube.ws.client.user.UpdateRequest;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueClient;
import org.sonar.wsclient.issue.IssueQuery;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.SettingTester;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsComponents.Component;
import org.sonarqube.ws.WsMeasures;
import org.sonarqube.ws.WsMeasures.Measure;
}
/**
- * @deprecated replaced by {@link org.sonarqube.tests.SettingTester#setGlobalSetting(String, String)}
+ * @deprecated replaced by {@link SettingTester#setGlobalSetting(String, String)}
*/
@Deprecated
public static void setServerProperty(Orchestrator orchestrator, String key, @Nullable String value) {
}
/**
- * @deprecated replaced by {@link org.sonarqube.tests.SettingTester#setProjectSetting(String, String, String)}
+ * @deprecated replaced by {@link SettingTester#setProjectSetting(String, String, String)}
*/
@Deprecated
public static void setServerProperty(Orchestrator orchestrator, @Nullable String componentKey, String key, @Nullable String value) {
}
/**
- * @deprecated replaced by {@link org.sonarqube.tests.SettingTester#setGlobalSetting(String, String)} or {@link org.sonarqube.tests.SettingTester#setProjectSettings(String, String...)}
+ * @deprecated replaced by {@link SettingTester#setGlobalSetting(String, String)} or {@link SettingTester#setProjectSettings(String, String...)}
*/
@Deprecated
public static void setServerProperties(Orchestrator orchestrator, @Nullable String componentKey, String... properties) {
}
/**
- * @deprecated replaced by {@link org.sonarqube.tests.SettingTester#resetSettings(String...)}
+ * @deprecated replaced by {@link SettingTester#resetSettings(String...)}
*/
@Deprecated
public static void resetSettings(Orchestrator orchestrator, @Nullable String componentKey, String... keys) {
import java.io.File;
import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
-import org.sonarqube.tests.Tester;
+import org.sonarqube.qa.util.Tester;
/**
* Selenium HTML tests, generally written with Selenium IDE
}
/**
- * @deprecated replaced by {@link Tester#runHtmlTests(String...)}
+ * Replaced by Selenide
*/
@Deprecated
public static void runSelenese(Orchestrator orchestrator, String... htmlFiles) {
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
+import org.sonarqube.qa.util.Tester;
/**
- * @deprecated replaced by {@link org.sonarqube.tests.Tester}
+ * @deprecated replaced by {@link Tester}
*/
@Deprecated
public interface GroupManagement {
import com.google.gson.Gson;
import java.util.List;
+import org.sonarqube.qa.util.Tester;
/**
- * @deprecated replaced by {@link org.sonarqube.tests.Tester}
+ * @deprecated replaced by {@link Tester}
*/
@Deprecated
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.junit.rules.ExternalResource;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.WsUsers;
import org.sonarqube.ws.client.GetRequest;
import static util.ItUtils.newAdminWsClient;
/**
- * @deprecated replaced by {@link org.sonarqube.tests.Tester}
+ * @deprecated replaced by {@link Tester}
*/
@Deprecated
public class UserRule extends ExternalResource implements GroupManagement {