private static final String ACTION = "set_homepage";
- private static final String PARAM_TYPE = "type";
+ public static final String PARAM_TYPE = "type";
private static final String PARAM_ORGANIZATION = "organization";
private static final String PARAM_COMPONENT = "component";
private static final String PARAM_BRANCH = "branch";
private final UserSession userSession;
private final DbClient dbClient;
private final ComponentFinder componentFinder;
- private HomepageTypes homepageTypes;
- public SetHomepageAction(UserSession userSession, DbClient dbClient, ComponentFinder componentFinder, HomepageTypes homepageTypes) {
+ public SetHomepageAction(UserSession userSession, DbClient dbClient, ComponentFinder componentFinder) {
this.userSession = userSession;
this.dbClient = dbClient;
this.componentFinder = componentFinder;
- this.homepageTypes = homepageTypes;
}
@Override
action.createParam(PARAM_TYPE)
.setDescription("Type of the requested page")
.setRequired(true)
- .setPossibleValues(homepageTypes.getTypes());
+ .setPossibleValues(HomepageTypes.Type.values());
action.createParam(PARAM_ORGANIZATION)
.setDescription("Organization key. It should only be used when parameter '%s' is set to '%s'", PARAM_TYPE, ORGANIZATION)
.setSince("7.1")
- .setInternal(false)
.setExampleValue("my-org");
action.createParam(PARAM_COMPONENT)
action.createParam(PARAM_BRANCH)
.setDescription("Branch key. It can only be used when parameter '%s' is set to '%s'", PARAM_TYPE, PROJECT)
.setExampleValue(KEY_BRANCH_EXAMPLE_001)
- .setInternal(true)
.setSince("7.1");
}
return dbClient.organizationDao().selectByKey(dbSession, organizationParameter)
.orElseThrow(() -> new NotFoundException(format("No organizationDto with key '%s'", organizationParameter)))
.getUuid();
+ case PROJECTS:
+ case ISSUES:
case MY_PROJECTS:
case MY_ISSUES:
checkArgument(isBlank(componentParameter), "Parameter '%s' must not be provided when type is '%s'", PARAM_COMPONENT, type.name());
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 {
@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
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();
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");
ws.newRequest()
.setMethod("POST")
- .setParam("type", "PROJECT")
+ .setParam(PARAM_TYPE, "PROJECT")
.setParam("component", project.getKey())
.execute();
ws.newRequest()
.setMethod("POST")
- .setParam("type", "PROJECT")
+ .setParam(PARAM_TYPE, "PROJECT")
.setParam("component", branch.getKey())
.setParam("branch", branch.getBranch())
.execute();
ws.newRequest()
.setMethod("POST")
- .setParam("type", "ORGANIZATION")
+ .setParam(PARAM_TYPE, "ORGANIZATION")
.setParam("organization", organization.getKey())
.execute();
}
@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());
}
@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());
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();
TestResponse response = ws.newRequest()
.setMethod("POST")
- .setParam("type", "MY_PROJECTS")
+ .setParam(PARAM_TYPE, "MY_PROJECTS")
.execute();
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
ws.newRequest()
.setMethod("POST")
- .setParam("type", "PROJECT")
+ .setParam(PARAM_TYPE, "PROJECT")
.execute();
}
ws.newRequest()
.setMethod("POST")
- .setParam("type", "ORGANIZATION")
+ .setParam(PARAM_TYPE, "ORGANIZATION")
.execute();
}