}
private ComponentDto newComponentDto(String uuid) {
- return ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), uuid).setName("name_" + uuid).setKey("key_" + uuid);
+ return ComponentTesting.newPublicProjectDto(dbTester.getDefaultOrganization(), uuid).setName("name_" + uuid).setKey("key_" + uuid);
}
private CeTask submit(String reportType, String componentUuid) {
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
@Test
public void select_projects() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto provisionedProject = db.components().insertProject();
+ ComponentDto provisionedProject = db.components().insertPrivateProject();
ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {
});
- String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
- String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
+ String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organization)).getComponentUuid();
+ String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organization).setEnabled(false)).getComponentUuid();
String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
assertThat(underTest.selectProjects(dbSession))
@Test
public void select_provisioned() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto provisionedProject = db.components().insertComponent(newProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project"));
+ ComponentDto provisionedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project"));
ComponentDto provisionedView = db.components().insertView(organization);
- String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
- String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
+ String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organization)).getComponentUuid();
+ String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organization).setEnabled(false)).getComponentUuid();
String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
Set<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
@Test
public void count_provisioned() {
OrganizationDto organization = db.organizations().insert();
- db.components().insertProject(organization);
- db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization));
+ db.components().insertPrivateProject(organization);
+ db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organization));
db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization));
assertThat(underTest.countProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT))).isEqualTo(1);
OrganizationDto organization = db.organizations().insert();
// ghosts because has at least one snapshot with status U but none with status P
- ComponentDto ghostProject = db.components().insertProject(organization);
+ ComponentDto ghostProject = db.components().insertPrivateProject(organization);
db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
- ComponentDto ghostProject2 = db.components().insertProject(organization);
+ ComponentDto ghostProject2 = db.components().insertPrivateProject(organization);
db.components().insertSnapshot(ghostProject2, dto -> dto.setStatus("U"));
- ComponentDto disabledGhostProject = db.components().insertProject(dto -> dto.setEnabled(false));
+ ComponentDto disabledGhostProject = db.components().insertPrivateProject(dto -> dto.setEnabled(false));
db.components().insertSnapshot(disabledGhostProject, dto -> dto.setStatus("U"));
- ComponentDto project1 = db.components().insertProject(organization);
+ ComponentDto project1 = db.components().insertPrivateProject(organization);
db.components().insertSnapshot(project1, dto -> dto.setStatus("P"));
db.components().insertSnapshot(project1, dto -> dto.setStatus("U"));
ComponentDto module = db.components().insertComponent(newModuleDto(project1));
ComponentDto dir = db.components().insertComponent(newDirectory(module, "foo"));
db.components().insertComponent(newFileDto(module, dir, "bar"));
- ComponentDto provisionedProject = db.components().insertProject(organization);
+ ComponentDto provisionedProject = db.components().insertPrivateProject(organization);
// not a ghost because has at least one snapshot with status P
- ComponentDto project2 = db.components().insertProject(organization);
+ ComponentDto project2 = db.components().insertPrivateProject(organization);
db.components().insertSnapshot(project2, dto -> dto.setStatus("P"));
// not a ghost because it's not a project
@Test
public void update() {
- db.components().insertProject(db.getDefaultOrganization(), "U1");
+ db.components().insertPrivateProject(db.getDefaultOrganization(), "U1");
underTest.update(dbSession, new ComponentUpdateDto()
.setUuid("U1")
@Test
public void updateBEnabledToFalse() {
- ComponentDto dto1 = newProjectDto(db.getDefaultOrganization(), "U1");
- ComponentDto dto2 = newProjectDto(db.getDefaultOrganization(), "U2");
- ComponentDto dto3 = newProjectDto(db.getDefaultOrganization(), "U3");
+ ComponentDto dto1 = newPrivateProjectDto(db.getDefaultOrganization(), "U1");
+ ComponentDto dto2 = newPrivateProjectDto(db.getDefaultOrganization(), "U2");
+ ComponentDto dto3 = newPrivateProjectDto(db.getDefaultOrganization(), "U3");
underTest.insert(dbSession, dto1, dto2, dto3);
underTest.updateBEnabledToFalse(dbSession, asList("U1", "U2"));
@Test
public void update_tags() {
- ComponentDto project = db.components().insertProject(p -> p.setTags(emptyList()));
+ ComponentDto project = db.components().insertPrivateProject(p -> p.setTags(emptyList()));
underTest.updateTags(dbSession, project.setTags(newArrayList("finance", "toto", "tutu")));
dbSession.commit();
@Test
public void delete() throws Exception {
- ComponentDto project1 = db.components().insertProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_1"));
- db.components().insertProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_2"));
+ ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_1"));
+ db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_2"));
underTest.delete(dbSession, project1.getId());
dbSession.commit();
@Test
public void selectByQuery_with_paging_query_and_qualifiers() {
OrganizationDto organizationDto = db.organizations().insert();
- db.components().insertProjectAndSnapshot(newProjectDto(organizationDto).setName("aaaa-name"));
+ db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto).setName("aaaa-name"));
db.components().insertProjectAndSnapshot(newView(organizationDto));
for (int i = 9; i >= 1; i--) {
- db.components().insertProjectAndSnapshot(newProjectDto(organizationDto).setName("project-" + i));
+ db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project-" + i));
}
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("oJect").setQualifiers(Qualifiers.PROJECT).build();
public void selectByQuery_with_organization_filters_on_specified_organization() {
OrganizationDto organization1 = db.organizations().insert();
OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project1 = db.components().insertProject(organization1);
- ComponentDto project2 = db.components().insertProject(organization2);
+ ComponentDto project1 = db.components().insertPrivateProject(organization1);
+ ComponentDto project2 = db.components().insertPrivateProject(organization2);
assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2))
.extracting(ComponentDto::uuid)
public void countByQuery_with_organization_filters_on_specified_organization() {
OrganizationDto organization1 = db.organizations().insert();
OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project1 = db.components().insertProject(organization1);
- ComponentDto project2 = db.components().insertProject(organization2);
+ ComponentDto project1 = db.components().insertPrivateProject(organization1);
+ ComponentDto project2 = db.components().insertPrivateProject(organization2);
assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY))
.isEqualTo(2);
@Test
public void selectByQuery_name_with_special_characters() {
- db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name"));
+ db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name"));
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("-\\_%/-").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@Test
public void selectByQuery_key_with_special_characters() {
- db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert()).setKey("project-_%-key"));
+ db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("project-_%-key"));
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@Test
public void selectByQuery_filter_on_language() {
- db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("java-project-key").setLanguage("java"));
- db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("cpp-project-key").setLanguage("cpp"));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("java-project-key").setLanguage("java"));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("cpp-project-key").setLanguage("cpp"));
ComponentQuery query = ComponentQuery.builder().setLanguage("java").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@Test
public void selectByQuery_on_component_ids() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto sonarqube = db.components().insertComponent(newProjectDto(organizationDto));
- ComponentDto jdk8 = db.components().insertComponent(newProjectDto(organizationDto));
- ComponentDto cLang = db.components().insertComponent(newProjectDto(organizationDto));
+ ComponentDto sonarqube = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
+ ComponentDto jdk8 = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
+ ComponentDto cLang = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
ComponentQuery query = ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT)
.setComponentIds(newHashSet(sonarqube.getId(), jdk8.getId())).build();
// organization
OrganizationDto organization = db.organizations().insert();
// project -> module -> file
- ComponentDto project = newProjectDto(organization, PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(organization, PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto(MODULE_UUID, project);
db.components().insertComponent(module);
@Test
public void select_descendants_with_children_stragegy() {
// project has 2 children: module and file 1. Other files are part of module.
- ComponentDto project = newProjectDto(db.organizations().insert(), PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto(MODULE_UUID, project);
db.components().insertComponent(module);
@Test
public void select_descendants_with_leaves_strategy() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
db.components().insertComponent(newModuleDto("module-1-uuid", project));
db.components().insertComponent(newFileDto(project, null, "file-1-uuid"));
ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name");
db.components().insertComponent(subView);
// one project and its copy linked to the view
- ComponentDto project = newProjectDto(organizationDto, PROJECT_UUID).setName("project name");
+ ComponentDto project = newPrivateProjectDto(organizationDto, PROJECT_UUID).setName("project name");
db.components().insertProjectAndSnapshot(project);
db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view));
ComponentTreeQuery dbQuery = newTreeQuery(A_VIEW_UUID).setNameOrKeyQuery("name").setStrategy(CHILDREN).build();
@Test
public void select_projects_by_name_query() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project1 = db.components().insertComponent(newProjectDto(organizationDto).setName("project1"));
+ ComponentDto project1 = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project1"));
ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setName("module1"));
ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module1).setName("subModule1"));
db.components().insertComponent(newFileDto(subModule1).setName("file"));
- ComponentDto project2 = db.components().insertComponent(newProjectDto(organizationDto).setName("project2"));
- ComponentDto project3 = db.components().insertComponent(newProjectDto(organizationDto).setName("project3"));
+ ComponentDto project2 = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project2"));
+ ComponentDto project3 = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project3"));
assertThat(underTest.selectProjectsByNameQuery(dbSession, null, false)).extracting(ComponentDto::uuid)
.containsOnly(project1.uuid(), project2.uuid(), project3.uuid());
OrganizationDto organizationDto = db.organizations().insert();
String[] uuids = {
- db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(true)).uuid(),
- db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(false)).uuid(),
- db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(true)).uuid(),
- db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(false)).uuid(),
- db.components().insertComponent(newProjectDto(organizationDto).setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(true)).uuid(),
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(false)).uuid(),
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(true)).uuid(),
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(false)).uuid(),
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
};
underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true);
import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
/**
* On H2, the index on PROJECTS.KEE is unique. In order to simulate the MySQL behaviour where the index is not unique,
@Test
public void select_components_having_same_key() {
OrganizationDto organizationDto = db.organizations().insert();
- insertProject(newProjectDto(organizationDto).setKey(PROJECT_KEY));
- insertProject(newProjectDto(organizationDto).setKey(PROJECT_KEY));
- insertProject(newProjectDto(organizationDto).setKey(PROJECT_KEY));
- insertProject(newProjectDto(organizationDto).setKey("ANOTHER_PROJECT_KEY"));
+ insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setKey(PROJECT_KEY));
+ insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setKey(PROJECT_KEY));
+ insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setKey(PROJECT_KEY));
+ insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("ANOTHER_PROJECT_KEY"));
assertThat(underTest.selectComponentsHavingSameKeyOrderedById(db.getSession(), PROJECT_KEY)).hasSize(3);
}
import java.util.Arrays;
import java.util.function.Consumer;
+import javax.annotation.Nullable;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
+import static com.google.common.base.Preconditions.checkState;
import static java.util.Arrays.asList;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPublicProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
}
public ComponentDto insertComponent(ComponentDto component) {
- return insertComponentImpl(component, noExtraConfiguration());
+ return insertComponentImpl(component, null, noExtraConfiguration());
}
- public ComponentDto insertProject() {
- return insertComponentImpl(newProjectDto(db.getDefaultOrganization()), noExtraConfiguration());
+ public ComponentDto insertPrivateProject() {
+ return insertComponentImpl(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, noExtraConfiguration());
+ }
+
+ public ComponentDto insertPublicProject() {
+ return insertComponentImpl(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, noExtraConfiguration());
+ }
+
+ @SafeVarargs
+ public final ComponentDto insertPrivateProject(Consumer<ComponentDto>... dtoPopulators) {
+ return insertComponentImpl(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, dtoPopulators);
+ }
+
+ @SafeVarargs
+ public final ComponentDto insertPublicProject(Consumer<ComponentDto>... dtoPopulators) {
+ return insertComponentImpl(newPublicProjectDto(db.getDefaultOrganization()), false, dtoPopulators);
}
@SafeVarargs
- public final ComponentDto insertProject(Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(newProjectDto(db.getDefaultOrganization()), dtoPopulators);
+ public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
+ return insertComponentImpl(ComponentTesting.newPrivateProjectDto(organizationDto), true, dtoPopulators);
}
@SafeVarargs
- public final ComponentDto insertProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
- return insertComponentImpl(newProjectDto(organizationDto), dtoPopulators);
+ public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
+ return insertComponentImpl(newPublicProjectDto(organizationDto), true, dtoPopulators);
+ }
+
+ public ComponentDto insertPrivateProject(OrganizationDto organizationDto) {
+ return insertComponentImpl(ComponentTesting.newPrivateProjectDto(organizationDto), true, noExtraConfiguration());
+ }
+
+ public ComponentDto insertPublicProject(OrganizationDto organizationDto) {
+ return insertComponentImpl(newPublicProjectDto(organizationDto), false, noExtraConfiguration());
}
- public ComponentDto insertProject(OrganizationDto organizationDto) {
- return insertComponentImpl(newProjectDto(organizationDto), noExtraConfiguration());
+ public ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid) {
+ return insertComponentImpl(newPrivateProjectDto(organizationDto, uuid), true, noExtraConfiguration());
}
- public ComponentDto insertProject(OrganizationDto organizationDto, String uuid) {
- return insertComponentImpl(newProjectDto(organizationDto, uuid), noExtraConfiguration());
+ public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) {
+ return insertComponentImpl(newPublicProjectDto(organizationDto, uuid), false, noExtraConfiguration());
}
public ComponentDto insertView() {
- return insertComponentImpl(newView(db.getDefaultOrganization()), noExtraConfiguration());
+ return insertComponentImpl(newView(db.getDefaultOrganization()), false, noExtraConfiguration());
}
public ComponentDto insertView(Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(newView(db.getDefaultOrganization()), dtoPopulator);
+ return insertComponentImpl(newView(db.getDefaultOrganization()), false, dtoPopulator);
}
public ComponentDto insertView(OrganizationDto organizationDto) {
- return insertComponentImpl(newView(organizationDto), noExtraConfiguration());
+ return insertComponentImpl(newView(organizationDto), false, noExtraConfiguration());
}
public ComponentDto insertView(OrganizationDto organizationDto, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(newView(organizationDto), dtoPopulator);
+ return insertComponentImpl(newView(organizationDto), false, dtoPopulator);
}
public ComponentDto insertView(String uuid) {
- return insertComponentImpl(newView(db.getDefaultOrganization(), uuid), noExtraConfiguration());
+ return insertComponentImpl(newView(db.getDefaultOrganization(), uuid), false, noExtraConfiguration());
}
public ComponentDto insertView(OrganizationDto organizationDto, String uuid) {
- return insertComponentImpl(newView(organizationDto, uuid), noExtraConfiguration());
+ return insertComponentImpl(newView(organizationDto, uuid), false, noExtraConfiguration());
}
private static <T> Consumer<T> noExtraConfiguration() {
}
@SafeVarargs
- private final ComponentDto insertComponentImpl(ComponentDto component, Consumer<ComponentDto>... dtoPopulators) {
+ private final ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto>... dtoPopulators) {
Arrays.stream(dtoPopulators)
.forEach(dtoPopulator -> dtoPopulator.accept(component));
+ checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag");
dbClient.componentDao().insert(dbSession, component);
db.commit();
@Test
public void test_formatUuidPathFromParent() {
- ComponentDto parent = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
+ ComponentDto parent = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
assertThat(ComponentDto.formatUuidPathFromParent(parent)).isEqualTo(".123.");
}
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
public class ComponentKeyUpdaterDaoTest {
@Test
public void updateKey_does_not_updated_inactive_components() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "A").setKey("my_project"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "A").setKey("my_project"));
ComponentDto directory = db.components().insertComponent(newDirectory(project, "/directory").setKey("my_project:directory"));
db.components().insertComponent(newFileDto(project, directory).setKey("my_project:directory/file"));
ComponentDto inactiveDirectory = db.components().insertComponent(newDirectory(project, "/inactive_directory").setKey("my_project:inactive_directory").setEnabled(false));
@Test
public void bulk_update_key_does_not_update_inactive_components() {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "A").setKey("my_project"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setKey("my_project"));
db.components().insertComponent(newModuleDto(project).setKey("my_project:module"));
db.components().insertComponent(newModuleDto(project).setKey("my_project:inactive_module").setEnabled(false));
@Test
public void updateKey_throws_IAE_when_sub_component_key_is_too_long() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = newProjectDto(organizationDto, "project-uuid").setKey("old-project-key");
+ ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setKey("old-project-key");
db.components().insertComponent(project);
db.components().insertComponent(newFileDto(project, null).setKey("old-project-key:file"));
String newLongProjectKey = Strings.repeat("a", 400);
@Test
public void fail_when_new_key_is_invalid() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Malformed key for 'my?project?key'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
@Test
public void check_component_keys_checks_inactive_components() {
OrganizationDto organizationDto = db.organizations().insert();
- db.components().insertComponent(newProjectDto(organizationDto).setKey("my-project"));
- db.components().insertComponent(newProjectDto(organizationDto).setKey("your-project").setEnabled(false));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("my-project"));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("your-project").setEnabled(false));
Map<String, Boolean> result = underTest.checkComponentKeys(dbSession, newArrayList("my-project", "your-project", "new-project"));
@Test
public void simulate_bulk_update_key_do_not_return_disable_components() {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "A").setKey("project"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setKey("project"));
db.components().insertComponent(newModuleDto(project).setKey("project:enabled-module"));
db.components().insertComponent(newModuleDto(project).setKey("project:disabled-module").setEnabled(false));
@Test
public void simulate_bulk_update_key_fails_if_invalid_componentKey() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "A").setKey("project"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "A").setKey("project"));
db.components().insertComponent(newModuleDto(project).setKey("project:enabled-module"));
db.components().insertComponent(newModuleDto(project).setKey("project:disabled-module").setEnabled(false));
import org.sonar.core.util.Uuids;
import org.sonar.db.organization.OrganizationDto;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
return newModuleDto(Uuids.createFast(), subProjectOrProject);
}
- public static ComponentDto newProjectDto(OrganizationDto organizationDto) {
- return newProjectDto(organizationDto.getUuid(), Uuids.createFast());
+ public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto) {
+ return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
}
- public static ComponentDto newProjectDto(OrganizationDto organizationDto, String uuid) {
- return newProjectDto(organizationDto.getUuid(), uuid);
+ public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto, String uuid) {
+ return newProjectDto(organizationDto.getUuid(), uuid, true);
}
- private static ComponentDto newProjectDto(String organizationUuid, String uuid) {
+ public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto) {
+ return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), false);
+ }
+
+ public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto, String uuid) {
+ return newProjectDto(organizationDto.getUuid(), uuid, false);
+ }
+
+ private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
return new ComponentDto()
.setOrganizationUuid(organizationUuid)
.setUuid(uuid)
.setQualifier(Qualifiers.PROJECT)
.setPath(null)
.setLanguage(null)
- .setEnabled(true);
+ .setEnabled(true)
+ .setPrivate(isPrivate);
}
public static ComponentDto newView(OrganizationDto organizationDto) {
}
public static ComponentDto newView(OrganizationDto organizationDto, String uuid) {
- return newProjectDto(organizationDto, uuid)
+ return newPrivateProjectDto(organizationDto, uuid)
.setUuid(uuid)
.setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.VIEW);
+ .setQualifier(Qualifiers.VIEW)
+ .setPrivate(false);
}
private static ComponentDto newView(String organizationUuid, String uuid) {
- return newProjectDto(organizationUuid, uuid)
- .setUuid(uuid)
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.VIEW);
+ return newProjectDto(organizationUuid, uuid, false)
+ .setUuid(uuid)
+ .setScope(Scopes.PROJECT)
+ .setQualifier(Qualifiers.VIEW);
}
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) {
}
public static ComponentDto newChildComponent(String uuid, ComponentDto moduleOrProject, ComponentDto parent) {
+ checkArgument(moduleOrProject.isPrivate() == parent.isPrivate(),
+ "private flag inconsistent between moduleOrProject (%s) and parent (%s)",
+ moduleOrProject.isPrivate(), parent.isPrivate());
return new ComponentDto()
.setOrganizationUuid(parent.getOrganizationUuid())
.setUuid(uuid)
.setModuleUuid(moduleOrProject.uuid())
.setModuleUuidPath(moduleOrProject.moduleUuidPath())
.setCreatedAt(new Date())
- .setEnabled(true);
+ .setEnabled(true)
+ .setPrivate(moduleOrProject.isPrivate());
}
}
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES;
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
@Test
public void test_getUuidPath() throws Exception {
assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(CHILDREN)
- .build().getUuidPath(newProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
+ .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(LEAVES)
- .build().getUuidPath(newProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
+ .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
}
@Test
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotDto.STATUS_PROCESSED;
import static org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED;
import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE;
@Test
public void test_selectByUuid() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(newAnalysis(project)
.setUuid("ABCD")
.setStatus("P")
@Test
public void selectLastSnapshotsByRootComponentUuids_returns_snapshots_flagged_as_last() {
- ComponentDto firstProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1"));
+ ComponentDto firstProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1"));
dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(false));
SnapshotDto lastSnapshotOfFirstProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(true));
- ComponentDto secondProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2"));
+ ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2"));
SnapshotDto lastSnapshotOfSecondProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(secondProject).setLast(true));
- db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()));
+ db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
List<SnapshotDto> result = underTest.selectLastAnalysesByRootComponentUuids(dbSession, newArrayList(firstProject.uuid(), secondProject.uuid()));
@Test
public void select_first_snapshots() throws Exception {
- ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
db.getDbClient().componentDao().insert(dbSession, project);
db.getDbClient().snapshotDao().insert(dbSession,
@Test
public void insert() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project)
.setStatus("P")
@Test
public void insert_snapshots() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
underTest.insert(db.getSession(),
newAnalysis(project).setLast(false).setUuid("u5"),
}
private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) {
- SnapshotDto snapshot = newAnalysis(ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
+ SnapshotDto snapshot = newAnalysis(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
.setLast(isLastFlag)
.setStatus(status)
.setUuid(uuid);
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.event.EventTesting.newEvent;
@Test
public void select_by_uuid() {
- SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.organizations().insert()));
+ SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A1"));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A2"));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A3"));
@Test
public void select_by_analysis_uuid() {
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
SnapshotDto otherAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbTester.commit();
@Test
public void select_by_analysis_uuids() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
SnapshotDto a1 = dbTester.components().insertSnapshot(newAnalysis(project));
SnapshotDto a2 = dbTester.components().insertSnapshot(newAnalysis(project));
SnapshotDto a42 = dbTester.components().insertSnapshot(newAnalysis(project));
@Test
public void update_name_and_description() {
- SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.organizations().insert()));
+ SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
dbTester.events().insertEvent(newEvent(analysis).setUuid("E1"));
underTest.update(dbSession, "E1", "New Name", "New Description");
@Test
public void delete_by_uuid() {
- dbTester.events().insertEvent(newEvent(newAnalysis(newProjectDto(dbTester.getDefaultOrganization()))).setUuid("E1"));
+ dbTester.events().insertEvent(newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()))).setUuid("E1"));
underTest.delete(dbTester.getSession(), "E1");
dbTester.commit();
private void prepareTables() {
dbTester.rules().insertRule(RULE);
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto projectDto = dbTester.components().insertProject(organizationDto, (t) -> t.setUuid(PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto projectDto = dbTester.components().insertPrivateProject(organizationDto, (t) -> t.setUuid(PROJECT_UUID).setKey(PROJECT_KEY));
dbTester.components().insertComponent(ComponentTesting.newFileDto(projectDto).setUuid(FILE_UUID).setKey(FILE_KEY));
underTest.insert(dbTester.getSession(), newIssueDto(ISSUE_KEY1)
.setMessage("the message")
public IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto> populateIssueDto) {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertProject(organizationDto);
+ ComponentDto project = db.components().insertPrivateProject(organizationDto);
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = newIssue(rule, file, project);
populateIssueDto.accept(issueDto);
@Before
public void setUp() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- project = ComponentTesting.newProjectDto(organizationDto);
+ project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbTester.getDbClient().componentDao().insert(dbSession, project);
file = ComponentTesting.newFileDto(project, null);
dbTester.getDbClient().componentDao().insert(dbSession, file);
@Test
public void test_inserted_and_selected_columns() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
db.components().insertComponent(newFileDto(project).setUuid("C4"));
@Test
public void selectByQuery() {
- ComponentDto project1 = db.components().insertProject();
+ ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project1));
db.components().insertComponent(newFileDto(module).setUuid("C1"));
db.components().insertComponent(newFileDto(module).setUuid("C2"));
insertAnalysis(OTHER_ANALYSIS_UUID, project1.uuid(), false);
String project2LastAnalysisUuid = "P2_LAST_ANALYSIS";
- ComponentDto project2 = db.components().insertProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
insertAnalysis(project2LastAnalysisUuid, project2.uuid(), true);
// project 1
@Test
public void selectSingle() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newFileDto(project).setUuid("C1"));
insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
insertMeasure("M1", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
@Test
public void select_tree_by_query() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto module1 = db.components().insertComponent(newModuleDto(project));
ComponentDto module2 = db.components().insertComponent(newModuleDto(project));
ComponentDto file1 = db.components().insertComponent(newFileDto(module1).setUuid("C1").setName("File One"));
@Test
public void select_tree_by_query_use_only_latest_analysis() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file1 = db.components().insertComponent(newFileDto(project).setUuid("C1").setName("File One"));
db.components().insertComponent(newFileDto(project).setUuid("C2").setName("File Two").setQualifier(UNIT_TEST_FILE));
insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
@Test
public void select_past_measures_with_several_analyses() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
long lastAnalysisDate = parseDate("2017-01-25").getTime();
long previousAnalysisDate = lastAnalysisDate - 10_000_000_000L;
long oldAnalysisDate = lastAnalysisDate - 100_000_000_000L;
@Test
public void selectByComponentsAndMetrics() {
- ComponentDto project1 = db.components().insertProject(db.getDefaultOrganization(), "P1");
+ ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization(), "P1");
ComponentDto module = db.components().insertComponent(newModuleDto(project1));
db.components().insertComponent(newFileDto(module).setUuid("C1"));
db.components().insertComponent(newFileDto(module).setUuid("C2"));
insertAnalysis(OTHER_ANALYSIS_UUID, project1.uuid(), false);
String project2LastAnalysisUuid = "P2_LAST_ANALYSIS";
- ComponentDto project2 = db.components().insertProject(db.getDefaultOrganization(), "P2");
+ ComponentDto project2 = db.components().insertPrivateProject(db.getDefaultOrganization(), "P2");
insertAnalysis(project2LastAnalysisUuid, project2.uuid(), true);
// project 1
@Test
public void test_getUuidPath() throws Exception {
assertThat(MeasureTreeQuery.builder().setStrategy(CHILDREN)
- .build().getUuidPath(ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
+ .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
assertThat(MeasureTreeQuery.builder().setStrategy(LEAVES)
- .build().getUuidPath(ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
+ .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
}
@Test
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures;
import org.sonar.db.metric.MetricDto;
import static org.sonar.api.measures.Metric.ValueType.INT;
import static org.sonar.api.measures.Metric.ValueType.LEVEL;
import static org.sonar.api.measures.Metric.ValueType.STRING;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
public void return_project_measure() {
MetricDto metric1 = insertIntMetric("ncloc");
MetricDto metric2 = insertIntMetric("coverage");
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization()).setKey("Project-Key").setName("Project Name").setTagsString("platform,java");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()).setKey("Project-Key").setName("Project Name").setTagsString("platform,java");
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
insertMeasure(project, analysis, metric1, 10d);
insertMeasure(project, analysis, metric2, 20d);
@Test
public void return_project_measure_having_leak() throws Exception {
MetricDto metric = insertIntMetric("new_lines");
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
insertMeasureOnLeak(project, analysis, metric, 10d);
@Test
public void return_language_distribution_measure() throws Exception {
MetricDto metric = insertMetric("ncloc_language_distribution", DATA);
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
insertMeasure(project, analysis, metric, "<null>=2;java=6;xoo=18");
MetricDto dataMetric = insertMetric("data", DATA);
MetricDto distribMetric = insertMetric("distrib", DISTRIB);
MetricDto stringMetric = insertMetric("string", STRING);
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
insertMeasure(project, analysis, dataMetric, "dat");
insertMeasure(project, analysis, distribMetric, "dis");
@Test
public void does_not_return_disabled_metrics() throws Exception {
MetricDto disabledMetric = insertMetric("disabled", false, false, INT);
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
insertMeasure(project, analysis, disabledMetric, 10d);
@Test
public void fail_when_measure_return_no_value() throws Exception {
MetricDto metric = insertIntMetric("new_lines");
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
insertMeasure(project, analysis, metric, 10d);
@Test
public void return_many_project_measures() {
- dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.getDefaultOrganization()));
- dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.getDefaultOrganization()));
- dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.getDefaultOrganization()));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
assertThat(createResultSetAndReturnDocsById()).hasSize(3);
}
@Test
public void return_project_without_analysis() throws Exception {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false));
dbSession.commit();
@Test
public void does_not_return_non_active_projects() throws Exception {
// Disabled project
- dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.getDefaultOrganization()).setEnabled(false));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()).setEnabled(false));
// Disabled project with analysis
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()).setEnabled(false));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()).setEnabled(false));
dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
// A view
@Test
public void return_only_docs_from_given_project() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
- dbTester.components().insertProjectAndSnapshot(newProjectDto(organizationDto));
- dbTester.components().insertProjectAndSnapshot(newProjectDto(organizationDto));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(project.uuid());
@Test
public void return_nothing_on_unknown_project() throws Exception {
- dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.getDefaultOrganization()));
+ dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById("UNKNOWN");
}
private MeasureDto insertProjectAndMeasure(String projectUuid, MetricDto metric, String value) {
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), projectUuid);
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), projectUuid);
SnapshotDto analysis1 = dbTester.components().insertProjectAndSnapshot(project);
return insertMeasure(project, analysis1, metric, value);
}
*/
@Test
public void selectOrganizationPermissions_for_logged_in_user() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertMember(group1, user);
db.users().insertPermissionOnUser(org, user, "perm1");
db.users().insertProjectPermissionOnUser(user, "perm42", project);
db.users().insertPermissionOnUser(org3, user, QUALITY_GATE_ADMIN);
// exclude project permission
- db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, db.components().insertProject());
+ db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, db.components().insertPrivateProject());
Set<String> orgUuids = underTest.selectOrganizationUuidsOfUserWithGlobalPermission(dbSession, user.getId(), SCAN_EXECUTION);
@Test
public void selectProjectPermissionsOfAnonymous_returns_permissions_of_anonymous_user_on_specified_project() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(db.users().insertUser(), UserRole.USER, project);
- ComponentDto otherProject = db.components().insertProject();
+ ComponentDto otherProject = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, otherProject);
assertThat(underTest.selectProjectPermissionsOfAnonymous(dbSession, project.uuid())).containsOnly(UserRole.CODEVIEWER);
@Test
public void selectProjectPermissionsOfAnonymous_returns_empty_set_when_project_does_not_exist() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
assertThat(underTest.selectProjectPermissionsOfAnonymous(dbSession, "does_not_exist")).isEmpty();
@Test
public void selectProjectPermissions_returns_empty_set_when_logged_in_user_and_project_does_not_exist() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
assertThat(underTest.selectProjectPermissions(dbSession, "does_not_exist", user.getId())).isEmpty();
@Test
public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project_through_anonymous_permissions() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, project);
@Test
public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(db.users().insertUser(), UserRole.ISSUE_ADMIN, project);
@Test
public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project_through_group_membership() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnGroup(group1, UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnGroup(group2, UserRole.ISSUE_ADMIN, project);
db.users().insertMember(group1, user);
@Test
public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project_through_all_possible_configurations() {
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, project);
db.users().insertProjectPermissionOnGroup(group1, UserRole.USER, project);
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.GroupDto;
import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.OrganizationPermission.SCAN;
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
- ComponentDto project1 = db.components().insertProject();
- ComponentDto project2 = db.components().insertProject();
- ComponentDto project3 = db.components().insertProject();
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
+ ComponentDto project3 = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnGroup(group1, ISSUE_ADMIN, project1);
db.users().insertProjectPermissionOnGroup(group1, ADMIN, project2);
GroupDto group2 = db.users().insertGroup(organizationDto, "Group-2");
GroupDto group3 = db.users().insertGroup(organizationDto, "Group-3");
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
db.users().insertPermissionOnAnyone(organizationDto, SCAN);
db.users().insertPermissionOnAnyone(organizationDto, PROVISION_PROJECTS);
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
- ComponentDto project = db.components().insertProject();
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
db.users().insertPermissionOnGroup(group1, SCAN);
GroupDto group2 = db.users().insertGroup(organizationDto, "Group-2");
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project);
GroupDto group3 = db.users().insertGroup(organizationDto, "Group-3");
db.users().insertPermissionOnGroup(group1, PROVISION_PROJECTS);
GroupDto group2 = db.users().insertGroup(org, "Group-2");
- ComponentDto project = db.components().insertComponent(newProjectDto(org));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(org));
db.users().insertProjectPermissionOnGroup(group2, USER, project);
GroupDto group3 = db.users().insertGroup(org, "Group-3");
OrganizationDto org2 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
GroupDto group2 = db.users().insertGroup(org2, "group2");
- ComponentDto project = db.components().insertProject(org1);
+ ComponentDto project = db.components().insertPrivateProject(org1);
db.users().insertPermissionOnAnyone(org1, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
public void selectProjectPermissionsOfGroup() {
OrganizationDto org1 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
- ComponentDto project1 = db.components().insertProject(org1);
- ComponentDto project2 = db.components().insertProject(org1);
+ ComponentDto project1 = db.components().insertPrivateProject(org1);
+ ComponentDto project2 = db.components().insertPrivateProject(org1);
db.users().insertPermissionOnAnyone(org1, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
public void selectAllPermissionsByGroupId() throws Exception {
OrganizationDto org1 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
- ComponentDto project1 = db.components().insertProject(org1);
- ComponentDto project2 = db.components().insertProject(org1);
+ ComponentDto project1 = db.components().insertPrivateProject(org1);
+ ComponentDto project2 = db.components().insertPrivateProject(org1);
db.users().insertPermissionOnAnyone(org1, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
GroupDto group2 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertProject(org);
- ComponentDto project2 = db.components().insertProject(org);
+ ComponentDto project1 = db.components().insertPrivateProject(org);
+ ComponentDto project2 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnGroup(group1, "perm1");
db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
db.users().insertProjectPermissionOnAnyone("perm3", project1);
public void delete_global_permission_from_group() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertProject(org);
+ ComponentDto project1 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
public void delete_global_permission_from_anyone() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertProject(org);
+ ComponentDto project1 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
public void delete_project_permission_from_group() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertProject(org);
+ ComponentDto project1 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
public void delete_project_permission_from_anybody() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertProject(org);
+ ComponentDto project1 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
dbClient.userDao().insert(dbSession, user2);
dbClient.userDao().insert(dbSession, user3);
organizationDto = dbTester.organizations().insert();
- project1 = dbTester.components().insertProject(organizationDto);
- project2 = dbTester.components().insertProject(organizationDto);
+ project1 = dbTester.components().insertPrivateProject(organizationDto);
+ project2 = dbTester.components().insertPrivateProject(organizationDto);
dbTester.organizations().addMember(organizationDto, user1);
dbTester.organizations().addMember(organizationDto, user2);
dbTester.organizations().addMember(organizationDto, user3);
public void selectUserIds() {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
- ComponentDto project1 = dbTester.components().insertProject(org1);
- ComponentDto project2 = dbTester.components().insertProject(org2);
+ ComponentDto project1 = dbTester.components().insertPrivateProject(org1);
+ ComponentDto project2 = dbTester.components().insertPrivateProject(org2);
addProjectPermission(org1, USER, user1, project1);
addProjectPermission(org1, USER, user2, project1);
@Test
public void selectProjectPermissionsOfUser() {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project3 = dbTester.components().insertProject(org);
+ ComponentDto project3 = dbTester.components().insertPrivateProject(org);
addGlobalPermission(organizationDto, "perm1", user1);
addProjectPermission(organizationDto, "perm2", user1, project1);
addProjectPermission(organizationDto, "perm3", user1, project1);
public void delete_permissions_of_an_organization_member() {
OrganizationDto organization1 = dbTester.organizations().insert();
OrganizationDto organization2 = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(organization1);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization1);
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser();
// user 1 permissions
public void deleteByUserId() {
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser();
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.users().insertPermissionOnUser(user1, SCAN);
dbTester.users().insertPermissionOnUser(user1, ADMINISTER);
dbTester.users().insertProjectPermissionOnUser(user1, ADMINISTER_QUALITY_GATES.getKey(), project);
@UseDataProvider("allValuesForSelect")
public void selectEnabledDescendantModuleProperties_supports_all_values(String dbValue, String expected) throws SQLException {
String projectUuid = "A";
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid);
dbClient.componentDao().insert(session, project);
long projectId = project.getId();
insertProperty("project.one", dbValue, projectId, null);
@Test
public void select_component_properties_by_keys() throws Exception {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
UserDto user = dbTester.users().insertUser();
String key = "key";
@Test
public void select_component_properties_by_ids() throws Exception {
- ComponentDto project = dbTester.components().insertProject();
- ComponentDto project2 = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
+ ComponentDto project2 = dbTester.components().insertPrivateProject();
UserDto user = UserTesting.newUserDto();
dbClient.userDao().insert(session, user);
@Test
public void select_properties_by_keys_and_component_ids() throws Exception {
- ComponentDto project = dbTester.components().insertProject();
- ComponentDto project2 = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
+ ComponentDto project2 = dbTester.components().insertPrivateProject();
UserDto user = UserTesting.newUserDto();
dbClient.userDao().insert(session, user);
public void delete_by_organization_and_user() throws SQLException {
OrganizationDto organization = dbTester.organizations().insert();
OrganizationDto anotherOrganization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(organization);
- ComponentDto anotherProject = dbTester.components().insertProject(anotherOrganization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto anotherProject = dbTester.components().insertPrivateProject(anotherOrganization);
UserDto user = dbTester.users().insertUser();
UserDto anotherUser = dbTester.users().insertUser();
insertProperty("KEY_11", "VALUE", project.getId(), user.getId());
public void delete_by_organization_and_matching_login() throws SQLException {
OrganizationDto organization = dbTester.organizations().insert();
OrganizationDto anotherOrganization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(organization);
- ComponentDto anotherProject = dbTester.components().insertProject(anotherOrganization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto anotherProject = dbTester.components().insertPrivateProject(anotherOrganization);
UserDto user = dbTester.users().insertUser();
UserDto anotherUser = dbTester.users().insertUser();
insertProperty("KEY_11", user.getLogin(), project.getId(), null);
@Test
public void delete_by_key_and_value() throws SQLException {
- ComponentDto project = dbTester.components().insertProject();
- ComponentDto anotherProject = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
+ ComponentDto anotherProject = dbTester.components().insertPrivateProject();
insertProperty("KEY", "VALUE", null, null);
insertProperty("KEY", "VALUE", project.getId(), null);
insertProperty("KEY", "VALUE", null, 100);
private ComponentDto insertProject(String uuid) {
String key = "project" + uuid;
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), uuid).setKey(key);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization(), uuid).setKey(key);
dbClient.componentDao().insert(session, project);
dbTester.commit();
return project;
@Test
public void delete_project_in_ce_activity_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and on on another project
@Test
public void delete_tasks_in_ce_queue_when_deleting_project() {
- ComponentDto projectToBeDeleted = dbTester.components().insertProject();
- ComponentDto anotherLivingProject = dbTester.components().insertProject();
+ ComponentDto projectToBeDeleted = dbTester.components().insertPrivateProject();
+ ComponentDto anotherLivingProject = dbTester.components().insertPrivateProject();
// Insert 3 rows in CE_QUEUE: two for the project that will be deleted (in order to check that status
// is not involved in deletion), and one on another project
@Test
public void select_qgate_id_is_absent() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
Optional<Long> result = underTest.selectQGateIdByComponentId(dbSession, project.getId());
@Test
public void deleteProjectAssociationsByProfileKeys_does_nothing_if_empty_keys() {
QualityProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
- ComponentDto project1 = dbTester.components().insertProject();
+ ComponentDto project1 = dbTester.components().insertPrivateProject();
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);
underTest.deleteProjectAssociationsByProfileKeys(dbSession, Collections.emptyList());
public void deleteProjectAssociationsByProfileKeys_deletes_rows_from_table_project_profiles() {
QualityProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
QualityProfileDto profile2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
- ComponentDto project1 = dbTester.components().insertProject();
- ComponentDto project2 = dbTester.components().insertProject();
- ComponentDto project3 = dbTester.components().insertProject();
+ ComponentDto project1 = dbTester.components().insertPrivateProject();
+ ComponentDto project2 = dbTester.components().insertPrivateProject();
+ ComponentDto project3 = dbTester.components().insertPrivateProject();
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profile1);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project3, profile2);
public void countProjectsByProfileKey() {
QualityProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
QualityProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization);
- ComponentDto project1 = dbTester.components().insertProject(organization);
- ComponentDto project2 = dbTester.components().insertProject(organization);
+ ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profileWithProjects);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profileWithProjects);
OrganizationDto otherOrg = dbTester.organizations().insert();
QualityProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
- ComponentDto projectInOtherOrg = dbTester.components().insertProject(otherOrg);
+ ComponentDto projectInOtherOrg = dbTester.components().insertPrivateProject(otherOrg);
dbTester.qualityProfiles().associateProjectWithQualityProfile(projectInOtherOrg, profileInOtherOrg);
assertThat(underTest.countProjectsByProfileKey(dbTester.getSession(), organization)).containsOnly(
@Test
public void select_selected_projects() throws Exception {
- ComponentDto project1 = dbTester.components().insertProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project2 = dbTester.components().insertProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project3 = dbTester.components().insertProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project1 = dbTester.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project2 = dbTester.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project3 = dbTester.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = dbTester.organizations().insert();
- ComponentDto project4 = dbTester.components().insertProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
QualityProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
@Test
public void select_deselected_projects() throws Exception {
- ComponentDto project1 = dbTester.components().insertProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project2 = dbTester.components().insertProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project3 = dbTester.components().insertProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project1 = dbTester.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project2 = dbTester.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project3 = dbTester.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = dbTester.organizations().insert();
- ComponentDto project4 = dbTester.components().insertProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
QualityProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
@Test
public void select_project_associations() throws Exception {
- ComponentDto project1 = dbTester.components().insertProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project2 = dbTester.components().insertProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
- ComponentDto project3 = dbTester.components().insertProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project1 = dbTester.components().insertPrivateProject(t -> t.setName("Project1 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project2 = dbTester.components().insertPrivateProject(t -> t.setName("Project2 name"), t -> t.setOrganizationUuid(organization.getUuid()));
+ ComponentDto project3 = dbTester.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = dbTester.organizations().insert();
- ComponentDto project4 = dbTester.components().insertProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
QualityProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
@Test
public void update_project_profile_association() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
QualityProfileDto profile1Language1 = insertQualityProfileDto("profile1", "Profile 1", "xoo");
QualityProfileDto profile2Language2 = insertQualityProfileDto("profile2", "Profile 2", "xoo2");
QualityProfileDto profile3Language1 = insertQualityProfileDto("profile3", "Profile 3", "xoo");
public void setUp() throws Exception {
user1 = db.users().insertUser();
user2 = db.users().insertUser();
- project1 = db.components().insertProject();
- project2 = db.components().insertProject();
+ project1 = db.components().insertPrivateProject();
+ project2 = db.components().insertPrivateProject();
}
@Test
public void delete_all_group_permissions_by_group_id() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.users().insertPermissionOnGroup(group1, "admin");
db.users().insertProjectPermissionOnGroup(group1, "profileadmin", project);
db.users().insertPermissionOnGroup(group1, "gateadmin");
@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
- ComponentDto componentDto = insertComponent(ComponentTesting.newProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
+ ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, componentDto.uuid(), null);
CeTask task = underTest.submit(taskSubmit);
@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_component_exists() {
- ComponentDto componentDto1 = insertComponent(ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1"));
+ ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1"));
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, componentDto1.uuid(), null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", "non existing component uuid", null);
import static org.sonar.api.rules.RuleType.BUG;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.rule.RuleTesting.newRule;
public class IssuesActionTest {
@Test
public void return_minimal_fields() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
ComponentDto module = db.components().insertComponent(newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY));
ComponentDto file = db.components().insertComponent(newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath(null));
db.rules().insert(RULE_DEFINITION);
@Test
public void issues_from_project() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY));
ComponentDto module = db.components().insertComponent(newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY));
ComponentDto file = db.components().insertComponent(newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java"));
db.rules().insert(RULE_DEFINITION);
@Test
public void issues_from_module() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
ComponentDto module = db.components().insertComponent(newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY));
ComponentDto file = db.components().insertComponent(newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java"));
db.rules().insert(RULE_DEFINITION);
@Test
public void issues_from_file() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
ComponentDto module = db.components().insertComponent(newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY));
ComponentDto file = db.components().insertComponent(newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java"));
db.rules().insert(RULE_DEFINITION);
@Test
public void issues_attached_on_module() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY));
ComponentDto module = db.components().insertComponent(newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY));
db.rules().insert(RULE_DEFINITION);
db.issues().insert(RULE_DEFINITION, project, module, issue -> issue
@Test
public void project_issues_attached_file_on_removed_module() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY));
// File and module are removed
ComponentDto module = db.components().insertComponent(newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY).setEnabled(false));
ComponentDto file = db.components().insertComponent(newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java").setEnabled(false));
@Test
public void fail_without_browse_permission_on_file() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
thrown.expect(ForbiddenException.class);
public void return_project_settings_with_global_scan_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_project_settings_with_project_scan_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn("john").addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void not_returned_secured_settings_when_lgged_but_no_scan_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn("john").addProjectPermission(UserRole.USER, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_project_with_module_settings() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_project_with_module_settings_inherited_from_project() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_project_with_module_with_sub_module() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_project_with_two_modules() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
// No snapshot attached on the project -> provisioned project
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_sub_module_settings() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
// No project properties
public void return_sub_module_settings_including_settings_from_parent_modules() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_sub_module_settings_only_inherited_from_project() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_sub_module_settings_inherited_from_project_and_module() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
public void fail_when_not_preview_and_only_browse_permission_without_scan_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
public void fail_when_preview_and_only_scan_permission_without_browse_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
public void return_file_data_from_single_project() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_file_data_from_multi_modules() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
public void return_file_data_from_module() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
@Test
public void throw_ForbiddenException_if_no_browse_permission_nor_scan_permission() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void throw_ForbiddenException_if_browse_permission_but_not_scan_permission() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
expectedException.expect(ForbiddenException.class);
@Test
public void issues_mode_is_allowed_if_user_has_browse_permission() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
ProjectRepositories repositories = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()).setIssuesMode(true));
@Test
public void issues_mode_is_forbidden_if_user_doesnt_have_browse_permission() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.logIn().addProjectPermission(GlobalPermissions.SCAN_EXECUTION, project);
expectedException.expect(ForbiddenException.class);
@Test
public void scan_permission_on_organization_is_enough_even_without_scan_permission_on_project() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.logIn().addPermission(SCAN, project.getOrganizationUuid());
userSession.logIn().addProjectPermission(UserRole.USER, project);
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import static org.mockito.Mockito.mock;
import static org.sonar.api.utils.DateUtils.formatDate;
import static org.sonar.api.utils.DateUtils.formatDateTime;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY;
public void get_all_past_activity() {
logInAsSystemAdministrator();
OrganizationDto org1 = dbTester.organizations().insert();
- dbTester.components().insertProject(org1, "PROJECT_1");
+ dbTester.components().insertPrivateProject(org1, "PROJECT_1");
OrganizationDto org2 = dbTester.organizations().insert();
- dbTester.components().insertProject(org2, "PROJECT_2");
+ dbTester.components().insertPrivateProject(org2, "PROJECT_2");
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
@Test
public void filter_by_status() {
logInAsSystemAdministrator();
- dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
- dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_2");
+ dbTester.components().insertPrivateProject(dbTester.getDefaultOrganization(), "PROJECT_1");
+ dbTester.components().insertPrivateProject(dbTester.getDefaultOrganization(), "PROJECT_2");
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
insertQueue("T3", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
public void filter_by_min_submitted_and_max_executed_at_include_day() {
logInAsSystemAdministrator();
OrganizationDto organizationDto = dbTester.organizations().insert();
- dbTester.components().insertProject(organizationDto, "PROJECT_1");
+ dbTester.components().insertPrivateProject(organizationDto, "PROJECT_1");
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
String today = formatDate(new Date(EXECUTED_AT));
@Test
public void filter_on_current_activities() {
- dbTester.components().insertProject(dbTester.organizations().insert(), "PROJECT_1");
+ dbTester.components().insertPrivateProject(dbTester.organizations().insert(), "PROJECT_1");
logInAsSystemAdministrator();
// T2 is the current activity (the most recent one)
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
public void limit_results() {
logInAsSystemAdministrator();
OrganizationDto organizationDto = dbTester.organizations().insert();
- dbTester.components().insertProject(organizationDto, "PROJECT_1");
- dbTester.components().insertProject(organizationDto, "PROJECT_2");
+ dbTester.components().insertPrivateProject(organizationDto, "PROJECT_1");
+ dbTester.components().insertPrivateProject(organizationDto, "PROJECT_2");
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
insertQueue("T3", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
@Test
public void project_administrator_can_access_his_project_activity() {
- ComponentDto project = dbTester.components().insertProject(dbTester.organizations().insert(), "PROJECT_1");
+ ComponentDto project = dbTester.components().insertPrivateProject(dbTester.organizations().insert(), "PROJECT_1");
// no need to be a system admin
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
@Test
public void return_401_if_user_is_not_logged_in() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.anonymous();
expectedException.expect(UnauthorizedException.class);
@Test
public void search_activity_by_component_name() throws IOException {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto struts = newProjectDto(organizationDto).setName("old apache struts").setUuid("P1").setProjectUuid("P1");
- ComponentDto zookeeper = newProjectDto(organizationDto).setName("new apache zookeeper").setUuid("P2").setProjectUuid("P2");
- ComponentDto eclipse = newProjectDto(organizationDto).setName("eclipse").setUuid("P3").setProjectUuid("P3");
+ ComponentDto struts = ComponentTesting.newPrivateProjectDto(organizationDto).setName("old apache struts").setUuid("P1").setProjectUuid("P1");
+ ComponentDto zookeeper = ComponentTesting.newPrivateProjectDto(organizationDto).setName("new apache zookeeper").setUuid("P2").setProjectUuid("P2");
+ ComponentDto eclipse = ComponentTesting.newPrivateProjectDto(organizationDto).setName("eclipse").setUuid("P3").setProjectUuid("P3");
dbTester.components().insertProjectAndSnapshot(struts);
dbTester.components().insertProjectAndSnapshot(zookeeper);
dbTester.components().insertProjectAndSnapshot(eclipse);
@Test
public void search_task_id_in_queue_ignoring_other_parameters() throws IOException {
logInAsSystemAdministrator();
- dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
+ dbTester.components().insertPrivateProject(dbTester.getDefaultOrganization(), "PROJECT_1");
insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
ActivityResponse result = call(
@Test
public void search_task_id_in_activity() {
logInAsSystemAdministrator();
- dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
+ dbTester.components().insertPrivateProject(dbTester.getDefaultOrganization(), "PROJECT_1");
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
ActivityResponse result = call(ws.newRequest().setParam(Param.TEXT_QUERY, "T1"));
@Test
public void search_task_by_component_id() {
- ComponentDto project = dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
+ ComponentDto project = dbTester.components().insertPrivateProject(dbTester.getDefaultOrganization(), "PROJECT_1");
insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.ce.CeQueueTesting.newCeQueueDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
String projectUuid = "project-uuid";
String anotherProjectUuid = "another-project-uuid";
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = newProjectDto(organizationDto, projectUuid);
+ ComponentDto project = newPrivateProjectDto(organizationDto, projectUuid);
db.components().insertComponent(project);
- db.components().insertComponent(newProjectDto(organizationDto, anotherProjectUuid));
+ db.components().insertComponent(newPrivateProjectDto(organizationDto, anotherProjectUuid));
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
// pending tasks returned
insertInQueue(CeQueueDto.Status.PENDING, projectUuid);
@Test
public void fail_if_component_uuid_and_key_are_provided() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
db.components().insertComponent(project);
expectedException.expect(IllegalArgumentException.class);
@Test
public void throw_ForbiddenException_if_not_administrator_of_requested_project() {
userSession.logIn();
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
import org.sonarqube.ws.WsCe;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.ce.ws.ComponentAction.PARAM_COMPONENT_ID;
import static org.sonar.server.ce.ws.ComponentAction.PARAM_COMPONENT_KEY;
@Test
public void empty_queue_and_empty_activity() {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
+ ComponentDto project = dbTester.components().insertComponent(newPrivateProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
userSession.addProjectPermission(UserRole.USER, project);
WsCe.ProjectResponse response = ws.newRequest()
@Test
public void project_tasks() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(organizationDto, "PROJECT_1"));
+ ComponentDto project = dbTester.components().insertComponent(newPrivateProjectDto(organizationDto, "PROJECT_1"));
userSession.addProjectPermission(UserRole.USER, project);
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
@Test
public void search_tasks_by_component_key() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
logInWithBrowsePermission(project);
insertActivity("T1", project.uuid(), CeActivityDto.Status.SUCCESS);
@Test
public void canceled_tasks_must_not_be_picked_as_current_analysis() {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1"));
+ ComponentDto project = dbTester.components().insertComponent(newPrivateProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1"));
userSession.addProjectPermission(UserRole.USER, project);
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
@Test
public void throw_ForbiddenException_if_user_cant_access_project() {
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void fail_when_no_component_parameter() {
expectedException.expect(IllegalArgumentException.class);
- logInWithBrowsePermission(dbTester.components().insertProject());
+ logInWithBrowsePermission(dbTester.components().insertPrivateProject());
ws.newRequest().execute();
}
@Before
public void setUp() {
organizationDto = dbTester.organizations().insert();
- project = dbTester.components().insertProject(organizationDto);
+ project = dbTester.components().insertPrivateProject(organizationDto);
}
@Test
public void formatQueue_with_component_and_other_fields() throws IOException {
String uuid = "COMPONENT_UUID";
OrganizationDto organizationDto = db.organizations().insert();
- db.components().insertProject(organizationDto, (t) -> t.setUuid(uuid).setKey("COMPONENT_KEY").setName("Component Name"));
+ db.components().insertPrivateProject(organizationDto, (t) -> t.setUuid(uuid).setKey("COMPONENT_KEY").setName("Component Name"));
CeQueueDto dto = new CeQueueDto();
dto.setUuid("UUID");
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.component.SnapshotTesting;
import org.sonar.db.issue.IssueDto;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
public class ComponentCleanerServiceTest {
@Test
public void fail_with_IAE_if_not_a_project() throws Exception {
mockResourceTypeAsValidProject();
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
dbClient.componentDao().insert(dbSession, project);
ComponentDto file = newFileDto(project, null);
dbClient.componentDao().insert(dbSession, file);
ResourceType resourceType = mock(ResourceType.class);
when(resourceType.getBooleanProperty("deletable")).thenReturn(false);
when(mockResourceTypes.get(anyString())).thenReturn(resourceType);
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
@Test
public void fail_to_delete_null_resource_type() throws Exception {
when(mockResourceTypes.get(anyString())).thenReturn(null);
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
private DbData insertData(int id) {
String suffix = String.valueOf(id);
- ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid-" + suffix)
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid-" + suffix)
.setKey("project-key-" + suffix);
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("sonarqube", "rule-" + suffix));
dbClient.ruleDao().insert(dbSession, rule);
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.server.exceptions.NotFoundException;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.component.ComponentFinder.ParamNames.ID_AND_KEY;
@Test
public void get_component_by_uuid() {
- db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
ComponentDto component = underTest.getByUuidOrKey(dbSession, "project-uuid", null, ID_AND_KEY);
@Test
public void get_component_by_key() {
- db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-key"));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("project-key"));
ComponentDto component = underTest.getByUuidOrKey(dbSession, null, "project-key", ID_AND_KEY);
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.server.es.ProjectIndexer;
import org.sonar.server.tester.UserSessionRule;
import static org.mockito.Mockito.mock;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
public class ComponentServiceTest {
@Test
public void bulk_update() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(dbTester.organizations().insert()).setKey("my_project"));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setKey("my_project"));
ComponentDto module = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:module"));
ComponentDto inactiveModule = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:inactive_module").setEnabled(false));
ComponentDto file = componentDb.insertComponent(newFileDto(module, null).setKey("my_project:root:module:src/File.xoo"));
import static org.mockito.Mockito.verify;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
public class ComponentServiceUpdateKeyTest {
@Test
public void fail_if_old_key_and_new_key_are_the_same() {
ComponentDto project = insertSampleRootProject();
- ComponentDto anotherProject = componentDb.insertProject();
+ ComponentDto anotherProject = componentDb.insertPrivateProject();
logInAsProjectAdministrator(project);
expectedException.expect(IllegalArgumentException.class);
@Test
public void bulk_update_key() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey("my_project"));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("my_project"));
ComponentDto module = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:module"));
ComponentDto inactiveModule = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:inactive_module").setEnabled(false));
ComponentDto file = componentDb.insertComponent(newFileDto(module, null).setKey("my_project:root:module:src/File.xoo"));
}
private ComponentDto insertProject(String key) {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey(key));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey(key));
return project;
}
@Test
public void fail_when_project_key_already_exists() throws Exception {
- ComponentDto existing = db.components().insertProject();
+ ComponentDto existing = db.components().insertPrivateProject();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Could not create Project, key already exists: " + existing.key());
@Test
public void fail_when_project_key_already_exists_on_other_organization() throws Exception {
- ComponentDto existing = db.components().insertProject(db.organizations().insert());
+ ComponentDto existing = db.components().insertPrivateProject(db.organizations().insert());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Could not create Project, key already exists: " + existing.key());
@Test
public void should_prefer_favorite_over_recently_browsed() {
- ComponentDto recentlyBrowsed = db.components().insertProject(c -> c.setName("File1"));
+ ComponentDto recentlyBrowsed = db.components().insertPrivateProject(c -> c.setName("File1"));
index(recentlyBrowsed);
- ComponentDto favorite = db.components().insertProject(c -> c.setName("File2"));
+ ComponentDto favorite = db.components().insertPrivateProject(c -> c.setName("File2"));
index(favorite);
ComponentIndexQuery query = ComponentIndexQuery.builder()
protected ComponentDto indexProject(String key, String name) {
return index(
- ComponentTesting.newProjectDto(organization, "UUID_" + key)
+ ComponentTesting.newPrivateProjectDto(organization, "UUID_" + key)
.setKey(key)
.setName(name));
}
protected ComponentDto newProject(String key, String name) {
- return ComponentTesting.newProjectDto(organization, "UUID_" + key)
+ return ComponentTesting.newPrivateProjectDto(organization, "UUID_" + key)
.setKey(key)
.setName(name);
}
@Test
public void index_everything() {
- insert(ComponentTesting.newProjectDto(organization));
+ insert(ComponentTesting.newPrivateProjectDto(organization));
index();
assertThat(count()).isEqualTo(1);
@Test
public void index_unexisting_project_while_database_contains_another() {
- insert(ComponentTesting.newProjectDto(organization, "UUID-1"));
+ insert(ComponentTesting.newPrivateProjectDto(organization, "UUID-1"));
index("UUID-2");
assertThat(count()).isEqualTo(0);
@Test
public void index_one_project() {
- ComponentDto project = ComponentTesting.newProjectDto(organization, "UUID-1");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organization, "UUID-1");
insert(project);
index(project);
@Test
public void index_one_project_containing_a_file() {
- ComponentDto projectComponent = ComponentTesting.newProjectDto(organization, "UUID-PROJECT-1");
+ ComponentDto projectComponent = ComponentTesting.newPrivateProjectDto(organization, "UUID-PROJECT-1");
insert(projectComponent);
insert(ComponentTesting.newFileDto(projectComponent));
public void index_and_update_and_reindex_project() {
// insert
- ComponentDto component = ComponentTesting.newProjectDto(organization, "UUID-1").setName("OldName");
+ ComponentDto component = ComponentTesting.newPrivateProjectDto(organization, "UUID-1").setName("OldName");
insert(component);
// verify insert
public void index_and_update_and_reindex_project_with_files() {
// insert
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project).setName("OldFile"));
// verify insert
public void full_reindexing_on_empty_index() {
// insert
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.components().insertComponent(ComponentTesting.newFileDto(project).setName("OldFile"));
// verify insert
}
private ComponentDto[] insertComponentsAndAnalysis() {
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), PROJECT_UUID)
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization(), PROJECT_UUID)
.setLongName("SonarQube")
.setKey(PROJECT_KEY);
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project)
public void componentDtoToWsComponent_throws_IAE_if_organization_uuid_of_component_does_not_match_organizationDto_uuid() {
OrganizationDto organizationDto1 = OrganizationTesting.newOrganizationDto();
OrganizationDto organizationDto2 = OrganizationTesting.newOrganizationDto();
- ComponentDto componentDto = ComponentTesting.newProjectDto(organizationDto1);
+ ComponentDto componentDto = ComponentTesting.newPrivateProjectDto(organizationDto1);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("OrganizationUuid (" + organizationDto1.getUuid() + ") of ComponentDto to convert " +
import org.sonar.api.web.UserRole;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.UserDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.WsComponents.Component;
@Test
public void search_by_key_query() throws IOException {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("project-_%-key"),
- newProjectDto(db.getDefaultOrganization()).setKey("project-key-without-escaped-characters"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("project-_%-key"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("project-key-without-escaped-characters"));
SearchWsResponse response = call(new SearchWsRequest().setQuery("project-_%-key").setQualifiers(singletonList(PROJECT)));
@Test
public void search_for_files() throws IOException {
- ComponentDto project = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
ComponentDto file1 = newFileDto(project).setKey("file1");
ComponentDto file2 = newFileDto(project).setKey("file2");
db.components().insertComponents(project, file1, file2);
OrganizationDto organizationDto = db.organizations().insert();
List<ComponentDto> componentDtoList = new ArrayList<>();
for (int i = 1; i <= 9; i++) {
- componentDtoList.add(newProjectDto(organizationDto, "project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i));
+ componentDtoList.add(newPrivateProjectDto(organizationDto, "project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i));
}
insertProjectsAuthorizedForUser(componentDtoList.toArray(new ComponentDto[] {}));
public void search_with_language() throws IOException {
OrganizationDto organizationDto = db.organizations().insert();
insertProjectsAuthorizedForUser(
- newProjectDto(organizationDto).setKey("java-project").setLanguage("java"),
- newProjectDto(organizationDto).setKey("cpp-project").setLanguage("cpp"));
+ ComponentTesting.newPrivateProjectDto(organizationDto).setKey("java-project").setLanguage("java"),
+ ComponentTesting.newPrivateProjectDto(organizationDto).setKey("cpp-project").setLanguage("cpp"));
SearchWsResponse response = call(new SearchWsRequest().setOrganization(organizationDto.getKey()).setLanguage("java").setQualifiers(singletonList(PROJECT)));
@Test
public void return_only_components_from_projects_on_which_user_has_browse_permission() throws IOException {
- ComponentDto project1 = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
ComponentDto file1 = newFileDto(project1).setKey("file1");
ComponentDto file2 = newFileDto(project1).setKey("file2");
- ComponentDto project2 = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
ComponentDto file3 = newFileDto(project2).setKey("file3");
db.components().insertComponents(project1, file1, file2, project2, file3);
setBrowsePermissionOnUser(project1);
@Test
public void do_not_verify_permissions_if_user_is_root() throws IOException {
OrganizationDto org = db.organizations().insert();
- ComponentDto project1 = newProjectDto(org);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(org);
ComponentDto file1 = newFileDto(project1);
- ComponentDto project2 = newProjectDto(org);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(org);
ComponentDto file2 = newFileDto(project2);
db.components().insertComponents(project1, file1, project2, file2);
public void test_json_example() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1");
db.components().insertComponent(newView(organizationDto));
- ComponentDto project = newProjectDto(organizationDto, "project-uuid").setName("Project Name").setKey("project-key");
+ ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setName("Project Name").setKey("project-key");
ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setKey("module-key");
ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setKey("directory-key").setName("Directory Name");
db.components().insertComponents(project, module, directory,
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.server.es.EsTester;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
public void json_example() {
OrganizationDto organization1Dto = db.organizations().insertForKey("my-org-key-1");
OrganizationDto organization2Dto = db.organizations().insertForKey("my-org-key-2");
- ComponentDto project1 = insertProjectInDbAndEs(newProjectDto(organization1Dto)
+ ComponentDto project1 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1Dto)
.setUuid(Uuids.UUID_EXAMPLE_01)
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_001)
.setName("My Project 1")
.setTagsString("finance, java"));
- insertProjectInDbAndEs(newProjectDto(organization1Dto)
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1Dto)
.setUuid(Uuids.UUID_EXAMPLE_02)
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_002)
.setName("My Project 2"));
- insertProjectInDbAndEs(newProjectDto(organization2Dto)
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization2Dto)
.setUuid(Uuids.UUID_EXAMPLE_03)
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_003)
.setName("My Project 3")
@Test
public void order_by_name_case_insensitive() {
- insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Maven"));
- insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Apache"));
- insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("guava"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("Maven"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("Apache"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("guava"));
SearchProjectsWsResponse result = call(request);
@Test
public void paginate_result() {
- IntStream.rangeClosed(1, 9).forEach(i -> insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("PROJECT-" + i)));
+ IntStream.rangeClosed(1, 9).forEach(i -> insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("PROJECT-" + i)));
SearchProjectsWsResponse result = call(request.setPage(2).setPageSize(3));
@Test
public void return_only_projects() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = newProjectDto(organizationDto).setName("SonarQube");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto).setName("SonarQube");
ComponentDto directory = newDirectory(project, "path");
insertProjectInDbAndEs(project);
componentDb.insertComponents(newModuleDto(project), newView(organizationDto), directory, newFileDto(project, directory));
@Test
public void filter_projects_with_query() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
insertMetrics(COVERAGE, NCLOC);
request.setFilter("coverage <= 80 and ncloc <= 10000");
public void filter_projects_with_query_within_specified_organization() {
OrganizationDto organization1 = db.organizations().insert();
OrganizationDto organization2 = db.organizations().insert();
- insertProjectInDbAndEs(newProjectDto(organization1).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organization1).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organization2).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization2).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
insertMetrics(COVERAGE, NCLOC);
assertThat(call(request.setOrganization(null)).getComponentsList())
@Test
public void filter_projects_by_quality_gate() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Java"), "OK");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown"), "OK");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube"), "ERROR");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Java"), "OK");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Markdown"), "OK");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Qube"), "ERROR");
insertMetrics(COVERAGE, NCLOC);
request.setFilter("alert_status = OK");
@Test
public void filter_projects_by_languages() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java", "xoo"));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java", "xoo"));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("xoo"));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("<null>", "java", "xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java", "xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java", "xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("<null>", "java", "xoo"));
insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
request.setFilter("languages IN (java, js, <null>)");
@Test
public void filter_projects_by_tags() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Java").setTags(newArrayList("finance", "platform")));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown").setTags(singletonList("marketing")));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube").setTags(newArrayList("offshore")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Java").setTags(newArrayList("finance", "platform")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Markdown").setTags(singletonList("marketing")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setName("Sonar Qube").setTags(newArrayList("offshore")));
request.setFilter("tags in (finance, offshore)");
SearchProjectsWsResponse result = call(request);
@Test
public void filter_projects_by_text_query() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1");
- insertProjectInDbAndEs(newProjectDto(organizationDto).setKey("sonar-java").setName("Sonar Java"));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setKey("sonar-groovy").setName("Sonar Groovy"));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setKey("sonar-markdown").setName("Sonar Markdown"));
- insertProjectInDbAndEs(newProjectDto(organizationDto).setKey("sonarqube").setName("Sonar Qube"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("sonar-java").setName("Sonar Java"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("sonar-groovy").setName("Sonar Groovy"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("sonar-markdown").setName("Sonar Markdown"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("sonarqube").setName("Sonar Qube"));
assertThat(call(request.setFilter("query = \"Groovy\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Groovy");
assertThat(call(request.setFilter("query = \"oNar\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Java", "Sonar Groovy", "Sonar Markdown",
OrganizationDto organization4 = db.organizations().insert();
OrganizationDto organization5 = db.organizations().insert();
List<Map<String, Object>> someMeasure = singletonList(newMeasure(COVERAGE, 81));
- ComponentDto favourite1_1 = insertProjectInDbAndEs(newProjectDto(organization1), someMeasure);
- ComponentDto favourite1_2 = insertProjectInDbAndEs(newProjectDto(organization1), someMeasure);
- ComponentDto nonFavourite1 = insertProjectInDbAndEs(newProjectDto(organization1), someMeasure);
- ComponentDto favourite2 = insertProjectInDbAndEs(newProjectDto(organization2), someMeasure);
- ComponentDto nonFavourite2 = insertProjectInDbAndEs(newProjectDto(organization2), someMeasure);
- ComponentDto favourite3 = insertProjectInDbAndEs(newProjectDto(organization3), someMeasure);
- ComponentDto nonFavourite4 = insertProjectInDbAndEs(newProjectDto(organization4), someMeasure);
+ ComponentDto favourite1_1 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1), someMeasure);
+ ComponentDto favourite1_2 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1), someMeasure);
+ ComponentDto nonFavourite1 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization1), someMeasure);
+ ComponentDto favourite2 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization2), someMeasure);
+ ComponentDto nonFavourite2 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization2), someMeasure);
+ ComponentDto favourite3 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization3), someMeasure);
+ ComponentDto nonFavourite4 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization4), someMeasure);
Stream.of(favourite1_1, favourite1_2, favourite2, favourite3)
.forEach(this::addFavourite);
insertMetrics(COVERAGE, NCLOC);
@Test
public void filter_projects_on_favorites() {
userSession.logIn();
- ComponentDto javaProject = insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization(), "java-id").setName("Sonar Java"),
+ ComponentDto javaProject = insertProjectInDbAndEs(newPrivateProjectDto(db.getDefaultOrganization(), "java-id").setName("Sonar Java"),
newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d)));
- ComponentDto markDownProject = insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization(), "markdown-id").setName("Sonar Markdown"),
+ ComponentDto markDownProject = insertProjectInDbAndEs(newPrivateProjectDto(db.getDefaultOrganization(), "markdown-id").setName("Sonar Markdown"),
newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(db.organizations().insert()).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
addFavourite(javaProject);
addFavourite(markDownProject);
dbSession.commit();
@Test
public void filtering_on_favorites_returns_empty_results_if_not_logged_in() {
- ComponentDto javaProject = insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization(), "java-id").setName("Sonar Java"),
+ ComponentDto javaProject = insertProjectInDbAndEs(newPrivateProjectDto(db.getDefaultOrganization(), "java-id").setName("Sonar Java"),
newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(db.organizations().insert()).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d)));
addFavourite(javaProject);
dbSession.commit();
request.setFilter("isFavorite");
@Test
public void do_not_return_isFavorite_if_anonymous_user() {
- insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81)));
insertMetrics(COVERAGE);
userSession.anonymous();
@Test
public void empty_list_if_isFavorite_filter_and_anonymous_user() {
- insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81)));
insertMetrics(COVERAGE);
userSession.anonymous();
request.setFilter("isFavorite");
@Test
public void return_nloc_facet() {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
insertMetrics(COVERAGE, NCLOC);
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NCLOC)));
@Test
public void return_languages_facet() {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java", "xoo"));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java", "xoo"));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("xoo"));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("<null>", "java", "xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java", "xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java", "xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("xoo"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("<null>", "java", "xoo"));
insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_LANGUAGES)));
@Test
public void return_languages_facet_with_language_having_no_project_if_language_is_in_filter() {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java"));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java"));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java"));
insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
SearchProjectsWsResponse result = call(request.setFilter("languages = xoo").setFacets(singletonList(FILTER_LANGUAGES)));
@Test
public void return_tags_facet() {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java").setTags(newArrayList("finance", "platform")));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown").setTags(singletonList("offshore")));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube").setTags(newArrayList("offshore")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java").setTags(newArrayList("finance", "platform")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown").setTags(singletonList("offshore")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube").setTags(newArrayList("offshore")));
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_TAGS)));
@Test
public void return_tags_facet_with_tags_having_no_project_if_tags_is_in_filter() {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java").setTags(newArrayList("finance", "platform")));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown").setTags(singletonList("offshore")));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube").setTags(newArrayList("offshore")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java").setTags(newArrayList("finance", "platform")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown").setTags(singletonList("offshore")));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube").setTags(newArrayList("offshore")));
SearchProjectsWsResponse result = call(request.setFilter("tags = marketing").setFacets(singletonList(FILTER_TAGS)));
@Test
public void default_sort_is_by_ascending_name() throws Exception {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
SearchProjectsWsResponse result = call(request);
@Test
public void sort_by_name() throws Exception {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
assertThat(call(request.setSort("name").setAsc(true)).getComponentsList()).extracting(Component::getName)
.containsExactly("Sonar Groovy", "Sonar Java", "Sonar Markdown", "Sonar Qube");
@Test
public void sort_by_coverage() throws Exception {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
insertMetrics(COVERAGE);
assertThat(call(request.setSort(COVERAGE).setAsc(true)).getComponentsList()).extracting(Component::getName)
@Test
public void sort_by_quality_gate() throws Exception {
OrganizationDto organization = db.getDefaultOrganization();
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), "ERROR");
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), "WARN");
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), "OK");
- insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), "OK");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Java"), "ERROR");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Groovy"), "WARN");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Markdown"), "OK");
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organization).setName("Sonar Qube"), "OK");
dbClient.metricDao().insert(dbSession, newMetricDto().setKey(QUALITY_GATE_STATUS).setValueType(LEVEL.name()).setEnabled(true).setHidden(false));
db.commit();
@Test
public void return_last_analysis_date() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project1 = insertProjectInDbAndEs(newProjectDto(organizationDto));
+ ComponentDto project1 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto));
db.components().insertSnapshot(newAnalysis(project1).setCreatedAt(10_000_000_000L).setLast(false));
db.components().insertSnapshot(newAnalysis(project1).setCreatedAt(20_000_000_000L).setLast(true));
- ComponentDto project2 = insertProjectInDbAndEs(newProjectDto(organizationDto));
+ ComponentDto project2 = insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto));
db.components().insertSnapshot(newAnalysis(project2).setCreatedAt(30_000_000_000L).setLast(true));
// No snapshot on project 3
- insertProjectInDbAndEs(newProjectDto(organizationDto));
+ insertProjectInDbAndEs(ComponentTesting.newPrivateProjectDto(organizationDto));
SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("analysisDate")));
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
@Test
public void show_with_browse_permission() {
- ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid");
componentDb.insertProjectAndSnapshot(project);
userSession.logIn().addProjectPermission(UserRole.USER, project);
@Test
public void show_provided_project() {
userSession.logIn().setRoot();
- componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setEnabled(false));
+ componentDb.insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid").setEnabled(false));
ShowWsResponse response = newRequest("project-uuid", null);
@Test
public void show_with_ancestors_when_not_project() throws Exception {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
ComponentDto module = componentDb.insertComponent(newModuleDto(project));
ComponentDto directory = componentDb.insertComponent(newDirectory(module, "dir"));
ComponentDto file = componentDb.insertComponent(newFileDto(directory));
@Test
public void show_without_ancestors_when_project() throws Exception {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
componentDb.insertComponent(newModuleDto(project));
userSession.addProjectPermission(UserRole.USER, project);
@Test
public void show_with_last_analysis_date() throws Exception {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(1_000_000_000L).setLast(false));
componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(2_000_000_000L).setLast(false));
componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
@Test
public void show_with_ancestors_and_analysis_date() throws Exception {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
ComponentDto module = componentDb.insertComponent(newModuleDto(project));
ComponentDto directory = componentDb.insertComponent(newDirectory(module, "dir"));
userSession.logIn();
expectedException.expect(ForbiddenException.class);
- componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
newRequest("project-uuid", null);
}
private void insertJsonExampleComponentsAndSnapshots() {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1");
- ComponentDto project = componentDb.insertComponent(newProjectDto(organizationDto, "AVIF98jgA3Ax6PH2efOW")
+ ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(organizationDto, "AVIF98jgA3Ax6PH2efOW")
.setKey("com.sonarsource:java-markdown")
.setName("Java Markdown")
.setDescription("Java Markdown Project")
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.component.index.ComponentIndexQuery.DEFAULT_LIMIT;
import static org.sonar.server.component.ws.SuggestionsAction.EXTENDED_LIMIT;
-import static org.sonar.server.component.ws.SuggestionsAction.SHORT_INPUT_WARNING;
import static org.sonar.server.component.ws.SuggestionsAction.PARAM_MORE;
import static org.sonar.server.component.ws.SuggestionsAction.PARAM_QUERY;
import static org.sonar.server.component.ws.SuggestionsAction.PARAM_RECENTLY_BROWSED;
+import static org.sonar.server.component.ws.SuggestionsAction.SHORT_INPUT_WARNING;
import static org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Category;
import static org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Organization;
@Test
public void exact_match_in_one_qualifier() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
@Test
public void must_not_search_if_no_valid_tokens_are_provided() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization).setName("SonarQube"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube"));
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
OrganizationDto organization1 = db.organizations().insert(o -> o.setKey("org-1").setName("Organization One"));
OrganizationDto organization2 = db.organizations().insert(o -> o.setKey("org-2").setName("Organization Two"));
- ComponentDto project1 = db.components().insertComponent(newProjectDto(organization1).setName("Project1"));
+ ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto(organization1).setName("Project1"));
componentIndexer.indexProject(project1.projectUuid(), ProjectIndexer.Cause.PROJECT_CREATION);
authorizationIndexerTester.allowOnlyAnyone(project1);
- ComponentDto project2 = db.components().insertComponent(newProjectDto(organization2).setName("Project2"));
+ ComponentDto project2 = db.components().insertComponent(newPrivateProjectDto(organization2).setName("Project2"));
componentIndexer.indexProject(project2.projectUuid(), ProjectIndexer.Cause.PROJECT_CREATION);
authorizationIndexerTester.allowOnlyAnyone(project2);
@Test
public void should_contain_project_names() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
db.components().insertComponent(newModuleDto(project).setName("Module1"));
db.components().insertComponent(newModuleDto(project).setName("Module2"));
componentIndexer.indexProject(project.projectUuid(), ProjectIndexer.Cause.PROJECT_CREATION);
@Test
public void should_mark_recently_browsed_items() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
ComponentDto module1 = newModuleDto(project).setName("Module1");
db.components().insertComponent(module1);
ComponentDto module2 = newModuleDto(project).setName("Module2");
@Test
public void should_mark_favorite_items() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
ComponentDto favorite = newModuleDto(project).setName("Module1");
db.components().insertComponent(favorite);
doReturn(singletonList(favorite)).when(favoriteFinder).list();
String namePrefix = "MyProject";
List<ComponentDto> projects = range(0, numberOfProjects)
- .mapToObj(i -> db.components().insertComponent(newProjectDto(organization).setName(namePrefix + i)))
+ .mapToObj(i -> db.components().insertComponent(newPrivateProjectDto(organization).setName(namePrefix + i)))
.collect(Collectors.toList());
componentIndexer.indexOnStartup(null);
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID;
@Test
public void return_children() throws IOException {
- ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid");
componentDb.insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto("module-uuid-1", project);
componentDb.insertComponent(module);
@Test
public void return_descendants() throws IOException {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto("module-uuid-1", project);
componentDb.insertComponent(module);
@Test
public void filter_descendants_by_qualifier() throws IOException {
- ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponent(newFileDto(project, 1));
componentDb.insertComponent(newFileDto(project, 2));
@Test
public void return_leaves() throws IOException {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
componentDb.insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto("module-uuid-1", project);
componentDb.insertComponent(module);
@Test
public void sort_descendants_by_qualifier() throws IOException {
- ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponent(newFileDto(project, 1));
componentDb.insertComponent(newFileDto(project, 2));
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto view = newView(organizationDto, "view-uuid");
componentDb.insertViewAndSnapshot(view);
- ComponentDto project = newProjectDto(organizationDto, "project-uuid-1").setName("project-name").setKey("project-key-1");
+ ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid-1").setName("project-name").setKey("project-key-1");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponent(newProjectCopy("project-uuid-1-copy", project, view));
componentDb.insertComponent(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
@Test
public void response_is_empty_on_provisioned_projects() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
logInWithBrowsePermission(project);
TreeWsResponse response = ws.newRequest()
@Test
public void return_projects_composing_a_view() {
- ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid");
componentDb.insertProjectAndSnapshot(project);
ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid");
componentDb.insertViewAndSnapshot(view);
@Test
public void fail_when_not_enough_privileges() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
userSession.logIn()
.addProjectPermission(UserRole.CODEVIEWER, project);
db.commit();
public void fail_when_page_size_above_500() {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'ps' parameter must be less than 500");
- componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
db.commit();
ws.newRequest()
public void fail_when_search_query_has_less_than_3_characters() {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'q' parameter must have at least 3 characters");
- componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ componentDb.insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
db.commit();
ws.newRequest()
@Test
public void fail_when_sort_is_unknown() {
expectedException.expect(IllegalArgumentException.class);
- componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
db.commit();
ws.newRequest()
@Test
public void fail_when_strategy_is_unknown() {
expectedException.expect(IllegalArgumentException.class);
- componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ componentDb.insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
db.commit();
ws.newRequest()
private ComponentDto initJsonExampleComponents() throws IOException {
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1");
- ComponentDto project = newProjectDto(organizationDto, "MY_PROJECT_ID")
+ ComponentDto project = newPrivateProjectDto(organizationDto, "MY_PROJECT_ID")
.setKey("MY_PROJECT_KEY")
.setName("Project Name");
componentDb.insertProjectAndSnapshot(project);
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.OrganizationPermission.SCAN;
public void submit_fails_with_organizationKey_does_not_match_organization_of_specified_component() {
userSession.logIn().setRoot();
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
mockSuccessfulPrepareSubmitCall();
underTest.submit(organization.getKey(), project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
@Test
public void submit_a_report_on_existing_project() {
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
userSession.logIn().addProjectPermission(SCAN_EXECUTION, project);
mockSuccessfulPrepareSubmitCall();
.addPermission(PROVISION_PROJECTS, organization);
mockSuccessfulPrepareSubmitCall();
- ComponentDto createdProject = newProjectDto(organization, PROJECT_UUID).setKey(PROJECT_KEY);
+ ComponentDto createdProject = newPrivateProjectDto(organization, PROJECT_UUID).setKey(PROJECT_KEY);
when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject);
when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), anyInt(), anyString(),
eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());
mockSuccessfulPrepareSubmitCall();
- ComponentDto createdProject = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY);
+ ComponentDto createdProject = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY);
when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject);
when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), anyInt(), anyString(),
eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());
mockSuccessfulPrepareSubmitCall();
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY);
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY);
when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(project);
when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), anyInt(), anyString(),
eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
@Test
public void user_with_scan_permission_on_organization_is_allowed_to_submit_a_report_on_existing_project() {
OrganizationDto org = db.organizations().insert();
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
userSession.addPermission(SCAN, org);
mockSuccessfulPrepareSubmitCall();
@Test
public void submit_a_report_on_existing_project_with_project_scan_permission() {
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
userSession.addProjectPermission(SCAN_EXECUTION, project);
mockSuccessfulPrepareSubmitCall();
@Test
public void fail_with_forbidden_exception_on_new_project_when_only_project_scan_permission() {
- userSession.addProjectPermission(SCAN_EXECUTION, ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
+ userSession.addProjectPermission(SCAN_EXECUTION, ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
mockSuccessfulPrepareSubmitCall();
when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(new ComponentDto().setUuid(PROJECT_UUID).setKey(PROJECT_KEY));
*/
@Test
public void project_branch_must_not_benefit_from_the_scan_permission_on_main_project() {
- ComponentDto mainProject = db.components().insertProject();
+ ComponentDto mainProject = db.components().insertPrivateProject();
userSession.addProjectPermission(GlobalPermissions.SCAN_EXECUTION, mainProject);
// user does not have the "scan" permission on the branch, so it can't scan it
String branchName = "branchFoo";
- ComponentDto branchProject = db.components().insertProject(p -> p.setKey(mainProject.getKey() + ":" + branchName));
+ ComponentDto branchProject = db.components().insertPrivateProject(p -> p.setKey(mainProject.getKey() + ":" + branchName));
thrown.expect(ForbiddenException.class);
underTest.submit(defaultOrganizationKey, mainProject.key(), branchName, PROJECT_NAME, IOUtils.toInputStream("{binary}"));
@Test
public void get_project_settings_from_db() {
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(ROOT.getKey());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setKey(ROOT.getKey());
dbClient.componentDao().insert(session, project);
dbClient.propertiesDao().saveProperty(session, new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value"));
session.commit();
}
private void addBaseIssue(RuleKey ruleKey) {
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY);
ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, file);
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.DIRECTORY;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE;
@Test
public void return_existing_uuids() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
+ ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
ComponentDto module = insertComponent(newModuleDto("BCDE", project).setKey(REPORT_MODULE_KEY));
ComponentDto directory = newDirectory(module, "CDEF", REPORT_DIR_KEY_1);
insertComponent(directory.setKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1));
@Test
public void return_existing_uuids_when_components_were_removed() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
+ ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
ComponentDto removedModule = insertComponent(newModuleDto("BCDE", project).setKey(REPORT_MODULE_KEY).setEnabled(false));
ComponentDto removedDirectory = insertComponent(newDirectory(removedModule, "CDEF", REPORT_DIR_KEY_1).setKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1).setEnabled(false));
insertComponent(newFileDto(removedModule, removedDirectory, "DEFG").setKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1).setEnabled(false));
@Test
public void set_no_base_project_snapshot_when_no_last_snapshot() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
+ ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
insertSnapshot(newAnalysis(project).setLast(false));
reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
@Test
public void set_base_project_snapshot_when_last_snapshot_exist() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
+ ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY));
insertSnapshot(newAnalysis(project).setLast(true));
reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
@Test
public void switch_islast_flag_and_mark_analysis_as_processed() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = ComponentTesting.newProjectDto(organization, REPORT_PROJECT.getUuid());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organization, REPORT_PROJECT.getUuid());
db.getDbClient().componentDao().insert(db.getSession(), project);
insertAnalysis(project, PREVIOUS_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, true);
insertAnalysis(project, CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_UNPROCESSED, false);
@Test
public void set_islast_flag_and_mark_as_processed_if_no_previous_analysis() {
- ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), REPORT_PROJECT.getUuid());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), REPORT_PROJECT.getUuid());
db.getDbClient().componentDao().insert(db.getSession(), project);
insertAnalysis(project, CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_UNPROCESSED, false);
db.commit();
@Before
public void setUp() throws Exception {
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
dbClient.componentDao().insert(dbSession, project);
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project);
dbClient.snapshotDao().insert(dbSession, projectSnapshot);
}
private ComponentDto createProject(String projectKey) {
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(projectKey);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setKey(projectKey);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
return project;
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
dbTester.rules().insert(rule);
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
dbClient.componentDao().insert(session, project);
ComponentDto file = ComponentTesting.newFileDto(project, null);
dbClient.componentDao().insert(session, file);
@Before
public void setUp() {
- project = dbTester.components().insertProject(dbTester.organizations().insert(), PROJECT_UUID);
+ project = dbTester.components().insertPrivateProject(dbTester.organizations().insert(), PROJECT_UUID);
}
@Test
@Test
public void persist_analysis() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module");
dbClient.componentDao().insert(dbTester.getSession(), moduleDto);
@Test
public void persist_snapshots_with_leak_period() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime());
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1"));
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto);
dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot);
@Test
public void set_no_period_on_snapshots_when_no_period() {
- ComponentDto projectDto = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto);
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.FILE;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
@Test
public void persist_only_new_components() {
// Project and module already exists
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module");
dbClient.componentDao().insert(dbTester.getSession(), module);
@Test
public void nothing_to_persist() {
- ComponentDto project = newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto project = newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module");
dbClient.componentDao().insert(dbTester.getSession(), module);
@Test
public void update_module_name_and_description() {
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project").setDescription("Project description");
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project").setDescription("Project description");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module");
dbClient.componentDao().insert(dbTester.getSession(), module);
@Test
public void update_module_path() {
- ComponentDto project = newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto project = newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module").setPath("path");
dbClient.componentDao().insert(dbTester.getSession(), module);
@Test
public void update_module_uuid_when_moving_a_module() {
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto moduleA = ComponentTesting.newModuleDto("EDCB", project)
.setKey("MODULE_A")
@Test
public void do_not_update_created_at_on_existing_component() {
Date oldDate = DateUtils.parseDate("2015-01-01");
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project").setCreatedAt(oldDate);
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project").setCreatedAt(oldDate);
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module").setPath("path").setCreatedAt(oldDate);
dbClient.componentDao().insert(dbTester.getSession(), module);
@Test
public void persist_components_that_were_previously_removed() {
- ComponentDto project = newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto project = newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto removedModule = ComponentTesting.newModuleDto("BCDE", project)
.setKey(MODULE_KEY)
@Test
public void update_module_uuid_when_reactivating_removed_component() {
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project");
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), project);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module");
ComponentDto removedModule = ComponentTesting.newModuleDto("EDCD", project).setKey("REMOVED_MODULE_KEY").setName("Removed Module").setEnabled(false);
public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
boolean isRootPrivate = new Random().nextBoolean();
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = newProjectDto(organization, "ABCD").setKey(PROJECT_KEY).setName("Project").setPrivate(isRootPrivate);
+ ComponentDto project = newPrivateProjectDto(organization, "ABCD").setKey(PROJECT_KEY).setName("Project").setPrivate(isRootPrivate);
dbTester.components().insertComponent(project);
treeRootHolder.setRoot(createSampleProjectComponentTree(project));
public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
boolean isRootPrivate = new Random().nextBoolean();
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = newProjectDto(organization, "ABCD").setKey(PROJECT_KEY).setName("Project").setPrivate(isRootPrivate);
+ ComponentDto project = newPrivateProjectDto(organization, "ABCD").setKey(PROJECT_KEY).setName("Project").setPrivate(isRootPrivate);
dbTester.components().insertComponent(project);
ComponentDto module = newModuleDto(project).setUuid("BCDE").setKey("MODULE").setPrivate(!isRootPrivate);
dbTester.components().insertComponent(module);
.setKey(MODULE_KEY)
.build());
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(MODULE_KEY);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(MODULE_KEY);
dbClient.componentDao().insert(dbTester.getSession(), project);
dbTester.getSession().commit();
.build());
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY);
- ComponentDto anotherProject = ComponentTesting.newProjectDto(organizationDto).setKey(anotherProjectKey);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY);
+ ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(organizationDto).setKey(anotherProjectKey);
dbClient.componentDao().insert(dbTester.getSession(), project, anotherProject);
ComponentDto module = ComponentTesting.newModuleDto("BCDE", anotherProject).setKey(MODULE_KEY);
dbClient.componentDao().insert(dbTester.getSession(), module);
.setKey(MODULE_KEY)
.build());
- ComponentDto anotherProject = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(anotherProjectKey);
+ ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setKey(anotherProjectKey);
dbClient.componentDao().insert(dbTester.getSession(), anotherProject);
ComponentDto module = ComponentTesting.newModuleDto("ABCD", anotherProject).setKey(PROJECT_KEY);
dbClient.componentDao().insert(dbTester.getSession(), module);
.addChildRef(2)
.build());
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY);
dbClient.componentDao().insert(dbTester.getSession(), project);
dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1420088400000L)); // 2015-01-01
dbTester.getSession().commit();
.addChildRef(2)
.build());
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY);
dbClient.componentDao().insert(dbTester.getSession(), project);
dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1433131200000L)); // 2015-06-01
dbTester.getSession().commit();
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setKey("KEY_VIEW"));
save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW"));
- save(newProjectDto(organizationDto, "proj"));
+ save(newPrivateProjectDto(organizationDto, "proj"));
dbTester.getSession().commit();
Component projectView = ViewsComponent.builder(PROJECT_VIEW, "KEY_PROJECT_COPY").setUuid("UUID_PROJECT_COPY").build();
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.SUBVIEW;
@Test
public void persist_view_with_projectView() {
- ComponentDto project = newProjectDto(dbTester.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
persistComponents(project);
treeRootHolder.setRoot(
@Test
public void persist_project_view_under_subview() {
- ComponentDto project = newProjectDto(dbTester.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
persistComponents(project);
treeRootHolder.setRoot(
public void update_project_view() {
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto view = newViewDto(organizationDto);
- ComponentDto project = newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
persistComponents(view, project);
ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view)
.setOrganizationUuid(ORGANIZATION_UUID)
public void update_copy_component_uuid_of_project_view() {
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto view = newViewDto(organizationDto);
- ComponentDto project1 = newProjectDto(organizationDto, "P1");
- ComponentDto project2 = newProjectDto(organizationDto, "P2");
+ ComponentDto project1 = newPrivateProjectDto(organizationDto, "P1");
+ ComponentDto project2 = newPrivateProjectDto(organizationDto, "P2");
persistComponents(view, project1, project2);
// Project view in DB is associated to project1
@Test
public void persists_new_components_as_public_if_root_does_not_exist_yet_out_of_functional_transaction() {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
treeRootHolder.setRoot(
createViewBuilder()
.addChildren(
@Test
public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
boolean isRootPrivate = new Random().nextBoolean();
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
OrganizationDto organization = dbTester.organizations().insert();
ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
dbTester.components().insertComponent(view);
@Test
public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
boolean isRootPrivate = new Random().nextBoolean();
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
OrganizationDto organization = dbTester.organizations().insert();
ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
dbTester.components().insertComponent(view);
@Before
public void setUp() {
- project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto())
+ project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto())
.setId(1L)
.setName("SonarQube")
.setLongName("SonarQube")
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
public class DuplicationsParserTest {
@Before
public void setUp() {
organizationDto = db.organizations().insert();
- project1 = newProjectDto(organizationDto)
+ project1 = ComponentTesting.newPrivateProjectDto(organizationDto)
.setName("SonarQube")
.setLongName("SonarQube")
.setKey("org.codehaus.sonar:sonar");
- project2 = newProjectDto(organizationDto);
+ project2 = ComponentTesting.newPrivateProjectDto(organizationDto);
componentDao.insert(dbSession, project1, project2);
// Current file
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnSameProject, 5, 2), new DuplicationsParser.Duplication(fileOnDifferentProject, 2, 2))).isEqualTo(-1);
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnDifferentProject, 5, 2), new DuplicationsParser.Duplication(fileOnSameProject, 2, 2))).isEqualTo(1);
// Files on 2 different projects
- ComponentDto project3 = newProjectDto(organizationDto).setId(3L);
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(organizationDto).setId(3L);
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnDifferentProject, 5, 2),
new DuplicationsParser.Duplication(project3, 2, 2))).isEqualTo(1);
@Test
public void return_file_with_missing_duplication_data() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js"));
db.components().insertSnapshot(newAnalysis(project));
@Test
public void return_403_if_user_is_not_allowed_to_access_project() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
expectedException.expect(ForbiddenException.class);
}
private void verifyCallToFileWithDuplications(Function<ComponentDto, WsTester.TestRequest> requestFactory) throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js"));
SnapshotDto snapshot = db.components().insertSnapshot(newAnalysis(project));
String xml = "<duplications>\n" +
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.property.PropertyQuery;
import org.sonar.server.exceptions.BadRequestException;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
public class FavoriteUpdaterTest {
private static final long COMPONENT_ID = 23L;
private static final String COMPONENT_KEY = "K1";
- private static final ComponentDto COMPONENT = newProjectDto(OrganizationTesting.newOrganizationDto())
+ private static final ComponentDto COMPONENT = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto())
.setId(COMPONENT_ID)
.setKey(COMPONENT_KEY);
private static final int USER_ID = 42;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonarqube.ws.client.favorite.FavoritesWsParameters.PARAM_COMPONENT;
public class AddActionTest {
}
private ComponentDto insertProject() {
- return db.components().insertComponent(newProjectDto(db.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY));
+ return db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY));
}
private ComponentDto insertProjectAndPermissions() {
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonarqube.ws.client.favorite.FavoritesWsParameters.PARAM_COMPONENT;
public class RemoveActionTest {
}
private ComponentDto insertProject() {
- return db.components().insertComponent(newProjectDto(db.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY));
+ return db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY));
}
private ComponentDto insertProjectAndPermissions() {
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.UserPermissionDto;
import org.sonar.server.exceptions.UnauthorizedException;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.WsRequest.Method.POST;
@Test
public void return_favorites() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "P1").setKey("K1").setName("N1");
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "P1").setKey("K1").setName("N1");
addComponent(project);
addComponent(newFileDto(project).setKey("K11").setName("N11"));
- addComponent(newProjectDto(db.getDefaultOrganization(), "P2").setKey("K2").setName("N2"));
+ addComponent(newPrivateProjectDto(db.getDefaultOrganization(), "P2").setKey("K2").setName("N2"));
SearchResponse result = call();
@Test
public void filter_authorized_components() {
OrganizationDto organizationDto = db.organizations().insert();
- addComponent(newProjectDto(organizationDto).setKey("K1"));
- ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto(organizationDto));
+ addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("K1"));
+ ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
db.favorites().add(unauthorizedProject, USER_ID);
SearchResponse result = call();
@Test
public void paginate_results() {
IntStream.rangeClosed(1, 9)
- .forEach(i -> addComponent(newProjectDto(db.getDefaultOrganization()).setKey("K" + i).setName("N" + i)));
- ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()));
+ .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("K" + i).setName("N" + i)));
+ ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
db.favorites().add(unauthorizedProject, USER_ID);
SearchResponse result = call(2, 3);
@Test
public void return_only_users_favorite() {
OrganizationDto organizationDto = db.organizations().insert();
- addComponent(newProjectDto(organizationDto).setKey("K1"));
- ComponentDto otherUserFavorite = newProjectDto(organizationDto).setKey("K42");
+ addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("K1"));
+ ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto(organizationDto).setKey("K42");
db.components().insertComponent(otherUserFavorite);
db.favorites().add(otherUserFavorite, 42);
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(organizationDto.getUuid(), UserRole.USER, 42, otherUserFavorite.getId()));
@Test
public void favorites_ordered_by_name() {
OrganizationDto organizationDto = db.organizations().insert();
- addComponent(newProjectDto(organizationDto).setName("N2"));
- addComponent(newProjectDto(organizationDto).setName("N3"));
- addComponent(newProjectDto(organizationDto).setName("N1"));
+ addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("N2"));
+ addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("N3"));
+ addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("N1"));
SearchResponse result = call();
public void json_example() {
OrganizationDto organization1 = db.organizations().insertForKey("my-org");
OrganizationDto organization2 = db.organizations().insertForKey("openjdk");
- addComponent(newProjectDto(organization1).setKey("K1").setName("Samba"));
- addComponent(newProjectDto(organization1).setKey("K2").setName("Apache HBase"));
- addComponent(newProjectDto(organization2).setKey("K3").setName("JDK9"));
+ addComponent(ComponentTesting.newPrivateProjectDto(organization1).setKey("K1").setName("Samba"));
+ addComponent(ComponentTesting.newPrivateProjectDto(organization1).setKey("K2").setName("Apache HBase"));
+ addComponent(ComponentTesting.newPrivateProjectDto(organization2).setKey("K3").setName("JDK9"));
String result = ws.newRequest().execute().getInput();
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.issue.IssueTesting.newDto;
import static org.sonar.db.rule.RuleTesting.newXooX1;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn("arthur");
- private ComponentDto project = newProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setKey(PROJECT_KEY);
+ private ComponentDto project = newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setKey(PROJECT_KEY);
private IssueDto issue = newDto(newXooX1().setId(10), newFileDto(project, null), project).setKee(ISSUE_KEY);
private ActionFinder underTest = new ActionFinder(userSession);
@Test
public void return_provided_actions_with_set_severity_and_set_type_when_issue_admin() {
- userSession.addProjectPermission(ISSUE_ADMIN, ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID));
+ userSession.addProjectPermission(ISSUE_ADMIN, ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID));
assertThat(underTest.listAvailableActions(issue)).containsOnly("comment", "assign", "set_tags", "set_type", "assign_to_me", "set_severity");
}
@Before
public void setUp() throws Exception {
issueOrganizationDto = db.organizations().insert();
- project = db.components().insertProject(issueOrganizationDto);
+ project = db.components().insertPrivateProject(issueOrganizationDto);
context = new BulkChangeAction.ActionContext(issue, issueChangeContext, project);
}
private IssueDto insertIssue() {
RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
return issueDbTester.insertIssue(newDto(rule, file, project));
}
@Test
public void create_from_parameters() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
@Test
public void fail_if_componentRoots_references_components_with_different_qualifier() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
SearchWsRequest request = new SearchWsRequest()
.setComponentRoots(asList(project.key(), file.key()));
@Test
public void param_componentUuids_enables_search_on_project_tree_by_default() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SearchWsRequest request = new SearchWsRequest()
.setComponentUuids(asList(project.uuid()));
@Test
public void onComponentOnly_restricts_search_to_specified_componentKeys() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SearchWsRequest request = new SearchWsRequest()
.setComponentKeys(asList(project.key()))
.setOnComponentOnly(true);
@Test
public void should_search_in_tree_with_module_uuid() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
SearchWsRequest request = new SearchWsRequest()
.setComponentUuids(asList(module.uuid()));
@Test
public void param_componentUuids_enables_search_in_directory_tree() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
SearchWsRequest request = new SearchWsRequest()
.setComponentUuids(asList(dir.uuid()));
@Test
public void param_componentUuids_enables_search_by_file() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
SearchWsRequest request = new SearchWsRequest()
.setComponentUuids(asList(file.uuid()));
@Test
public void param_componentUuids_enables_search_by_test_file() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project).setQualifier(Qualifiers.UNIT_TEST_FILE));
SearchWsRequest request = new SearchWsRequest()
.setComponentUuids(asList(file.uuid()));
private ComponentDto newProject() {
OrganizationDto organization = OrganizationTesting.newOrganizationDto();
tester.get(OrganizationDao.class).insert(session, organization);
- ComponentDto project = ComponentTesting.newProjectDto(organization);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organization);
tester.get(ComponentDao.class).insert(session, project);
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
@Test
public void verify_notification() throws Exception {
RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
DefaultIssue issue = issueDbTester.insertIssue(newDto(rule, file, project)).setSeverity(MAJOR).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
@Test
public void verify_notification_when_issue_is_linked_on_removed_rule() throws Exception {
RuleDto rule = ruleDbTester.insertRule(newRuleDto().setStatus(RuleStatus.REMOVED));
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
DefaultIssue issue = issueDbTester.insertIssue(newDto(rule, file, project)).setSeverity(MAJOR).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
private IssueDto newIssue() {
RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
return newDto(rule, file, project);
}
private IssueDto newIssue() {
RuleDto rule = db.rules().insertRule(newRuleDto());
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
return newDto(rule, file, project);
}
private IssueDto newIssue() {
RuleDto rule = db.rules().insertRule(newRuleDto());
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
return newDto(rule, file, project);
}
private IssueDto newIssue() {
RuleDto rule = newRuleDto().setId(10);
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto());
ComponentDto file = (newFileDto(project));
return newDto(rule, file, project);
}
private void loginAndAddProjectPermission(String login, String permission) {
- userSession.logIn(login).addProjectPermission(permission, ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), issue.projectUuid()));
+ userSession.logIn(login).addProjectPermission(permission, ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), issue.projectUuid()));
}
}
@Test
public void list_transitions() throws Exception {
IssueDto issue = newIssue().setStatus(STATUS_OPEN).setResolution(null);
- userSession.logIn("john").addProjectPermission(ISSUE_ADMIN, ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), issue.getProjectUuid()));
+ userSession.logIn("john").addProjectPermission(ISSUE_ADMIN, ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), issue.getProjectUuid()));
List<Transition> result = underTest.listTransitions(issue.toDefaultIssue());
private IssueDto newIssue() {
RuleDto rule = newRuleDto().setId(10);
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto());
ComponentDto file = (newFileDto(project));
return newDto(rule, file, project);
}
@Test
public void facets_on_projects() {
OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD");
- ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto, "EFGH");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD");
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto, "EFGH");
indexIssues(
IssueDocTesting.newDoc("ISSUE1", ComponentTesting.newFileDto(project, null)).setEffort(10L),
@Test
public void facets_on_components() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto(), "A");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto(), "A");
ComponentDto file1 = ComponentTesting.newFileDto(project, null, "ABCD");
ComponentDto file2 = ComponentTesting.newFileDto(project, null, "BCDE");
ComponentDto file3 = ComponentTesting.newFileDto(project, null, "CDEF");
@Test
public void facets_on_directories() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo");
@Test
public void facets_on_severities() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
indexIssues(
@Test
public void facets_on_statuses() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
indexIssues(
@Test
public void facets_on_resolutions() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
indexIssues(
@Test
public void facets_on_languages() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
@Test
public void facets_on_assignees() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
indexIssues(
@Test
public void facets_on_authors() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
indexIssues(
@Test
public void deprecated_debt_facets() {
OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD");
- ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto, "EFGH");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD");
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto, "EFGH");
indexIssues(
IssueDocTesting.newDoc("ISSUE1", ComponentTesting.newFileDto(project, null)).setEffort(10L),
}
protected SearchOptions fixtureForCreatedAtFacet() {
- ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setFuncCreationDate(DateUtils.parseDateTime("2011-04-25T01:05:13+0100"));
import static org.sonar.api.utils.DateUtils.parseDate;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
import static org.sonar.db.user.GroupTesting.newGroupDto;
import static org.sonar.db.user.UserTesting.newUserDto;
@Test
public void get_by_key() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
IssueDoc issue = newDoc("ISSUE1", file)
.setEffort(100L);
@Test
public void get_by_key_with_attributes() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
IssueDoc issue = newDoc("ISSUE1", file).setAttributes((KeyValueFormat.format(ImmutableMap.of("jira-issue-key", "SONAR-1234"))));
indexIssues(issue);
@Test(expected = IllegalStateException.class)
public void comments_field_is_not_available() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
IssueDoc issue = newDoc("ISSUE1", file);
indexIssues(issue);
@Test(expected = IllegalStateException.class)
public void is_new_field_is_not_available() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
IssueDoc issue = newDoc("ISSUE1", file);
indexIssues(issue);
@Test
public void filter_by_keys() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
indexIssues(
newDoc("1", newFileDto(project, null)),
@Test
public void filter_by_projects() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto subModule = ComponentTesting.newModuleDto(module);
@Test
public void facets_on_projects() {
OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project = newProjectDto(organizationDto, "ABCD");
- ComponentDto project2 = newProjectDto(organizationDto, "EFGH");
+ ComponentDto project = newPrivateProjectDto(organizationDto, "ABCD");
+ ComponentDto project2 = newPrivateProjectDto(organizationDto, "EFGH");
indexIssues(
newDoc("ISSUE1", newFileDto(project, null)),
@Test
public void filter_by_modules() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto subModule = ComponentTesting.newModuleDto(module);
ComponentDto file = newFileDto(subModule, null);
@Test
public void filter_by_components_on_contextualized_search() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto subModule = ComponentTesting.newModuleDto(module);
ComponentDto file1 = newFileDto(project, null);
@Test
public void filter_by_components_on_non_contextualized_search() {
- ComponentDto project = newProjectDto(newOrganizationDto(), "project");
+ ComponentDto project = newPrivateProjectDto(newOrganizationDto(), "project");
ComponentDto file1 = newFileDto(project, null, "file1");
ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("module");
ComponentDto file2 = newFileDto(module, null, "file2");
@Test
public void facets_on_components() {
- ComponentDto project = newProjectDto(newOrganizationDto(), "A");
+ ComponentDto project = newPrivateProjectDto(newOrganizationDto(), "A");
ComponentDto file1 = newFileDto(project, null, "ABCD");
ComponentDto file2 = newFileDto(project, null, "BCDE");
ComponentDto file3 = newFileDto(project, null, "CDEF");
@Test
public void filter_by_directories() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
@Test
public void facets_on_directories() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
@Test
public void filter_by_views() {
OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project1 = newProjectDto(organizationDto);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organizationDto);
ComponentDto file1 = newFileDto(project1, null);
- ComponentDto project2 = newProjectDto(organizationDto);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto);
indexIssues(
// Project1 has 2 issues (one on a file and one on the project itself)
newDoc("ISSUE1", project1),
@Test
public void filter_by_severities() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void facets_on_severities() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_statuses() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void facets_on_statuses() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_resolutions() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void facets_on_resolutions() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_resolved() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_rules() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
@Test
public void filter_by_languages() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
@Test
public void facets_on_languages() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
@Test
public void filter_by_assignees() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void facets_on_assignees() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void facets_on_assignees_supports_dashes() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_assigned() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_authors() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void facets_on_authors() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_after() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_before() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_after_and_before() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_create_after_and_before_take_into_account_timezone() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void filter_by_created_at() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")));
}
private SearchOptions fixtureForCreatedAtFacet() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
IssueDoc issue0 = newDoc("ISSUE0", file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000"));
@Test
public void paging() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
for (int i = 0; i < 12; i++) {
indexIssues(newDoc("ISSUE" + i, file));
@Test
public void search_with_max_limit() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
List<IssueDoc> issues = newArrayList();
for (int i = 0; i < 500; i++) {
@Test
public void sort_by_status() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void sort_by_severity() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void sort_by_assignee() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void sort_by_creation_date() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void sort_by_update_date() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void sort_by_close_date() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
@Test
public void sort_by_file_and_line() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file1 = newFileDto(project, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo");
ComponentDto file2 = newFileDto(project, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
@Test
public void default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key() {
OrganizationDto organizationDto = newOrganizationDto();
- ComponentDto project1 = newProjectDto(organizationDto, "P1");
+ ComponentDto project1 = newPrivateProjectDto(organizationDto, "P1");
ComponentDto file1 = newFileDto(project1, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo");
ComponentDto file2 = newFileDto(project1, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
- ComponentDto project2 = newProjectDto(organizationDto, "P2");
+ ComponentDto project2 = newPrivateProjectDto(organizationDto, "P2");
ComponentDto file3 = newFileDto(project2, null, "F3").setPath("src/main/xoo/org/sonar/samples/File3.xoo");
indexIssues(
@Test
public void authorized_issues_on_groups() {
OrganizationDto org = newOrganizationDto();
- ComponentDto project1 = newProjectDto(org);
- ComponentDto project2 = newProjectDto(org);
- ComponentDto project3 = newProjectDto(org);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(org);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(org);
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(org);
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
ComponentDto file3 = newFileDto(project3, null);
@Test
public void authorized_issues_on_user() {
OrganizationDto org = newOrganizationDto();
- ComponentDto project1 = newProjectDto(org);
- ComponentDto project2 = newProjectDto(org);
- ComponentDto project3 = newProjectDto(org);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(org);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(org);
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(org);
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
ComponentDto file3 = newFileDto(project3, null);
@Test
public void root_user_is_authorized_to_access_all_issues() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
indexIssue(newDoc("I1", project));
userSessionRule.logIn().setRoot();
@Test
public void search_issues_for_batch_return_needed_fields() {
- ComponentDto project = newProjectDto(newOrganizationDto(), "PROJECT");
+ ComponentDto project = newPrivateProjectDto(newOrganizationDto(), "PROJECT");
ComponentDto file = newFileDto(project, null).setPath("src/File.xoo");
IssueDoc issue = newDoc("ISSUE", file)
@Test
public void search_issues_for_batch() {
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto subModule = ComponentTesting.newModuleDto(module);
ComponentDto file = newFileDto(subModule, null);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(module))).hasSize(3);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(subModule))).hasSize(2);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(file))).hasSize(1);
- assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(newProjectDto(newOrganizationDto())))).isEmpty();
+ assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(ComponentTesting.newPrivateProjectDto(newOrganizationDto())))).isEmpty();
}
@Test
@Test
public void search_issues_for_batch_return_only_authorized_issues() {
OrganizationDto org = newOrganizationDto();
- ComponentDto project1 = newProjectDto(org);
- ComponentDto project2 = newProjectDto(org);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(org);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(org);
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
GroupDto allowedGroup = newGroupDto();
ruleIndexer.indexRuleDefinition(r2.getKey());
OrganizationDto org = db.organizations().insert();
- ComponentDto project = newProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
newDoc("ISSUE1", file).setOrganizationUuid(org.getUuid()).setRuleKey(r1.getKey().toString()).setTags(of("convention", "java8", "bug")),
@Test
public void filter_by_organization() {
OrganizationDto org1 = newOrganizationDto();
- ComponentDto projectInOrg1 = newProjectDto(org1);
+ ComponentDto projectInOrg1 = ComponentTesting.newPrivateProjectDto(org1);
OrganizationDto org2 = newOrganizationDto();
- ComponentDto projectInOrg2 = newProjectDto(org2);
+ ComponentDto projectInOrg2 = ComponentTesting.newPrivateProjectDto(org2);
indexIssues(newDoc("issueInOrg1", projectInOrg1), newDoc("issue1InOrg2", projectInOrg2), newDoc("issue2InOrg2", projectInOrg2));
@Test
public void filter_by_organization_and_project() {
OrganizationDto org1 = newOrganizationDto();
- ComponentDto projectInOrg1 = newProjectDto(org1);
+ ComponentDto projectInOrg1 = ComponentTesting.newPrivateProjectDto(org1);
OrganizationDto org2 = newOrganizationDto();
- ComponentDto projectInOrg2 = newProjectDto(org2);
+ ComponentDto projectInOrg2 = ComponentTesting.newPrivateProjectDto(org2);
indexIssues(newDoc("issueInOrg1", projectInOrg1), newDoc("issue1InOrg2", projectInOrg2), newDoc("issue2InOrg2", projectInOrg2));
@Test
public void indexOnStartup_loads_and_indexes_all_issues() {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(org);
+ ComponentDto project = dbTester.components().insertPrivateProject(org);
ComponentDto dir = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project, dir, "F1"));
RuleDto rule = dbTester.rules().insertRule();
@Test
public void index_loads_and_indexes_issues_with_specified_keys() {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(org);
+ ComponentDto project = dbTester.components().insertPrivateProject(org);
ComponentDto dir = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project, dir, "F1"));
RuleDto rule = dbTester.rules().insertRule();
@Test
public void indexProject_loads_and_indexes_issues_with_specified_project_uuid() {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project1 = dbTester.components().insertProject(org);
+ ComponentDto project1 = dbTester.components().insertPrivateProject(org);
ComponentDto file1 = dbTester.components().insertComponent(ComponentTesting.newFileDto(project1));
- ComponentDto project2 = dbTester.components().insertProject(org);
+ ComponentDto project2 = dbTester.components().insertPrivateProject(org);
ComponentDto file2 = dbTester.components().insertComponent(ComponentTesting.newFileDto(project2));
RuleDto rule = dbTester.rules().insertRule();
IssueDto issue1 = dbTester.issues().insertIssue(IssueTesting.newDto(rule, file1, project1));
private void verifyThatProjectIsNotIndexed(ProjectIndexer.Cause cause) {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(org);
+ ComponentDto project = dbTester.components().insertPrivateProject(org);
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project));
RuleDto rule = dbTester.rules().insertRule();
IssueDto issue = dbTester.issues().insertIssue(IssueTesting.newDto(rule, file, project));
issueWorkflow.start();
rule = db.rules().insertRule(newRuleDto());
organization = db.organizations().insert();
- project = db.components().insertProject(organization);
+ project = db.components().insertPrivateProject(organization);
file = db.components().insertComponent(newFileDto(project));
user = db.users().insertUser("john");
when(system2.now()).thenReturn(NOW);
@Test
public void issues_on_which_user_has_not_browse_permission_are_ignored() throws Exception {
setUserProjectPermissions(USER, ISSUE_ADMIN);
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
ComponentDto anotherFile = db.components().insertComponent(newFileDto(anotherProject));
IssueDto authorizedIssue = db.issues().insertIssue(newUnresolvedIssue(rule, file, project).setType(BUG));
// User has not browse permission on these 2 issues
@Test
public void does_not_update_type_when_no_issue_admin_permission() throws Exception {
setUserProjectPermissions(USER, ISSUE_ADMIN);
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
ComponentDto anotherFile = db.components().insertComponent(newFileDto(anotherProject));
addUserProjectPermissions(anotherProject, USER);
@Test
public void does_not_update_severity_when_no_issue_admin_permission() throws Exception {
setUserProjectPermissions(USER, ISSUE_ADMIN);
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
ComponentDto anotherFile = db.components().insertComponent(newFileDto(anotherProject));
addUserProjectPermissions(anotherProject, USER);
@Before
public void setUp() throws Exception {
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
file = db.components().insertComponent(newFileDto(project));
}
@Test
public void changelog_of_file_move_contains_file_names() throws Exception {
RuleDto rule = db.rules().insertRule(newRuleDto());
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
ComponentDto file1 = db.components().insertComponent(newFileDto(project));
ComponentDto file2 = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = db.issues().insertIssue(newDto(rule, file2, project));
@Before
public void setUp() throws Exception {
- project = componentDbTester.insertProject();
+ project = componentDbTester.insertPrivateProject();
file = componentDbTester.insertComponent(newFileDto(project));
workflow.start();
}
@Test
public void issues_on_different_projects() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
IssueDto issue = IssueTesting.newDto(rule, file, project)
.setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100"));
db.issueDao().insert(session, issue);
- ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P2").setKey("PK2"));
+ ComponentDto project2 = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "P2").setKey("PK2"));
setDefaultProjectPermission(project2);
ComponentDto file2 = insertComponent(newFileDto(project2, null, "F2").setKey("FK2"));
IssueDto issue2 = IssueTesting.newDto(rule, file2, project2)
@Test
public void do_not_return_module_key_on_single_module_projects() throws IOException {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto module = insertComponent(newModuleDto("M1", project).setKey("MK1"));
ComponentDto file = insertComponent(newFileDto(module, null, "F1").setKey("FK1"));
@Test
public void search_by_project_uuid() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
@Test
public void search_since_leak_period_on_project() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
db.snapshotDao().insert(session,
@Test
public void search_since_leak_period_on_file_in_module_project() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto module = insertComponent(newModuleDto(project));
ComponentDto file = insertComponent(newFileDto(module, null, "F1").setKey("FK1"));
@Test
public void project_facet_is_sticky() throws Exception {
- ComponentDto project1 = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
- ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P2").setKey("PK2"));
- ComponentDto project3 = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P3").setKey("PK3"));
+ ComponentDto project1 = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project2 = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P2").setKey("PK2"));
+ ComponentDto project3 = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "P3").setKey("PK3"));
setDefaultProjectPermission(project1);
setDefaultProjectPermission(project2);
setDefaultProjectPermission(project3);
@Test
public void search_by_file_uuid() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
@Test
public void search_by_file_key() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
ComponentDto unitTest = insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("FK2"));
@Test
public void display_file_facet() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file1 = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
ComponentDto file2 = insertComponent(newFileDto(project, null, "F2").setKey("FK2"));
@Test
public void search_by_directory_path() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir"));
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java"));
@Test
public void search_by_directory_path_in_different_modules() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto module1 = insertComponent(newModuleDto("M1", project).setKey("MK1"));
ComponentDto module2 = insertComponent(newModuleDto("M2", project).setKey("MK2"));
@Test
public void display_module_facet() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto module = insertComponent(newModuleDto("M1", project).setKey("MK1"));
ComponentDto subModule1 = insertComponent(newModuleDto("SUBM1", module).setKey("SUBMK1"));
@Test
public void display_directory_facet() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir"));
ComponentDto file = insertComponent(newFileDto(project, directory, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java"));
@Test
public void search_by_view_uuid() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- ComponentDto view = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
+ ComponentDto view = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
indexView(view.uuid(), newArrayList(project.uuid()));
setAnyoneProjectPermission(view, UserRole.USER);
@Test
public void search_by_view_uuid_return_only_authorized_view() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- ComponentDto view = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
+ ComponentDto view = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
indexView(view.uuid(), newArrayList(project.uuid()));
setAnyoneProjectPermission(view, UserRole.USER);
@Test
public void search_by_sub_view_uuid() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- ComponentDto view = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
+ ComponentDto view = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
indexView(view.uuid(), newArrayList(project.uuid()));
- ComponentDto subView = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView"));
+ ComponentDto subView = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView"));
indexView(subView.uuid(), newArrayList(project.uuid()));
setAnyoneProjectPermission(view, UserRole.USER);
@Test
public void search_by_sub_view_uuid_return_only_authorized_view() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- ComponentDto view = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
+ ComponentDto view = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView"));
indexView(view.uuid(), newArrayList(project.uuid()));
- ComponentDto subView = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView"));
+ ComponentDto subView = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView"));
indexView(subView.uuid(), newArrayList(project.uuid()));
setAnyoneProjectPermission(view, UserRole.USER);
@Test
public void search_by_author() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "P1").setKey("PK1"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
RuleDto newRule = newRule();
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
db.userDao().insert(session, new UserDto().setLogin("john").setName("John"));
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com"));
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
public void load_additional_fields() throws Exception {
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java"));
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js"));
setProjectPermission(project, USER);
public void load_additional_fields_with_issue_admin_permission() throws Exception {
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java"));
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js"));
setProjectPermission(project, USER, ISSUE_ADMIN);
@Test
public void issue_on_removed_file() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto removedFile = insertComponent(ComponentTesting.newFileDto(project, null).setUuid("REMOVED_FILE_ID")
.setKey("REMOVED_FILE_KEY")
@Test
public void issue_contains_component_id_for_eclipse() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project);
@Test
public void apply_paging_with_one_component() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
for (int i = 0; i < SearchOptions.MAX_LIMIT + 1; i++) {
@Test
public void components_contains_sub_projects() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("ProjectHavingModule"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("ProjectHavingModule"));
setDefaultProjectPermission(project);
ComponentDto module = insertComponent(ComponentTesting.newModuleDto(project).setKey("ModuleHavingFile"));
ComponentDto file = insertComponent(ComponentTesting.newFileDto(module, null, "BCDE").setKey("FileLinkedToModule"));
@Test
public void display_facets() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
@Test
public void display_facets_in_effort_mode() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
@Test
public void display_zero_valued_facets_for_selected_items() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
public void filter_by_assigned_to_me() throws Exception {
db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
RuleDto rule = newRule();
public void filter_by_assigned_to_me_unauthenticated() throws Exception {
userSessionRule.logIn();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
RuleDto rule = newRule();
public void assigned_to_me_facet_is_sticky_relative_to_assignees() throws Exception {
db.userDao().insert(session, new UserDto().setLogin("alice").setName("Alice").setEmail("alice@email.com"));
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
RuleDto rule = newRule();
@Test
public void sort_by_updated_at() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
db.issueDao().insert(session, IssueTesting.newDto(rule, file, project)
@Test
public void paging() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
for (int i = 0; i < 12; i++) {
@Test
public void paging_with_page_size_to_minus_one() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
for (int i = 0; i < 12; i++) {
@Test
public void deprecated_paging() throws Exception {
RuleDto rule = newRule();
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
for (int i = 0; i < 12; i++) {
@Test
public void display_deprecated_debt_fields() throws Exception {
- ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
+ ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
IssueDto issue = IssueTesting.newDto(newRule(), file, project)
private IssueDto newIssue() {
RuleDto rule = dbTester.rules().insertRule(newRuleDto());
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
return newDto(rule, file, project);
}
private IssueDto newIssue() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
return IssueTesting.newIssue(rule, file, project);
}
private void setUserWithBrowsePermission(IssueDto issueDto) {
- logInAndAddProjectPermission(issueDto, USER);
+ userSession.logIn("john").addProjectPermission(USER, dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
}
private void logInAndAddProjectPermission(IssueDto issueDto, String permission) {
private IssueDto newIssue() {
RuleDto rule = dbTester.rules().insertRule(newRuleDto());
- ComponentDto project = dbTester.components().insertProject();
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
return newDto(rule, file, project);
}
}
private IssueDto insertIssue(RuleDefinitionDto rule, String... tags) {
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = IssueTesting.newIssue(rule, file, project).setTags(asList(tags));
return db.issues().insertIssue(issueDto);
dbSession.commit();
OrganizationDto organizationDto = db.organizations().insert();
- project = ComponentTesting.newProjectDto(organizationDto, DEFAULT_PROJECT_UUID).setKey(DEFAULT_PROJECT_KEY);
+ project = ComponentTesting.newPrivateProjectDto(organizationDto, DEFAULT_PROJECT_UUID).setKey(DEFAULT_PROJECT_KEY);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
userSession.logIn("login").addProjectPermission(UserRole.ADMIN, project);
@Test
public void project_administrator_can_delete_custom_measures() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
long id = insertCustomMeasure(project);
@Test
public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
long id = insertCustomMeasure(project);
userSession.logIn().setNonSystemAdministrator();
@Test
public void throw_UnauthorizedException_if_not_logged_in() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
long id = insertCustomMeasure(project);
userSession.anonymous();
}
private ComponentDto insertProject(String projectUuid, String projectKey) {
- ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), projectUuid)
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), projectUuid)
.setKey(projectKey);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
}
private ComponentDto insertProject(String projectUuid, String projectKey) {
- ComponentDto project = ComponentTesting.newProjectDto(db.organizations().insert(), projectUuid)
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert(), projectUuid)
.setKey(projectKey);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
@Test
public void update_text_value_and_description_in_db() throws Exception {
MetricDto metric = insertNewMetric(ValueType.STRING);
- ComponentDto component = db.components().insertProject(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto component = db.components().insertPrivateProject(db.getDefaultOrganization(), "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric)
.setDescription("custom-measure-description")
.setTextValue("text-measure-value");
public void update_double_value_and_description_in_db() throws Exception {
MetricDto metric = insertNewMetric(ValueType.INT);
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto component = db.components().insertProject(organizationDto, "project-uuid");
+ ComponentDto component = db.components().insertPrivateProject(organizationDto, "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric)
.setDescription("custom-measure-description")
.setValue(42d);
.setKey("metric-key");
dbClient.metricDao().insert(dbSession, metric);
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto component = ComponentTesting.newProjectDto(organizationDto, "project-uuid").setKey("project-key");
+ ComponentDto component = ComponentTesting.newPrivateProjectDto(organizationDto, "project-uuid").setKey("project-key");
dbClient.componentDao().insert(dbSession, component);
CustomMeasureDto customMeasure = newCustomMeasure(component, metric)
.setCreatedAt(100_000_000L)
@Test
public void update_value_only() throws Exception {
MetricDto metric = insertNewMetric(ValueType.STRING);
- ComponentDto component = db.components().insertProject(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto component = db.components().insertPrivateProject(db.getDefaultOrganization(), "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric)
.setDescription("custom-measure-description")
.setTextValue("text-measure-value");
public void update_description_only() throws Exception {
MetricDto metric = insertNewMetric(ValueType.STRING);
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto component = db.components().insertProject(organizationDto, "project-uuid");
+ ComponentDto component = db.components().insertPrivateProject(organizationDto, "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric)
.setMetricId(metric.getId())
.setComponentUuid(component.uuid())
userSessionRule.logIn();
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name());
dbClient.metricDao().insert(dbSession, metric);
- ComponentDto component = ComponentTesting.newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto component = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
dbClient.componentDao().insert(dbSession, component);
CustomMeasureDto customMeasure = newCustomMeasureDto()
.setMetricId(metric.getId())
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name());
dbClient.metricDao().insert(dbSession, metric);
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto component = ComponentTesting.newProjectDto(organizationDto, "project-uuid");
+ ComponentDto component = ComponentTesting.newPrivateProjectDto(organizationDto, "project-uuid");
dbClient.componentDao().insert(dbSession, component);
CustomMeasureDto customMeasure = newCustomMeasureDto()
.setMetricId(metric.getId())
import org.sonar.api.config.MapSettings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.user.GroupDto;
import static org.sonar.api.measures.Metric.Level.ERROR;
import static org.sonar.api.measures.Metric.Level.OK;
import static org.sonar.api.measures.Metric.Level.WARN;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.user.GroupTesting.newGroupDto;
import static org.sonar.db.user.UserTesting.newUserDto;
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS;
private static final String LANGUAGES = "languages";
private static final OrganizationDto ORG = OrganizationTesting.newOrganizationDto();
- private static final ComponentDto PROJECT1 = newProjectDto(ORG).setUuid("Project-1").setName("Project 1").setKey("key-1");
- private static final ComponentDto PROJECT2 = newProjectDto(ORG).setUuid("Project-2").setName("Project 2").setKey("key-2");
- private static final ComponentDto PROJECT3 = newProjectDto(ORG).setUuid("Project-3").setName("Project 3").setKey("key-3");
+ private static final ComponentDto PROJECT1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-1").setName("Project 1").setKey("key-1");
+ private static final ComponentDto PROJECT2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-2").setName("Project 2").setKey("key-2");
+ private static final ComponentDto PROJECT3 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-3").setName("Project 3").setKey("key-3");
private static final UserDto USER1 = newUserDto();
private static final UserDto USER2 = newUserDto();
private static final GroupDto GROUP1 = newGroupDto();
@Test
public void default_sort_is_by_ascending_case_insensitive_name_then_by_key() {
- ComponentDto windows = newProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
- ComponentDto apachee = newProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
- ComponentDto apache1 = newProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
- ComponentDto apache2 = newProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
+ ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
+ ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
+ ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
+ ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
index(newDoc(windows), newDoc(apachee), newDoc(apache1), newDoc(apache2));
assertResults(new ProjectMeasuresQuery(), apache1, apache2, apachee, windows);
@Test
public void sort_by_insensitive_name() {
- ComponentDto windows = newProjectDto(ORG).setUuid("windows").setName("Windows");
- ComponentDto apachee = newProjectDto(ORG).setUuid("apachee").setName("apachee");
- ComponentDto apache = newProjectDto(ORG).setUuid("apache").setName("Apache");
+ ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows");
+ ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee");
+ ComponentDto apache = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache").setName("Apache");
index(newDoc(windows), newDoc(apachee), newDoc(apache));
assertResults(new ProjectMeasuresQuery().setSort("name").setAsc(true), apache, apachee, windows);
@Test
public void sort_by_a_metric_then_by_name_then_by_key() {
- ComponentDto windows = newProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
- ComponentDto apachee = newProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
- ComponentDto apache1 = newProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
- ComponentDto apache2 = newProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
+ ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
+ ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
+ ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
+ ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
index(
newDoc(windows, NCLOC, 10_000d),
newDoc(apachee, NCLOC, 5_000d),
@Test
public void sort_by_quality_gate_status() {
- ComponentDto project4 = newProjectDto(ORG).setUuid("Project-4").setName("Project 4").setKey("key-4");
+ ComponentDto project4 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-4").setName("Project 4").setKey("key-4");
index(
newDoc(PROJECT1).setQualityGateStatus(OK.name()),
newDoc(PROJECT2).setQualityGateStatus(ERROR.name()),
@Test
public void sort_by_quality_gate_status_then_by_name_then_by_key() {
- ComponentDto windows = newProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
- ComponentDto apachee = newProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
- ComponentDto apache1 = newProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
- ComponentDto apache2 = newProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
+ ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
+ ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
+ ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
+ ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
index(
newDoc(windows).setQualityGateStatus(WARN.name()),
newDoc(apachee).setQualityGateStatus(OK.name()),
@Test
public void paginate_results() {
IntStream.rangeClosed(1, 9)
- .forEach(i -> index(newDoc(newProjectDto(ORG, "P" + i))));
+ .forEach(i -> index(newDoc(newPrivateProjectDto(ORG, "P" + i))));
SearchIdResult<String> result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().setPage(2, 3));
@Test
public void filter_on_languages() {
- ComponentDto project4 = newProjectDto(ORG).setUuid("Project-4").setName("Project 4").setKey("key-4");
+ ComponentDto project4 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-4").setName("Project 4").setKey("key-4");
index(
newDoc(PROJECT1).setLanguages(singletonList("java")),
newDoc(PROJECT2).setLanguages(singletonList("xoo")),
@Test
public void filter_on_query_text() {
- ComponentDto windows = newProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
- ComponentDto apachee = newProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
- ComponentDto apache1 = newProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
- ComponentDto apache2 = newProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
+ ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setKey("project1");
+ ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setKey("project2");
+ ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setKey("project3");
+ ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setKey("project4");
index(newDoc(windows), newDoc(apachee), newDoc(apache1), newDoc(apache2));
assertResults(new ProjectMeasuresQuery().setQueryText("windows"), windows);
public void filter_on_organization() {
OrganizationDto org1 = OrganizationTesting.newOrganizationDto();
OrganizationDto org2 = OrganizationTesting.newOrganizationDto();
- ComponentDto projectInOrg1 = newProjectDto(org1);
- ComponentDto projectInOrg2 = newProjectDto(org2);
+ ComponentDto projectInOrg1 = ComponentTesting.newPrivateProjectDto(org1);
+ ComponentDto projectInOrg2 = ComponentTesting.newPrivateProjectDto(org2);
index(newDoc(projectInOrg1), newDoc(projectInOrg2));
ProjectMeasuresQuery query1 = new ProjectMeasuresQuery().setOrganizationUuid(org1.getUuid());
}
private static ProjectMeasuresDoc newDoc() {
- return newDoc(newProjectDto(ORG));
+ return newDoc(ComponentTesting.newPrivateProjectDto(ORG));
}
private static ProjectMeasuresDoc newDoc(ComponentDto project, String metric1, Object value1) {
}
private static ProjectMeasuresDoc newDoc(String metric1, Object value1) {
- return newDoc(newProjectDto(ORG), metric1, value1);
+ return newDoc(ComponentTesting.newPrivateProjectDto(ORG), metric1, value1);
}
private static ProjectMeasuresDoc newDoc(String metric1, Object value1, String metric2, Object value2) {
- return newDoc(newProjectDto(ORG), metric1, value1, metric2, value2);
+ return newDoc(ComponentTesting.newPrivateProjectDto(ORG), metric1, value1, metric2, value2);
}
private static ProjectMeasuresDoc newDoc(String metric1, Object value1, String metric2, Object value2, String metric3, Object value3) {
- return newDoc(newProjectDto(ORG), metric1, value1, metric2, value2, metric3, value3);
+ return newDoc(ComponentTesting.newPrivateProjectDto(ORG), metric1, value1, metric2, value2, metric3, value3);
}
private void assertResults(ProjectMeasuresQuery query, ComponentDto... expectedProjects) {
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.es.EsTester;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_ANALYSED_AT;
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_KEY;
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_NAME;
@Test
public void index_all_project() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto));
- componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto));
- componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto));
+ componentDbTester.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto));
+ componentDbTester.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto));
+ componentDbTester.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto));
underTest.indexOnStartup(null);
*/
@Test
public void index_provisioned_projects() {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
underTest.indexOnStartup(null);
@Test
public void indexProject_indexes_provisioned_project() {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
underTest.indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_CREATION);
@Test
public void indexProject_indexes_project_when_its_key_is_updated() {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
underTest.indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE);
@Test
public void index_one_project() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = newProjectDto(organizationDto);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
componentDbTester.insertProjectAndSnapshot(project);
- componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto));
+ componentDbTester.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto));
underTest.indexProject(project.uuid(), ProjectIndexer.Cause.NEW_ANALYSIS);
.setName("Old Name")
.setTags(singletonList("old tag"))
.setAnalysedAt(new Date(1_000_000L)));
- ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), uuid).setKey("New key").setName("New name").setTagsString("new tag");
+ ComponentDto project = newPrivateProjectDto(dbTester.getDefaultOrganization(), uuid).setKey("New key").setName("New name").setTagsString("new tag");
SnapshotDto analysis = componentDbTester.insertProjectAndSnapshot(project);
underTest.indexProject(project.uuid(), ProjectIndexer.Cause.NEW_ANALYSIS);
@Test
public void delete_project() {
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project1 = newProjectDto(organizationDto);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organizationDto);
componentDbTester.insertProjectAndSnapshot(project1);
- ComponentDto project2 = newProjectDto(organizationDto);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto);
componentDbTester.insertProjectAndSnapshot(project2);
- ComponentDto project3 = newProjectDto(organizationDto);
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(organizationDto);
componentDbTester.insertProjectAndSnapshot(project3);
underTest.indexOnStartup(null);
@Test
public void does_nothing_when_deleting_unknown_project() throws Exception {
- ComponentDto project = newProjectDto(dbTester.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
componentDbTester.insertProjectAndSnapshot(project);
underTest.indexOnStartup(null);
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
@Test
public void provided_project() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
+ ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
userSession.addProjectPermission(UserRole.USER, project);
insertNclocMetric();
@Test
public void without_additional_fields() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
insertNclocMetric();
String response = ws.newRequest()
@Test
public void reference_uuid_in_the_response() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
componentDb.insertProjectAndSnapshot(project);
ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid");
componentDb.insertViewAndSnapshot(view);
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Component id 'unknown-developer-id' not found");
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
insertNclocMetric();
ws.newRequest()
@Test
public void fail_when_a_metric_is_not_found() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), PROJECT_UUID));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID));
insertNclocMetric();
insertComplexityMetric();
@Test
public void fail_when_empty_metric_keys_parameter() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("At least one metric key must be provided");
@Test
public void fail_when_not_enough_permission() {
userSession.logIn();
- componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), PROJECT_UUID));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID));
insertNclocMetric();
expectedException.expect(ForbiddenException.class);
}
private void insertJsonExampleData() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project)
.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
.setPeriodMode("previous_version")
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY;
@Test
public void empty_response() {
- componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
@Test
public void load_measures_and_periods() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
componentDb.insertComponent(projectDto);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession,
newAnalysis(projectDto)
@Test
public void load_measures_with_best_value() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
@Test
public void use_best_value_for_rating() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
componentDb.insertComponent(projectDto);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(projectDto)
@Test
public void load_measures_multi_sort_with_metric_key_and_paginated() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file9 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-9").setName("file-1"));
ComponentDto file8 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-8").setName("file-1"));
@Test
public void sort_by_metric_value() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
@Test
public void remove_components_without_measure_on_the_metric_sort() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
ComponentDto file1 = newFileDto(project, null, "file-uuid-1");
ComponentDto file2 = newFileDto(project, null, "file-uuid-2");
@Test
public void sort_by_metric_period() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
@Test
public void remove_components_without_measure_on_the_metric_period_sort() {
- ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+ ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
public void load_measures_when_no_leave_qualifier() {
resourceTypes.setLeavesQualifiers();
String projectUuid = "project-uuid";
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), projectUuid);
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), projectUuid);
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponent(newFileDto(project, null));
insertNclocMetric();
@Test
public void fail_when_metric_keys_parameter_is_empty() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'metricKeys' parameter must contain at least one metric key");
@Test
public void fail_when_a_metric_is_not_found() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
insertNclocMetric();
insertNewViolationsMetric();
expectedException.expect(NotFoundException.class);
@Test
public void fail_when_using_DISTRIB_metrics() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("distrib1").setValueType(DISTRIB.name()));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("distrib2").setValueType(DISTRIB.name()));
db.commit();
@Test
public void fail_when_using_DATA_metrics() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data1").setValueType(DISTRIB.name()));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data2").setValueType(DISTRIB.name()));
db.commit();
@Test
public void fail_when_setting_more_than_15_metric_keys() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
List<String> metrics = IntStream.range(0, 20)
.mapToObj(i -> "metric" + i)
.collect(MoreCollectors.toList());
@Test
public void fail_when_search_query_have_less_than_3_characters() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
insertNclocMetric();
insertNewViolationsMetric();
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_insufficient_privileges() {
userSession.logIn();
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
expectedException.expect(ForbiddenException.class);
ws.newRequest()
@Test
public void fail_when_sort_by_metric_and_no_metric_sort_provided() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
expectedException.expect(BadRequestException.class);
expectedException
.expectMessage("To sort by a metric, the 's' parameter must contain 'metric' or 'metricPeriod', and a metric key must be provided in the 'metricSort' parameter");
@Test
public void fail_when_sort_by_metric_and_not_in_the_list_of_metric_keys() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("To sort by the 'complexity' metric, it must be in the list of metric keys in the 'metricKeys' parameter");
@Test
public void fail_when_sort_by_metric_period_and_no_metric_period_sort_provided() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("To sort by a metric period, the 's' parameter must contain 'metricPeriod' and the 'metricPeriodSort' must be provided.");
@Test
public void fail_when_paging_parameter_is_too_big() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
insertNclocMetric();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'ps' parameter must be less than 500");
@Test
public void fail_when_with_measures_only_and_no_metric_sort() {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
insertNclocMetric();
expectedException.expect(BadRequestException.class);
expectedException
}
private void insertJsonExampleData() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-id")
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-id")
.setKey("MY_PROJECT")
.setName("My Project")
.setQualifier(Qualifiers.PROJECT);
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.organization.OrganizationDto;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
@Test
public void return_measures() throws Exception {
- ComponentDto project = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto projectSnapshot = db.components().insertProjectAndSnapshot(project);
setBrowsePermissionOnUser(project);
MetricDto coverage = insertCoverageMetric();
@Test
public void return_measures_on_leak_period() throws Exception {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto projectSnapshot = db.components().insertProjectAndSnapshot(project);
setBrowsePermissionOnUser(project);
MetricDto coverage = insertCoverageMetric();
MetricDto coverage = insertCoverageMetric();
MetricDto complexity = insertComplexityMetric();
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project1 = newProjectDto(organizationDto).setName("C");
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organizationDto).setName("C");
SnapshotDto projectSnapshot1 = db.components().insertProjectAndSnapshot(project1);
- ComponentDto project2 = newProjectDto(organizationDto).setName("A");
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto).setName("A");
SnapshotDto projectSnapshot2 = db.components().insertProjectAndSnapshot(project2);
- ComponentDto project3 = newProjectDto(organizationDto).setName("B");
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(organizationDto).setName("B");
SnapshotDto projectSnapshot3 = db.components().insertProjectAndSnapshot(project3);
setBrowsePermissionOnUser(project1, project2, project3);
dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project1, projectSnapshot1).setValue(5.5d));
@Test
public void only_returns_authorized_projects() {
MetricDto metricDto = insertComplexityMetric();
- ComponentDto project1 = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto projectSnapshot1 = db.components().insertProjectAndSnapshot(project1);
- ComponentDto project2 = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto projectSnapshot2 = db.components().insertProjectAndSnapshot(project2);
dbClient.measureDao().insert(dbSession,
newMeasureDto(metricDto, project1, projectSnapshot1).setValue(15.5d),
@Test
public void do_not_verify_permissions_if_user_is_root() {
MetricDto metricDto = insertComplexityMetric();
- ComponentDto project1 = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto projectSnapshot1 = db.components().insertProjectAndSnapshot(project1);
dbClient.measureDao().insert(dbSession, newMeasureDto(metricDto, project1, projectSnapshot1).setValue(15.5d));
db.commit();
@Test
public void fail_if_no_metric() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
setBrowsePermissionOnUser(project);
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_empty_metric() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
setBrowsePermissionOnUser(project);
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_unknown_metric() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
setBrowsePermissionOnUser(project);
insertComplexityMetric();
@Test
public void fail_if_more_than_100_project_keys() {
List<String> keys = IntStream.rangeClosed(1, 101)
- .mapToObj(i -> db.components().insertProject())
+ .mapToObj(i -> db.components().insertPrivateProject())
.map(ComponentDto::key)
.collect(Collectors.toList());
insertComplexityMetric();
@Test
public void does_not_fail_on_100_projects() {
List<String> keys = IntStream.rangeClosed(1, 100)
- .mapToObj(i -> db.components().insertProject())
+ .mapToObj(i -> db.components().insertPrivateProject())
.map(ComponentDto::key)
.collect(Collectors.toList());
insertComplexityMetric();
@Test
public void fail_if_module() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
setBrowsePermissionOnUser(project);
insertComplexityMetric();
@Test
public void fail_if_directory() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(newDirectory(project, "dir"));
setBrowsePermissionOnUser(project);
insertComplexityMetric();
@Test
public void fail_if_file() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
setBrowsePermissionOnUser(project);
insertComplexityMetric();
private List<String> insertJsonExampleData() {
List<String> projectKeys = new ArrayList<>();
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project1 = newProjectDto(organizationDto).setKey("MY_PROJECT_1").setName("Project 1");
- ComponentDto project2 = newProjectDto(organizationDto).setKey("MY_PROJECT_2").setName("Project 2");
- ComponentDto project3 = newProjectDto(organizationDto).setKey("MY_PROJECT_3").setName("Project 3");
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organizationDto).setKey("MY_PROJECT_1").setName("Project 1");
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto).setKey("MY_PROJECT_2").setName("Project 2");
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(organizationDto).setKey("MY_PROJECT_3").setName("Project 3");
projectKeys.addAll(asList(project1.key(), project2.key(), project3.key()));
db.components().insertComponents(project1, project2, project3);
SnapshotDto projectSnapshot1 = dbClient.snapshotDao().insert(dbSession, newAnalysis(project1)
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.component.ComponentFinder;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
@Before
public void setUp() {
- project = newProjectDto(db.getDefaultOrganization());
+ project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
analysis = db.components().insertProjectAndSnapshot(project);
userSession.addProjectPermission(UserRole.USER, project);
nclocMetric = insertNclocMetric();
@Test
public void empty_response() {
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
wsRequest
.setComponent(project.getKey())
@Test
public void pagination_applies_to_analyses() {
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
List<String> analysisDates = LongStream.rangeClosed(1, 9)
.mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(i * 1_000_000_000)))
@Test
public void inclusive_from_and_to_dates() {
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
List<String> analysisDates = LongStream.rangeClosed(1, 9)
.mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L)))
@Test
public void json_example() {
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
long now = parseDateTime("2017-01-23T17:00:53+0100").getTime();
LongStream.rangeClosed(0, 2)
@Test
public void add_a_project_notification() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
call(request.setProject(project.getKey()));
@Test
public void add_a_global_notification_when_a_project_one_exists() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
call(request.setProject(project.getKey()));
call(request.setProject(null));
@Test
public void add_a_project_notification_when_a_global_one_exists() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
call(request);
call(request.setProject(project.getKey()));
@Test
public void fail_when_unknown_project_dispatcher() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher3]");
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.UserPermissionDto;
import org.sonar.server.exceptions.UnauthorizedException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION;
import static org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
@Test
public void filter_unauthorized_projects() {
- ComponentDto project = addComponent(newProjectDto(db.organizations().insert()).setKey("K1"));
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto project = addComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("K1"));
+ ComponentDto anotherProject = db.components().insertPrivateProject();
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, project);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, anotherProject);
dbSession.commit();
@Test
public void filter_per_project_dispatchers() {
- ComponentDto project = addComponent(newProjectDto(db.organizations().insert()).setKey("K1"));
+ ComponentDto project = addComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("K1"));
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, project);
notificationUpdater.add(dbSession, emailChannel.getKey(), "Unknown Notification", project);
dbSession.commit();
@Test
public void order_with_global_then_by_channel_and_dispatcher() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = addComponent(newProjectDto(organization).setKey("K1"));
+ ComponentDto project = addComponent(ComponentTesting.newPrivateProjectDto(organization).setKey("K1"));
notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_NEW_ISSUES, null);
@Test
public void json_example() {
OrganizationDto organization = db.organizations().insertForKey("my-org-1");
- ComponentDto project = addComponent(newProjectDto(organization).setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project"));
+ ComponentDto project = addComponent(ComponentTesting.newPrivateProjectDto(organization).setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project"));
notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_NEW_ISSUES, null);
@Test
public void remove_a_project_notification() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, project);
dbSession.commit();
@Test
public void fail_when_remove_a_global_notification_when_a_project_one_exists() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, project);
dbSession.commit();
@Test
public void fail_when_remove_a_project_notification_when_a_global_one_exists() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, null);
dbSession.commit();
@Test
public void fail_when_unknown_project_dispatcher() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher3]");
@Test
public void request_also_deletes_components_of_specified_organization() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(module, "a/b"));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module, directory));
GroupDto otherGroup1 = db.users().insertGroup(otherOrg);
GroupDto otherGroup2 = db.users().insertGroup(otherOrg);
- ComponentDto projectDto = db.components().insertProject(org);
- ComponentDto otherProjectDto = db.components().insertProject(otherOrg);
+ ComponentDto projectDto = db.components().insertPrivateProject(org);
+ ComponentDto otherProjectDto = db.components().insertPrivateProject(otherOrg);
db.users().insertPermissionOnAnyone(org, "u1");
db.users().insertPermissionOnAnyone(otherOrg, "not deleted u1");
OrganizationDto defaultOrganization = db.getDefaultOrganization();
UserDto user = db.users().insertUser();
GroupDto sonarUsersGroup = db.users().insertDefaultGroup(defaultOrganization, "sonar-users");
- ComponentDto project = db.components().insertProject(defaultOrganization);
+ ComponentDto project = db.components().insertPrivateProject(defaultOrganization);
db.users().insertPermissionOnGroup(sonarUsersGroup, "user");
db.users().insertProjectPermissionOnGroup(sonarUsersGroup, "codeviewer", project);
// Should be ignored
@Before
public void setUp() {
organization = db.organizations().insert();
- project = db.components().insertProject(organization);
+ project = db.components().insertPrivateProject(organization);
user = db.users().insertUser();
db.organizations().addMember(organization, user);
public void remove_organization_permissions() {
UserDto anotherUser = db.users().insertUser();
OrganizationDto anotherOrganization = db.organizations().insert();
- ComponentDto anotherProject = db.components().insertProject(anotherOrganization);
+ ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
assertMember(organization.getUuid(), user);
db.users().insertPermissionOnUser(organization, user, ADMINISTER);
db.users().insertPermissionOnUser(organization, user, SCAN);
@Test
public void remove_from_org_properties() {
OrganizationDto anotherOrganization = db.organizations().insert();
- ComponentDto anotherProject = db.components().insertProject(anotherOrganization);
+ ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
UserDto anotherUser = db.users().insertUser();
insertProperty("KEY_11", "VALUE", project.getId(), user.getId());
insertProperty("KEY_12", "VALUE", project.getId(), user.getId());
@Test
public void remove_from_default_assignee_properties() {
OrganizationDto anotherOrganization = db.organizations().insert();
- ComponentDto anotherProject = db.components().insertProject(anotherOrganization);
+ ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
UserDto anotherUser = db.users().insertUser();
insertProperty(DEFAULT_ISSUE_ASSIGNEE, user.getLogin(), project.getId(), null);
insertProperty("ANOTHER_KEY", user.getLogin(), project.getId(), null);
public void setUp() throws Exception {
org = db.organizations().insert();
group = db.users().insertGroup(org, "a-group");
- project = db.components().insertProject(org);
+ project = db.components().insertPrivateProject(org);
}
@Test
@Test
public void apply_permission_template() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
GroupDto adminGroup = dbTester.users().insertGroup(organization);
GroupDto userGroup = dbTester.users().insertGroup(organization);
UserDto user = dbTester.users().insertUser();
org2 = db.organizations().insert();
user1 = db.users().insertUser();
user2 = db.users().insertUser();
- project = db.components().insertProject(org1);
+ project = db.components().insertPrivateProject(org1);
}
@Test
@Test
public void remove_project_permission_from_user() {
- ComponentDto project2 = db.components().insertProject(org1);
+ ComponentDto project2 = db.components().insertPrivateProject(org1);
db.users().insertPermissionOnUser(user1, ADMINISTER_QUALITY_GATES);
db.users().insertProjectPermissionOnUser(user1, ISSUE_ADMIN, project);
db.users().insertProjectPermissionOnUser(user1, USER, project);
@Before
public void setUp() throws Exception {
- project1 = componentDbTester.insertProject();
- project2 = componentDbTester.insertProject();
+ project1 = componentDbTester.insertPrivateProject();
+ project2 = componentDbTester.insertPrivateProject();
view1 = componentDbTester.insertView();
view2 = componentDbTester.insertView();
user1 = userDbTester.insertUser();
public void select_by_projects_with_high_number_of_projects() throws Exception {
List<String> projects = new ArrayList<>();
for (int i = 0; i < 350; i++) {
- ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), Integer.toString(i));
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization(), Integer.toString(i));
dbClient.componentDao().insert(dbSession, project);
projects.add(project.uuid());
GroupPermissionDto dto = new GroupPermissionDto()
}
private ComponentDto createAndIndexProject() {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
fooIndexer.indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_CREATION);
return project;
}
private ComponentDto createAndIndexProject(OrganizationDto org) {
- ComponentDto project = componentDbTester.insertProject(org);
+ ComponentDto project = componentDbTester.insertPrivateProject(org);
fooIndexer.indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_CREATION);
return project;
}
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
@Test
public void add_permission_to_project_referenced_by_its_id() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
loginAsAdmin(db.getDefaultOrganization());
newRequest()
@Test
public void add_permission_to_project_referenced_by_its_key() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
loginAsAdmin(db.getDefaultOrganization());
newRequest()
public void adding_a_project_permission_fails_if_component_is_not_a_project() throws Exception {
OrganizationDto organizationDto = db.getDefaultOrganization();
GroupDto group = db.users().insertGroup(organizationDto, "sonar-administrators");
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, A_PROJECT_UUID).setKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, A_PROJECT_UUID).setKey(A_PROJECT_KEY));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project, null, "file-uuid"));
loginAsAdmin(db.getDefaultOrganization());
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
GroupDto group = db.users().insertGroup();
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void adding_project_permission_fails_if_not_administrator_of_project() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
newRequest()
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION;
public void add_permission_to_project_referenced_by_its_id() throws Exception {
OrganizationDto organization = db.organizations().insert();
addUserAsMemberOfOrganization(organization);
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
loginAsAdmin(organization);
newRequest()
@Test
public void add_permission_to_project_referenced_by_its_key() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
loginAsAdmin(db.getDefaultOrganization());
newRequest()
@Test
public void fail_when_component_is_not_a_project() throws Exception {
- db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert(), "project-uuid"), null, "file-uuid"));
+ db.components().insertComponent(newFileDto(newPrivateProjectDto(db.organizations().insert(), "project-uuid"), null, "file-uuid"));
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
- db.components().insertProject();
+ db.components().insertPrivateProject();
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void adding_project_permission_fails_if_not_administrator_of_project() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
*/
@Test
public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@Test
public void organization_parameter_must_not_be_set_on_project_permissions() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
import org.junit.Test;
import org.sonar.api.security.DefaultGroups;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.exceptions.BadRequestException;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.SCAN;
@Test
public void search_groups_with_project_permissions() throws Exception {
OrganizationDto organizationDto = db.getDefaultOrganization();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "project-uuid"));
GroupDto group = db.users().insertGroup(organizationDto, "project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
- ComponentDto anotherProject = db.components().insertComponent(newProjectDto(organizationDto));
+ ComponentDto anotherProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
GroupDto anotherGroup = db.users().insertGroup(organizationDto, "another-project-group-name");
db.users().insertProjectPermissionOnGroup(anotherGroup, ISSUE_ADMIN, anotherProject);
@Test
public void return_also_groups_without_permission_when_search_query() throws Exception {
OrganizationDto organizationDto = db.getDefaultOrganization();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "project-uuid"));
GroupDto group = db.users().insertGroup(organizationDto, "group-with-permission");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
@Test
public void return_only_groups_with_permission_when_no_search_query() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
@Test
public void return_anyone_group_when_search_query_and_no_param_permission() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "project-uuid"));
GroupDto group = db.users().insertGroup(organizationDto, "group-with-permission");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
@Test
public void fail_if_project_uuid_and_project_key_are_provided() throws Exception {
- db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key"));
+ db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key"));
expectedException.expect(BadRequestException.class);
import org.junit.Test;
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.exceptions.BadRequestException;
import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
@Test
public void remove_project_permission() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.users().insertPermissionOnGroup(aGroup, ADMINISTER);
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, project);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
@Test
public void remove_with_project_key() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.users().insertPermissionOnGroup(aGroup, ADMINISTER);
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, project);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
@Test
public void fail_when_component_is_not_a_project() throws Exception {
- ComponentDto file = db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert()), null, "file-uuid"));
+ ComponentDto file = db.components().insertComponent(newFileDto(ComponentTesting.newPrivateProjectDto(db.organizations().insert()), null, "file-uuid"));
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void removing_project_permission_fails_if_not_administrator_of_project() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
*/
@Test
public void removing_project_permission_is_allowed_to_project_administrators() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnGroup(aGroup, CODEVIEWER, project);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
import org.junit.Test;
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import static org.sonar.core.permission.GlobalPermissions.QUALITY_GATE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES;
@Test
public void remove_permission_from_project() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
loginAsAdmin(db.getDefaultOrganization());
@Test
public void remove_with_project_key() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
loginAsAdmin(db.getDefaultOrganization());
@Test
public void fail_when_component_is_not_a_project() throws Exception {
- db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert()), null, "file-uuid"));
+ db.components().insertComponent(newFileDto(ComponentTesting.newPrivateProjectDto(db.organizations().insert()), null, "file-uuid"));
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void removing_project_permission_fails_if_not_administrator_of_project() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
*/
@Test
public void removing_project_permission_is_allowed_to_project_administrators() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.GroupDto;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.test.JsonAssert.assertJson;
@Test
public void search_project_permissions_with_project_permission() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
String result = newRequest()
public void has_projects_ordered_by_name() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
for (int i = 9; i >= 1; i--) {
- db.components().insertComponent(newProjectDto(organizationDto)
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto)
.setName("project-name-" + i));
}
@Test
public void search_by_query_on_name() throws Exception {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("project-name"));
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("another-name"));
+ componentDb.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("project-name"));
+ componentDb.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("another-name"));
String result = newRequest()
.setParam(TEXT_QUERY, "project")
@Test
public void search_by_query_on_key_must_match_exactly() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
- componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto).setKey("project-key"));
- componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto).setKey("another-key"));
+ componentDb.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("project-key"));
+ componentDb.insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("another-key"));
String result = newRequest()
.setParam(TEXT_QUERY, "project-key")
@Test
public void handle_more_than_1000_projects() throws Exception {
for (int i = 1; i <= 1001; i++) {
- componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid-" + i));
+ componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid-" + i));
}
String result = newRequest()
public void filter_by_qualifier() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
db.components().insertComponent(newView(organizationDto, "view-uuid"));
- db.components().insertComponent(newProjectDto(organizationDto, "project-uuid"));
+ db.components().insertComponent(newPrivateProjectDto(organizationDto, "project-uuid"));
WsPermissions.SearchProjectPermissionsWsResponse result = newRequest()
.setParam(PARAM_QUALIFIER, Qualifiers.PROJECT)
}
private ComponentDto insertClang() {
- return db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid-2")
+ return db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid-2")
.setName("Clang")
.setKey("clang")
.setUuid("ce4c03d6-430f-40a9-b777-ad877c00aa4d"));
}
private ComponentDto insertJdk7() {
- return db.components().insertComponent(newProjectDto(db.getDefaultOrganization())
+ return db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization())
.setName("JDK 7")
.setKey("net.java.openjdk:jdk7")
.setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
import org.sonar.api.server.ws.WebService.SelectionMode;
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
@Test
public void search_for_users_with_permission_on_project() throws Exception {
// User has permission on project
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
UserDto user = db.users().insertUser(newUserDto());
db.organizations().addMember(db.getDefaultOrganization(), user);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
// User has permission on another project
- ComponentDto anotherProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto anotherProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
UserDto userHavePermissionOnAnotherProject = db.users().insertUser(newUserDto());
db.organizations().addMember(db.getDefaultOrganization(), userHavePermissionOnAnotherProject);
db.users().insertProjectPermissionOnUser(userHavePermissionOnAnotherProject, ISSUE_ADMIN, anotherProject);
@Test
public void search_only_for_users_with_permission_when_no_search_query() throws Exception {
// User have permission on project
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
db.organizations().addMember(db.getDefaultOrganization(), user);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
@Test
public void search_also_for_users_without_permission_when_filtering_name() throws Exception {
// User with permission on project
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
UserDto user = db.users().insertUser(newUserDto("with-permission-login", "with-permission-name", "with-permission-email"));
db.organizations().addMember(db.getDefaultOrganization(), user);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
@Test
public void search_also_for_users_without_permission_when_filtering_email() throws Exception {
// User with permission on project
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
UserDto user = db.users().insertUser(newUserDto("with-permission-login", "with-permission-name", "with-permission-email"));
db.organizations().addMember(db.getDefaultOrganization(), user);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
@Test
public void search_also_for_users_without_permission_when_filtering_login() throws Exception {
// User with permission on project
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
UserDto user = db.users().insertUser(newUserDto("with-permission-login", "with-permission-name", "with-permission-email"));
db.organizations().addMember(db.getDefaultOrganization(), user);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
@Test
public void fail_if_project_uuid_and_project_key_are_provided() throws Exception {
- db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key"));
+ db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key"));
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
addGroupToTemplate(group1, template2, UserRole.USER);
addGroupToTemplate(group2, template2, UserRole.USER);
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project);
db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, project);
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, project);
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.template.PermissionTemplateDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER;
public void bulk_apply_template_by_template_uuid() throws Exception {
// this project should not be applied the template
OrganizationDto otherOrganization = db.organizations().insert();
- db.components().insertProject(otherOrganization);
+ db.components().insertPrivateProject(otherOrganization);
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto view = db.components().insertView(organization);
loginAsAdmin(organization);
@Test
public void bulk_apply_template_by_template_name() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organization));
loginAsAdmin(organization);
newRequest()
@Test
public void apply_template_by_qualifier() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organization));
ComponentDto view = db.components().insertComponent(newView(organization));
loginAsAdmin(organization);
@Test
public void apply_template_by_query_on_name_and_key() throws Exception {
- ComponentDto projectFoundByKey = newProjectDto(organization).setKey("sonar");
+ ComponentDto projectFoundByKey = ComponentTesting.newPrivateProjectDto(organization).setKey("sonar");
db.components().insertProjectAndSnapshot(projectFoundByKey);
- ComponentDto projectFoundByName = newProjectDto(organization).setName("name-sonar-name");
+ ComponentDto projectFoundByName = ComponentTesting.newPrivateProjectDto(organization).setName("name-sonar-name");
db.components().insertProjectAndSnapshot(projectFoundByName);
// match must be exact on key
- ComponentDto projectUntouched = newProjectDto(organization).setKey("new-sonar").setName("project-name");
+ ComponentDto projectUntouched = ComponentTesting.newPrivateProjectDto(organization).setKey("new-sonar").setName("project-name");
db.components().insertProjectAndSnapshot(projectUntouched);
loginAsAdmin(organization);
}
private ComponentDoc newComponentDoc() {
- return ComponentIndexer.toDocument(ComponentTesting.newProjectDto(organization));
+ return ComponentIndexer.toDocument(ComponentTesting.newPrivateProjectDto(organization));
}
}
@Test
public void system_administrator_deletes_projects_by_uuids_in_all_organizations() throws Exception {
userSession.logIn().setSystemAdministrator();
- ComponentDto toDeleteInOrg1 = db.components().insertProject(org1);
- ComponentDto toDeleteInOrg2 = db.components().insertProject(org2);
- ComponentDto toKeep = db.components().insertProject(org2);
+ ComponentDto toDeleteInOrg1 = db.components().insertPrivateProject(org1);
+ ComponentDto toDeleteInOrg2 = db.components().insertPrivateProject(org2);
+ ComponentDto toKeep = db.components().insertPrivateProject(org2);
WsTester.Result result = ws.newPostRequest("api/projects", ACTION)
.setParam("ids", toDeleteInOrg1.uuid() + "," + toDeleteInOrg2.uuid())
@Test
public void system_administrator_deletes_projects_by_keys_in_all_organizations() throws Exception {
userSession.logIn().setSystemAdministrator();
- ComponentDto toDeleteInOrg1 = db.components().insertProject(org1);
- ComponentDto toDeleteInOrg2 = db.components().insertProject(org2);
- ComponentDto toKeep = db.components().insertProject(org2);
+ ComponentDto toDeleteInOrg1 = db.components().insertPrivateProject(org1);
+ ComponentDto toDeleteInOrg2 = db.components().insertPrivateProject(org2);
+ ComponentDto toKeep = db.components().insertPrivateProject(org2);
WsTester.Result result = ws.newPostRequest("api/projects", ACTION)
.setParam("keys", toDeleteInOrg1.key() + "," + toDeleteInOrg2.key())
@Test
public void projects_that_dont_exist_are_ignored_and_dont_break_bulk_deletion() throws Exception {
userSession.logIn().setSystemAdministrator();
- ComponentDto toDelete1 = db.components().insertProject(org1);
- ComponentDto toDelete2 = db.components().insertProject(org1);
+ ComponentDto toDelete1 = db.components().insertPrivateProject(org1);
+ ComponentDto toDelete2 = db.components().insertPrivateProject(org1);
WsTester.Result result = ws.newPostRequest("api/projects", ACTION)
.setParam("keys", toDelete1.key() + ",missing," + toDelete2.key() + ",doesNotExist")
@Test
public void throw_ForbiddenException_if_organization_administrator_does_not_set_organization_parameter() throws Exception {
userSession.logIn().addPermission(ADMINISTER, org1);
- ComponentDto project = db.components().insertProject(org1);
+ ComponentDto project = db.components().insertPrivateProject(org1);
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void organization_administrator_deletes_projects_by_keys_in_his_organization() throws Exception {
userSession.logIn().addPermission(ADMINISTER, org1);
- ComponentDto toDelete = db.components().insertProject(org1);
- ComponentDto cantBeDeleted = db.components().insertProject(org2);
+ ComponentDto toDelete = db.components().insertPrivateProject(org1);
+ ComponentDto cantBeDeleted = db.components().insertPrivateProject(org2);
WsTester.Result result = ws.newPostRequest("api/projects", ACTION)
.setParam("organization", org1.getKey())
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.ComponentService;
import static org.mockito.Mockito.verify;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_DRY_RUN;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_FROM;
@Test
public void json_example() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = componentDb.insertComponent(newProjectDto(organizationDto).setKey("my_project"));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("my_project"));
componentDb.insertComponent(newModuleDto(project).setKey("my_project:module_1"));
- ComponentDto anotherProject = componentDb.insertComponent(newProjectDto(organizationDto).setKey("another_project"));
+ ComponentDto anotherProject = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("another_project"));
componentDb.insertComponent(newModuleDto(anotherProject).setKey("my_new_project:module_1"));
ComponentDto module2 = componentDb.insertComponent(newModuleDto(project).setKey("my_project:module_2"));
componentDb.insertComponent(newFileDto(module2, null));
@Test
public void bulk_update_provisioned_project_key() {
String newKey = "provisionedProject2";
- ComponentDto provisionedProject = componentDb.insertProject();
+ ComponentDto provisionedProject = componentDb.insertPrivateProject();
callByKey(provisionedProject.key(), provisionedProject.getKey(), newKey);
@Test
public void fail_to_bulk_if_a_component_already_exists_with_the_same_key() {
- componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("my_project"));
- componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("your_project"));
+ componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("my_project"));
+ componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("your_project"));
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Impossible to update key: a component with key \"your_project\" already exists.");
}
private ComponentDto insertMyProject() {
- return componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey(MY_PROJECT_KEY));
+ return componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey(MY_PROJECT_KEY));
}
private BulkUpdateKeyWsResponse callDryRunByUuid(@Nullable String uuid, @Nullable String from, @Nullable String to) {
@Test
public void organization_administrator_deletes_project_by_id() throws Exception {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
userSessionRule.logIn().addPermission(ADMINISTER, project.getOrganizationUuid());
WsTester.TestRequest request = newRequest().setParam(PARAM_PROJECT_ID, project.uuid());
@Test
public void organization_administrator_deletes_project_by_key() throws Exception {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
userSessionRule.logIn().addPermission(ADMINISTER, project.getOrganizationUuid());
call(newRequest().setParam(PARAM_PROJECT, project.key()));
@Test
public void project_administrator_deletes_the_project_by_uuid() throws Exception {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, project);
call(newRequest().setParam(PARAM_PROJECT_ID, project.uuid()));
@Test
public void project_administrator_deletes_the_project_by_key() throws Exception {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, project);
call(newRequest().setParam(PARAM_PROJECT, project.key()));
@Test
public void return_403_if_not_project_admin_nor_org_admin() throws Exception {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
userSessionRule.logIn()
.addProjectPermission(UserRole.CODEVIEWER, project)
@Test
public void return_401_if_not_logged_in() throws Exception {
- ComponentDto project = componentDbTester.insertProject();
+ ComponentDto project = componentDbTester.insertPrivateProject();
userSessionRule.anonymous();
expectedException.expect(UnauthorizedException.class);
@Test
public void ghost_projects_base_on_json_example() throws Exception {
OrganizationDto organization = db.organizations().insert();
- ComponentDto hBaseProject = ComponentTesting.newProjectDto(organization, "ce4c03d6-430f-40a9-b777-ad877c00aa4d")
+ ComponentDto hBaseProject = ComponentTesting.newPrivateProjectDto(organization, "ce4c03d6-430f-40a9-b777-ad877c00aa4d")
.setKey("org.apache.hbas:hbase")
.setName("HBase")
.setCreatedAt(DateUtils.parseDateTime("2015-03-04T23:03:44+0100"));
dbClient.componentDao().insert(db.getSession(), hBaseProject);
dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(hBaseProject)
.setStatus(STATUS_UNPROCESSED));
- ComponentDto roslynProject = ComponentTesting.newProjectDto(organization, "c526ef20-131b-4486-9357-063fa64b5079")
+ ComponentDto roslynProject = ComponentTesting.newPrivateProjectDto(organization, "c526ef20-131b-4486-9357-063fa64b5079")
.setKey("com.microsoft.roslyn:roslyn")
.setName("Roslyn")
.setCreatedAt(DateUtils.parseDateTime("2013-03-04T23:03:44+0100"));
}
private ComponentDto insertGhostProject(OrganizationDto organization, Consumer<ComponentDto> consumer) {
- ComponentDto project = db.components().insertProject(organization, consumer);
+ ComponentDto project = db.components().insertPrivateProject(organization, consumer);
db.components().insertSnapshot(project, dto -> dto.setStatus(STATUS_UNPROCESSED));
return project;
}
private ComponentDto insertActiveProject(OrganizationDto organization) {
- ComponentDto project = db.components().insertProject(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
db.components().insertSnapshot(project, dto -> dto.setStatus(STATUS_PROCESSED));
return project;
}
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.user.UserDto;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
public class IndexActionTest {
@Test
public void search_all_projects() throws Exception {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call(null, null, null);
@Test
public void search_projects_with_modules() throws Exception {
- ComponentDto project1 = newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin");
- ComponentDto project2 = newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task");
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin");
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task");
insertProjectsAuthorizedForUser(project1, project2);
db.components().insertComponents(
newModuleDto(project1).setKey("org.jenkins-ci.plugins:sonar-common").setName("Common"),
@Test
public void search_project_by_key() throws Exception {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call("org.jenkins-ci.plugins:sonar", null, null);
@Test
public void search_project_by_id() throws Exception {
- ComponentDto project = newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin");
insertProjectsAuthorizedForUser(
project,
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call(Long.toString(project.getId()), null, null);
@Test
public void search_projects_by_name() throws Exception {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call(null, "Plu", null);
@Test
public void search_projects_with_modules_by_name() throws Exception {
- ComponentDto project1 = newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin");
- ComponentDto project2 = newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task");
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin");
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task");
insertProjectsAuthorizedForUser(project1, project2);
db.components().insertComponents(
newModuleDto(project1).setKey("org.jenkins-ci.plugins:sonar-common-db").setName("Jenkins Common DB"),
@Test
public void return_empty_list_when_no_project_match_search() throws Exception {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call(null, "Unknown", null);
@Test
public void return_only_projects_authorized_for_user() throws Exception {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"));
db.components()
- .insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ .insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call(null, null, null);
@Test
public void do_not_verify_permissions_if_user_is_root() throws Exception {
- ComponentDto project = db.components().insertProject(p -> p.setKey("P1").setName("POne"));
+ ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("P1").setName("POne"));
String result = call(null, null, null);
@Test
public void test_example() {
insertProjectsAuthorizedForUser(
- newProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
- newProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.jenkins-ci.plugins:sonar").setName("Jenkins Sonar Plugin"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-ant-task").setName("Sonar Ant Task"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("org.codehaus.sonar-plugins:sonar-build-breaker-plugin").setName("Sonar Build Breaker Plugin"));
String result = call(null, null, null);
@Test
public void all_provisioned_projects_without_analyzed_projects() throws Exception {
OrganizationDto org = db.organizations().insert();
- ComponentDto analyzedProject = ComponentTesting.newProjectDto(org, "analyzed-uuid-1");
+ ComponentDto analyzedProject = ComponentTesting.newPrivateProjectDto(org, "analyzed-uuid-1");
db.components().insertComponents(newProvisionedProject(org, "1"), newProvisionedProject(org, "2"), analyzedProject);
db.components().insertSnapshot(SnapshotTesting.newAnalysis(analyzedProject));
userSessionRule.logIn().addPermission(PROVISION_PROJECTS, org);
@Test
public void provisioned_projects_as_defined_in_the_example() throws Exception {
OrganizationDto org = db.organizations().insert();
- ComponentDto hBaseProject = ComponentTesting.newProjectDto(org, "ce4c03d6-430f-40a9-b777-ad877c00aa4d")
+ ComponentDto hBaseProject = ComponentTesting.newPrivateProjectDto(org, "ce4c03d6-430f-40a9-b777-ad877c00aa4d")
.setKey("org.apache.hbas:hbase")
.setName("HBase")
.setCreatedAt(DateUtils.parseDateTime("2015-03-04T23:03:44+0100"));
- ComponentDto roslynProject = ComponentTesting.newProjectDto(org, "c526ef20-131b-4486-9357-063fa64b5079")
+ ComponentDto roslynProject = ComponentTesting.newPrivateProjectDto(org, "c526ef20-131b-4486-9357-063fa64b5079")
.setKey("com.microsoft.roslyn:roslyn")
.setName("Roslyn")
.setCreatedAt(DateUtils.parseDateTime("2013-03-04T23:03:44+0100"));
private static ComponentDto newProvisionedProject(OrganizationDto organizationDto, String uuid) {
return ComponentTesting
- .newProjectDto(organizationDto, "provisioned-uuid-" + uuid)
+ .newPrivateProjectDto(organizationDto, "provisioned-uuid-" + uuid)
.setName("provisioned-name-" + uuid)
.setKey("provisioned-key-" + uuid);
}
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
public void search_by_key_query() throws IOException {
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
db.components().insertComponents(
- newProjectDto(db.getDefaultOrganization()).setKey("project-_%-key"),
- newProjectDto(db.getDefaultOrganization()).setKey("project-key-without-escaped-characters"));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("project-_%-key"),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("project-key-without-escaped-characters"));
SearchWsResponse response = call(SearchWsRequest.builder().setQuery("project-_%-key").build());
public void search_projects_when_no_qualifier_set() throws IOException {
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
db.components().insertComponents(
- newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
newView(db.getDefaultOrganization()));
SearchWsResponse response = call(SearchWsRequest.builder().build());
@Test
public void search_projects() throws IOException {
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
- ComponentDto project = newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1);
ComponentDto module = newModuleDto(project);
ComponentDto directory = newDirectory(module, "dir");
ComponentDto file = newFileDto(directory);
db.components().insertComponents(
project, module, directory, file,
- newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_2),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_2),
newView(db.getDefaultOrganization()));
SearchWsResponse response = call(SearchWsRequest.builder().setQualifiers(singletonList("TRK")).build());
public void search_views() throws IOException {
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
db.components().insertComponents(
- newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
newView(db.getDefaultOrganization()).setKey("view1"));
SearchWsResponse response = call(SearchWsRequest.builder().setQualifiers(singletonList("VW")).build());
public void search_projects_and_views() throws IOException {
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
db.components().insertComponents(
- newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
newView(db.getDefaultOrganization()).setKey("view1"));
SearchWsResponse response = call(SearchWsRequest.builder().setQualifiers(asList("TRK", "VW")).build());
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
OrganizationDto otherOrganization = db.organizations().insert();
db.components().insertComponents(
- newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
- newProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_2),
- newProjectDto(otherOrganization).setKey(PROJECT_KEY_3));
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_1),
+ ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey(PROJECT_KEY_2),
+ ComponentTesting.newPrivateProjectDto(otherOrganization).setKey(PROJECT_KEY_3));
SearchWsResponse response = call(SearchWsRequest.builder().build());
OrganizationDto organization1 = db.organizations().insert();
OrganizationDto organization2 = db.organizations().insert();
userSession.addPermission(ADMINISTER, organization1);
- ComponentDto project1 = newProjectDto(organization1);
- ComponentDto project2 = newProjectDto(organization1);
- ComponentDto project3 = newProjectDto(organization2);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organization1);
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organization1);
+ ComponentDto project3 = ComponentTesting.newPrivateProjectDto(organization2);
db.components().insertComponents(project1, project2, project3);
SearchWsResponse response = call(SearchWsRequest.builder().setOrganization(organization1.getKey()).build());
userSession.addPermission(ADMINISTER, db.getDefaultOrganization());
List<ComponentDto> componentDtoList = new ArrayList<>();
for (int i = 1; i <= 9; i++) {
- componentDtoList.add(newProjectDto(db.getDefaultOrganization(), "project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i));
+ componentDtoList.add(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i));
}
db.components().insertComponents(componentDtoList.toArray(new ComponentDto[] {}));
OrganizationDto organization = db.organizations().insertForKey("my-org-1");
userSession.addPermission(ADMINISTER, organization);
db.components().insertComponents(
- newProjectDto(organization, "project-uuid-1").setName("Project Name 1").setKey("project-key-1"),
- newProjectDto(organization, "project-uuid-2").setName("Project Name 1").setKey("project-key-2"));
+ newPrivateProjectDto(organization, "project-uuid-1").setName("Project Name 1").setKey("project-key-1"),
+ newPrivateProjectDto(organization, "project-uuid-2").setName("Project Name 1").setKey("project-key-2"));
String response = ws.newRequest()
.setMediaType(MediaTypes.JSON)
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentLinkDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
@Test
public void sort_projects_by_name() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto b_project = db.components().insertComponent(newProjectDto(organizationDto).setName("B_project_name"));
- ComponentDto c_project = db.components().insertComponent(newProjectDto(organizationDto).setName("c_project_name"));
- ComponentDto a_project = db.components().insertComponent(newProjectDto(organizationDto).setName("A_project_name"));
+ ComponentDto b_project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("B_project_name"));
+ ComponentDto c_project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("c_project_name"));
+ ComponentDto a_project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("A_project_name"));
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, b_project);
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, a_project);
public void paginate_projects() {
OrganizationDto organizationDto = db.organizations().insert();
for (int i = 0; i < 10; i++) {
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setName("project-" + i));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project-" + i));
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, project);
}
OrganizationDto org = db.organizations().insert();
ComponentDto jdk7 = insertJdk7(org);
ComponentDto cLang = insertClang(org);
- ComponentDto sonarqube = db.components().insertProject(org);
+ ComponentDto sonarqube = db.components().insertPrivateProject(org);
GroupDto group = db.users().insertGroup(org);
db.users().insertMember(group, user);
}
private ComponentDto insertClang(OrganizationDto organizationDto) {
- return db.components().insertComponent(newProjectDto(organizationDto, Uuids.UUID_EXAMPLE_01)
+ return db.components().insertComponent(newPrivateProjectDto(organizationDto, Uuids.UUID_EXAMPLE_01)
.setName("Clang")
.setKey("clang"));
}
private ComponentDto insertJdk7(OrganizationDto organizationDto) {
- return db.components().insertComponent(newProjectDto(organizationDto, Uuids.UUID_EXAMPLE_02)
+ return db.components().insertComponent(newPrivateProjectDto(organizationDto, Uuids.UUID_EXAMPLE_02)
.setName("JDK 7")
.setKey("net.java.openjdk:jdk7")
.setDescription("JDK"));
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.ComponentService;
import org.sonar.server.exceptions.NotFoundException;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_TO;
}
private ComponentDto insertProject() {
- return componentDb.insertComponent(newProjectDto(db.organizations().insert()));
+ return componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
}
private String callByUuid(@Nullable String uuid, @Nullable String newKey) {
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.component.SnapshotTesting;
import org.sonar.db.event.EventDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.component.SnapshotTesting.newSnapshot;
@Test
public void json_example() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SnapshotDto analysis = dbClient.snapshotDao().insert(dbSession, SnapshotTesting.newAnalysis(project).setUuid("A2"));
db.commit();
uuidFactory = mock(UuidFactory.class);
@Test
public void create_event_in_db() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void create_event_as_project_admin() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "P1");
+ ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "P1");
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void create_version_event() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void create_other_event_with_ws_response() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void create_event_without_description() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void create_2_version_events_on_same_project() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto firstAnalysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder firstRequest = CreateEventRequest.builder()
.setAnalysis(firstAnalysis.getUuid())
@Test
public void fail_if_not_blank_name() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setName(" ");
logInAsProjectAdministrator(project);
@Test
public void fail_if_2_version_events_on_the_same_analysis() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void fail_if_2_other_events_on_same_analysis_with_same_name() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
@Test
public void fail_if_category_other_than_authorized() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
logInAsProjectAdministrator(project);
@Test
public void throw_ForbiddenException_if_not_project_administrator() {
- SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "P1"));
+ SnapshotDto analysis = db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "P1"));
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
.setCategory(VERSION)
@Test
public void project_administrator_deletes_analysis() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_PROCESSED));
db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setLast(true).setStatus(STATUS_PROCESSED));
logInAsProjectAdministrator(project);
@Test
public void last_analysis_cannot_be_deleted() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(true));
logInAsProjectAdministrator(project);
@Test
public void fail_when_analysis_is_unprocessed() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_UNPROCESSED));
logInAsProjectAdministrator(project);
@Test
public void fail_when_not_enough_permission() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false));
userSession.logIn();
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.event.EventTesting.newEvent;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION;
@Test
public void delete_event() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
db.events().insertEvent(newEvent(analysis).setUuid("E1"));
db.events().insertEvent(newEvent(analysis).setUuid("E2"));
@Test
public void delete_version_event() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6.3").setLast(false));
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));
logInAsProjectAdministrator(project);
@Test
public void fail_if_version_for_last_analysis() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6.3").setLast(true));
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));
logInAsProjectAdministrator(project);
@Test
public void fail_if_category_different_than_other_and_version() {
- ComponentDto project = newProjectDto(db.organizations().insert(), "P1");
+ ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "P1");
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory("Profile"));
logInAsProjectAdministrator(project);
@Test
public void fail_if_not_enough_permission() {
- SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert()));
+ SnapshotDto analysis = db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
db.events().insertEvent(newEvent(analysis).setUuid("E1"));
userSession.logIn();
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.event.EventDto;
import org.sonar.db.event.EventTesting;
import org.sonar.db.organization.OrganizationTesting;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonarqube.ws.client.projectanalysis.EventCategory.QUALITY_GATE;
}
private EventDto newEvent() {
- return EventTesting.newEvent(newAnalysis(newProjectDto(OrganizationTesting.newOrganizationDto())));
+ return EventTesting.newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto())));
}
}
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.core.util.Protobuf.setNullable;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.event.EventTesting.newEvent;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
@Test
public void json_example() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey(KEY_PROJECT_EXAMPLE_001));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey(KEY_PROJECT_EXAMPLE_001));
userSession.addProjectPermission(UserRole.USER, project);
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime()));
SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(parseDateTime("2016-12-12T17:12:45+0100").getTime()));
@Test
public void return_analyses_ordered_by_analysis_date() {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("P1"));
userSession.addProjectPermission(UserRole.USER, project);
db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
@Test
public void return_only_processed_analyses() {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("P1"));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setKey("P1"));
userSession.addProjectPermission(UserRole.USER, project);
db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED));
@Test
public void return_events() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey("P1"));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setKey("P1"));
userSession.addProjectPermission(UserRole.USER, project);
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
- SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto(organizationDto)).setUuid("A42"));
+ SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(ComponentTesting.newPrivateProjectDto(organizationDto)).setUuid("A42"));
EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1"));
EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2"));
db.events().insertEvent(newEvent(a42));
@Test
public void paginate_analyses() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
IntStream.rangeClosed(1, 9).forEach(i -> db.components().insertSnapshot(newAnalysis(project).setCreatedAt(1_000_000L * i).setUuid("A" + i)));
@Test
public void filter_by_category() {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("P1"));
userSession.addProjectPermission(UserRole.USER, project);
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2"));
@Test
public void paginate_with_filter_on_category() {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("P1"));
userSession.addProjectPermission(UserRole.USER, project);
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
@Test
public void fail_if_not_enough_permissions() {
userSession.anonymous();
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
expectedException.expect(ForbiddenException.class);
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.server.exceptions.ForbiddenException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.util.Protobuf.setNullable;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.event.EventTesting.newEvent;
import static org.sonar.test.JsonAssert.assertJson;
@Test
public void json_example() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setUuid("A2"));
db.events().insertEvent(newEvent(analysis)
.setUuid("E1")
@Test
public void throw_ForbiddenException_if_not_project_administrator() {
- ComponentDto project = newProjectDto(db.organizations().insert());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
db.events().insertEvent(newEvent(analysis).setUuid("E1"));
userSession.logIn().addProjectPermission(UserRole.USER, project);
}
private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion(version));
logInAsProjectAdministrator(project);
return analysis;
private ComponentDto insertProject() {
OrganizationDto org = db.organizations().insert();
return db.components().insertComponent(
- ComponentTesting.newProjectDto(org, PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentTesting.newPrivateProjectDto(org, PROJECT_UUID).setKey(PROJECT_KEY));
}
private void createAndTest(ComponentDto project, String name, String url, String type) throws IOException {
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_ID;
@Test
public void request_does_not_fail_when_link_has_no_name() throws IOException {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setType("type");
insertLink(foo);
logInAsProjectAdministrator(project);
@Test
public void request_does_not_fail_when_link_has_no_type() throws IOException {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setName("name");
insertLink(foo);
logInAsProjectAdministrator(project);
}
private ComponentDto insertProject(String projectKey, String projectUuid) {
- return componentDb.insertComponent(newProjectDto(db.organizations().insert(), projectUuid).setKey(projectKey));
+ return componentDb.insertComponent(newPrivateProjectDto(db.organizations().insert(), projectUuid).setKey(projectKey));
}
private ComponentDto insertProject() {
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.server.es.EsTester;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.util.Protobuf.setNullable;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES;
import static org.sonar.test.JsonAssert.assertJson;
}
private static ProjectMeasuresDoc newDoc() {
- return newDoc(newProjectDto(ORG));
+ return newDoc(ComponentTesting.newPrivateProjectDto(ORG));
}
private SearchResponse call(@Nullable String textQuery, @Nullable Integer pageSize) {
@Before
public void setUp() {
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
}
@Test
@Test
public void reset_tags() {
- project = db.components().insertProject(p -> p.setTagsString("platform,scanner"));
+ project = db.components().insertPrivateProject(p -> p.setTagsString("platform,scanner"));
call(project.key(), "");
@Test
public void override_existing_tags() {
- project = db.components().insertProject(p -> p.setTagsString("marketing,languages"));
+ project = db.components().insertPrivateProject(p -> p.setTagsString("marketing,languages"));
call(project.key(), "finance,offshore,platform");
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.property.PropertyDbTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
import static org.sonar.test.JsonAssert.assertJson;
@Before
public void setUp() throws Exception {
- project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
}
@Test
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.qualitygate.ProjectQgateAssociation;
import static com.google.common.collect.FluentIterable.from;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.qualitygate.ProjectQgateAssociationQuery.IN;
import static org.sonar.db.qualitygate.ProjectQgateAssociationQuery.OUT;
import static org.sonar.db.qualitygate.ProjectQgateAssociationQuery.builder;
@Test
public void return_all_projects() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
- ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
+ ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@Test
public void return_only_associated_project() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
- insertProjectAuthorizedToAnyone(newProjectDto(org));
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
+ insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@Test
public void return_only_unassociated_project() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
- ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
+ ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
public void return_only_authorized_projects() throws Exception {
UserDto user = dbTester.users().insertUser("a_login");
OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project1 = componentDbTester.insertComponent(newProjectDto(organizationDto));
- componentDbTester.insertComponent(newProjectDto(organizationDto));
+ ComponentDto project1 = componentDbTester.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
+ componentDbTester.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
// User can only see project 1
dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, project1);
@Test
public void do_not_verify_permissions_if_user_is_root() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project = componentDbTester.insertProject(org);
+ ComponentDto project = componentDbTester.insertPrivateProject(org);
ProjectQgateAssociationQuery query = builder()
.gateId(Long.toString(qGate.getId()))
.build();
@Test
public void test_paging() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project1 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 1"));
- ComponentDto project2 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 2"));
- ComponentDto project3 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 3"));
+ ComponentDto project1 = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org).setName("Project 1"));
+ ComponentDto project2 = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org).setName("Project 2"));
+ ComponentDto project3 = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org).setName("Project 3"));
associateProjectToQualitGate(project1.getId());
// Return partial result on first page
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.server.exceptions.NotFoundException;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
public class QualityGateFinderTest {
@Test
public void return_default_quality_gate_for_project() {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
QualityGateDto dbQualityGate = dbTester.qualityGates().createDefaultQualityGate("Sonar way");
Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, project.getId());
@Test
public void return_project_quality_gate_over_default() {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
dbTester.qualityGates().createDefaultQualityGate("Sonar way");
QualityGateDto dbQualityGate = dbTester.qualityGates().insertQualityGate("My team QG");
dbTester.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
@Test
public void return_nothing_when_no_default_qgate_and_no_qgate_defined_for_project() {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, project.getId());
@Test
public void fail_when_default_qgate_defined_in_properties_does_not_exists() throws Exception {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
QualityGateDto dbQualityGate = dbTester.qualityGates().createDefaultQualityGate("Sonar way");
dbTester.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
@Test
public void fail_when_project_qgate_defined_in_properties_does_not_exists() throws Exception {
- ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()));
+ ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()));
QualityGateDto dbQualityGate = dbTester.qualityGates().insertQualityGate("My team QG");
dbTester.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
dbTester.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
@RunWith(MockitoJUnitRunner.class)
public class QualityGatesTest {
when(dbClient.componentDao()).thenReturn(componentDao);
when(componentDao.selectOrFailById(eq(dbSession), anyLong())).thenReturn(
- newProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setId(1L).setKey(PROJECT_KEY));
+ newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setId(1L).setKey(PROJECT_KEY));
underTest = new QualityGates(dbClient, metricFinder, userSession);
underTest = new DeselectAction(qualityGates, dbClient, componentFinder);
ws = new WsActionTester(underTest);
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
gate = insertQualityGate();
}
public void deselect_by_id() throws Exception {
logInAsRoot();
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
String gateId = String.valueOf(gate.getId());
associateProjectToQualityGate(project.getId(), gateId);
associateProjectToQualityGate(anotherProject.getId(), gateId);
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonarqube.ws.WsQualityGates.GetByProjectWsResponse;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY;
@Test
public void json_example() {
OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = componentDb.insertComponent(newProjectDto(organizationDto));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
QualityGateDto qualityGate = insertQualityGate("My team QG");
associateProjectToQualityGate(project.getId(), qualityGate.getId());
logInAsProjectUser(project);
@Test
public void empty_response() {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
insertQualityGate("Another QG");
logInAsProjectUser(project);
@Test
public void default_quality_gate() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
setDefaultQualityGate(dbQualityGate.getId());
logInAsProjectUser(project);
@Test
public void project_quality_gate_over_default() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
QualityGateDto defaultDbQualityGate = insertQualityGate("Sonar way");
QualityGateDto dbQualityGate = insertQualityGate("My team QG");
setDefaultQualityGate(defaultDbQualityGate.getId());
@Test
public void get_by_project_key() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
QualityGateDto dbQualityGate = insertQualityGate("My team QG");
associateProjectToQualityGate(project.getId(), dbQualityGate.getId());
logInAsProjectUser(project);
@Test
public void get_with_project_admin_permission() {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
setDefaultQualityGate(dbQualityGate.getId());
@Test
public void get_with_project_user_permission() {
- ComponentDto project = componentDb.insertProject();
+ ComponentDto project = componentDb.insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
setDefaultQualityGate(dbQualityGate.getId());
@Test
public void fail_when_insufficient_permission() {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
userSession.logIn();
QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
setDefaultQualityGate(dbQualityGate.getId());
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.component.ComponentFinder;
import org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse.Status;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
@Test
public void json_example() throws IOException {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
userSession.addProjectPermission(UserRole.USER, project);
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
@Test
public void return_status_by_project_id() throws IOException {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodMode("last_version")
.setPeriodParam("2015-12-07")
@Test
public void return_status_by_project_key() throws IOException {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("project-key"));
+ ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("project-key"));
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodMode("last_version")
.setPeriodParam("2015-12-07")
@Test
public void return_undefined_status_if_measure_is_not_found() {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
userSession.addProjectPermission(UserRole.USER, project);
@Test
public void return_undefined_status_if_snapshot_is_not_found() {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
userSession.addProjectPermission(UserRole.USER, project);
ProjectStatusWsResponse result = callByProjectUuid(project.uuid());
@Test
public void project_administrator_is_allowed_to_get_project_status() {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
userSession.addProjectPermission(UserRole.ADMIN, project);
@Test
public void project_user_is_allowed_to_get_project_status() {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
userSession.addProjectPermission(UserRole.USER, project);
@Test
public void fail_if_insufficient_privileges() {
- ComponentDto project = db.components().insertProject(db.organizations().insert());
+ ComponentDto project = db.components().insertPrivateProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
userSession.logIn();
ComponentFinder componentFinder = new ComponentFinder(dbClient);
underTest = new SelectAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- project = db.components().insertProject();
+ project = db.components().insertPrivateProject();
gate = insertQualityGate();
}
private QualityProfileDto createRandomProfile(OrganizationDto org) {
QualityProfileDto profile = db.qualityProfiles().insert(org);
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.qualityProfiles().associateProjectWithQualityProfile(project, profile);
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
.setProfileId(profile.getId())
@Test
public void add_project_on_profile_of_default_organization() {
logInAsProfileAdmin(db.getDefaultOrganization());
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
TestResponse response = call(project, profile);
public void add_project_on_profile_of_specified_organization() {
OrganizationDto org1 = db.organizations().insert();
logInAsProfileAdmin(org1);
- ComponentDto project = db.components().insertProject(org1);
+ ComponentDto project = db.components().insertPrivateProject(org1);
QualityProfileDto profile = db.qualityProfiles().insert(org1, p -> p.setLanguage(LANGUAGE_1));
TestResponse response = call(org1, project, profile);
OrganizationDto org1 = db.organizations().insert();
OrganizationDto org2 = db.organizations().insert();
logInAsProfileAdmin(org1);
- ComponentDto project = db.components().insertProject(org1);
+ ComponentDto project = db.components().insertPrivateProject(org1);
QualityProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
expectedException.expect(IllegalArgumentException.class);
OrganizationDto org1 = db.organizations().insert();
OrganizationDto org2 = db.organizations().insert();
logInAsProfileAdmin(org1);
- ComponentDto project = db.components().insertProject(org1);
+ ComponentDto project = db.components().insertPrivateProject(org1);
QualityProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
expectedException.expect(NotFoundException.class);
public void change_association_in_default_organization() throws Exception {
logInAsProfileAdmin(db.getDefaultOrganization());
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
// two profiles on same language
QualityProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
QualityProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
@Test
public void changing_association_does_not_change_other_language_associations() throws Exception {
logInAsProfileAdmin(db.getDefaultOrganization());
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile1Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
QualityProfileDto profile2Language2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
QualityProfileDto profile3Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
@Test
public void project_administrator_can_change_profile() throws Exception {
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@Test
public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
userSession.logIn();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(ForbiddenException.class);
@Test
public void throw_UnauthorizedException_if_not_logged_in() {
userSession.anonymous();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(UnauthorizedException.class);
@Test
public void throw_NotFoundException_if_profile_does_not_exist() {
logInAsProfileAdmin(db.getDefaultOrganization());
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Quality Profile with key 'unknown' does not exist");
@Test
public void delete_profile_by_key() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
QualityProfileDto profile1 = createProfile(organization);
QualityProfileDto profile2 = createProfile(organization);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
@Test
public void delete_profile_by_language_and_name_in_default_organization() throws Exception {
OrganizationDto organization = dbTester.getDefaultOrganization();
- ComponentDto project = dbTester.components().insertProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
QualityProfileDto profile1 = createProfile(organization);
QualityProfileDto profile2 = createProfile(organization);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
@Test
public void delete_profile_by_language_and_name_in_specified_organization() {
OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
QualityProfileDto profile1 = createProfile(organization);
QualityProfileDto profile2 = createProfile(organization);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
}
private ComponentDto newProject(String uuid, String name) {
- return ComponentTesting.newProjectDto(organizationDto, uuid).setName(name);
+ return ComponentTesting.newPrivateProjectDto(organizationDto, uuid).setName(name);
}
private void addBrowsePermissionToAnyone(ComponentDto... projects) {
public void remove_profile_from_project_in_default_organization() {
logInAsProfileAdmin();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profileLang1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
QualityProfileDto profileLang2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
db.qualityProfiles().associateProjectWithQualityProfile(project, profileLang1);
public void removal_does_not_fail_if_profile_is_not_associated_to_project() {
logInAsProfileAdmin();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
TestResponse response = call(project, profile);
@Test
public void project_administrator_can_remove_profile() throws Exception {
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
db.qualityProfiles().associateProjectWithQualityProfile(project, profile);
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@Test
public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
userSession.logIn();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(ForbiddenException.class);
@Test
public void throw_UnauthorizedException_if_not_logged_in() {
userSession.anonymous();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(UnauthorizedException.class);
@Test
public void throw_NotFoundException_if_profile_does_not_exist() {
logInAsProfileAdmin();
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Quality Profile with key 'unknown' does not exist");
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.utils.DateUtils.parseDateTime;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS;
.setDefault(true);
qualityProfileDao.insert(dbSession, defaultProfile, parentProfile, childProfile, profileOnUnknownLang);
- ComponentDto project1 = db.components().insertProject(organization);
- ComponentDto project2 = db.components().insertProject(organization);
+ ComponentDto project1 = db.components().insertPrivateProject(organization);
+ ComponentDto project2 = db.components().insertPrivateProject(organization);
db.qualityProfiles().associateProjectWithQualityProfile(project1, parentProfile);
db.qualityProfiles().associateProjectWithQualityProfile(project2, parentProfile);
.setRulesUpdatedAt("2016-12-21T19:10:03+0100")
.setLastUsed(time)
.setName("Another way");
- ComponentDto project = newProjectDto(org, "project-uuid");
+ ComponentDto project = newPrivateProjectDto(org, "project-uuid");
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
qualityProfileDb.insertProjectWithQualityProfileAssociations(project, qualityProfileOnXoo1, qualityProfileOnXoo2);
.setName("Another way")
.setDefault(true);
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
- ComponentDto project = componentDb.insertComponent(newProjectDto(org, "project-uuid"));
+ ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(org, "project-uuid"));
String result = ws.newRequest()
.setParam(PARAM_ORGANIZATION, org.getKey())
@Test
public void name_and_component_query_is_valid() throws Exception {
minimalValidSetup();
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
SearchWsRequest request = new SearchWsRequest()
.setProfileName("bla")
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileLookup;
-import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonarqube.ws.client.qualityprofile.SearchWsRequest;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
}
private ComponentDto insertProject() {
- ComponentDto project = dbTester.components().insertProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject(organization);
doReturn(project).when(componentFinder).getByKey(any(DbSession.class), eq(project.getKey()));
return project;
}
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.SCAN;
import static org.sonarqube.ws.MediaTypes.JSON;
@Before
public void setUp() throws Exception {
- project = componentDb.insertComponent(newProjectDto(db.organizations().insert()));
+ project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
}
@Test
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.property.PropertyDbTester;
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
import static org.sonar.db.property.PropertyTesting.newUserPropertyDto;
@Before
public void setUp() throws Exception {
- project = componentDb.insertComponent(newProjectDto(db.organizations().insert()));
+ project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
}
@Test
@Test
public void persist_new_project_setting() {
propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
logInAsProjectAdministrator(project);
callForProjectSettingByKey("my.key", "my project value", project.key());
@Test
public void persist_project_property_with_project_admin_permission() {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
logInAsProjectAdministrator(project);
callForProjectSettingByKey("my.key", "my value", project.key());
@Test
public void update_existing_project_setting() {
propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project));
assertComponentSetting("my.key", "my project value", project.getId());
logInAsProjectAdministrator(project);
.type(PropertyType.STRING)
.build()))
.build());
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
propertyDb.insertProperties(
newGlobalPropertyDto("my.key", "1"),
newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"),
.fields(newArrayList(PropertyFieldDefinition.build("firstField").name("First Field").type(PropertyType.STRING).build()))
.build());
i18n.put("qualifier." + Qualifiers.PROJECT, "Project");
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
logInAsProjectAdministrator(project);
expectedException.expect(BadRequestException.class);
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.property.PropertyDto;
import static com.google.common.collect.Sets.newHashSet;
import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.PropertyType.PROPERTY_SET;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
@Test
public void return_component_settings() throws Exception {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
addDefinitions(PropertyDefinition.builder("property").defaultValue("default").build());
insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one"));
@Test
public void return_component_setting_even_if_no_definition() throws Exception {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one"));
Multimap<String, Setting> settings = underTest.loadComponentSettings(dbSession, newHashSet("property"), project);
@Test
public void return_component_settings_with_property_set() throws Exception {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
addDefinitions(PropertyDefinition.builder("set1")
.type(PROPERTY_SET)
.fields(asList(
@Test
public void return_module_settings() throws Exception {
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
ComponentDto module = componentDb.insertComponent(newModuleDto(project));
ComponentDto subModule = componentDb.insertComponent(newModuleDto(module));
- ComponentDto anotherProject = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
+ ComponentDto anotherProject = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
insertProperties(
newComponentPropertyDto(project).setKey("property").setValue("one"),
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.property.PropertyDbTester;
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
import static org.sonar.db.property.PropertyTesting.newUserPropertyDto;
@Before
public void setUp() throws Exception {
- project = componentDb.insertComponent(newProjectDto(db.organizations().insert()));
+ project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()));
}
@Test
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.property.PropertyDbTester;
import org.sonar.server.component.ComponentFinder;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.SCAN;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
@Before
public void setUp() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
- project = componentDb.insertComponent(newProjectDto(organizationDto));
+ project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
}
@Test
@Test
public void get_json() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(CODEVIEWER, project);
ComponentDto file = db.components().insertComponent(newFileDto(project));
insertFileWithData(file, newData("public class HelloWorld {", "}"));
@Test
public void limit_range() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(CODEVIEWER, project);
ComponentDto file = db.components().insertComponent(newFileDto(project));
insertFileWithData(file, newData("/**", " */", "public class HelloWorld {", "}", "", "foo"));
@Test
public void fail_when_missing_code_viewer_permission() throws Exception {
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
ComponentDto file = db.components().insertComponent(newFileDto(project));
componentDao = new ComponentDao();
wsTester = new WsTester(new SourcesWs(
new LinesAction(new ComponentFinder(dbTester.getDbClient()), dbTester.getDbClient(), sourceService, htmlSourceDecorator, userSessionRule)));
- project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
+ project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
}
WsTester tester;
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
@Before
tester = new WsTester(
new SourcesWs(new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), userSessionRule, new ComponentFinder(dbClient))));
- project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
+ project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
dbClient.componentDao().insert(dbTester.getSession(), project, file);
dbTester.getSession().commit();
@Mock
ComponentDao componentDao;
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto());
ComponentDto file = ComponentTesting.newFileDto(project, null);
@Before
@Test
public void display_log_on_deprecated_project() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(organizationDto)
+ dbClient.componentDao().insert(dbSession, ComponentTesting.newPrivateProjectDto(organizationDto)
.setKey(DEPRECATED_PROJECT_KEY)
.setDeprecatedKey(null));
dbSession.commit();
@Test
public void not_display_log_when_task_already_executed() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(organizationDto)
+ dbClient.componentDao().insert(dbSession, ComponentTesting.newPrivateProjectDto(organizationDto)
.setKey(DEPRECATED_PROJECT_KEY)
.setDeprecatedKey(null));
dbSession.commit();
@Test
public void nothing_do_when_no_deprecated_project() throws Exception {
OrganizationDto organizationDto = dbTester.organizations().insert();
- dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(organizationDto)
+ dbClient.componentDao().insert(dbSession, ComponentTesting.newPrivateProjectDto(organizationDto)
.setKey(PROJECT_KEY)
.setDeprecatedKey(PROJECT_KEY));
dbSession.commit();
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.server.test.ws.CoveredFilesAction.TEST_ID;
import static org.sonar.test.JsonAssert.assertJson;
@Test
public void covered_files() {
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "SonarQube");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "SonarQube");
ComponentDto file = ComponentTesting.newFileDto(project, null, "test-file-uuid");
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
when(dbClient.componentDao().selectByUuids(any(DbSession.class), anyList())).thenReturn(
Arrays.asList(
- newFileDto(newProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"),
- newFileDto(newProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
+ newFileDto(ComponentTesting.newPrivateProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"),
+ newFileDto(ComponentTesting.newPrivateProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
TestRequest request = ws.newRequest().setParam(TEST_ID, "test-uuid");
@Test
public void fail_when_test_uuid_is_unknown() {
- ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "SonarQube");
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "SonarQube");
ComponentDto file = ComponentTesting.newFileDto(project);
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
when(dbClient.componentDao().selectByUuids(any(DbSession.class), anyList())).thenReturn(
Arrays.asList(
- newFileDto(newProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"),
- newFileDto(newProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
+ newFileDto(ComponentTesting.newPrivateProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"),
+ newFileDto(ComponentTesting.newPrivateProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Test with id 'test-uuid' is not found");
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.protobuf.DbFileSources;
import org.sonar.db.source.FileSourceDto;
import org.sonar.server.component.ComponentFinder;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.protobuf.DbFileSources.Test.TestStatus.OK;
import static org.sonar.server.test.db.TestTesting.newTest;
import static org.sonar.server.test.ws.ListAction.SOURCE_FILE_ID;
@Before
public void setUp() throws Exception {
- project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()));
+ project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
mainFile = db.components().insertComponent(newFileDto(project));
testFile = db.components().insertComponent(newFileDto(project).setQualifier(UNIT_TEST_FILE));
}
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
@Before
public void before() {
OrganizationDto organization = dbTester.organizations().insertForKey("my-org");
- project = newProjectDto(organization, "abcd")
+ project = newPrivateProjectDto(organization, "abcd")
.setKey("polop")
.setName("Polop")
.setDescription("test project")
public void test_example_response() throws Exception {
init(createPages());
OrganizationDto organizationDto = dbTester.organizations().insertForKey("my-org-1");
- ComponentDto project = newProjectDto(organizationDto, "ABCD")
+ ComponentDto project = newPrivateProjectDto(organizationDto, "ABCD")
.setKey("org.codehaus.sonar:sonar")
.setName("Sonarqube")
.setDescription("Open source platform for continuous inspection of code quality");
public void canApplyPermissionTemplate_is_true_if_logged_in_as_organization_administrator() {
init(createPages());
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertProject(org);
+ ComponentDto project = dbTester.components().insertPrivateProject(org);
userSession.logIn()
.addProjectPermission(UserRole.ADMIN, project)
@Before
public void setUp() throws Exception {
organization = db.organizations().insert();
- publicProject = db.components().insertProject(organization, PUBLIC_PROJECT_UUID);
- privateProject = db.components().insertProject(organization, dto -> dto.setUuid(PRIVATE_PROJECT_UUID).setProjectUuid(PRIVATE_PROJECT_UUID).setPrivate(true));
+ publicProject = db.components().insertPublicProject(organization, PUBLIC_PROJECT_UUID);
+ privateProject = db.components().insertPrivateProject(organization, dto -> dto.setUuid(PRIVATE_PROJECT_UUID).setProjectUuid(PRIVATE_PROJECT_UUID).setPrivate(true));
db.components().insertComponent(ComponentTesting.newFileDto(publicProject, null, FILE_UUID).setKey(FILE_KEY));
user = db.users().insertUser(LOGIN);
groupOfUser = db.users().insertGroup(organization);
@Test
public void test_hasPermission_on_organization_for_logged_in_user() {
OrganizationDto org = db.organizations().insert();
- ComponentDto project = db.components().insertProject(org);
+ ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertPermissionOnUser(org, user, PROVISION_PROJECTS);
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, project);
public void deactivate_user_deletes_his_properties() {
logInAsSystemAdministrator();
UserDto user = insertUser(newUserDto());
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.properties().insertProperty(newUserPropertyDto(user));
db.properties().insertProperty(newUserPropertyDto(user));
db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId()));
public void deactivate_user_deletes_his_permissions() {
logInAsSystemAdministrator();
UserDto user = insertUser(newUserDto());
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
db.users().insertPermissionOnUser(user, SCAN);
db.users().insertPermissionOnUser(user, ADMINISTER_QUALITY_PROFILES);
db.users().insertProjectPermissionOnUser(user, USER, project);
public void deactivate_user_deletes_his_default_assignee_settings() {
logInAsSystemAdministrator();
UserDto user = insertUser(newUserDto());
- ComponentDto project = db.components().insertProject();
- ComponentDto anotherProject = db.components().insertProject();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(project.getId()));
db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(anotherProject.getId()));
db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setResourceId(anotherProject.getId()));
addAdminToDefaultOrganization();
insertDefaultGroupOnDefaultOrganization();
GroupDto group = db.users().insertGroup();
- ComponentDto project = componentTester.insertComponent(ComponentTesting.newProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = componentTester.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, project);
loginAsAdminOnDefaultOrganization();
}
private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto org) {
- ComponentDto project = ComponentTesting.newProjectDto(org);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(org);
ComponentDto file = ComponentTesting.newFileDto(project, null);
dbTester.components().insertComponents(project, file);
dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.webhook.WebhookDeliveryDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonarqube.ws.Webhooks;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.webhook.WebhookDbTesting.newWebhookDeliveryDto;
import static org.sonar.test.JsonAssert.assertJson;
ComponentFinder componentFinder = new ComponentFinder(dbClient);
WebhookDeliveriesAction underTest = new WebhookDeliveriesAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("my-project"));
+ project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("my-project"));
}
@Test
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.webhook.WebhookDeliveryDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonarqube.ws.Webhooks;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.webhook.WebhookDbTesting.newWebhookDeliveryDto;
import static org.sonar.test.JsonAssert.assertJson;
ComponentFinder componentFinder = new ComponentFinder(dbClient);
WebhookDeliveryAction underTest = new WebhookDeliveryAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("my-project"));
+ project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("my-project"));
}
@Test