import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
OrganizationDto organizationDto = db.organizations().insert();
db.components().insertProjectAndSnapshot(newProjectDto(organizationDto).setName("aaaa-name"));
db.components().insertProjectAndSnapshot(newView(organizationDto));
- db.components().insertProjectAndSnapshot(newDeveloper(organizationDto, "project-name"));
for (int i = 9; i >= 1; i--) {
db.components().insertProjectAndSnapshot(newProjectDto(organizationDto).setName("project-" + i));
}
import org.sonar.db.organization.OrganizationDto;
import static java.util.Arrays.asList;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
return insertComponentAndSnapshot(component);
}
- public SnapshotDto insertDeveloperAndSnapshot(ComponentDto component) {
- return insertComponentAndSnapshot(component);
- }
-
private SnapshotDto insertComponentAndSnapshot(ComponentDto component) {
dbClient.componentDao().insert(dbSession, component);
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(component));
return insertComponentImpl(newView(organizationDto, uuid), noExtraConfiguration());
}
- public ComponentDto insertDeveloper(String name, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(newDeveloper(db.getDefaultOrganization(), name), dtoPopulator);
- }
-
- public ComponentDto insertDeveloper(String name) {
- return insertComponentImpl(newDeveloper(db.getDefaultOrganization(), name), noExtraConfiguration());
- }
-
- public ComponentDto insertDeveloper(String name, String uuid) {
- return insertComponentImpl(newDeveloper(db.getDefaultOrganization(), name, uuid), noExtraConfiguration());
- }
-
private static <T> Consumer<T> noExtraConfiguration() {
return (t) -> {
};
.setEnabled(true);
}
- public static ComponentDto newDeveloper(OrganizationDto organizationDto, String name) {
- return newDeveloper(organizationDto.getUuid(), name, Uuids.createFast());
- }
-
- public static ComponentDto newDeveloper(OrganizationDto organizationDto, String name, String uuid) {
- return newDeveloper(organizationDto.getUuid(), name, uuid);
- }
-
- private static ComponentDto newDeveloper(String organizationUuid, String name, String uuid) {
- return new ComponentDto()
- .setOrganizationUuid(organizationUuid)
- .setUuid(uuid)
- .setUuidPath(ComponentDto.UUID_PATH_OF_ROOT)
- .setProjectUuid(uuid)
- .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
- .setRootUuid(uuid)
- .setKey(uuid)
- .setName(name)
- .setLongName(name)
- .setScope(Scopes.PROJECT)
- // XXX No constant !
- .setQualifier("DEV")
- .setPath(null)
- .setLanguage(null)
- .setEnabled(true);
- }
-
public static ComponentDto newView(OrganizationDto organizationDto) {
return newView(organizationDto.getUuid(), Uuids.createFast());
}
.setLanguage(null);
}
- public static ComponentDto newDevProjectCopy(String uuid, ComponentDto project, ComponentDto developer) {
- checkNotNull(project.getId(), "The project need to be persisted before creating this technical project.");
- return newChildComponent(uuid, developer, developer)
- .setUuid(uuid)
- .setKey(developer.key() + ":" + project.key())
- .setName(project.name())
- .setLongName(project.longName())
- .setCopyComponentUuid(project.uuid())
- .setScope(Scopes.PROJECT)
- .setQualifier("DEV_PRJ")
- .setPath(null)
- .setLanguage(null);
- }
-
public static ComponentDto newChildComponent(String uuid, ComponentDto moduleOrProject, ComponentDto parent) {
return new ComponentDto()
.setOrganizationUuid(parent.getOrganizationUuid())
package org.sonar.db.measure;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactoryImpl;
import org.sonar.db.DbClient;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.component.SnapshotTesting;
-import org.sonar.db.organization.OrganizationDto;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.resources.Qualifiers.FILE;
-import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
-import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.api.utils.DateUtils.parseDate;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
selectSingle(MeasureQuery.builder().setComponentUuid("C1"));
}
- @Test
- public void selectProjectMeasuresOfDeveloper() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto dev = db.components().insertComponent(newDeveloper(organizationDto, "DEV"));
- insertAnalysis(LAST_ANALYSIS_UUID, dev.uuid(), true);
- insertAnalysis(PREVIOUS_ANALYSIS_UUID, dev.uuid(), false);
- List<Integer> allMetricIds = Arrays.asList(NCLOC_METRIC_ID, COMPLEXITY_METRIC_ID, COVERAGE_METRIC_ID);
- long developerId = dev.getId();
- assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds)).isEmpty();
-
- String projectUuid = insertComponent(Scopes.PROJECT, PROJECT, true);
- String viewUuid = insertComponent(Scopes.PROJECT, VIEW, true);
- String disabledProjectUuid = insertComponent(Scopes.PROJECT, PROJECT, false);
- insertMeasure("M1", LAST_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
- insertMeasure("M2", LAST_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
- insertMeasure("M3", LAST_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
- insertMeasure("M4", PREVIOUS_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
- insertMeasure("M5", PREVIOUS_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
- insertMeasure("M6", PREVIOUS_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
- insertMeasure("M11", LAST_ANALYSIS_UUID, projectUuid, developerId, NCLOC_METRIC_ID);
- insertMeasure("M12", LAST_ANALYSIS_UUID, projectUuid, developerId, COMPLEXITY_METRIC_ID);
- insertMeasure("M13", LAST_ANALYSIS_UUID, projectUuid, developerId, COVERAGE_METRIC_ID);
- insertMeasure("M14", PREVIOUS_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
- insertMeasure("M15", PREVIOUS_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
- insertMeasure("M16", PREVIOUS_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
- insertMeasure("M51", LAST_ANALYSIS_UUID, viewUuid, NCLOC_METRIC_ID);
- insertMeasure("M52", LAST_ANALYSIS_UUID, viewUuid, COMPLEXITY_METRIC_ID);
- insertMeasure("M53", LAST_ANALYSIS_UUID, viewUuid, COVERAGE_METRIC_ID);
- insertMeasure("M54", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, NCLOC_METRIC_ID);
- insertMeasure("M55", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, COMPLEXITY_METRIC_ID);
- insertMeasure("M56", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, COVERAGE_METRIC_ID);
-
- assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds))
- .extracting(MeasureDto::getData)
- .containsOnly("M11", "M12", "M13", "M54", "M55", "M56");
- assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, singletonList(NCLOC_METRIC_ID)))
- .extracting(MeasureDto::getData)
- .containsOnly("M11", "M54");
- }
-
@Test
public void select_tree_by_query() {
ComponentDto project = db.components().insertProject();
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.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
// A view
dbTester.components().insertProjectAndSnapshot(newView(dbTester.getDefaultOrganization()));
- // A developer
- dbTester.components().insertProjectAndSnapshot(newDeveloper(dbTester.getDefaultOrganization(), "dev"));
-
dbSession.commit();
assertResultSetIsEmpty();
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.newDeveloper;
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;
}
@Test
- public void search_activity_returns_views_and_developers() {
+ public void search_activity_returns_views() {
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto apacheView = newView(organizationDto).setName("Apache View").setUuid("V1").setProjectUuid("V1");
- ComponentDto developer = newDeveloper(organizationDto, "Apache Developer").setUuid("D1").setProjectUuid("D1");
- dbTester.components().insertDeveloperAndSnapshot(developer);
dbTester.components().insertViewAndSnapshot(apacheView);
logInAsSystemAdministrator();
- insertActivity("T1", "D1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "V1", CeActivityDto.Status.SUCCESS);
ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac"));
- assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T1", "T2");
+ assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T2");
}
@Test
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.Common;
-import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.WsComponents.Component;
import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse;
import org.sonarqube.ws.client.component.SearchProjectsRequest;
import static org.sonar.api.server.ws.WebService.Param.SORT;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.core.util.stream.MoreCollectors.toList;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
ComponentDto project = newProjectDto(organizationDto).setName("SonarQube");
ComponentDto directory = newDirectory(project, "path");
insertProjectInDbAndEs(project);
- componentDb.insertComponents(newModuleDto(project), newView(organizationDto), newDeveloper(organizationDto, "Sonar Developer"), directory, newFileDto(project, directory));
+ componentDb.insertComponents(newModuleDto(project), newView(organizationDto), directory, newFileDto(project, directory));
SearchProjectsWsResponse result = call(request);
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.ComponentTesting.newDevProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
assertThat(response.getPaging().getPageIndex()).isEqualTo(1);
}
- @Test
- public void return_developers() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid");
- componentDb.insertProjectAndSnapshot(project);
- ComponentDto developer = newDeveloper(db.organizations().insert(), "developer-name");
- componentDb.insertDeveloperAndSnapshot(developer);
- componentDb.insertComponent(newDevProjectCopy("project-copy-uuid", project, developer));
- db.commit();
- logInWithBrowsePermission(developer);
-
- TreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_ID, developer.uuid()).executeProtobuf(TreeWsResponse.class);
-
- assertThat(response.getBaseComponent().getId()).isEqualTo(developer.uuid());
- assertThat(response.getComponentsCount()).isEqualTo(1);
- assertThat(response.getComponents(0).getId()).isEqualTo("project-copy-uuid");
- assertThat(response.getComponents(0).getRefId()).isEqualTo("project-uuid");
- }
-
@Test
public void return_projects_composing_a_view() {
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
ComponentDto project = newProjectDto(organizationDto, "MY_PROJECT_ID")
.setKey("MY_PROJECT_KEY")
.setName("Project Name");
- SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
+ componentDb.insertProjectAndSnapshot(project);
Date now = new Date();
JsonParser jsonParser = new JsonParser();
JsonElement jsonTree = jsonParser.parse(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8));
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.component.SnapshotTesting;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.utils.DateUtils.parseDateTime;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
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.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;
public class ComponentActionTest {
assertThat(response.getComponent().getRefKey()).isEqualTo("project-key");
}
- @Test
- public void developer_measure_by_developer_uuid() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto developer = newDeveloper(organizationDto, "developer-name");
- componentDb.insertDeveloperAndSnapshot(developer);
- ComponentDto project = newProjectDto(organizationDto, "project-uuid");
- SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
- ComponentDto file = newFileDto(project, null, "file-uuid");
- componentDb.insertComponent(file);
- MetricDto ncloc = insertNclocMetric();
- dbClient.measureDao().insert(dbSession,
- newMeasureDto(ncloc, file, projectSnapshot).setValue(42.0d).setDeveloperId(null),
- newMeasureDto(ncloc, file, projectSnapshot).setValue(1984.0d).setDeveloperId(developer.getId()));
- db.commit();
-
- ComponentWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "file-uuid")
- .setParam(PARAM_DEVELOPER_ID, developer.uuid())
- .setParam(PARAM_METRIC_KEYS, "ncloc").executeProtobuf(ComponentWsResponse.class);
-
- assertThat(result.getComponent().getMeasuresCount()).isEqualTo(1);
- assertThat(result.getComponent().getMeasures(0).getValue()).isEqualTo("1984");
- }
-
- @Test
- public void developer_measure_by_developer_key() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto developer = newDeveloper(organizationDto, "developer-name");
- componentDb.insertDeveloperAndSnapshot(developer);
- ComponentDto project = newProjectDto(organizationDto, PROJECT_UUID);
- SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
- ComponentDto file = newFileDto(project, null, "file-uuid");
- componentDb.insertComponent(file);
- MetricDto ncloc = insertNclocMetric();
- dbClient.measureDao().insert(dbSession,
- newMeasureDto(ncloc, file, projectSnapshot).setValue(42.0d).setDeveloperId(null),
- newMeasureDto(ncloc, file, projectSnapshot).setValue(1984.0d).setDeveloperId(developer.getId()));
- db.commit();
-
- ComponentWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "file-uuid")
- .setParam(PARAM_DEVELOPER_KEY, developer.key())
- .setParam(PARAM_METRIC_KEYS, "ncloc").executeProtobuf(ComponentWsResponse.class);
-
- assertThat(result.getComponent().getMeasuresCount()).isEqualTo(1);
- assertThat(result.getComponent().getMeasures(0).getValue()).isEqualTo("1984");
- }
-
@Test
public void fail_when_developer_is_not_found() {
expectedException.expect(NotFoundException.class);
import static org.sonar.api.measures.Metric.ValueType.INT;
import static org.sonar.api.measures.Metric.ValueType.RATING;
import static org.sonar.api.utils.DateUtils.parseDateTime;
-import static org.sonar.db.component.ComponentTesting.newDevProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newDeveloper;
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.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
-import static org.sonar.server.measure.ws.ComponentTreeAction.CHILDREN_STRATEGY;
import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY;
import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT;
import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT;
.doesNotContain("file-uuid-4");
}
- @Test
- public void load_developer_descendants() {
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
- componentDb.insertProjectAndSnapshot(project);
- ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
- componentDb.insertDeveloperAndSnapshot(developer);
- componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
- insertNclocMetric();
- db.commit();
-
- ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_BASE_COMPONENT_ID, developer.uuid())
- .setParam(PARAM_METRIC_KEYS, "ncloc")
- .executeProtobuf(ComponentTreeWsResponse.class);
-
- assertThat(response.getComponentsCount()).isEqualTo(1);
- WsMeasures.Component projectCopy = response.getComponents(0);
- assertThat(projectCopy.getId()).isEqualTo("project-uuid-copy");
- assertThat(projectCopy.getRefId()).isEqualTo("project-uuid");
- assertThat(projectCopy.getRefKey()).isEqualTo("project-key");
- }
-
- @Test
- public void load_developer_measures_by_developer_uuid() {
- ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
- componentDb.insertDeveloperAndSnapshot(developer);
- SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
- ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid"));
- ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file2-uuid"));
- componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
- MetricDto ncloc = insertNclocMetric();
- dbClient.measureDao().insert(dbSession,
- newMeasureDto(ncloc, project, projectSnapshot).setDeveloperId(developer.getId()),
- newMeasureDto(ncloc, file1, projectSnapshot)
- .setValue(3d)
- .setDeveloperId(developer.getId()),
- // measures are not specific to the developer
- newMeasureDto(ncloc, file1, projectSnapshot).setDeveloperId(null),
- newMeasureDto(ncloc, file2, projectSnapshot).setDeveloperId(null));
- db.commit();
-
- ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
- .setParam(PARAM_DEVELOPER_ID, "developer-uuid")
- .setParam(PARAM_STRATEGY, CHILDREN_STRATEGY)
- .setParam(PARAM_METRIC_KEYS, "ncloc")
- .executeProtobuf(ComponentTreeWsResponse.class);
-
- assertThat(response.getComponentsCount()).isEqualTo(2);
- WsMeasures.Component file = response.getComponents(0);
- assertThat(file.getId()).isEqualTo("file1-uuid");
- assertThat(file.getMeasuresCount()).isEqualTo(1);
- assertThat(file.getMeasures(0).getValue()).isEqualTo("3");
- }
-
- @Test
- public void load_developer_measures_by_developer_key() {
- ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
- componentDb.insertDeveloperAndSnapshot(developer);
- SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
- ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid"));
- componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
- MetricDto ncloc = insertNclocMetric();
- dbClient.measureDao().insert(dbSession,
- newMeasureDto(ncloc, file1, projectSnapshot)
- .setValue(3d)
- .setDeveloperId(developer.getId()));
- db.commit();
-
- ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
- .setParam(PARAM_DEVELOPER_KEY, developer.key())
- .setParam(PARAM_METRIC_KEYS, "ncloc")
- .executeProtobuf(ComponentTreeWsResponse.class);
-
- assertThat(response.getComponentsCount()).isEqualTo(1);
- WsMeasures.Component file = response.getComponents(0);
- assertThat(file.getId()).isEqualTo("file1-uuid");
- assertThat(file.getMeasuresCount()).isEqualTo(1);
- assertThat(file.getMeasures(0).getValue()).isEqualTo("3");
- }
-
@Test
public void load_measures_when_no_leave_qualifier() {
resourceTypes.setLeavesQualifiers();
assertThat(result.getComponentsCount()).isEqualTo(0);
}
- @Test
- public void fail_when_developer_is_unknown() {
- expectedException.expect(NotFoundException.class);
-
- ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
- componentDb.insertDeveloperAndSnapshot(developer);
- SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
- ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid"));
- componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
- MetricDto ncloc = insertNclocMetric();
- dbClient.measureDao().insert(dbSession,
- newMeasureDto(ncloc, file1, projectSnapshot)
- .setValue(3d)
- .setDeveloperId(developer.getId()));
- db.commit();
-
- ws.newRequest()
- .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
- .setParam(PARAM_DEVELOPER_KEY, "unknown-developer-key")
- .setParam(PARAM_METRIC_KEYS, "ncloc")
- .executeProtobuf(ComponentTreeWsResponse.class);
- }
-
@Test
public void fail_when_metric_keys_parameter_is_empty() {
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
import static org.sonar.api.server.ws.WebService.Param.PAGE;
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.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
ComponentDto jdk7 = insertJdk7();
ComponentDto project2 = insertClang();
- ComponentDto dev = insertDeveloper();
ComponentDto view = insertView();
insertProjectInView(jdk7, view);
db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnUser(user3, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnUser(user1, UserRole.ISSUE_ADMIN, project2);
- db.users().insertProjectPermissionOnUser(user1, UserRole.ISSUE_ADMIN, dev);
db.users().insertProjectPermissionOnUser(user1, UserRole.ISSUE_ADMIN, view);
// global permission
db.users().insertPermissionOnUser(user1, ADMINISTER);
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group3, UserRole.ADMIN, jdk7);
- db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, dev);
db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, view);
db.commit();
public void filter_by_qualifier() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
db.components().insertComponent(newView(organizationDto, "view-uuid"));
- db.components().insertComponent(newDeveloper(organizationDto, "developer-name"));
db.components().insertComponent(newProjectDto(organizationDto, "project-uuid"));
WsPermissions.SearchProjectPermissionsWsResponse result = newRequest()
assertThat(result.getProjectsList())
.extracting("id")
.contains("project-uuid")
- .doesNotContain("view-uuid")
- .doesNotContain("developer-name");
+ .doesNotContain("view-uuid");
}
@Test
return db.components().insertComponent(newProjectCopy("project-in-view-uuid", project, view));
}
- private ComponentDto insertDeveloper() {
- return db.components().insertComponent(newDeveloper(db.getDefaultOrganization(), "Simon Brandhof")
- .setUuid("4e607bf9-7ed0-484a-946d-d58ba7dab2fb")
- .setKey("simon-brandhof"));
- }
-
private ComponentDto insertClang() {
return db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid-2")
.setName("Clang")
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.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
}
@Test
- public void do_not_return_views_or_developers() {
+ public void do_not_return_views() {
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto jdk7 = insertJdk7(organizationDto);
- ComponentDto dev = insertDeveloper(organizationDto);
ComponentDto view = insertView(organizationDto);
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7);
- db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, dev);
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, view);
SearchMyProjectsWsResponse result = call_ws();
.setKey("Java"));
}
- private ComponentDto insertDeveloper(OrganizationDto organizationDto) {
- return db.components().insertComponent(newDeveloper(organizationDto, "Joda", "4e607bf9-7ed0-484a-946d-d58ba7dab2fb")
- .setKey("joda"));
- }
-
private SearchMyProjectsWsResponse call_ws() {
return ws.newRequest()
.executeProtobuf(SearchMyProjectsWsResponse.class);