@Test public void no_changes() { ruleDao.insert( dbSession, RuleTesting.newDto(RULE_KEY) // the following fields are not supposed to be updated .setNoteData("my *note*") .setNoteUserLogin("me") .setTags(ImmutableSet.of("tag1")) .setSubCharacteristicId(33) .setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()) .setRemediationCoefficient("1d") .setRemediationOffset("5min")); dbSession.commit(); RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY); assertThat(update.isEmpty()).isTrue(); updater.update(update, userSessionRule); dbSession.clearCache(); RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY); assertThat(rule.getNoteData()).isEqualTo("my *note*"); assertThat(rule.getNoteUserLogin()).isEqualTo("me"); assertThat(rule.getTags()).containsOnly("tag1"); assertThat(rule.getSubCharacteristicId()).isEqualTo(33); assertThat(rule.getRemediationFunction()) .isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()); assertThat(rule.getRemediationCoefficient()).isEqualTo("1d"); assertThat(rule.getRemediationOffset()).isEqualTo("5min"); }
@Test public void get_profile_by_project_and_language() { ComponentDto project = new ComponentDto() .setId(1L) .setUuid("ABCD") .setKey("org.codehaus.sonar:sonar") .setName("SonarQube") .setLongName("SonarQube") .setQualifier("TRK") .setScope("TRK") .setEnabled(true); db.componentDao().insert(dbSession, project); QualityProfileDto profileDto = QProfileTesting.newXooP1(); db.qualityProfileDao().insert(dbSession, profileDto); dbSession.commit(); dbSession.clearCache(); assertThat(factory.getByProjectAndLanguage("org.codehaus.sonar:sonar", "xoo")).isNull(); tester .get(QProfileProjectOperations.class) .addProject( profileDto.getKey(), project.uuid(), new MockUserSession("me").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN), dbSession); dbSession.commit(); dbSession.clearCache(); assertThat(factory.getByProjectAndLanguage("org.codehaus.sonar:sonar", "xoo").getKey()) .isEqualTo(XOO_P1_KEY); }
@Test public void update_manual_rule() { // Create manual rule RuleDto manualRule = RuleTesting.newManualRule("My manual") .setName("Old name") .setDescription("Old description") .setSeverity(Severity.INFO); ruleDao.insert(dbSession, manualRule); dbSession.commit(); // Update manual rule RuleUpdate update = RuleUpdate.createForManualRule(manualRule.getKey()) .setName("New name") .setMarkdownDescription("New description") .setSeverity(Severity.CRITICAL); updater.update(update, userSessionRule); dbSession.clearCache(); // Verify manual rule is updated Rule manualRuleReloaded = ruleIndex.getByKey(manualRule.getKey()); assertThat(manualRuleReloaded).isNotNull(); assertThat(manualRuleReloaded.name()).isEqualTo("New name"); assertThat(manualRuleReloaded.htmlDescription()).isEqualTo("New description"); assertThat(manualRuleReloaded.severity()).isEqualTo(Severity.CRITICAL); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn().checkPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN); String name = request.mandatoryParam(PARAM_PROFILE_NAME); String language = request.mandatoryParam(PARAM_LANGUAGE); DbSession dbSession = dbClient.openSession(false); try { QProfileResult result = new QProfileResult(); QualityProfileDto profile = profileFactory.create(dbSession, QProfileName.createFor(language, name)); result.setProfile(profile); for (ProfileImporter importer : importers) { InputStream contentToImport = request.paramAsInputStream(getBackupParamName(importer.getKey())); if (contentToImport != null) { result.add(exporters.importXml(profile, importer.getKey(), contentToImport, dbSession)); } } dbSession.commit(); response.stream().setMediaType(request.getMediaType()); JsonWriter jsonWriter = JsonWriter.of(new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8)); writeResult(jsonWriter, result); } finally { dbSession.close(); } }
public List<DefaultIssue> loadForComponentUuid(String componentUuid) { DbSession session = dbClient.openSession(false); final List<DefaultIssue> result = new ArrayList<>(); try { session .getMapper(IssueMapper.class) .selectNonClosedByComponentUuid( componentUuid, new ResultHandler() { @Override public void handleResult(ResultContext resultContext) { DefaultIssue issue = ((IssueDto) resultContext.getResultObject()).toDefaultIssue(); // TODO this field should be set outside this class if (!isActive(issue.ruleKey()) || ruleRepository.getByKey(issue.ruleKey()).getStatus() == RuleStatus.REMOVED) { issue.setOnDisabledRule(true); // TODO to be improved, why setOnDisabledRule(true) is not enough ? issue.setBeingClosed(true); } // FIXME issue.setSelectedAt(System.currentTimeMillis()); result.add(issue); } }); return result; } finally { MyBatis.closeQuietly(session); } }
public Issue plan(String issueKey, @Nullable String actionPlanKey) { verifyLoggedIn(); DbSession session = dbClient.openSession(false); try { ActionPlan actionPlan = null; if (!Strings.isNullOrEmpty(actionPlanKey)) { actionPlan = actionPlanService.findByKey(actionPlanKey, userSession); if (actionPlan == null) { throw new BadRequestException("Unknown action plan: " + actionPlanKey); } } DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin()); if (issueUpdater.plan(issue, actionPlan, context)) { saveIssue(session, issue, context, null); } return issue; } finally { session.close(); } }
@Override public void handle(Request request, Response response) throws Exception { if (settings.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_ANYONE_CAN_CREATE)) { userSession.checkLoggedIn(); } else { userSession.checkIsRoot(); } String name = wsSupport.getAndCheckMandatoryName(request); String requestKey = getAndCheckKey(request); String key = useOrGenerateKey(requestKey, name); wsSupport.getAndCheckDescription(request); wsSupport.getAndCheckUrl(request); wsSupport.getAndCheckAvatar(request); try (DbSession dbSession = dbClient.openSession(false)) { checkKeyIsNotUsed(dbSession, key, requestKey, name); OrganizationDto dto = createOrganizationDto(request, name, key); dbClient.organizationDao().insert(dbSession, dto); GroupDto group = createOwnersGroup(dbSession, dto); addCurrentUserToGroup(dbSession, group); dbSession.commit(); writeResponse(request, response, dto); } }
@Test public void reset() throws Exception { QualityProfileDto profile = QProfileTesting.newXooP1(); QualityProfileDto subProfile = QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY); db.qualityProfileDao().insert(session, profile, subProfile); RuleDto rule = createRule(profile.getLanguage(), "rule"); ActiveRuleDto active1 = ActiveRuleDto.createFor(profile, rule).setSeverity(rule.getSeverityString()); ActiveRuleDto active2 = ActiveRuleDto.createFor(subProfile, rule).setSeverity("MINOR"); db.activeRuleDao().insert(session, active1); db.activeRuleDao().insert(session, active2); session.commit(); ruIndexer.index(); activeRuIndexer.index(); // 0. assert rule child rule is minor assertThat(db.activeRuleDao().selectOrFailByKey(session, active2.getKey()).getSeverityString()) .isEqualTo("MINOR"); // 1. reset child rule WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION); request.setParam("profile_key", subProfile.getKey()); request.setParam("rule_key", rule.getKey().toString()); request.setParam("reset", "true"); request.execute(); session.clearCache(); // 2. assert rule child rule is NOT minor assertThat(db.activeRuleDao().selectOrFailByKey(session, active2.getKey()).getSeverityString()) .isNotEqualTo("MINOR"); }
@Test public void bulk_activate_rule_not_all() throws Exception { QualityProfileDto java = createProfile("java"); QualityProfileDto php = createProfile("php"); createRule(java.getLanguage(), "toto"); createRule(java.getLanguage(), "tata"); createRule(php.getLanguage(), "hello"); createRule(php.getLanguage(), "world"); session.commit(); ruIndexer.index(); // 0. Assert No Active Rule for profile assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).isEmpty(); // 1. Activate Rule WsTester.TestRequest request = wsTester.newPostRequest( QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION); request.setParam(RuleActivationActions.PROFILE_KEY, php.getKey()); request.setParam(PARAM_LANGUAGES, "php"); request.execute().assertJson(getClass(), "bulk_activate_rule_not_all.json"); session.clearCache(); // 2. Assert ActiveRule in DAO assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2); }
@Test public void does_not_return_warnings_when_bulk_activate_on_profile_and_rules_exist_on_another_language_than_profile() throws Exception { QualityProfileDto javaProfile = createProfile("java"); createRule(javaProfile.getLanguage(), "toto"); createRule(javaProfile.getLanguage(), "tata"); QualityProfileDto phpProfile = createProfile("php"); createRule(phpProfile.getLanguage(), "hello"); createRule(phpProfile.getLanguage(), "world"); session.commit(); ruIndexer.index(); // 1. Activate Rule WsTester.TestRequest request = wsTester.newPostRequest( QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION); request.setParam(RuleActivationActions.PROFILE_KEY, javaProfile.getKey()); request.setParam(PARAM_QPROFILE, javaProfile.getKey()); request.setParam("activation", "false"); request .execute() .assertJson( getClass(), "does_not_return_warnings_when_bulk_activate_on_profile_and_rules_exist_on_another_language_than_profile.json"); session.clearCache(); // 2. Assert ActiveRule in DAO assertThat(db.activeRuleDao().selectByProfileKey(session, javaProfile.getKey())).hasSize(2); }
@Test public void bulk_deactivate_rule_by_profile() throws Exception { QualityProfileDto profile = createProfile("java"); RuleDto rule0 = createRule(profile.getLanguage(), "hello"); RuleDto rule1 = createRule(profile.getLanguage(), "world"); createActiveRule(rule0, profile); createActiveRule(rule1, profile); session.commit(); ruIndexer.index(); activeRuIndexer.index(); // 0. Assert No Active Rule for profile assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2); // 1. Deactivate Rule WsTester.TestRequest request = wsTester.newPostRequest( QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION); request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey()); request.setParam(WebService.Param.TEXT_QUERY, "hello"); WsTester.Result result = request.execute(); session.clearCache(); // 2. Assert ActiveRule in DAO assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1); }
@Test public void activate_rule_override_severity() throws Exception { QualityProfileDto profile = createProfile("java"); RuleDto rule = createRule(profile.getLanguage(), "toto"); session.commit(); ruIndexer.index(); // 0. Assert No Active Rule for profile assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty(); // 1. Activate Rule WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION); request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey()); request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString()); request.setParam(RuleActivationActions.SEVERITY, "MINOR"); WsTester.Result result = request.execute(); session.clearCache(); // 2. Assert ActiveRule in DAO ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey()); assertThat(db.activeRuleDao().selectOrFailByKey(session, activeRuleKey).getSeverityString()) .isEqualTo("MINOR"); }
@Test public void delete_descendants() { initRules(); // create parent and child profiles db.qualityProfileDao() .insert( dbSession, QProfileTesting.newXooP1(), QProfileTesting.newXooP2(), QProfileTesting.newXooP3()); tester.get(RuleActivator.class).setParent(dbSession, XOO_P2_KEY, XOO_P1_KEY); tester.get(RuleActivator.class).setParent(dbSession, XOO_P3_KEY, XOO_P1_KEY); tester .get(RuleActivator.class) .activate(dbSession, new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); assertThat(db.qualityProfileDao().selectAll(dbSession)).hasSize(3); assertThat(db.activeRuleDao().selectAll(dbSession)).hasSize(3); factory.delete(XOO_P1_KEY); dbSession.clearCache(); assertThat(db.qualityProfileDao().selectAll(dbSession)).isEmpty(); assertThat(db.activeRuleDao().selectAll(dbSession)).isEmpty(); assertThat(db.activeRuleDao().selectAllParams(dbSession)).isEmpty(); assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P1_KEY)).isEmpty(); assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P2_KEY)).isEmpty(); assertThat(index.get(ActiveRuleIndex.class).findByProfile(XOO_P3_KEY)).isEmpty(); }
@Test public void fail_to_update_custom_when_description_is_empty() { // Template rule RuleDto templateRule = ruleDao.insert(session, RuleTesting.newTemplateRule(RuleKey.of("java", "S001"))); // Custom rule RuleDto customRule = RuleTesting.newCustomRule(templateRule); ruleDao.insert(session, customRule); session.commit(); session.clearCache(); WsTester.TestRequest request = wsTester .newPostRequest("api/rules", "update") .setParam("key", customRule.getKey().toString()) .setParam("name", "My custom rule") .setParam("markdown_description", ""); try { request.execute(); fail(); } catch (Exception e) { assertThat(e) .isInstanceOf(IllegalArgumentException.class) .hasMessage("The description is missing"); } }
@Before public void before() { tester.clearDbAndIndexes(); db = tester.get(DbClient.class); dbSession = db.openSession(false); ruleActivator = tester.get(RuleActivator.class); index = tester.get(ActiveRuleIndex.class); copier = tester.get(QProfileCopier.class); // create pre-defined rules RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR"); RuleDto xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR"); db.deprecatedRuleDao().insert(dbSession, xooRule1, xooRule2); db.deprecatedRuleDao() .insertRuleParam( dbSession, xooRule1, RuleParamDto.createFor(xooRule1) .setName("max") .setDefaultValue("10") .setType(RuleParamType.INTEGER.type())); // create pre-defined profile db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1()); dbSession.commit(); dbSession.clearCache(); }
@Test public void create_target_profile_with_same_parent_than_source() { // two profiles : parent and its child db.qualityProfileDao() .insert(dbSession, QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY)); // parent and child with x1 activated RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "7"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); // copy child -> profile2 is created with parent P1 copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName()); verifyOneActiveRule( QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); QualityProfileDto profile2Dto = db.qualityProfileDao().selectByKey(dbSession, QProfileTesting.XOO_P2_KEY); assertThat(profile2Dto.getParentKee()).isEqualTo(QProfileTesting.XOO_P1_KEY); }
@Test public void update_target_profile() { // source with x1 activated RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "7"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); // create target with both x1 and x2 activated db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2()); activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.CRITICAL); activation.setParameter("max", "20"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P2_KEY); activation = new RuleActivation(RuleTesting.XOO_X2); activation.setSeverity(Severity.CRITICAL); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P2_KEY); dbSession.commit(); dbSession.clearCache(); // copy -> reset x1 and deactivate x2 copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName()); verifyOneActiveRule( QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, null, ImmutableMap.of("max", "7")); }
/** * List of available transitions. * * <p>Never return null, but return an empty list if the issue does not exist. */ public List<Transition> listTransitions(String issueKey) { DbSession session = dbClient.openSession(false); try { return listTransitions(getByKeyForUpdate(session, issueKey).toDefaultIssue()); } finally { session.close(); } }
public void update(IssueFilterDto filter) { DbSession session = mybatis.openSession(false); try { mapper(session).update(filter); session.commit(); } finally { MyBatis.closeQuietly(session); } }
public void delete(long id) { DbSession session = mybatis.openSession(false); try { mapper(session).delete(id); session.commit(); } finally { MyBatis.closeQuietly(session); } }
public void bulkUpdateKey(long projectId, String stringToReplace, String replacementString) { DbSession session = mybatis.openSession(true); try { bulkUpdateKey(session, projectId, stringToReplace, replacementString); session.commit(); } finally { MyBatis.closeQuietly(session); } }
@Test public void update_custom_rule() { // Create template rule RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); ruleDao.insert(dbSession, templateRule); RuleParamDto templateRuleParam1 = RuleParamDto.createFor(templateRule) .setName("regex") .setType("STRING") .setDescription("Reg ex") .setDefaultValue(".*"); RuleParamDto templateRuleParam2 = RuleParamDto.createFor(templateRule) .setName("format") .setType("STRING") .setDescription("Format"); ruleDao.insertRuleParam(dbSession, templateRule, templateRuleParam1); ruleDao.insertRuleParam(dbSession, templateRule, templateRuleParam2); // Create custom rule RuleDto customRule = RuleTesting.newCustomRule(templateRule) .setName("Old name") .setDescription("Old description") .setSeverity(Severity.MINOR) .setStatus(RuleStatus.BETA); ruleDao.insert(dbSession, customRule); ruleDao.insertRuleParam(dbSession, customRule, templateRuleParam1.setDefaultValue("a.*")); ruleDao.insertRuleParam(dbSession, customRule, templateRuleParam2.setDefaultValue(null)); dbSession.commit(); // Update custom rule RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey()) .setName("New name") .setMarkdownDescription("New description") .setSeverity("MAJOR") .setStatus(RuleStatus.READY) .setParameters(ImmutableMap.of("regex", "b.*")); updater.update(update, userSessionRule); dbSession.clearCache(); // Verify custom rule is updated Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey()); assertThat(customRuleReloaded).isNotNull(); assertThat(customRuleReloaded.name()).isEqualTo("New name"); assertThat(customRuleReloaded.htmlDescription()).isEqualTo("New description"); assertThat(customRuleReloaded.severity()).isEqualTo("MAJOR"); assertThat(customRuleReloaded.status()).isEqualTo(RuleStatus.READY); assertThat(customRuleReloaded.params()).hasSize(2); assertThat(customRuleReloaded.params().get(0).defaultValue()).isEqualTo("b.*"); assertThat(customRuleReloaded.params().get(1).defaultValue()).isNull(); }
public void executeDeprecated() { DbSession session = db.openSession(false); try { synchronize(session, db.deprecatedRuleDao(), index.get(RuleIndex.class)); synchronize(session, db.activeRuleDao(), index.get(ActiveRuleIndex.class)); session.commit(); } finally { session.close(); } }
@Test public void get_profile_by_name_and_language() { QualityProfileDto profileDto = QProfileTesting.newQProfileDto(new QProfileName("xoo", "SonarQube way"), "abcd"); db.qualityProfileDao().insert(dbSession, profileDto); dbSession.commit(); dbSession.clearCache(); assertThat(factory.getByNameAndLanguage("SonarQube way", "xoo").getKey()).isEqualTo("abcd"); assertThat(factory.getByNameAndLanguage("SonarQube way", "java")).isNull(); assertThat(factory.getByNameAndLanguage("Unfound", "xoo")).isNull(); }
public void delete(List<NotificationQueueDto> dtos) { DbSession session = mybatis.openSession(true); NotificationQueueMapper mapper = session.getMapper(NotificationQueueMapper.class); try { for (NotificationQueueDto dto : dtos) { mapper.delete(dto.getId()); } session.commit(); } finally { MyBatis.closeQuietly(session); } }
@Override public void execute() { DbSession session = dbClient.openSession(false); try { Map<String, ComponentDto> existingComponentDtosByKey = indexExistingDtosByKey(session); new PathAwareCrawler<>(new PersistComponentStepsVisitor(existingComponentDtosByKey, session)) .visit(treeRootHolder.getRoot()); session.commit(); } finally { dbClient.closeSession(session); } }
@Test public void set_default_profile() { db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1()); dbSession.commit(); dbSession.clearCache(); assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P1_KEY).isDefault()).isFalse(); factory.setDefault(XOO_P1_KEY); dbSession.clearCache(); assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P1_KEY).isDefault()).isTrue(); }
private long doIndex(BulkIndexer bulk, long lastUpdatedAt) { DbSession dbSession = dbClient.openSession(false); long maxDate; try { ActiveRuleResultSetIterator rowIt = ActiveRuleResultSetIterator.create(dbClient, dbSession, lastUpdatedAt); maxDate = doIndex(bulk, rowIt); rowIt.close(); return maxDate; } finally { dbSession.close(); } }
public DefaultIssue createManualIssue( String componentKey, RuleKey ruleKey, @Nullable Integer line, @Nullable String message, @Nullable String severity) { verifyLoggedIn(); DbSession dbSession = dbClient.openSession(false); try { Optional<ComponentDto> componentOptional = dbClient.componentDao().selectByKey(dbSession, componentKey); if (!componentOptional.isPresent()) { throw new BadRequestException( String.format("Component with key '%s' not found", componentKey)); } ComponentDto component = componentOptional.get(); ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, component.projectUuid()); userSession.checkComponentPermission(UserRole.USER, project.getKey()); if (!ruleKey.isManual()) { throw new IllegalArgumentException( "Issues can be created only on rules marked as 'manual': " + ruleKey); } Rule rule = getNullableRuleByKey(ruleKey); if (rule == null) { throw new IllegalArgumentException("Unknown rule: " + ruleKey); } DefaultIssue issue = new DefaultIssueBuilder() .componentKey(component.getKey()) .projectKey(project.getKey()) .line(line) .message(!Strings.isNullOrEmpty(message) ? message : rule.getName()) .severity(Objects.firstNonNull(severity, Severity.MAJOR)) .ruleKey(ruleKey) .reporter(userSession.getLogin()) .assignee(findSourceLineUser(dbSession, component.uuid(), line)) .build(); Date now = new Date(); issue.setCreationDate(now); issue.setUpdateDate(now); issueStorage.save(issue); return issue; } finally { dbSession.close(); } }
@Test public void fail_renaming_if_name_already_exists() { QualityProfileDto p1 = factory.create(dbSession, new QProfileName("xoo", "P1")); QualityProfileDto p2 = factory.create(dbSession, new QProfileName("xoo", "P2")); dbSession.commit(); dbSession.clearCache(); try { factory.rename(p1.getKey(), "P2"); fail(); } catch (BadRequestException e) { assertThat(e).hasMessage("Quality profile already exists: P2"); } }