diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-08-16 16:20:02 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 10:59:56 +0200 |
commit | 7adee5ee96b30672fbdebd0f80981faa4aa4cf0d (patch) | |
tree | a3e97e10bb189306c8a08270c02f9985e59fd64a | |
parent | 2666f225879148e335913d1ea4247c33397961e8 (diff) | |
download | sonarqube-7adee5ee96b30672fbdebd0f80981faa4aa4cf0d.tar.gz sonarqube-7adee5ee96b30672fbdebd0f80981faa4aa4cf0d.zip |
SONAR-9616 Fix api/projectbranches/show when invalid branch
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java | 2 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java index 1bcaaf4ba82..9ede7b80bc1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java @@ -122,7 +122,7 @@ public class ShowAction implements BranchWsAction { private BranchDto getBranch(DbSession dbSession, String uuid) { Optional<BranchDto> branch = dbClient.branchDao().selectByUuid(dbSession, uuid); - checkState(branch != null, "Branch uuid '%s' not found", uuid); + checkState(branch.isPresent(), "Branch uuid '%s' not found", uuid); return branch.get(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java index e2d48dc024a..a6adf956b79 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java @@ -219,6 +219,23 @@ public class ShowActionTest { } @Test + public void fail_if_branch_exists_in_projects_table_but_not_in_project_branches_table() { + ComponentDto project = db.components().insertPrivateProject(); + userSession.addProjectPermission(UserRole.USER, project); + ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); + db.executeDdl("delete from project_branches where uuid = '" + branch.uuid() + "'"); + db.commit(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Branch uuid '" + branch.uuid() + "' not found"); + + ws.newRequest() + .setParam("component", branch.getKey()) + .setParam("branch", branch.getBranch()) + .execute(); + } + + @Test public void test_example() { ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube")); ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(BranchType.LONG)); |