* The two exclusive options to reference a profile are:
* <ul>
* <li>by its id (to be deprecated)</li>
- * <li>by the tuple {organizationKey, language, name}</li>
+ * <li>by the tuple {language, name}</li>
* </ul>
*/
public class QProfileReference {
/**
* Get the Quality profile specified by the reference {@code ref}.
*
- * @throws org.sonar.server.exceptions.NotFoundException if the specified organization or profile do not exist
+ * @throws org.sonar.server.exceptions.NotFoundException if the specified profile do not exist
*/
public QProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
QProfileDto profile;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QProfileDto;
"<rules/>" +
"</profile>";
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public ExpectedException expectedException = none();
@Rule
public DbTester db = DbTester.create(system2);
- private DummyReset reset = new DummyReset();
- private QProfileFactory profileFactory = new DummyProfileFactory();
- private RuleCreator ruleCreator = mock(RuleCreator.class);
+ private final DummyReset reset = new DummyReset();
+ private final QProfileFactory profileFactory = new DummyProfileFactory();
+ private final RuleCreator ruleCreator = mock(RuleCreator.class);
- private QProfileBackuper underTest = new QProfileBackuperImpl(db.getDbClient(), reset, profileFactory, ruleCreator, new QProfileParser());
+ private final QProfileBackuper underTest = new QProfileBackuperImpl(db.getDbClient(), reset, profileFactory, ruleCreator, new QProfileParser());
@Test
public void backup_generates_xml_file() {
@Test
public void fail_to_restore_external_rule() {
db.rules().insert(RuleKey.of("sonarjs", "s001"), r -> r.setIsExternal(true));
- OrganizationDto organization = db.organizations().getDefaultOrganization();
Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
"<profile><name>foo</name>" +
"<language>js</language>" +
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
.setName("min").setType(RuleParamType.INTEGER.type()));
- left = QProfileTesting.newXooP1();
- right = QProfileTesting.newXooP2();
+ left = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
+ right = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
db.qualityProfileDao().insert(dbSession, left, right);
dbSession.commit();
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
public class QProfileCopierTest {
private static final String BACKUP = "<backup/>";
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public JUnitTempFolder temp = new JUnitTempFolder();
- private DummyProfileFactory profileFactory = new DummyProfileFactory();
- private QProfileBackuper backuper = mock(QProfileBackuper.class);
- private QProfileCopier underTest = new QProfileCopier(db.getDbClient(), profileFactory, backuper);
+ private final DummyProfileFactory profileFactory = new DummyProfileFactory();
+ private final QProfileBackuper backuper = mock(QProfileBackuper.class);
+ private final QProfileCopier underTest = new QProfileCopier(db.getDbClient(), profileFactory, backuper);
@Test
public void create_target_profile_and_copy_rules() {
@Test
public void copy_to_existing_profile() {
- OrganizationDto organization = db.organizations().getDefaultOrganization();
QProfileDto profile1 = db.qualityProfiles().insert();
QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(profile1.getLanguage()));
throw new UnsupportedOperationException();
}
- @Override public QProfileDto createCustom(DbSession dbSession, QProfileName key, @Nullable String parentKey) {
+ @Override
+ public QProfileDto createCustom(DbSession dbSession, QProfileName key, @Nullable String parentKey) {
createdProfile = QualityProfileTesting.newQualityProfileDto()
.setLanguage(key.getLanguage())
.setParentKee(parentKey)
package org.sonar.server.qualityprofile;
import java.io.IOException;
+import java.io.InputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.rule.DefaultRuleFinder;
import org.sonar.server.tester.UserSessionRule;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.IOUtils.toInputStream;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
public class QProfileExportersTest {
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@org.junit.Rule
public ExpectedException expectedException = ExpectedException.none();
@org.junit.Rule
public DbTester db = DbTester.create(system2);
- private RuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient());
- private ProfileExporter[] exporters = new ProfileExporter[] {
+ private final RuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient());
+ private final ProfileExporter[] exporters = new ProfileExporter[] {
new StandardExporter(), new XooExporter()};
- private ProfileImporter[] importers = new ProfileImporter[] {
+ private final ProfileImporter[] importers = new ProfileImporter[] {
new XooProfileImporter(), new XooProfileImporterWithMessages(), new XooProfileImporterWithError()};
private RuleDefinitionDto rule;
- private QProfileRules qProfileRules = mock(QProfileRules.class);
- private QProfileExporters underTest = new QProfileExporters(db.getDbClient(), ruleFinder, qProfileRules, exporters, importers);
+ private final QProfileRules qProfileRules = mock(QProfileRules.class);
+ private final QProfileExporters underTest = new QProfileExporters(db.getDbClient(), ruleFinder, qProfileRules, exporters, importers);
@Before
public void setUp() {
public void import_xml() {
QProfileDto profile = createProfile();
-
underTest.importXml(profile, "XooProfileImporter", toInputStream("<xml/>", UTF_8), db.getSession());
ArgumentCaptor<QProfileDto> profileCapture = ArgumentCaptor.forClass(QProfileDto.class);
@Test
public void fail_to_import_xml_when_error_in_importer() {
- try {
- underTest.importXml(QProfileTesting.newXooP1(), "XooProfileImporterWithError", toInputStream("<xml/>", UTF_8), db.getSession());
- fail();
- } catch (BadRequestException e) {
- assertThat(e).hasMessage("error!");
- }
+ QProfileDto qProfileDto = newQualityProfileDto();
+ InputStream inputStream = toInputStream("<xml/>", UTF_8);
+ DbSession dbSession = db.getSession();
+ assertThatThrownBy(() -> underTest.importXml(
+ qProfileDto, "XooProfileImporterWithError", inputStream, dbSession))
+ .isInstanceOf(BadRequestException.class)
+ .hasMessage("error!");
}
@Test
public void fail_to_import_xml_on_unknown_importer() {
- try {
- underTest.importXml(QProfileTesting.newXooP1(), "Unknown", toInputStream("<xml/>", UTF_8), db.getSession());
- fail();
- } catch (BadRequestException e) {
- assertThat(e).hasMessage("No such importer : Unknown");
- }
+ QProfileDto qProfileDto = newQualityProfileDto();
+ InputStream inputStream = toInputStream("<xml/>", UTF_8);
+ DbSession dbSession = db.getSession();
+ assertThatThrownBy(() -> underTest.importXml(qProfileDto, "Unknown", inputStream, dbSession))
+ .isInstanceOf(BadRequestException.class)
+ .hasMessage("No such importer : Unknown");
}
@Test
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.qualityprofile;
-
-import org.sonar.db.qualityprofile.QProfileDto;
-
-/**
- * Utility class for tests involving quality profiles.
- * @deprecated replaced by {@link org.sonar.db.qualityprofile.QualityProfileDbTester}
- */
-@Deprecated
-public class QProfileTesting {
-
- public static final QProfileName XOO_P1_NAME = new QProfileName("xoo", "P1");
- public static final String XOO_P1_KEY = "XOO_P1";
- public static final QProfileName XOO_P2_NAME = new QProfileName("xoo", "P2");
- public static final String XOO_P2_KEY = "XOO_P2";
- public static final QProfileName XOO_P3_NAME = new QProfileName("xoo", "P3");
- public static final String XOO_P3_KEY = "XOO_P3";
-
- /**
- * @deprecated provide organization as dto
- */
- @Deprecated
- public static QProfileDto newQProfileDto(QProfileName name, String key) {
- return new QProfileDto()
- .setKee(key)
- .setRulesProfileUuid("rp-" + key)
- .setName(name.getName())
- .setLanguage(name.getLanguage());
- }
-
- /**
- * @deprecated provide organization as dto
- */
- @Deprecated
- public static QProfileDto newXooP1() {
- return newQProfileDto(XOO_P1_NAME, XOO_P1_KEY);
- }
-
- /**
- * @deprecated provide organization as dto
- */
- @Deprecated
- public static QProfileDto newXooP2() {
- return newQProfileDto(XOO_P2_NAME, XOO_P2_KEY);
- }
-
- /**
- * @deprecated provide organization as dto
- */
- @Deprecated
- public static QProfileDto newXooP3() {
- return newQProfileDto(XOO_P3_NAME, XOO_P3_KEY);
- }
-}
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private ArgumentCaptor<Collection<RuleActivation>> ruleActivationCaptor = ArgumentCaptor.forClass(Collection.class);
- private DbClient dbClient = db.getDbClient();
- private QProfileRules qProfileRules = mock(QProfileRules.class);
+ private final ArgumentCaptor<Collection<RuleActivation>> ruleActivationCaptor = ArgumentCaptor.forClass(Collection.class);
+ private final DbClient dbClient = db.getDbClient();
+ private final QProfileRules qProfileRules = mock(QProfileRules.class);
private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
- private WsActionTester ws = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSession, wsSupport));
+ private final WsActionTester ws = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSession, wsSupport));
@Before
public void before() {
}
@Test
- public void fail_if_not_organization_quality_profile_administrator() {
+ public void fail_if_not_global_quality_profile_administrator() {
userSession.logIn(db.users().insertUser());
QProfileDto qualityProfile = db.qualityProfiles().insert();
TestRequest request = ws.newRequest()
public DbTester db = DbTester.create();
private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
- private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
- private WsActionTester ws = new WsActionTester(new AddGroupAction(db.getDbClient(), uuidFactory, wsSupport, LANGUAGES));
+ private final WsActionTester ws = new WsActionTester(new AddGroupAction(db.getDbClient(), uuidFactory, wsSupport, LANGUAGES));
@Test
public void test_definition() {
}
@Test
- public void uses_default_organization_when_no_organization() {
+ public void uses_global_permission() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
GroupDto group = db.users().insertGroup();
userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.UserDto;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private DbClient dbClient = db.getDbClient();
- private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
- private AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, TestComponentFinder.from(db), wsSupport);
- private WsActionTester tester = new WsActionTester(underTest);
+ private final DbClient dbClient = db.getDbClient();
+ private final Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
+ private final AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, TestComponentFinder.from(db), wsSupport);
+ private final WsActionTester tester = new WsActionTester(underTest);
@Test
public void definition() {
@Test
public void add_project_on_profile() {
logInAsProfileAdmin();
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
TestResponse response = call(project, profile);
}
@Test
- public void change_association_in_default_organization() {
+ public void change_association() {
logInAsProfileAdmin();
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
// two profiles on same language
QProfileDto profile1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
@Test
public void changing_association_does_not_change_other_language_associations() {
logInAsProfileAdmin();
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile1Language1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
QProfileDto profile2Language2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_2));
QProfileDto profile3Language1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
@Test
public void project_administrator_can_change_profile() {
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project);
}
@Test
- public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
+ public void throw_ForbiddenException_if_not_project_nor_global_administrator() {
userSession.logIn(db.users().insertUser());
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
expectedException.expect(ForbiddenException.class);
@Test
public void throw_UnauthorizedException_if_not_logged_in() {
userSession.anonymous();
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile = db.qualityProfiles().insert();
expectedException.expect(UnauthorizedException.class);
@Test
public void throw_NotFoundException_if_profile_does_not_exist() {
logInAsProfileAdmin();
- ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject();
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Quality Profile for language 'xoo' and name 'unknown' does not exist");
.setParam("qualityProfile", qualityProfile.getName());
return request.execute();
}
-
- private TestResponse call(OrganizationDto organization, ProjectDto project, QProfileDto qualityProfile) {
- TestRequest request = tester.newRequest()
- .setParam("organization", organization.getKey())
- .setParam("project", project.getKey())
- .setParam("language", qualityProfile.getLanguage())
- .setParam("qualityProfile", qualityProfile.getName());
- return request.execute();
- }
}
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LOGIN;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE;
assertThat(db.getDbClient().qProfileEditUsersDao().exists(db.getSession(), profile, user)).isTrue();
}
- @Test
- public void uses_default_organization_when_no_organization() {
- QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
- UserDto user = db.users().insertUser();
- userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES);
-
- ws.newRequest()
- .setParam(PARAM_QUALITY_PROFILE, profile.getName())
- .setParam(PARAM_LANGUAGE, XOO)
- .setParam(PARAM_LOGIN, user.getLogin())
- .execute();
-
- assertThat(db.getDbClient().qProfileEditUsersDao().exists(db.getSession(), profile, user)).isTrue();
- }
-
@Test
public void fail_when_user_does_not_exist() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private QProfileBackuper backuper = new QProfileBackuperImpl(db.getDbClient(), null, null, null, new QProfileParser());
+ private final QProfileBackuper backuper = new QProfileBackuperImpl(db.getDbClient(), null, null, null, new QProfileParser());
private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
- private Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
- private WsActionTester tester = new WsActionTester(new BackupAction(db.getDbClient(), backuper, wsSupport, languages));
+ private final Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
+ private final WsActionTester tester = new WsActionTester(new BackupAction(db.getDbClient(), backuper, wsSupport, languages));
@Test
public void returns_backup_of_profile_with_specified_key() {
}
@Test
- public void returns_backup_of_profile_with_specified_name_on_default_organization() {
+ public void returns_backup_of_profile_with_specified_name() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
private static final String DATE = "2011-04-25T01:15:42+0100";
- private TestSystem2 system2 = new TestSystem2().setNow(DateUtils.parseDateTime(DATE).getTime());
+ private final TestSystem2 system2 = new TestSystem2().setNow(DateUtils.parseDateTime(DATE).getTime());
@Rule
public DbTester db = DbTester.create(system2);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
- private WsActionTester ws = new WsActionTester(new ChangelogAction(wsSupport, new Languages(), db.getDbClient()));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
+ private final WsActionTester ws = new WsActionTester(new ChangelogAction(wsSupport, new Languages(), db.getDbClient()));
@Test
public void return_change_with_all_fields() {
"}");
}
- @Test
- public void find_changelog_by_organization_and_language_and_name() {
- QProfileDto qualityProfile = db.qualityProfiles().insert();
- RuleDefinitionDto rule = db.rules().insert();
- UserDto user = db.users().insertUser();
- insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
- ImmutableMap.of(
- "ruleUuid", rule.getUuid(),
- "severity", "MINOR"));
-
- String response = ws.newRequest()
- .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
- .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName())
- .execute()
- .getInput();
-
- assertJson(response).isSimilarTo("{\n" +
- " \"events\": [\n" +
- " {\n" +
- " \"date\": \"" + DATE + "\",\n" +
- " \"authorLogin\": \"" + user.getLogin() + "\",\n" +
- " \"action\": \"ACTIVATED\",\n" +
- " \"ruleKey\": \"" + rule.getKey() + "\",\n" +
- " \"ruleName\": \"" + rule.getName() + "\",\n" +
- " \"params\": {\n" +
- " \"severity\": \"MINOR\"\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
- "}");
- }
-
@Test
public void changelog_empty() {
QProfileDto qualityProfile = db.qualityProfiles().insert();
}
@Test
- public void copy_rules_on_existing_profile_in_default_organization() {
+ public void copy_rules_on_existing_profile() {
logInAsQProfileAdministrator();
QProfileDto sourceProfile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
QProfileDto targetProfile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
}
@Test
- public void throw_ForbiddenException_if_not_profile_administrator_of_organization() {
+ public void throw_ForbiddenException_if_not_profile_global_administrator() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
userSession.logIn().addPermission(GlobalPermission.SCAN);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private ArgumentCaptor<Collection<String>> ruleUuidsCaptor = ArgumentCaptor.forClass(Collection.class);
- private DbClient dbClient = db.getDbClient();
- private QProfileRules qProfileRules = mock(QProfileRules.class);
+ private final ArgumentCaptor<Collection<String>> ruleUuidsCaptor = ArgumentCaptor.forClass(Collection.class);
+ private final DbClient dbClient = db.getDbClient();
+ private final QProfileRules qProfileRules = mock(QProfileRules.class);
private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
- private DeactivateRuleAction underTest = new DeactivateRuleAction(dbClient, qProfileRules, userSession, wsSupport);
- private WsActionTester ws = new WsActionTester(underTest);
+ private final DeactivateRuleAction underTest = new DeactivateRuleAction(dbClient, qProfileRules, userSession, wsSupport);
+ private final WsActionTester ws = new WsActionTester(underTest);
@Before
public void before() {
}
@Test
- public void deactivate_rule_in_default_organization() {
+ public void deactivate_rule() {
userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
QProfileDto qualityProfile = db.qualityProfiles().insert();
RuleDefinitionDto rule = db.rules().insert(RuleTesting.randomRuleKey());
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
- private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private final ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
- private DeleteAction underTest = new DeleteAction(
+ private final DeleteAction underTest = new DeleteAction(
new Languages(LanguageTesting.newLanguage(A_LANGUAGE)),
new QProfileFactoryImpl(dbClient, UuidFactoryFast.getInstance(), System2.INSTANCE, activeRuleIndexer), dbClient, userSession,
new QProfileWsSupport(dbClient, userSession));
- private WsActionTester ws = new WsActionTester(underTest);
+ private final WsActionTester ws = new WsActionTester(underTest);
@Test
- public void delete_profile_by_language_and_name_in_default_organization() {
+ public void delete_profile_by_language_and_name() {
ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile1 = createProfile();
QProfileDto profile2 = createProfile();
verifyProfileExists(profile2);
}
- @Test
- public void delete_profile_by_language_and_name_in_specified_organization() {
- ProjectDto project = db.components().insertPrivateProjectDto();
- QProfileDto profile1 = createProfile();
- QProfileDto profile2 = createProfile();
- db.qualityProfiles().associateWithProject(project, profile1);
- logInAsQProfileAdministrator();
-
- TestResponse response = ws.newRequest()
- .setMethod("POST")
- .setParam(PARAM_LANGUAGE, profile1.getLanguage())
- .setParam(PARAM_QUALITY_PROFILE, profile1.getName())
- .execute();
- assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
-
- verifyProfileDoesNotExist(profile1);
- verifyProfileExists(profile2);
- }
-
@Test
public void as_qprofile_editor() {
QProfileDto profile = createProfile();
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.QProfileDto;
-import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.QProfileBackuper;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationDto.Subscription.PAID;
public class ExportActionTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DbClient dbClient = db.getDbClient();
- private QProfileBackuper backuper = new TestBackuper();
+ private final DbClient dbClient = db.getDbClient();
+ private final QProfileBackuper backuper = new TestBackuper();
@Test
- public void export_profile_in_default_organization() {
+ public void export_profile() {
QProfileDto profile = createProfile(false);
WsActionTester tester = newWsActionTester(newExporter("polop"), newExporter("palap"));
}
@Test
- public void throw_NotFoundException_if_profile_with_specified_name_does_not_exist_in_default_organization() {
+ public void throw_NotFoundException_if_profile_with_specified_name_does_not_exist() {
expectedException.expect(NotFoundException.class);
newWsActionTester().newRequest()
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.UserDto;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private WsActionTester ws = new WsActionTester(new ProjectsAction(db.getDbClient(), userSession));
+ private final WsActionTester ws = new WsActionTester(new ProjectsAction(db.getDbClient(), userSession));
@Test
public void list_authorized_projects_only() {
@Test
public void paginate() {
- OrganizationDto organization = db.organizations().getDefaultOrganization();
- ProjectDto project1 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project One"));
- ProjectDto project2 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project Two"));
- ProjectDto project3 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project Three"));
- ProjectDto project4 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project Four"));
+ ProjectDto project1 = db.components().insertPublicProjectDto(p -> p.setName("Project One"));
+ ProjectDto project2 = db.components().insertPublicProjectDto(p -> p.setName("Project Two"));
+ ProjectDto project3 = db.components().insertPublicProjectDto(p -> p.setName("Project Three"));
+ ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setName("Project Four"));
QProfileDto qualityProfile = db.qualityProfiles().insert();
associateProjectsWithProfile(qualityProfile, project1, project2, project3, project4);
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.qualityprofile.QProfileName;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.qualityprofile.QProfileRulesImpl;
-import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.index.RuleIndex;
@Rule
public DbTester dbTester = DbTester.create();
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbTester.getSession();
- private RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
- private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbClient);
- private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
- private TypeValidations typeValidations = new TypeValidations(emptyList());
- private RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSessionRule);
- private QProfileRules qProfileRules = new QProfileRulesImpl(dbClient, ruleActivator, ruleIndex, activeRuleIndexer);
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final DbSession dbSession = dbTester.getSession();
+ private final RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
+ private final RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbClient);
+ private final ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
+ private final TypeValidations typeValidations = new TypeValidations(emptyList());
+ private final RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSessionRule);
+ private final QProfileRules qProfileRules = new QProfileRulesImpl(dbClient, ruleActivator, ruleIndex, activeRuleIndexer);
private final QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSessionRule);
private final RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(dbClient);
@Test
public void reset() {
- QProfileDto profile = QProfileTesting.newXooP1();
- QProfileDto childProfile = QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY);
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setLanguage("java");
+ QProfileDto childProfile = QualityProfileTesting.newQualityProfileDto().setParentKee(profile.getKee()).setLanguage("java");
dbClient.qualityProfileDao().insert(dbSession, profile, childProfile);
RuleDefinitionDto rule = createRule(profile.getLanguage(), "rule");
}
private QProfileDto createProfile(String lang) {
- QProfileDto profile = QProfileTesting.newQProfileDto(new QProfileName(lang, "P" + lang), "p" + lang);
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setName("P" + lang).setLanguage(lang);
dbClient.qualityProfileDao().insert(dbSession, profile);
return profile;
}
private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
- private WsActionTester ws = new WsActionTester(new RemoveGroupAction(db.getDbClient(), wsSupport, LANGUAGES));
+ private final WsActionTester ws = new WsActionTester(new RemoveGroupAction(db.getDbClient(), wsSupport, LANGUAGES));
@Test
public void test_definition() {
assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isFalse();
}
- @Test
- public void uses_default_organization_when_no_organization() {
- QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
- GroupDto group = db.users().insertGroup();
- db.qualityProfiles().addGroupPermission(profile, group);
- userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
-
- ws.newRequest()
- .setParam(PARAM_QUALITY_PROFILE, profile.getName())
- .setParam(PARAM_LANGUAGE, XOO)
- .setParam(PARAM_GROUP, group.getName())
- .execute();
-
- assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isFalse();
- }
-
@Test
public void fail_when_group_does_not_exist() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private DbClient dbClient = db.getDbClient();
- private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
+ private final DbClient dbClient = db.getDbClient();
+ private final Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
- private RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages,
+ private final RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages,
new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)), wsSupport);
- private WsActionTester ws = new WsActionTester(underTest);
+ private final WsActionTester ws = new WsActionTester(underTest);
@Test
public void definition() {
public void remove_profile_from_project() {
logInAsProfileAdmin();
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profileLang1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
QProfileDto profileLang2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_2));
db.qualityProfiles().associateWithProject(project, profileLang1);
@Test
public void project_administrator_can_remove_profile() {
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
db.qualityProfiles().associateWithProject(project, profile);
userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project);
@Test
public void fail_if_not_enough_permissions() {
userSession.logIn(db.users().insertUser());
- ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+ ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
expectedException.expect(ForbiddenException.class);
}
@Test
- public void uses_default_organization_when_no_organization() {
+ public void uses_global_permission() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
UserDto user = db.users().insertUser();
db.qualityProfiles().addUserPermission(profile, user);
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private TestBackuper backuper = new TestBackuper();
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
- private WsActionTester tester = new WsActionTester(new RestoreAction(db.getDbClient(), backuper, languages, userSession));
+ private final TestBackuper backuper = new TestBackuper();
+ private final Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
+ private final WsActionTester tester = new WsActionTester(new RestoreAction(db.getDbClient(), backuper, languages, userSession));
@Test
public void test_definition() {
}
@Test
- public void profile_is_restored_on_default_organization_with_the_name_provided_in_backup() {
+ public void profile_is_restored_with_the_name_provided_in_backup() {
logInAsQProfileAdministrator();
- TestResponse response = restore("<backup/>", null);
+ TestResponse response = restore("<backup/>");
assertThat(backuper.restoredBackup).isEqualTo("<backup/>");
assertThat(backuper.restoredSummary.getProfile().getName()).isEqualTo("the-name-in-backup");
"}");
}
- @Test
- public void profile_is_restored_on_specified_organization_with_the_name_provided_in_backup() {
- OrganizationDto org = db.organizations().insert();
- logInAsQProfileAdministrator();
- TestResponse response = restore("<backup/>", org.getKey());
-
- assertThat(backuper.restoredBackup).isEqualTo("<backup/>");
- assertThat(backuper.restoredSummary.getProfile().getName()).isEqualTo("the-name-in-backup");
- JsonAssert.assertJson(response.getInput()).isSimilarTo("{" +
- " \"profile\": {" +
- " \"name\": \"the-name-in-backup\"," +
- " \"language\": \"xoo\"," +
- " \"languageName\": \"Xoo\"," +
- " \"isDefault\": false," +
- " \"isInherited\": false" +
- " }," +
- " \"ruleSuccesses\": 0," +
- " \"ruleFailures\": 0" +
- "}");
-
- }
-
@Test
public void throw_IAE_if_backup_is_missing() {
logInAsQProfileAdministrator();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
- restore("<backup/>", null);
+ restore("<backup/>");
}
@Test
expectedException.expect(UnauthorizedException.class);
expectedException.expectMessage("Authentication is required");
- restore("<backup/>", null);
+ restore("<backup/>");
}
private void logInAsQProfileAdministrator() {
.addPermission(ADMINISTER_QUALITY_PROFILES);
}
- private TestResponse restore(String backupContent, @Nullable String organizationKey) {
+ private TestResponse restore(String backupContent) {
TestRequest request = tester.newRequest()
.setMethod("POST")
.setParam("backup", backupContent);
- if (organizationKey != null) {
- request.setParam("organization", organizationKey);
- }
return request.execute();
}
throw new UnsupportedOperationException();
}
- @Override public QProfileRestoreSummary copy(DbSession dbSession, QProfileDto from, QProfileDto to) {
+ @Override
+ public QProfileRestoreSummary copy(DbSession dbSession, QProfileDto from, QProfileDto to) {
throw new UnsupportedOperationException();
}
}
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.qualityprofile.QProfileDto;
public class SearchActionTest {
- private static Language XOO1 = newLanguage("xoo1");
- private static Language XOO2 = newLanguage("xoo2");
- private static Languages LANGUAGES = new Languages(XOO1, XOO2);
+ private static final Language XOO1 = newLanguage("xoo1");
+ private static final Language XOO2 = newLanguage("xoo2");
+ private static final Languages LANGUAGES = new Languages(XOO1, XOO2);
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private QualityProfileDbTester qualityProfileDb = db.qualityProfiles();
- private DbClient dbClient = db.getDbClient();
+ private final QualityProfileDbTester qualityProfileDb = db.qualityProfiles();
+ private final DbClient dbClient = db.getDbClient();
private SearchAction underTest = new SearchAction(userSession, LANGUAGES, dbClient, new ComponentFinder(dbClient, null));
private WsActionTester ws = new WsActionTester(underTest);
assertThat(result.getProfilesList()).isEmpty();
}
- @Test
- public void default_organization() {
- QProfileDto profile1OnDefaultOrg = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
- QProfileDto profile2OnDefaultOrg = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
-
- SearchWsResponse result = call(ws.newRequest());
-
- assertThat(result.getProfilesList()).extracting(QualityProfile::getKey)
- .containsExactlyInAnyOrder(profile1OnDefaultOrg.getKee(), profile2OnDefaultOrg.getKee());
- }
-
@Test
public void filter_on_default_profile() {
QProfileDto defaultProfile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
@Test
public void actions_when_user_is_global_qprofile_administer() {
- OrganizationDto organization = db.organizations().getDefaultOrganization();
QProfileDto customProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
QProfileDto builtInProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()).setIsBuiltIn(true));
QProfileDto defaultProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
@Test
public void actions_when_user_can_edit_profile() {
- OrganizationDto organization = db.organizations().getDefaultOrganization();
QProfileDto profile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
QProfileDto profile3 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
- private WsActionTester ws = new WsActionTester(new SearchGroupsAction(db.getDbClient(), wsSupport, LANGUAGES));
+ private final WsActionTester ws = new WsActionTester(new SearchGroupsAction(db.getDbClient(), wsSupport, LANGUAGES));
@Test
public void test_definition() {
}
@Test
- public void uses_default_organization_when_no_organization() {
+ public void uses_global_permission() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
GroupDto group = db.users().insertGroup();
db.qualityProfiles().addGroupPermission(profile, group);
}
@Test
- public void uses_default_organization_when_no_organization() {
+ public void uses_global_permission() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
UserDto user1 = db.users().insertUser();
db.qualityProfiles().addUserPermission(profile, user1);
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
-import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.rule.index.RuleQuery;
static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
- private System2 system2 = new TestSystem2().setNow(Instant.now().toEpochMilli());
+ private final System2 system2 = new TestSystem2().setNow(Instant.now().toEpochMilli());
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public EsTester es = EsTester.create();
- private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
- private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
- private DbSession dbSession = db.getSession();
+ private final RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
+ private final RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
+ private final DbSession dbSession = db.getSession();
- private RuleUpdater underTest = new RuleUpdater(db.getDbClient(), ruleIndexer, system2);
+ private final RuleUpdater underTest = new RuleUpdater(db.getDbClient(), ruleIndexer, system2);
@Test
public void do_not_update_rule_with_removed_status() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Rule with REMOVED status cannot be updated: squid:S001");
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
}
@Test
RuleUpdate update = createForPluginRule(RULE_KEY);
assertThat(update.isEmpty()).isTrue();
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
RuleUpdate update = createForPluginRule(RULE_KEY)
.setMarkdownNote("my *note*");
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
RuleUpdate update = createForPluginRule(RULE_KEY)
.setMarkdownNote(null);
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
// java8 is a system tag -> ignore
RuleUpdate update = createForPluginRule(RULE_KEY)
.setTags(Sets.newHashSet("bug", "java8"));
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getTags()).containsOnly("bug");
RuleUpdate update = createForPluginRule(RULE_KEY)
.setTags(null);
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
DefaultDebtRemediationFunction fn = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "1min");
RuleUpdate update = createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(fn);
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
RuleUpdate update = createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "2d", null));
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
RuleUpdate update = createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "10min"));
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
RuleUpdate update = createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(null);
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
// verify debt is coming from default values
.setSeverity("MAJOR")
.setStatus(RuleStatus.READY)
.setParameters(ImmutableMap.of("regex", "b.*"));
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
.setMarkdownDescription("New description")
.setSeverity("MAJOR")
.setStatus(RuleStatus.READY);
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
dbSession.clearCache();
db.rules().insertRuleParam(customRule, param -> param.setName("message").setType("STRING").setDescription("message"));
// Create a quality profile
- QProfileDto profileDto = QProfileTesting.newXooP1();
+ QProfileDto profileDto = QualityProfileTesting.newQualityProfileDto();
db.getDbClient().qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
// Update custom rule parameter 'regex', add 'message' and remove 'format'
RuleUpdate update = createForCustomRule(customRule.getKey())
.setParameters(ImmutableMap.of("regex", "b.*", "message", "a message"));
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
// Verify custom rule parameters has been updated
List<RuleParamDto> params = db.getDbClient().ruleDao().selectRuleParamsByRuleKey(dbSession, customRule.getKey());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The name is missing");
- underTest.update(dbSession, update, userSessionRule);
+ underTest.update(dbSession, update, userSessionRule);
}
@Test
underTest.update(dbSession,
createForCustomRule(customRule.getKey()).setName("New name").setMarkdownDescription(""),
- userSessionRule);
+ userSessionRule);
}
@Test