Skip to content

Commit

Permalink
Improve integration tests by using new Tester class
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Jun 23, 2017
1 parent 8af2f37 commit 78e2ea2
Show file tree
Hide file tree
Showing 91 changed files with 1,792 additions and 1,913 deletions.
6 changes: 0 additions & 6 deletions cix.sh
Expand Up @@ -18,12 +18,6 @@ case "$RUN_ACTIVITY" in
./run-integration-tests.sh "${CATEGORY}" "http://infra.internal.sonarsource.com/jenkins/orch-${DB_ENGINE}.properties" ./run-integration-tests.sh "${CATEGORY}" "http://infra.internal.sonarsource.com/jenkins/orch-${DB_ENGINE}.properties"
;; ;;


run-integration-tests-*)
CATEGORY=$(sed "s/run-integration-tests-//g" <<< $RUN_ACTIVITY)

./run-integration-tests.sh "${CATEGORY}" "http://infra.internal.sonarsource.com/jenkins/orch-embedded.properties"
;;

run-it-released-plugins) run-it-released-plugins)
./run-integration-tests.sh "Plugins" "http://infra.internal.sonarsource.com/jenkins/orch-h2.properties" ./run-integration-tests.sh "Plugins" "http://infra.internal.sonarsource.com/jenkins/orch-h2.properties"
;; ;;
Expand Down
2 changes: 0 additions & 2 deletions it/it-tests/src/test/java/it/Category4Suite.java
Expand Up @@ -46,7 +46,6 @@
import it.user.LocalAuthenticationTest; import it.user.LocalAuthenticationTest;
import it.user.MyAccountPageTest; import it.user.MyAccountPageTest;
import it.user.OAuth2IdentityProviderTest; import it.user.OAuth2IdentityProviderTest;
import it.user.OnboardingTest;
import it.ws.WsLocalCallTest; import it.ws.WsLocalCallTest;
import it.ws.WsTest; import it.ws.WsTest;
import org.junit.ClassRule; import org.junit.ClassRule;
Expand All @@ -66,7 +65,6 @@
// user // user
MyAccountPageTest.class, MyAccountPageTest.class,
FavoritesWsTest.class, FavoritesWsTest.class,
OnboardingTest.class,
// authentication // authentication
ForceAuthenticationTest.class, ForceAuthenticationTest.class,
LocalAuthenticationTest.class, LocalAuthenticationTest.class,
Expand Down
4 changes: 3 additions & 1 deletion it/it-tests/src/test/java/it/Category5Suite.java
Expand Up @@ -25,6 +25,7 @@
import it.settings.LicensesPageTest; import it.settings.LicensesPageTest;
import it.settings.SettingsTestRestartingOrchestrator; import it.settings.SettingsTestRestartingOrchestrator;
import it.updateCenter.UpdateCenterTest; import it.updateCenter.UpdateCenterTest;
import it.user.OnboardingTest;
import it.user.RealmAuthenticationTest; import it.user.RealmAuthenticationTest;
import it.user.SsoAuthenticationTest; import it.user.SsoAuthenticationTest;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
Expand All @@ -45,7 +46,8 @@
// update center // update center
UpdateCenterTest.class, UpdateCenterTest.class,
RealmAuthenticationTest.class, RealmAuthenticationTest.class,
SsoAuthenticationTest.class SsoAuthenticationTest.class,
OnboardingTest.class
}) })
public class Category5Suite { public class Category5Suite {


Expand Down
Expand Up @@ -48,8 +48,7 @@ public class ProjectsAdministrationTest {
@Rule @Rule
public UserRule userRule = UserRule.from(orchestrator); public UserRule userRule = UserRule.from(orchestrator);


@Rule private Navigation nav = Navigation.create(orchestrator);
public Navigation nav = Navigation.get(orchestrator);


private String adminUser; private String adminUser;


Expand Down
Expand Up @@ -366,7 +366,7 @@ Date getDate() {
private static Date getAnalysisDate(Function<List<ProjectAnalyses.Analysis>, Optional<ProjectAnalyses.Analysis>> chooseItem) { private static Date getAnalysisDate(Function<List<ProjectAnalyses.Analysis>, Optional<ProjectAnalyses.Analysis>> chooseItem) {
return Optional.of( return Optional.of(
ItUtils.newWsClient(ORCHESTRATOR) ItUtils.newWsClient(ORCHESTRATOR)
.projectAnanlysis() .projectAnalysis()
.search(SearchRequest.builder().setProject(SAMPLE_PROJECT_KEY).build()) .search(SearchRequest.builder().setProject(SAMPLE_PROJECT_KEY).build())
.getAnalysesList()) .getAnalysesList())
.flatMap(chooseItem) .flatMap(chooseItem)
Expand Down
63 changes: 28 additions & 35 deletions it/it-tests/src/test/java/it/issue/IssueTagsTest.java
Expand Up @@ -29,20 +29,18 @@
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.sonarqube.ws.Organizations; import org.sonarqube.test.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsUsers.CreateWsResponse.User;
import org.sonarqube.ws.client.issue.SearchWsRequest; import org.sonarqube.ws.client.issue.SearchWsRequest;
import org.sonarqube.ws.client.permission.AddUserWsRequest; import org.sonarqube.ws.client.permission.AddUserWsRequest;
import org.sonarqube.ws.client.project.CreateRequest; import org.sonarqube.ws.client.project.CreateRequest;
import util.ItUtils; import util.ItUtils;
import util.OrganizationRule;
import util.user.UserRule;


import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.newProjectKey; import static util.ItUtils.newProjectKey;
import static util.ItUtils.newUserWsClient;
import static util.ItUtils.projectDir; import static util.ItUtils.projectDir;
import static util.ItUtils.restoreProfile; import static util.ItUtils.restoreProfile;


Expand All @@ -53,23 +51,22 @@ public class IssueTagsTest {


@ClassRule @ClassRule
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;

@Rule @Rule
public UserRule userRule = new UserRule(orchestrator); public Tester tester = new Tester(orchestrator);
@Rule
public OrganizationRule organizationRule = new OrganizationRule(orchestrator);


private Organizations.Organization organization; private Organization organization;


@Before @Before
public void setUp() { public void setUp() {
organization = organizationRule.create(); organization = tester.organizations().generate();
} }


@Test @Test
public void getTags() { public void getTags() {
restoreProfile(orchestrator, IssueTagsTest.class.getResource("/issue/one-issue-per-line-profile.xml"), organization.getKey()); restoreProfile(orchestrator, IssueTagsTest.class.getResource("/issue/one-issue-per-line-profile.xml"), organization.getKey());
String projectKey = newProjectKey(); String projectKey = newProjectKey();
ItUtils.newAdminWsClient(orchestrator).projects().create( tester.wsClient().projects().create(
CreateRequest.builder() CreateRequest.builder()
.setKey(projectKey) .setKey(projectKey)
.setOrganization(organization.getKey()) .setOrganization(organization.getKey())
Expand All @@ -78,8 +75,8 @@ public void getTags() {
.build()); .build());
analyzeProject(projectKey); analyzeProject(projectKey);


String issue = newAdminWsClient(orchestrator).issues().search(new SearchWsRequest()).getIssues(0).getKey(); String issue = tester.wsClient().issues().search(new SearchWsRequest()).getIssues(0).getKey();
newAdminWsClient(orchestrator).issues().setTags(issue, "bla", "blubb"); tester.wsClient().issues().setTags(issue, "bla", "blubb");


String[] publicTags = {"bad-practice", "convention", "pitfall"}; String[] publicTags = {"bad-practice", "convention", "pitfall"};
String[] privateTags = {"bad-practice", "bla", "blubb", "convention", "pitfall"}; String[] privateTags = {"bad-practice", "bla", "blubb", "convention", "pitfall"};
Expand All @@ -88,48 +85,44 @@ public void getTags() {
// anonymous must not see custom tags of private project // anonymous must not see custom tags of private project
{ {
String anonymous = null; String anonymous = null;
String anonymousPassword = null; assertTags(anonymous, organization.getKey(), publicTags);
assertTags(anonymous, anonymousPassword, organization.getKey(), publicTags); assertTags(anonymous, defaultOrganization, publicTags);
assertTags(anonymous, anonymousPassword, defaultOrganization, publicTags);
} }


// stranger must not see custom tags of private project // stranger must not see custom tags of private project
{ {
String stranger = randomAlphabetic(10).toLowerCase(); User stranger = tester.users().generate();
String strangerPassword = randomAlphabetic(8); assertTags(stranger.getLogin(), organization.getKey(), publicTags);
userRule.createUser(stranger, strangerPassword); assertTags(stranger.getLogin(), defaultOrganization, publicTags);
assertTags(stranger, strangerPassword, organization.getKey(), publicTags);
assertTags(stranger, strangerPassword, defaultOrganization, publicTags);
} }


// member with user permission must be able to see custom tags of private project, if he provides the organization parameter // member with user permission must be able to see custom tags of private project, if he provides the organization parameter
{ {
String member = randomAlphabetic(10).toLowerCase(); User member = tester.users().generate();
String memberPassword = randomAlphabetic(8); addMemberToOrganization(member);
userRule.createUser(member, memberPassword);
addMember(member);
grantUserPermission(projectKey, member); grantUserPermission(projectKey, member);
assertTags(member, memberPassword, organization.getKey(), privateTags); assertTags(member.getLogin(), organization.getKey(), privateTags);
assertTags(member, memberPassword, defaultOrganization, publicTags); assertTags(member.getLogin(), defaultOrganization, publicTags);
} }
} }


private void addMember(String member) { private void addMemberToOrganization(User member) {
newAdminWsClient(orchestrator).organizations().addMember(organization.getKey(), member); tester.organizations().service().addMember(organization.getKey(), member.getLogin());
} }


private void grantUserPermission(String projectKey, String member) { private void grantUserPermission(String projectKey, User member) {
newAdminWsClient(orchestrator).permissions().addUser( tester.wsClient().permissions().addUser(
new AddUserWsRequest() new AddUserWsRequest()
.setLogin(member) .setLogin(member.getLogin())
.setPermission("user") .setPermission("user")
.setProjectKey(projectKey)); .setProjectKey(projectKey));
} }


private void assertTags(@Nullable String user, @Nullable String password, @Nullable String organization, String... expectedTags) { private void assertTags(@Nullable String userLogin, @Nullable String organization, String... expectedTags) {
assertThat( assertThat(
(List<String>) ItUtils.jsonToMap( (List<String>) ItUtils.jsonToMap(
newUserWsClient(orchestrator, user, password) tester.as(userLogin)
.wsClient()
.issues() .issues()
.getTags(organization) .getTags(organization)
.content()) .content())
Expand Down
4 changes: 2 additions & 2 deletions it/it-tests/src/test/java/it/issue/IssuesPageTest.java
Expand Up @@ -43,8 +43,7 @@ public class IssuesPageTest {
@Rule @Rule
public UserRule userRule = UserRule.from(ORCHESTRATOR); public UserRule userRule = UserRule.from(ORCHESTRATOR);


@Rule public Navigation nav = Navigation.create(ORCHESTRATOR);
public Navigation nav = Navigation.get(ORCHESTRATOR);


private String adminUser; private String adminUser;


Expand Down Expand Up @@ -73,6 +72,7 @@ public void should_display_actions() {


@Test @Test
public void should_not_display_actions() { public void should_not_display_actions() {
Navigation nav = Navigation.create(ORCHESTRATOR);
IssuesPage page = nav.openIssues(); IssuesPage page = nav.openIssues();
Issue issue = page.getFirstIssue(); Issue issue = page.getFirstIssue();
issue.shouldNotAllowAssign().shouldNotAllowChangeType(); issue.shouldNotAllowAssign().shouldNotAllowChangeType();
Expand Down

0 comments on commit 78e2ea2

Please sign in to comment.