@Test public void return_false_when_jwt_throws_unauthorized_exception() throws Exception { doThrow(AuthenticationException.class).when(jwtHttpHandler).validateToken(request, response); when(basicAuthentication.authenticate(request)).thenReturn(Optional.empty()); underTest.doFilter(request, response, chain); verify(response).setContentType(MediaTypes.JSON); JsonAssert.assertJson(stringWriter.toString()).isSimilarTo("{\"valid\":false}"); }
@Test public void verify_example() throws Exception { when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(DateUtils.parseDateTime("2015-02-23T18:54:23+0100")); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-migrate_db.json")); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_has_default_msg_when_dbmigration_status_is_SUCCEEDED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(SUCCEEDED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_SUCCEEDED, MESSAGE_STATUS_SUCCEEDED, SOME_DATE)); }
@Test public void msg_is_operational_and_state_from_databasemigration_when_databaseversion_status_is_UP_TO_DATE() throws Exception { when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.UP_TO_DATE); when(migrationState.getStatus()).thenReturn(NONE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_NO_MIGRATION, MESSAGE_STATUS_NONE)); }
@Test public void return_sonarqube_version() { init(); when(server.getVersion()).thenReturn("6.2"); assertJson(call()).isSimilarTo("{" + " \"version\": \"6.2\"" + "}"); }
@Test public void empty_arrays_are_returned_when_update_center_is_unavailable() throws Exception { logInAsSystemAdministrator(); when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.absent()); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo( "{" + " \"installing\": []," + " \"removing\": []," + " \"updating\": []" + "}"); }
@Test public void empty_array_is_returned_when_update_center_is_not_accessible() throws Exception { logInAsSystemAdministrator(); when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.absent()); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void branch_support() { init(); branchFeature.setEnabled(true); assertJson(call()).isSimilarTo("{\"branchesEnabled\":true}"); branchFeature.setEnabled(false); assertJson(call()).isSimilarTo("{\"branchesEnabled\":false}"); }
@Test public void empty_array_is_returned_when_there_is_not_plugin_installed() { String response = tester.newRequest().execute().getInput(); assertJson(response).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST); }
@Test public void importers_nominal() { String result = ws.newRequest().execute().getInput(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); }
@Test public void support_json_response() { logInAsSystemAdministrator(); TestResponse wsResponse = ws.newRequest() .setMediaType(MediaTypes.JSON) .execute(); JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"tasks\":[]}"); }
@Test public void return_SONARQUBE_subscription_flag() { OrganizationDto sonarQubeOrganization = db.organizations().insert(o -> o.setSubscription(SONARQUBE)); TestResponse response = executeRequest(sonarQubeOrganization); assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"SONARQUBE\"}}"); }
@Test public void example_with_key() { ComponentDto project = db.components().insertPrivateProject(); logInAsProjectAdministrator(project); String result = ws.newRequest() .setMethod("POST") .setParam(PARAM_PROJECT_KEY, project.getDbKey()) .setParam(PARAM_NAME, "Custom") .setParam(PARAM_URL, "http://example.org") .execute().getInput(); assertJson(result).ignoreFields("id").isSimilarTo(getClass().getResource("create-example.json")); }
@Test public void example_with_id() { ComponentDto project = db.components().insertPrivateProject(); logInAsProjectAdministrator(project); String result = ws.newRequest() .setMethod("POST") .setParam(PARAM_PROJECT_ID, project.uuid()) .setParam(PARAM_NAME, "Custom") .setParam(PARAM_URL, "http://example.org") .execute().getInput(); assertJson(result).ignoreFields("id").isSimilarTo(getClass().getResource("create-example.json")); }
@Test public void does_not_return_branches_when_searching_all_components() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); userSession.setRoot(); String result = call(null, null, null); assertJson(result).isSimilarTo("[" + " {" + " \"id\":" + project.getId() + "," + " }" + "]"); }
@Test public void canMarkAsFavorite_is_false_when_not_logged() { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); String result = ws.newRequest() .setParam("component", project.getKey()) .execute() .getInput(); assertJson(result).isSimilarTo("{\n" + " \"canMarkAsFavorite\": false,\n" + "}\n"); }
@Test public void changelog_empty() { OrganizationDto organization = db.organizations().insert(); QProfileDto qualityProfile = db.qualityProfiles().insert(organization); String response = ws.newRequest() .setParam(PARAM_KEY, qualityProfile.getKee()) .execute() .getInput(); assertJson(response).isSimilarTo("{\"total\":0,\"p\":1,\"ps\":50,\"events\":[]}"); }
@Test public void should_return_public_flag_for_project() { OrganizationDto org = db.organizations().insert(); db.qualityGates().createDefaultQualityGate(org); ComponentDto project = db.components().insertPublicProject(org); init(); userSession.logIn() .addProjectPermission(UserRole.ADMIN, project) .addPermission(OrganizationPermission.ADMINISTER, org); assertJson(execute(project.getDbKey())).isSimilarTo("{\"visibility\": \"public\"}"); }
@Test public void json_example() { ComponentDto project = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, project, issue -> issue.setAuthorLogin("luke.skywalker")); db.issues().insert(rule, project, project, issue -> issue.setAuthorLogin("leia.organa")); issueIndexer.indexOnStartup(emptySet()); userSession.logIn().addMembership(db.getDefaultOrganization()); String result = ws.newRequest().execute().getInput(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); }
@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" + "}"); }