@Test public void get_duplications_by_file_key() throws Exception { TestRequest request = newBaseRequest(); verifyCallToFileWithDuplications(file -> request.setParam("key", file.getDbKey())); }
@Test public void get_duplications_by_file_id() throws Exception { TestRequest request = newBaseRequest(); verifyCallToFileWithDuplications(file -> request.setParam("uuid", file.uuid())); }
@Test public void fail_if_no_parameter_provided() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Either 'uuid' or 'key' must be provided"); newBaseRequest().execute(); }
@Test public void fail_if_file_does_not_exist() { expectedException.expect(NotFoundException.class); newBaseRequest().setParam("key", "missing").execute(); }
@Test public void fail_if_user_is_not_allowed_to_access_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); expectedException.expect(ForbiddenException.class); newBaseRequest().setParam("key", file.getDbKey()).execute(); }
@Test public void return_file_with_missing_duplication_data() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project).setDbKey("foo.js")); db.components().insertSnapshot(newAnalysis(project)); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); TestResponse result = newBaseRequest().setParam("key", file.getDbKey()).execute(); assertJson(result.getInput()).isSimilarTo("{\n" + " \"duplications\": [],\n" + " \"files\": {}\n" + "}"); }