Search in sources :

Example 1 with Diff

use of org.sonarqube.ws.Common.Changelog.Diff in project sonarqube by SonarSource.

the class ShowActionTest method verify_response_example.

@Test
public void verify_response_example() {
    ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto.setName("test-project").setLongName("test-project").setDbKey("com.sonarsource:test-project"));
    userSessionRule.registerComponents(project).addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
    ComponentDto file = dbTester.components().insertComponent(newFileDto(project).setDbKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java").setName("FourthClass.java").setLongName("src/main/java/com/sonarsource/FourthClass.java").setPath("src/main/java/com/sonarsource/FourthClass.java"));
    UserDto author = dbTester.users().insertUser(u -> u.setLogin("joe").setName("Joe"));
    long time = 1577976190000L;
    RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT, r -> r.setRuleKey("S4787").setRepositoryKey("java").setName("rule-name").setSecurityStandards(Sets.newHashSet(SQCategory.WEAK_CRYPTOGRAPHY.getKey())));
    IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, h -> h.setAssigneeUuid("assignee-uuid").setAuthorLogin("joe").setMessage("message").setLine(10).setChecksum("a227e508d6646b55a086ee11d63b21e9").setIssueCreationTime(time).setIssueUpdateTime(time).setAuthorLogin(author.getLogin()).setAssigneeUuid(author.getUuid()).setKee("AW9mgJw6eFC3pGl94Wrf"));
    List<Common.Changelog> changelog = IntStream.range(0, 3).mapToObj(i -> Common.Changelog.newBuilder().setUser("joe").setCreationDate("2020-01-02T14:44:55+0100").addDiffs(Diff.newBuilder().setKey("diff-key-" + i).setNewValue("new-value-" + i).setOldValue("old-value-" + i)).setIsUserActive(true).setUserName("Joe").setAvatar("my-avatar").build()).collect(Collectors.toList());
    List<Common.Comment> comments = IntStream.range(0, 3).mapToObj(i -> Common.Comment.newBuilder().setKey("comment-" + i).setHtmlText("html text " + i).setLogin("Joe").setMarkdown("markdown " + i).setCreatedAt("2020-01-02T14:47:47+0100").build()).collect(Collectors.toList());
    mockChangelogAndCommentsFormattingContext();
    when(issueChangeSupport.formatChangelog(any(), any())).thenReturn(changelog.stream());
    when(issueChangeSupport.formatComments(any(), any(), any())).thenReturn(comments.stream());
    assertThat(actionTester.getDef().responseExampleAsString()).isNotNull();
    newRequest(hotspot).execute().assertJson(actionTester.getDef().responseExampleAsString());
}
Also used : Arrays(java.util.Arrays) SecurityStandards(org.sonar.server.security.SecurityStandards) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) ArgumentMatcher(org.mockito.ArgumentMatcher) DbIssues(org.sonar.db.protobuf.DbIssues) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) DbTester(org.sonar.db.DbTester) RuleTesting(org.sonar.db.rule.RuleTesting) ImmutableSet(com.google.common.collect.ImmutableSet) System2(org.sonar.api.utils.System2) Hotspots(org.sonarqube.ws.Hotspots) Set(java.util.Set) AvatarResolver(org.sonar.server.issue.AvatarResolver) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NotFoundException(org.sonar.server.exceptions.NotFoundException) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) Location(org.sonarqube.ws.Common.Location) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) SQCategory(org.sonar.server.security.SecurityStandards.SQCategory) UserTesting(org.sonar.db.user.UserTesting) Diff(org.sonarqube.ws.Common.Changelog.Diff) IntStream(java.util.stream.IntStream) IssueChangeWSSupport(org.sonar.server.issue.IssueChangeWSSupport) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) RuleType(org.sonar.api.rules.RuleType) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) Load(org.sonar.server.issue.IssueChangeWSSupport.Load) User(org.sonarqube.ws.Common.User) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) Nullable(javax.annotation.Nullable) UserSessionRule(org.sonar.server.tester.UserSessionRule) Tuple(org.assertj.core.groups.Tuple) BranchType(org.sonar.db.component.BranchType) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) DbCommons(org.sonar.db.protobuf.DbCommons) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) Issue(org.sonar.api.issue.Issue) UserResponseFormatter(org.sonar.server.issue.ws.UserResponseFormatter) MARKDOWN(org.sonar.db.rule.RuleDto.Format.MARKDOWN) Collections(java.util.Collections) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Tuple (org.assertj.core.groups.Tuple)1