private final System2 system2 = mock(System2.class);
private final DbClient dbClient = dbTester.getDbClient();
private Date now;
- private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS);
private PersistComponentsStep underTest;
}
private void persistComponents(ComponentDto... componentDtos) {
- componentDbTester.insertComponents(componentDtos);
+ dbTester.components().insertComponents(componentDtos);
}
private ComponentDto getComponentFromDb(String componentKey) {
private final System2 system2 = mock(System2.class);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
@Captor
ArgumentCaptor<ComponentNewValue> newValueCaptor;
private final DbSession dbSession;
private final boolean useDifferentUuids;
- public ComponentDbTester(DbTester db) {
- this(db, false);
- }
-
public ComponentDbTester(DbTester db, boolean useDifferentProjectUuids) {
this.db = db;
this.dbClient = db.getDbClient();
private final DbClient dbClient = dbTester.getDbClient();
private final DbSession dbSession = dbTester.getSession();
- private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
private final UserDbTester userDbTester = new UserDbTester(dbTester);
private ProjectDto publicProject;
@Before
public void setUp() {
- publicProject = componentDbTester.insertPublicProject().getProjectDto();
- privateProject1 = componentDbTester.insertPrivateProject().getProjectDto();
- privateProject2 = componentDbTester.insertPrivateProject().getProjectDto();
- view1 = componentDbTester.insertPublicPortfolioDto();
- view2 = componentDbTester.insertPublicPortfolioDto();
- application = componentDbTester.insertPublicApplication().getProjectDto();
+ publicProject = dbTester.components().insertPublicProject().getProjectDto();
+ privateProject1 = dbTester.components().insertPrivateProject().getProjectDto();
+ privateProject2 = dbTester.components().insertPrivateProject().getProjectDto();
+ view1 = dbTester.components().insertPublicPortfolioDto();
+ view2 = dbTester.components().insertPublicPortfolioDto();
+ application = dbTester.components().insertPublicApplication().getProjectDto();
user1 = userDbTester.insertUser();
user2 = userDbTester.insertUser();
group = userDbTester.insertGroup();
protected ComponentIndex index = new ComponentIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE);
protected PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer);
- private final ComponentDbTester componentDbTester = new ComponentDbTester(db);
-
protected void assertResultOrder(String query, String... resultsInOrder) {
List<ProjectDto> projects = Arrays.stream(resultsInOrder)
- .map(r -> componentDbTester.insertPublicProject(c -> c.setName(r)).getProjectDto())
+ .map(r -> db.components().insertPublicProject(c -> c.setName(r)).getProjectDto())
.toList();
// index them, but not in the expected order
}
protected ProjectDto indexProject(String key, String name) {
- return index(componentDbTester.insertPublicProject("UUID" + key, c -> c.setKey(key).setName(name)).getProjectDto());
+ return index(db.components().insertPublicProject("UUID" + key, c -> c.setKey(key).setName(name)).getProjectDto());
}
protected EntityDto newProject(String key, String name) {
- return componentDbTester.insertPublicProject("UUID_" + key, c -> c.setKey(key).setName(name)).getProjectDto();
+ return db.components().insertPublicProject("UUID_" + key, c -> c.setKey(key).setName(name)).getProjectDto();
}
protected ProjectDto index(ProjectDto dto) {
public final UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public final DbTester db = DbTester.create(system2);
-
- private ComponentDbTester componentDb = new ComponentDbTester(db);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
private TestProjectIndexers projectIndexers = new TestProjectIndexers();
@Test
public void update_project_key() {
ComponentDto project = insertSampleProject();
- ComponentDto file = componentDb.insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo"));
- ComponentDto inactiveFile = componentDb.insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false));
+ ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo"));
+ ComponentDto inactiveFile = db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("sample:root:src/InactiveFile.xoo").setEnabled(false));
dbSession.commit();
logInAsProjectAdministrator(project);
- underTest.updateKey(dbSession, componentDb.getProjectDtoByMainBranch(project), "sample2:root");
+ underTest.updateKey(dbSession, db.components().getProjectDtoByMainBranch(project), "sample2:root");
dbSession.commit();
// Check project key has been updated
dbSession.commit();
logInAsProjectAdministrator(provisionedProject);
- underTest.updateKey(dbSession, componentDb.getProjectDtoByMainBranch(provisionedProject), "provisionedProject2");
+ underTest.updateKey(dbSession, db.components().getProjectDtoByMainBranch(provisionedProject), "provisionedProject2");
dbSession.commit();
assertComponentKeyHasBeenUpdated(provisionedProject.getKey(), "provisionedProject2");
ComponentDto project = insertSampleProject();
userSession.logIn("john").addProjectPermission(UserRole.USER, project);
- ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project);
+ ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project);
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "sample2:root"))
.isInstanceOf(ForbiddenException.class);
}
@Test
public void fail_if_old_key_and_new_key_are_the_same() {
ComponentDto project = insertSampleProject();
- ComponentDto anotherProject = componentDb.insertPrivateProject().getMainBranchComponent();
+ ComponentDto anotherProject = db.components().insertPrivateProject().getMainBranchComponent();
logInAsProjectAdministrator(project);
- ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project);
+ ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project);
String anotherProjectDbKey = anotherProject.getKey();
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto,
anotherProjectDbKey))
ComponentDto project = insertSampleProject();
logInAsProjectAdministrator(project);
- ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project);
+ ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project);
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, ""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Malformed key for ''. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
ComponentDto project = insertSampleProject();
logInAsProjectAdministrator(project);
- ProjectDto projectDto = componentDb.getProjectDtoByMainBranch(project);
+ ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project);
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "sample?root"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Malformed key for 'sample?root'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
}
private ComponentDto insertProject(String key) {
- return componentDb.insertPrivateProject(c -> c.setKey(key)).getMainBranchComponent();
+ return db.components().insertPrivateProject(c -> c.setKey(key)).getMainBranchComponent();
}
private void assertComponentKeyHasBeenUpdated(String oldKey, String newKey) {
private HotspotWsSupport hotspotWsSupport = new HotspotWsSupport(dbClient, userSessionRule, system2);
private ChangeStatusAction underTest = new ChangeStatusAction(dbClient, hotspotWsSupport, transitionService, issueFieldsSetter, issueUpdater, hotspotChangeEventService);
private WsActionTester actionTester = new WsActionTester(underTest);
- private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
private BranchDto branchDto = mock(BranchDto.class);
@Before
private final ComponentFinder componentFinder = new ComponentFinder(db.getDbClient(), resourceTypes);
private final IssueDbTester issueDbTester = new IssueDbTester(db);
- private final ComponentDbTester componentDbTester = new ComponentDbTester(db);
private final PullAction underTest = new PullAction(system2, componentFinder, db.getDbClient(), userSession,
pullActionProtobufObjectGenerator);
@Test
public void wsExecution_whenHotspotOnAnotherBranchThanMain_shouldReturnOneIssue() throws IOException {
- ProjectData projectData = componentDbTester.insertPrivateProjectWithCustomBranch("develop");
+ ProjectData projectData = db.components().insertPrivateProjectWithCustomBranch("develop");
ProjectDto project = projectData.getProjectDto();
ComponentDto developBranch = projectData.getMainBranchComponent();
ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch));
private RuleDbTester ruleDbTester = new RuleDbTester(db);
private IssueDbTester issueDbTester = new IssueDbTester(db);
- private ComponentDbTester componentDbTester = new ComponentDbTester(db);
private IssueFinder underTest = new IssueFinder(db.getDbClient(), userSession);
private IssueDto insertIssue() {
RuleDto rule = ruleDbTester.insert(newRule());
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
- ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
return issueDbTester.insert(newIssue(rule, project, file));
}
private final ComponentFinder componentFinder = new ComponentFinder(db.getDbClient(), resourceTypes);
private final IssueDbTester issueDbTester = new IssueDbTester(db);
- private final ComponentDbTester componentDbTester = new ComponentDbTester(db);
private final PullAction underTest = new PullAction(system2, componentFinder, db.getDbClient(), userSession,
pullActionProtobufObjectGenerator, taintChecker);
@Test
public void givenIssueOnAnotherBranch_returnOneIssue() throws IOException {
- ComponentDto developBranch = componentDbTester.insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent();
+ ComponentDto developBranch = db.components().insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent();
ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch));
generateIssues(correctRule, developBranch, developFile, 1);
loginWithBrowsePermission(developBranch.uuid(), developFile.uuid());
private final ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
private final ComponentFinder componentFinder = new ComponentFinder(db.getDbClient(), resourceTypes);
private final IssueDbTester issueDbTester = new IssueDbTester(db);
- private final ComponentDbTester componentDbTester = new ComponentDbTester(db);
private PullTaintActionProtobufObjectGenerator objectGenerator = new PullTaintActionProtobufObjectGenerator(db.getDbClient(), userSession);
private PullTaintAction underTest = new PullTaintAction(system2, componentFinder, db.getDbClient(), userSession,
@Test
public void givenTaintOnAnotherBranch_returnOneTaint() throws IOException {
- ComponentDto developBranch = componentDbTester.insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent();
+ ComponentDto developBranch = db.components().insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent();
ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch));
generateTaints(correctRule, developBranch, developFile, 1);
loginWithBrowsePermission(developBranch.uuid(), developFile.uuid());
private static final String DEFAULT_PROJECT_ID = "12345";
private static final String MAIN_BRANCH = "main";
- private ComponentDbTester componentDb = new ComponentDbTester(db);
private DbSession dbSession = db.getSession();
private DbClient dbClient = db.getDbClient();
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
- /*
- * SonarQube
- * Copyright (C) 2009-2023 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.sonar.server.newcodeperiod.ws;
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.sonar.server.newcodeperiod.ws;
import java.time.Instant;
import java.util.Optional;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDao;
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
- public class ListActionIT {
- @Rule
- public UserSessionRule userSession = UserSessionRule.standalone();
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE, true);
-
- private ComponentDbTester componentDb = new ComponentDbTester(db);
- private DbClient dbClient = db.getDbClient();
- private ComponentFinder componentFinder = TestComponentFinder.from(db);
- private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance());
- private NewCodePeriodDbTester tester = new NewCodePeriodDbTester(db);
- private DocumentationLinkGenerator documentationLinkGenerator = mock(DocumentationLinkGenerator.class);
- private WsActionTester ws;
-
- @Before
- public void setup(){
- when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/");
- ws = new WsActionTester(new ListAction(dbClient, userSession, componentFinder, dao, documentationLinkGenerator));
- }
+public class ListActionIT {
+ @Rule
+ public UserSessionRule userSession = UserSessionRule.standalone();
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
+ private DbClient dbClient = db.getDbClient();
+ private ComponentFinder componentFinder = TestComponentFinder.from(db);
+ private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance());
+ private NewCodePeriodDbTester tester = new NewCodePeriodDbTester(db);
+ private DocumentationLinkGenerator documentationLinkGenerator = mock(DocumentationLinkGenerator.class);
+ private WsActionTester ws;
+
+ @Before
+ public void setup() {
+ when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/");
+ ws = new WsActionTester(new ListAction(dbClient, userSession, componentFinder, dao, documentationLinkGenerator));
+ }
- @Test
- public void test_definition() {
+ @Test
+ public void test_definition() {
- WebService.Action definition = ws.getDef();
+ WebService.Action definition = ws.getDef();
- assertThat(definition.description()).contains("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/");
+ assertThat(definition.description()).contains("https://docs.sonarqube.org/9.9/project-administration/defining-new-code/");
- assertThat(definition.key()).isEqualTo("list");
- assertThat(definition.isInternal()).isFalse();
- assertThat(definition.since()).isEqualTo("8.0");
- assertThat(definition.isPost()).isFalse();
+ assertThat(definition.key()).isEqualTo("list");
+ assertThat(definition.isInternal()).isFalse();
+ assertThat(definition.since()).isEqualTo("8.0");
+ assertThat(definition.isPost()).isFalse();
- assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("project");
- assertThat(definition.param("project").isRequired()).isTrue();
- }
+ assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("project");
+ assertThat(definition.param("project").isRequired()).isTrue();
+ }
- @Test
- public void throw_NFE_if_project_not_found() {
- assertThatThrownBy(() -> ws.newRequest()
- .setParam("project", "unknown")
- .execute())
- .isInstanceOf(NotFoundException.class)
- .hasMessageContaining("Project 'unknown' not found");
- }
+ @Test
+ public void throw_NFE_if_project_not_found() {
+ assertThatThrownBy(() -> ws.newRequest()
+ .setParam("project", "unknown")
+ .execute())
+ .isInstanceOf(NotFoundException.class)
+ .hasMessageContaining("Project 'unknown' not found");
+ }
- @Test
- public void throw_FE_if_no_project_permission() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ @Test
+ public void throw_FE_if_no_project_permission() {
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
- assertThatThrownBy(() -> ws.newRequest()
- .setParam("project", project.getKey())
- .execute())
- .isInstanceOf(ForbiddenException.class)
- .hasMessageContaining("Insufficient privileges");
- }
+ assertThatThrownBy(() -> ws.newRequest()
+ .setParam("project", project.getKey())
+ .execute())
+ .isInstanceOf(ForbiddenException.class)
+ .hasMessageContaining("Insufficient privileges");
+ }
- @Test
- public void list_only_branches() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ @Test
+ public void list_only_branches() {
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
- createBranches(project, 5, BranchType.BRANCH);
- createBranches(project, 3, BranchType.PULL_REQUEST);
+ createBranches(project, 5, BranchType.BRANCH);
+ createBranches(project, 3, BranchType.PULL_REQUEST);
- logInAsProjectAdministrator(project);
+ logInAsProjectAdministrator(project);
- ListWSResponse response = ws.newRequest()
- .setParam("project", project.getKey())
- .executeProtobuf(ListWSResponse.class);
+ ListWSResponse response = ws.newRequest()
+ .setParam("project", project.getKey())
+ .executeProtobuf(ListWSResponse.class);
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
- //check if global default is set
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
- .contains(NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION);
- }
+ //check if global default is set
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
+ .contains(NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION);
+ }
- @Test
- public void list_inherited_global_settings() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid"));
+ @Test
+ public void list_inherited_global_settings() {
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid"));
- createBranches(project, 5, BranchType.BRANCH);
+ createBranches(project, 5, BranchType.BRANCH);
- logInAsProjectAdministrator(project);
+ logInAsProjectAdministrator(project);
- ListWSResponse response = ws.newRequest()
- .setParam("project", project.getKey())
- .executeProtobuf(ListWSResponse.class);
+ ListWSResponse response = ws.newRequest()
+ .setParam("project", project.getKey())
+ .executeProtobuf(ListWSResponse.class);
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
- //check if global default is set
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
- .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue)
- .contains("uuid");
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited)
- .contains(true);
- }
+ //check if global default is set
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
+ .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue)
+ .contains("uuid");
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited)
+ .contains(true);
+ }
- @Test
- public void list_inherited_project_settings() {
- ComponentDto projectWithOwnSettings = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto projectWithGlobalSettings = componentDb.insertPublicProject().getMainBranchComponent();
- tester.insert(new NewCodePeriodDto()
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("global_uuid"));
- tester.insert(new NewCodePeriodDto()
- .setProjectUuid(projectWithOwnSettings.uuid())
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("project_uuid"));
-
- createBranches(projectWithOwnSettings, 5, BranchType.BRANCH);
-
- logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings);
-
- ListWSResponse response = ws.newRequest()
- .setParam("project", projectWithOwnSettings.getKey())
- .executeProtobuf(ListWSResponse.class);
-
- //verify project with project level settings
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
-
- //check if project setting is set
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
- .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue)
- .containsOnly("project_uuid");
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited)
- .containsOnly(true);
-
- //verify project with global level settings
- response = ws.newRequest()
- .setParam("project", projectWithGlobalSettings.getKey())
- .executeProtobuf(ListWSResponse.class);
-
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isOne();
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .containsOnly(DEFAULT_MAIN_BRANCH_NAME);
-
- //check if global setting is set
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
- .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue)
- .contains("global_uuid");
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited)
- .containsOnly(true);
- }
+ @Test
+ public void list_inherited_project_settings() {
+ ProjectDto projectWithOwnSettings = db.components().insertPublicProject().getProjectDto();
+ ProjectDto projectWithGlobalSettings = db.components().insertPublicProject().getProjectDto();
+ tester.insert(new NewCodePeriodDto()
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("global_uuid"));
+ tester.insert(new NewCodePeriodDto()
+ .setProjectUuid(projectWithOwnSettings.getUuid())
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("project_uuid"));
+
+ createBranches(projectWithOwnSettings, 5, BranchType.BRANCH);
+
+ logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings);
+
+ ListWSResponse response = ws.newRequest()
+ .setParam("project", projectWithOwnSettings.getKey())
+ .executeProtobuf(ListWSResponse.class);
+
+ //verify project with project level settings
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+
+ //check if project setting is set
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
+ .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue)
+ .containsOnly("project_uuid");
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited)
+ .containsOnly(true);
+
+ //verify project with global level settings
+ response = ws.newRequest()
+ .setParam("project", projectWithGlobalSettings.getKey())
+ .executeProtobuf(ListWSResponse.class);
+
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isOne();
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .containsOnly(DEFAULT_MAIN_BRANCH_NAME);
+
+ //check if global setting is set
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
+ .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue)
+ .contains("global_uuid");
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited)
+ .containsOnly(true);
+ }
- @Test
- public void list_branch_and_inherited_global_settings() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS"));
- componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS"));
-
- tester.insert(new NewCodePeriodDto()
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("global_uuid"));
-
- tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
- .setBranchUuid(branchWithOwnSettings.uuid())
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("branch_uuid"));
-
- logInAsProjectAdministrator(project);
-
- ListWSResponse response = ws.newRequest()
- .setParam("project", project.getKey())
- .executeProtobuf(ListWSResponse.class);
-
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS");
-
- Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
- .filter(s -> !s.getInherited())
- .findFirst();
-
- assertThat(ownSettings)
- .isNotNull()
- .isNotEmpty();
- assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey());
- assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS");
- assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid");
- assertThat(ownSettings.get().getInherited()).isFalse();
-
- //check if global default is set
- assertThat(response.getNewCodePeriodsList())
- .filteredOn(ShowWSResponse::getInherited)
- .extracting(ShowWSResponse::getType)
- .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(response.getNewCodePeriodsList())
- .filteredOn(ShowWSResponse::getInherited)
- .extracting(ShowWSResponse::getValue)
- .contains("global_uuid");
- }
+ @Test
+ public void list_branch_and_inherited_global_settings() {
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branchWithOwnSettings = db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS"));
+ db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS"));
+
+ tester.insert(new NewCodePeriodDto()
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("global_uuid"));
+
+ tester.insert(new NewCodePeriodDto()
+ .setProjectUuid(project.getUuid())
+ .setBranchUuid(branchWithOwnSettings.getUuid())
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("branch_uuid"));
+
+ logInAsProjectAdministrator(project);
+
+ ListWSResponse response = ws.newRequest()
+ .setParam("project", project.getKey())
+ .executeProtobuf(ListWSResponse.class);
+
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS");
+
+ Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
+ .filter(s -> !s.getInherited())
+ .findFirst();
+
+ assertThat(ownSettings)
+ .isNotNull()
+ .isNotEmpty();
+ assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey());
+ assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS");
+ assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid");
+ assertThat(ownSettings.get().getInherited()).isFalse();
+
+ //check if global default is set
+ assertThat(response.getNewCodePeriodsList())
+ .filteredOn(ShowWSResponse::getInherited)
+ .extracting(ShowWSResponse::getType)
+ .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(response.getNewCodePeriodsList())
+ .filteredOn(ShowWSResponse::getInherited)
+ .extracting(ShowWSResponse::getValue)
+ .contains("global_uuid");
+ }
- @Test
- public void list_branch_and_inherited_project_settings() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS"));
- componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS"));
-
- tester.insert(new NewCodePeriodDto()
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("global_uuid"));
-
- tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("project_uuid"));
-
- tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
- .setBranchUuid(branchWithOwnSettings.uuid())
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue("branch_uuid"));
-
- logInAsProjectAdministrator(project);
-
- ListWSResponse response = ws.newRequest()
- .setParam("project", project.getKey())
- .executeProtobuf(ListWSResponse.class);
-
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS");
-
- Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
- .filter(s -> !s.getInherited())
- .findFirst();
-
- assertThat(ownSettings)
- .isNotNull()
- .isNotEmpty();
- assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey());
- assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS");
- assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid");
- assertThat(ownSettings.get().getInherited()).isFalse();
-
- //check if global default is set
- assertThat(response.getNewCodePeriodsList())
- .filteredOn(ShowWSResponse::getInherited)
- .extracting(ShowWSResponse::getType)
- .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(response.getNewCodePeriodsList())
- .filteredOn(ShowWSResponse::getInherited)
- .extracting(ShowWSResponse::getValue)
- .contains("project_uuid");
- }
+ @Test
+ public void list_branch_and_inherited_project_settings() {
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branchWithOwnSettings = db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS"));
+ db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS"));
+
+ tester.insert(new NewCodePeriodDto()
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("global_uuid"));
+
+ tester.insert(new NewCodePeriodDto()
+ .setProjectUuid(project.getUuid())
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("project_uuid"));
+
+ tester.insert(new NewCodePeriodDto()
+ .setProjectUuid(project.getUuid())
+ .setBranchUuid(branchWithOwnSettings.getUuid())
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue("branch_uuid"));
+
+ logInAsProjectAdministrator(project);
+
+ ListWSResponse response = ws.newRequest()
+ .setParam("project", project.getKey())
+ .executeProtobuf(ListWSResponse.class);
+
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS");
+
+ Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
+ .filter(s -> !s.getInherited())
+ .findFirst();
+
+ assertThat(ownSettings)
+ .isNotNull()
+ .isNotEmpty();
+ assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey());
+ assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS");
+ assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid");
+ assertThat(ownSettings.get().getInherited()).isFalse();
+
+ //check if global default is set
+ assertThat(response.getNewCodePeriodsList())
+ .filteredOn(ShowWSResponse::getInherited)
+ .extracting(ShowWSResponse::getType)
+ .contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(response.getNewCodePeriodsList())
+ .filteredOn(ShowWSResponse::getInherited)
+ .extracting(ShowWSResponse::getValue)
+ .contains("project_uuid");
+ }
- @Test
- public void verify_specific_analysis_effective_value() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH"));
-
- SnapshotDto analysis = componentDb.insertSnapshot(newAnalysis(project)
- .setUuid("A1")
- .setCreatedAt(Instant.now().toEpochMilli())
- .setProjectVersion("1.2")
- .setBuildString("1.2.0.322")
- .setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf")
- );
-
- componentDb.insertSnapshot(newAnalysis(project)
- .setUuid("A2")
- .setCreatedAt(Instant.now().toEpochMilli())
- .setProjectVersion("1.2")
- .setBuildString("1.2.0.322")
- .setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04")
- );
-
- tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
- .setBranchUuid(branch.uuid())
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue(analysis.getUuid()));
-
- logInAsProjectAdministrator(project);
-
- ListWSResponse response = ws.newRequest()
- .setParam("project", project.getKey())
- .executeProtobuf(ListWSResponse.class);
-
- assertThat(response).isNotNull();
- assertThat(response.getNewCodePeriodsCount()).isEqualTo(2);
- assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .containsOnly(DEFAULT_MAIN_BRANCH_NAME, "PROJECT_BRANCH");
-
- ShowWSResponse result = response.getNewCodePeriodsList().get(0);
- assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
- assertThat(result.getValue()).isEqualTo("A1");
- assertThat(result.getProjectKey()).isEqualTo(project.getKey());
- assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH");
- assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt()));
- }
+ @Test
+ public void verify_specific_analysis_effective_value() {
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH"));
+
+ SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(projectData.getMainBranchComponent())
+ .setUuid("A1")
+ .setCreatedAt(Instant.now().toEpochMilli())
+ .setProjectVersion("1.2")
+ .setBuildString("1.2.0.322")
+ .setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf")
+ );
+
+ db.components().insertSnapshot(newAnalysis(projectData.getMainBranchComponent())
+ .setUuid("A2")
+ .setCreatedAt(Instant.now().toEpochMilli())
+ .setProjectVersion("1.2")
+ .setBuildString("1.2.0.322")
+ .setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04")
+ );
+
+ tester.insert(new NewCodePeriodDto()
+ .setProjectUuid(project.getUuid())
+ .setBranchUuid(branch.getUuid())
+ .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
+ .setValue(analysis.getUuid()));
+
+ logInAsProjectAdministrator(project);
+
+ ListWSResponse response = ws.newRequest()
+ .setParam("project", project.getKey())
+ .executeProtobuf(ListWSResponse.class);
+
+ assertThat(response).isNotNull();
+ assertThat(response.getNewCodePeriodsCount()).isEqualTo(2);
+ assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
+ .containsOnly(DEFAULT_MAIN_BRANCH_NAME, "PROJECT_BRANCH");
+
+ ShowWSResponse result = response.getNewCodePeriodsList().get(0);
+ assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
+ assertThat(result.getValue()).isEqualTo("A1");
+ assertThat(result.getProjectKey()).isEqualTo(project.getKey());
+ assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH");
+ assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt()));
+ }
- private void createBranches(ComponentDto project, int numberOfBranches, BranchType branchType) {
- for (int branchCount = 0; branchCount < numberOfBranches; branchCount++) {
- String branchKey = String.format("%s_%d", branchType.name(), branchCount);
- componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey(branchKey).setBranchType(branchType));
- }
+ private void createBranches(ProjectDto project, int numberOfBranches, BranchType branchType) {
+ for (int branchCount = 0; branchCount < numberOfBranches; branchCount++) {
+ String branchKey = String.format("%s_%d", branchType.name(), branchCount);
+ db.components().insertProjectBranch(project, branchDto -> branchDto.setKey(branchKey).setBranchType(branchType));
}
+ }
- private void logInAsProjectAdministrator(ComponentDto... project) {
- userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
- }
+ private void logInAsProjectAdministrator(ProjectDto... project) {
+ userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
}
+}
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDao;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE, true);
-
- private ComponentDbTester componentDb = new ComponentDbTester(db);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
private ComponentFinder componentFinder = TestComponentFinder.from(db);
@Test
public void throw_IAE_if_type_is_invalid_for_project() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
@Test
public void throw_IAE_if_no_value_for_days() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
@Test
public void throw_IAE_if_no_value_for_analysis() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
@Test
public void throw_IAE_if_days_is_invalid() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
@Test
public void throw_IAE_if_setting_is_not_cayc_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
TestRequest request = ws.newRequest()
@Test
public void no_error_if_setting_is_cayc_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
ws.newRequest()
.setParam("value", "90")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "90");
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "90");
}
@Test
public void throw_IAE_if_analysis_is_not_found() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
@Test
public void throw_IAE_if_analysis_doesnt_belong_to_branch() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
+ ComponentDto branch = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch"));
SnapshotDto analysisMaster = db.components().insertSnapshot(project);
SnapshotDto analysisBranch = db.components().insertSnapshot(branch);
@Test
public void throw_NFE_if_branch_not_found() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
// permission
@Test
public void throw_NFE_if_no_project_permission() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
@Test
public void set_project_period_to_number_of_days() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "number_of_days")
.setParam("value", "5")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5");
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5");
}
@Test
@UseDataProvider("provideNewCodePeriodTypeAndValue")
public void never_set_project_value_in_community_edition(NewCodePeriodType type, @Nullable String value) {
when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
if (value != null && NewCodePeriodType.SPECIFIC_ANALYSIS.equals(type)) {
db.components().insertSnapshot(project, snapshotDto -> snapshotDto.setUuid(value));
}
request.execute();
- assertTableContainsOnly(project.uuid(), project.uuid(), type, value);
+ assertTableContainsOnly(project.getUuid(), projectData.getMainBranchComponent().uuid(), type, value);
}
@DataProvider
@Test
public void set_project_twice_period_to_number_of_days() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "previous_version")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "number_of_days")
.setParam("value", "5")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5");
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5");
}
@Test
public void set_branch_period_to_analysis() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
+ ComponentDto branch = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch"));
SnapshotDto analysisMaster = db.components().insertSnapshot(project);
SnapshotDto analysisBranch = db.components().insertSnapshot(branch);
.setParam("value", analysisBranch.getUuid())
.execute();
- assertTableContainsOnly(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, analysisBranch.getUuid());
+ assertTableContainsOnly(project.getUuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, analysisBranch.getUuid());
}
@Test
public void set_branch_period_twice_to_analysis() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(projectData.getProjectDto(), b -> b.setKey("branch"));
SnapshotDto analysisMaster = db.components().insertSnapshot(project);
SnapshotDto analysisBranch = db.components().insertSnapshot(branch);
.setParam("branch", "branch")
.execute();
- assertTableContainsOnly(project.uuid(), branch.uuid(), NewCodePeriodType.PREVIOUS_VERSION, null);
+ assertTableContainsOnly(project.getUuid(), branch.getUuid(), NewCodePeriodType.PREVIOUS_VERSION, null);
}
private void assertTableContainsOnly(@Nullable String projectUuid, @Nullable String branchUuid, NewCodePeriodType type, @Nullable String value) {
.containsOnly(entry("PROJECT_UUID", projectUuid), entry("BRANCH_UUID", branchUuid), entry("TYPE", type.name()), entry("VALUE", value));
}
- private void logInAsProjectAdministrator(ComponentDto project) {
+ private void logInAsProjectAdministrator(ProjectDto project) {
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
}
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDao;
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE, true);
-
- private ComponentDbTester componentDb = new ComponentDbTester(db);
private DbClient dbClient = db.getDbClient();
private ComponentFinder componentFinder = TestComponentFinder.from(db);
private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance());
@Test
public void throw_FE_if_no_project_permission() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
@Test
public void throw_FE_if_project_issue_admin() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectIssueAdmin(project);
assertThatThrownBy(() -> ws.newRequest()
@Test
public void show_project_setting() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
+ .setProjectUuid(project.getUuid())
.setType(NewCodePeriodType.NUMBER_OF_DAYS)
.setValue("4"));
@Test
public void show_branch_setting() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
- .setBranchUuid(branch.uuid())
+ .setProjectUuid(project.getUuid())
+ .setBranchUuid(branch.getUuid())
.setType(NewCodePeriodType.NUMBER_OF_DAYS)
.setValue("1"));
@Test
public void show_inherited_project_setting() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.PREVIOUS_VERSION));
@Test
public void show_inherited_branch_setting_from_project() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
tester.insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
+ .setProjectUuid(project.getUuid())
.setType(NewCodePeriodType.NUMBER_OF_DAYS)
.setValue("1"));
@Test
public void show_inherited_branch_setting_from_global() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ BranchDto branchDto = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("3"));
ShowWSResponse response = ws.newRequest()
@Test
public void show_inherited_if_branch_not_found() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectScan(project);
- tester.insert(project.branchUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "3");
+ tester.insert(project.getUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "3");
ShowWSResponse response = ws.newRequest()
.setParam("project", project.getKey())
assertThat(response.getType()).isEqualTo(type);
}
- private void logInAsProjectAdministrator(ComponentDto project) {
+ private void logInAsProjectAdministrator(ProjectDto project) {
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
}
- private void logInAsProjectScan(ComponentDto project) {
+ private void logInAsProjectScan(ProjectDto project) {
userSession.logIn().addProjectPermission(UserRole.SCAN, project);
}
- private void logInAsProjectIssueAdmin(ComponentDto project) {
+ private void logInAsProjectIssueAdmin(ProjectDto project) {
userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project);
}
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.newcodeperiod.NewCodePeriodDao;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE, true);
-
- private ComponentDbTester componentDb = new ComponentDbTester(db);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
private ComponentFinder componentFinder = TestComponentFinder.from(db);
@Test
public void throw_NFE_if_branch_not_found() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
assertThatThrownBy(() -> ws.newRequest()
// permission
@Test
public void throw_NFE_if_no_project_permission() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
@Test
public void delete_project_period() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
logInAsProjectAdministrator(project);
ws.newRequest()
.setParam("project", project.getKey())
@Test
public void delete_project_period_twice() {
- ComponentDto project1 = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto project2 = componentDb.insertPublicProject().getMainBranchComponent();
- db.newCodePeriods().insert(project1.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1");
- db.newCodePeriods().insert(project2.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
+ ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPublicProject().getProjectDto();
+ db.newCodePeriods().insert(project1.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1");
+ db.newCodePeriods().insert(project2.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
logInAsProjectAdministrator(project1);
ws.newRequest()
.setParam("project", project1.getKey())
.execute();
- assertTableContainsOnly(project2.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
+ assertTableContainsOnly(project2.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
ws.newRequest()
.setParam("project", project1.getKey())
.execute();
- assertTableContainsOnly(project2.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
+ assertTableContainsOnly(project2.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
}
@Test
public void delete_branch_period() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20");
- db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20");
+ db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
logInAsProjectAdministrator(project);
.setParam("branch", "branch")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20");
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "20");
}
@Test
public void delete_branch_and_project_period_in_community_edition() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1");
- db.newCodePeriods().insert(project.uuid(), project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid1");
+ db.newCodePeriods().insert(project.getUuid(), projectData.getMainBranchComponent().uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid2");
when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
@Test
public void throw_IAE_if_unset_branch_NCD_and_project_NCD_not_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "97");
- db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "97");
+ db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
TestRequest request = ws.newRequest()
.setParam("project", project.getKey())
@Test
public void throw_IAE_if_unset_branch_NCD_and_no_project_NCD_and_instance_NCD_not_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
db.newCodePeriods().insert(null, null, NewCodePeriodType.NUMBER_OF_DAYS, "97");
- db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
TestRequest request = ws.newRequest()
.setParam("project", project.getKey())
@Test
public void throw_IAE_if_unset_project_NCD_and_instance_NCD_not_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
db.newCodePeriods().insert(null, null, NewCodePeriodType.NUMBER_OF_DAYS, "97");
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
logInAsProjectAdministrator(project);
@Test
public void do_not_throw_IAE_if_unset_project_NCD_and_no_instance_NCD() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
logInAsProjectAdministrator(project);
ws.newRequest()
@Test
public void do_not_throw_IAE_if_unset_branch_NCD_and_project_NCD_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
- db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
logInAsProjectAdministrator(project);
ws.newRequest()
.setParam("branch", "branch")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
}
@Test
public void do_not_throw_IAE_if_unset_branch_NCD_and_project_NCD_not_compliant_and_no_branch_NCD() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93");
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93");
logInAsProjectAdministrator(project);
ws.newRequest()
.setParam("branch", "branch")
.execute();
- assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93");
+ assertTableContainsOnly(project.getUuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "93");
}
@Test
public void do_not_throw_IAE_if_unset_branch_NCD_and_no_project_NCD_and_instance_NCD_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
- db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
db.newCodePeriods().insert(null, null, NewCodePeriodType.PREVIOUS_VERSION, null);
logInAsProjectAdministrator(project);
@Test
public void do_not_throw_IAE_if_unset_branch_NCD_and_no_project_NCD_and_no_instance() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
- db.newCodePeriods().insert(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ db.newCodePeriods().insert(project.getUuid(), branch.getUuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "uuid");
logInAsProjectAdministrator(project);
ws.newRequest()
@Test
public void do_not_throw_IAE_if_unset_project_NCD_and_instance_NCD_compliant() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
db.newCodePeriods().insert(null, null, NewCodePeriodType.PREVIOUS_VERSION, null);
- db.newCodePeriods().insert(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
+ db.newCodePeriods().insert(project.getUuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
logInAsProjectAdministrator(project);
ws.newRequest()
@Test
public void do_not_throw_IAE_if_unset_project_NCD_and_instance_NCD_not_compliant_and_no_project_NCD() {
- ComponentDto project = componentDb.insertPublicProject().getMainBranchComponent();
- ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
db.newCodePeriods().insert(null, null, NewCodePeriodType.NUMBER_OF_DAYS, "93");
logInAsProjectAdministrator(project);
.containsOnly(entry("PROJECT_UUID", projectUuid), entry("BRANCH_UUID", branchUuid), entry("TYPE", type.name()), entry("VALUE", value));
}
- private void logInAsProjectAdministrator(ComponentDto project) {
+ private void logInAsProjectAdministrator(ProjectDto project) {
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
}
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
private final WebhookDbTester webhookDbTester = db.webhooks();
- private final ComponentDbTester componentDbTester = new ComponentDbTester(db);
private final ComponentCleanerService componentCleanerService = mock(ComponentCleanerService.class);
private final ProjectLifeCycleListeners projectLifeCycleListeners = mock(ProjectLifeCycleListeners.class);
private final ResourceTypes mockResourceTypes = mock(ResourceTypes.class);
@Test
public void global_administrator_deletes_project_by_key() {
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSessionRule.logIn().addPermission(GlobalPermission.ADMINISTER);
call(tester.newRequest().setParam(PARAM_PROJECT, project.getKey()));
@Test
public void project_administrator_deletes_the_project_by_key() {
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, project);
call(tester.newRequest().setParam(PARAM_PROJECT, project.getKey()));
@Test
public void project_deletion_also_ensure_that_homepage_on_this_project_if_it_exists_is_cleared() {
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
UserDto insert = dbClient.userDao().insert(dbSession,
newUserDto().setHomepageType("PROJECT").setHomepageParameter(project.uuid()));
dbSession.commit();
@Test
public void project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted() {
- ProjectDto project = componentDbTester.insertPrivateProject().getProjectDto();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
@Test
public void return_403_if_not_project_admin_nor_org_admin() {
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSessionRule.logIn()
.addProjectPermission(UserRole.CODEVIEWER, project)
@Test
public void return_401_if_not_logged_in() {
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSessionRule.anonymous();
DbSession dbSession = db.getSession();
PropertyDbTester propertyDb = new PropertyDbTester(db);
- ComponentDbTester componentDb = new ComponentDbTester(db);
PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE);
ProjectDto project;
@Before
public void setUp() {
- project = componentDb.insertPrivateProject().getProjectDto();
+ project = db.components().insertPrivateProject().getProjectDto();
}
@Test
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(new AlwaysIncreasingSystem2());
-
- private final ComponentDbTester componentTester = new ComponentDbTester(db);
private final GroupService groupService = new GroupService(db.getDbClient(), UuidFactoryImpl.INSTANCE);
private final ManagedInstanceService managedInstanceService = mock(ManagedInstanceService.class);
addAdmin();
insertDefaultGroup();
GroupDto group = db.users().insertGroup();
- ComponentDto project = componentTester.insertPrivateProject().getMainBranchComponent();
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, project);
loginAsAdmin();