|
|
@@ -40,10 +40,13 @@ import static org.apache.http.HttpStatus.SC_NO_CONTENT; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
import static org.sonar.server.user.ws.HomepageTypes.Type.ISSUES; |
|
|
|
import static org.sonar.server.user.ws.HomepageTypes.Type.MY_ISSUES; |
|
|
|
import static org.sonar.server.user.ws.HomepageTypes.Type.MY_PROJECTS; |
|
|
|
import static org.sonar.server.user.ws.HomepageTypes.Type.ORGANIZATION; |
|
|
|
import static org.sonar.server.user.ws.HomepageTypes.Type.PROJECT; |
|
|
|
import static org.sonar.server.user.ws.HomepageTypes.Type.PROJECTS; |
|
|
|
import static org.sonar.server.user.ws.SetHomepageAction.PARAM_TYPE; |
|
|
|
|
|
|
|
public class SetHomepageActionTest { |
|
|
|
|
|
|
@@ -64,7 +67,7 @@ public class SetHomepageActionTest { |
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
when(homepageTypes.getTypes()).thenReturn(asList(PROJECT, ORGANIZATION, MY_ISSUES, MY_PROJECTS)); |
|
|
|
ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db), homepageTypes)); |
|
|
|
ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
@@ -81,7 +84,6 @@ public class SetHomepageActionTest { |
|
|
|
WebService.Param typeParam = action.param("type"); |
|
|
|
assertThat(typeParam.isRequired()).isTrue(); |
|
|
|
assertThat(typeParam.description()).isEqualTo("Type of the requested page"); |
|
|
|
assertThat(typeParam.possibleValues()).containsExactlyInAnyOrder("PROJECT", "ORGANIZATION", "MY_PROJECTS", "MY_ISSUES"); |
|
|
|
|
|
|
|
WebService.Param componentParam = action.param("component"); |
|
|
|
assertThat(componentParam.isRequired()).isFalse(); |
|
|
@@ -90,7 +92,6 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
WebService.Param branchParam = action.param("branch"); |
|
|
|
assertThat(branchParam.isRequired()).isFalse(); |
|
|
|
assertThat(branchParam.isInternal()).isTrue(); |
|
|
|
assertThat(branchParam.description()).isEqualTo("Branch key. It can only be used when parameter 'type' is set to 'PROJECT'"); |
|
|
|
assertThat(branchParam.since()).isEqualTo("7.1"); |
|
|
|
|
|
|
@@ -110,7 +111,7 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "PROJECT") |
|
|
|
.setParam(PARAM_TYPE, "PROJECT") |
|
|
|
.setParam("component", project.getKey()) |
|
|
|
.execute(); |
|
|
|
|
|
|
@@ -130,7 +131,7 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "PROJECT") |
|
|
|
.setParam(PARAM_TYPE, "PROJECT") |
|
|
|
.setParam("component", branch.getKey()) |
|
|
|
.setParam("branch", branch.getBranch()) |
|
|
|
.execute(); |
|
|
@@ -150,7 +151,7 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "ORGANIZATION") |
|
|
|
.setParam(PARAM_TYPE, "ORGANIZATION") |
|
|
|
.setParam("organization", organization.getKey()) |
|
|
|
.execute(); |
|
|
|
|
|
|
@@ -161,13 +162,13 @@ public class SetHomepageActionTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void set_my_issues_homepage() { |
|
|
|
public void set_sonarcloud_my_issues_homepage() { |
|
|
|
UserDto user = db.users().insertUser(); |
|
|
|
userSession.logIn(user); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "MY_ISSUES") |
|
|
|
.setParam(PARAM_TYPE, "MY_ISSUES") |
|
|
|
.execute(); |
|
|
|
|
|
|
|
UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin()); |
|
|
@@ -177,13 +178,33 @@ public class SetHomepageActionTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void set_my_projects_homepage() { |
|
|
|
public void set_sonarqube_issues_homepage() { |
|
|
|
|
|
|
|
when(homepageTypes.getTypes()).thenReturn(asList(PROJECT, ORGANIZATION, ISSUES, PROJECTS)); |
|
|
|
ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db))); |
|
|
|
|
|
|
|
UserDto user = db.users().insertUser(); |
|
|
|
userSession.logIn(user); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam(PARAM_TYPE, "ISSUES") |
|
|
|
.execute(); |
|
|
|
|
|
|
|
UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin()); |
|
|
|
assertThat(actual).isNotNull(); |
|
|
|
assertThat(actual.getHomepageType()).isEqualTo("ISSUES"); |
|
|
|
assertThat(actual.getHomepageParameter()).isNullOrEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void set_sonarcloud_my_projects_homepage() { |
|
|
|
UserDto user = db.users().insertUser(); |
|
|
|
userSession.logIn(user); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "MY_PROJECTS") |
|
|
|
.setParam(PARAM_TYPE, "MY_PROJECTS") |
|
|
|
.execute(); |
|
|
|
|
|
|
|
UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin()); |
|
|
@@ -192,6 +213,25 @@ public class SetHomepageActionTest { |
|
|
|
assertThat(actual.getHomepageParameter()).isNullOrEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void set_sonarqube_projects_homepage() { |
|
|
|
when(homepageTypes.getTypes()).thenReturn(asList(PROJECT, ORGANIZATION, ISSUES, PROJECTS)); |
|
|
|
ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db))); |
|
|
|
|
|
|
|
UserDto user = db.users().insertUser(); |
|
|
|
userSession.logIn(user); |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam(PARAM_TYPE, "PROJECTS") |
|
|
|
.execute(); |
|
|
|
|
|
|
|
UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin()); |
|
|
|
assertThat(actual).isNotNull(); |
|
|
|
assertThat(actual.getHomepageType()).isEqualTo("PROJECTS"); |
|
|
|
assertThat(actual.getHomepageParameter()).isNullOrEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void response_has_no_content() { |
|
|
|
UserDto user = db.users().insertUser(); |
|
|
@@ -199,7 +239,7 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
TestResponse response = ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "MY_PROJECTS") |
|
|
|
.setParam(PARAM_TYPE, "MY_PROJECTS") |
|
|
|
.execute(); |
|
|
|
|
|
|
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT); |
|
|
@@ -216,7 +256,7 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "PROJECT") |
|
|
|
.setParam(PARAM_TYPE, "PROJECT") |
|
|
|
.execute(); |
|
|
|
|
|
|
|
} |
|
|
@@ -231,7 +271,7 @@ public class SetHomepageActionTest { |
|
|
|
|
|
|
|
ws.newRequest() |
|
|
|
.setMethod("POST") |
|
|
|
.setParam("type", "ORGANIZATION") |
|
|
|
.setParam(PARAM_TYPE, "ORGANIZATION") |
|
|
|
.execute(); |
|
|
|
} |
|
|
|
|