return getByKey(dbSession, checkParamNotEmpty(componentKey, parameterNames.getKeyParam()));
}
- public ComponentDto getRootComponentByUuidOrKey(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey, ParamNames parameterNames) {
- checkByUuidOrKey(componentUuid, componentKey, parameterNames);
-
- if (componentUuid != null) {
- return checkIsProject(getByUuid(dbSession, checkParamNotEmpty(componentUuid, parameterNames.getUuidParam()), LABEL_PROJECT));
- }
-
- return checkIsProject(getByKey(dbSession, checkParamNotEmpty(componentKey, parameterNames.getKeyParam()), LABEL_PROJECT));
- }
-
private static String checkParamNotEmpty(String value, String param) {
checkArgument(!value.isEmpty(), MSG_PARAMETER_MUST_NOT_BE_EMPTY, param);
return value;
package org.sonar.server.project.ws;
import javax.annotation.Nullable;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone();
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
@Rule
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()),
new ComponentIndexDefinition(new MapSettings().asConfig()));
private WsActionTester ws = new WsActionTester(
new BulkUpdateKeyAction(dbClient, componentFinder, componentService, userSession));
- @Before
- public void setUp() {
- userSession.logIn().setRoot();
- }
-
@Test
public void json_example() {
OrganizationDto organizationDto = db.organizations().insert();
verify(componentService).bulkUpdateKey(any(DbSession.class), eq(provisionedProject), eq(provisionedProject.getDbKey()), eq(newKey));
}
+ @Test
+ public void fail_to_bulk_update_key_using_branch_db_key() {
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(project);
+ userSession.addProjectPermission(UserRole.USER, project);
+
+ expectedException.expect(NotFoundException.class);
+ expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey()));
+
+ callByKey(branch.getDbKey(), FROM, TO);
+ }
+
+ @Test
+ public void fail_to_bulk_update_key_using_branch_uuid() {
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(project);
+ userSession.addProjectPermission(UserRole.USER, project);
+
+ expectedException.expect(NotFoundException.class);
+ expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid()));
+
+ callByUuid(branch.uuid(), FROM, TO);
+ }
+
@Test
public void fail_to_bulk_if_a_component_already_exists_with_the_same_key() {
componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("my_project"));