Search in sources :

Example 1 with APP

use of org.sonar.api.resources.Qualifiers.APP in project sonarqube by SonarSource.

the class SuggestionsActionTest method should_only_provide_project_for_certain_qualifiers.

@Test
public void should_only_provide_project_for_certain_qualifiers() {
    String query = randomAlphabetic(10);
    ComponentDto app = db.components().insertPublicApplication(v -> v.setName(query));
    ComponentDto view = db.components().insertPublicPortfolio(v -> v.setName(query));
    ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view).setName(query));
    ComponentDto project = db.components().insertPrivateProject(p -> p.setName(query));
    ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query));
    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query));
    ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE));
    componentIndexer.indexAll();
    authorizationIndexerTester.allowOnlyAnyone(project);
    authorizationIndexerTester.allowOnlyAnyone(view);
    authorizationIndexerTester.allowOnlyAnyone(app);
    SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, project.name()).executeProtobuf(SuggestionsWsResponse.class);
    assertThat(response.getResultsList()).extracting(Category::getQ, c -> c.getItemsList().stream().map(Suggestion::hasProject).findFirst().orElse(null)).containsExactlyInAnyOrder(tuple(SuggestionCategory.APP.getName(), false), tuple(SuggestionCategory.VIEW.getName(), false), tuple(SuggestionCategory.SUBVIEW.getName(), false), tuple(SuggestionCategory.PROJECT.getName(), false));
}
Also used : PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) IntStream.range(java.util.stream.IntStream.range) ComponentIndexer(org.sonar.server.component.index.ComponentIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FILE(org.sonar.api.resources.Qualifiers.FILE) PARAM_RECENTLY_BROWSED(org.sonar.server.component.ws.SuggestionsAction.PARAM_RECENTLY_BROWSED) Collections.singletonList(java.util.Collections.singletonList) WebService(org.sonar.api.server.ws.WebService) Arrays.asList(java.util.Arrays.asList) PARAM_MORE(org.sonar.server.component.ws.SuggestionsAction.PARAM_MORE) ComponentTesting.newPublicProjectDto(org.sonar.db.component.ComponentTesting.newPublicProjectDto) ComponentTesting(org.sonar.db.component.ComponentTesting) ResourceTypesRule(org.sonar.db.component.ResourceTypesRule) Mockito.doReturn(org.mockito.Mockito.doReturn) FavoriteFinder(org.sonar.server.favorite.FavoriteFinder) DbTester(org.sonar.db.DbTester) APP(org.sonar.api.resources.Qualifiers.APP) System2(org.sonar.api.utils.System2) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Collectors(java.util.stream.Collectors) Suggestion(org.sonarqube.ws.Components.SuggestionsWsResponse.Suggestion) Collectors.joining(java.util.stream.Collectors.joining) ComponentDto(org.sonar.db.component.ComponentDto) List(java.util.List) Stream(java.util.stream.Stream) VIEW(org.sonar.api.resources.Qualifiers.VIEW) SUBVIEW(org.sonar.api.resources.Qualifiers.SUBVIEW) Mockito.mock(org.mockito.Mockito.mock) EsTester(org.sonar.server.es.EsTester) SHORT_INPUT_WARNING(org.sonar.server.component.ws.SuggestionsAction.SHORT_INPUT_WARNING) PROJECT(org.sonar.api.resources.Qualifiers.PROJECT) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) MediaTypes(org.sonarqube.ws.MediaTypes) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) USER(org.sonar.api.web.UserRole.USER) Optional.ofNullable(java.util.Optional.ofNullable) TestRequest(org.sonar.server.ws.TestRequest) PARAM_QUERY(org.sonar.server.component.ws.SuggestionsAction.PARAM_QUERY) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) Rule(org.junit.Rule) Qualifiers(org.sonar.api.resources.Qualifiers) UNIT_TEST_FILE(org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE) Change(org.sonar.api.server.ws.Change) ComponentIndex(org.sonar.server.component.index.ComponentIndex) Category(org.sonarqube.ws.Components.SuggestionsWsResponse.Category) MODULE(org.sonar.api.resources.Qualifiers.MODULE) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) TestResponse(org.sonar.server.ws.TestResponse) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) Suggestion(org.sonarqube.ws.Components.SuggestionsWsResponse.Suggestion) ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 2 with APP

use of org.sonar.api.resources.Qualifiers.APP in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method search_by_application_key_and_branch.

@Test
public void search_by_application_key_and_branch() {
    ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app"));
    ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1"));
    ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1"));
    ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
    ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
    ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2"));
    db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
    db.components().insertComponents(newProjectCopy(project2, applicationBranch1));
    db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2));
    // Search on applicationBranch1
    assertThat(underTest.create(new SearchRequest().setComponents(singletonList(applicationBranch1.getKey())).setBranch(applicationBranch1.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch).containsOnly(applicationBranch1.uuid(), Collections.emptyList(), false);
    // Search on project1Branch1
    assertThat(underTest.create(new SearchRequest().setComponents(singletonList(applicationBranch1.getKey())).setProjects(singletonList(project1.getKey())).setBranch(applicationBranch1.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch).containsOnly(applicationBranch1.uuid(), singletonList(project1.uuid()), false);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RuleDbTester(org.sonar.db.rule.RuleDbTester) RuleTesting.newRule(org.sonar.db.rule.RuleTesting.newRule) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) DateUtils.addDays(org.sonar.api.utils.DateUtils.addDays) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) APP(org.sonar.api.resources.Qualifiers.APP) REFERENCE_BRANCH(org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ZoneId(java.time.ZoneId) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTesting.newSubPortfolio(org.sonar.db.component.ComponentTesting.newSubPortfolio) Rule(org.junit.Rule) Qualifiers(org.sonar.api.resources.Qualifiers) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) RuleKey(org.sonar.api.rule.RuleKey) Clock(java.time.Clock) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) SearchRequest(org.sonar.server.issue.SearchRequest) ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 Mockito.mock (org.mockito.Mockito.mock)2 Qualifiers (org.sonar.api.resources.Qualifiers)2 APP (org.sonar.api.resources.Qualifiers.APP)2 USER (org.sonar.api.web.UserRole.USER)2 DbTester (org.sonar.db.DbTester)2 ComponentDto (org.sonar.db.component.ComponentDto)2 ComponentTesting.newModuleDto (org.sonar.db.component.ComponentTesting.newModuleDto)2 Clock (java.time.Clock)1 ZoneId (java.time.ZoneId)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1