@Test public void encode_and_decode_pull_request_data() { String branch = "feature/pr1"; String title = "Dummy Feature Title"; String url = "http://example.com/pullRequests/pr1"; DbProjectBranches.PullRequestData pullRequestData = DbProjectBranches.PullRequestData.newBuilder() .setBranch(branch) .setTitle(title) .setUrl(url) .build(); underTest.setPullRequestData(pullRequestData); DbProjectBranches.PullRequestData decoded = underTest.getPullRequestData(); assertThat(decoded).isNotNull(); assertThat(decoded.getBranch()).isEqualTo(branch); assertThat(decoded.getTitle()).isEqualTo(title); assertThat(decoded.getUrl()).isEqualTo(url); }
.setBranch(branch) .setTitle(title) .setUrl(url) .putAttributes(tokenAttributeName, tokenAttributeValue) .build();
.setBranch(branch) .setTitle(title) .setUrl(url) .putAttributes(tokenAttributeName, tokenAttributeValue) .build();
.setBranch(branch + "-dummy-suffix") .setTitle(title + "-dummy-suffix") .setUrl(url + "-dummy-suffix") .putAttributes(tokenAttributeName, tokenAttributeValue + "-dummy-suffix") .build(); .setBranch(branch) .setTitle(title) .setUrl(url) .putAttributes(tokenAttributeName, tokenAttributeValue) .build();
@Test public void json_example() { ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube")); ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(LONG)); ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setKey("123") .setBranchType(PULL_REQUEST) .setMergeBranchUuid(longLivingBranch.uuid()) .setPullRequestData(DbProjectBranches.PullRequestData.newBuilder() .setBranch("feature/bar") .setTitle("Add feature X") .setUrl("https://github.com/SonarSource/sonar-core-plugins/pull/32") .build())); db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(pullRequest).setLast(true).setCreatedAt(DateUtils.parseDateTime("2017-04-01T01:15:42+0100").getTime())); db.measures().insertLiveMeasure(pullRequest, qualityGateStatus, m -> m.setData("OK")); userSession.logIn().addProjectPermission(UserRole.USER, project); db.commit(); String json = ws.newRequest() .setParam(PARAM_PROJECT, project.getKey()) .execute() .getInput(); assertJson(json).isSimilarTo(ws.getDef().responseExampleAsString()); assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(json); }