import com.google.common.base.Strings;
import org.sonar.api.ServerComponent;
import org.sonar.api.component.Component;
-import org.sonar.api.rule.RuleKey;
import org.sonar.core.component.ComponentDto;
-import org.sonar.core.qualityprofile.db.ActiveRuleDao;
import org.sonar.core.qualityprofile.db.QualityProfileDao;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.core.resource.ResourceDao;
public class QProfiles implements ServerComponent {
private final QualityProfileDao qualityProfileDao;
- private final ActiveRuleDao activeRuleDao;
private final ResourceDao resourceDao;
private final QProfileProjectService projectService;
private final QProfileOperations operations;
private final ProfileRules rules;
- public QProfiles(QualityProfileDao qualityProfileDao, ActiveRuleDao activeRuleDao, ResourceDao resourceDao, QProfileProjectService projectService, QProfileSearch search,
+ public QProfiles(QualityProfileDao qualityProfileDao, ResourceDao resourceDao, QProfileProjectService projectService, QProfileSearch search,
QProfileOperations operations, ProfileRules rules) {
this.qualityProfileDao = qualityProfileDao;
- this.activeRuleDao = activeRuleDao;
this.resourceDao = resourceDao;
this.projectService = projectService;
this.search = search;
this.rules = rules;
}
+ // TODO
+ //
+ // PROFILES
+ //
+ // search profile from profile id
+ // delete profile from profile id (Delete alerts, activeRules, activeRuleParams, activeRuleNotes, Projects)
+ // copy profile
+ // export profile from profile id
+ // export profile from profile id and plugin key
+ // restore profile
+ //
+ // INHERITANCE
+ // get inheritance of profile id
+ // change inheritance of a profile id
+ //
+ // CHANGELOG
+ // display changelog for a profile id
+ //
+ // ACTIVE RULES
+ // activate a rule
+ // deactivate a rule
+ // update parameter on a active rule
+ // add note on an active rule
+ // delete note on an active rule
+ // edit note on an active rule
+ // extends extension of a rule
+ //
+ // TEMPLATE RULES
+ // create template rule
+ // edit template rule
+ // delete template rule
+
public List<QProfile> searchProfiles() {
return search.searchProfiles();
}
- public void searchProfile(Integer profileId) {
- throw new UnsupportedOperationException();
- }
-
public NewProfileResult newProfile(String name, String language, Map<String, String> xmlProfilesByPlugin) {
validateNewProfile(name, language);
return operations.newProfile(name, language, xmlProfilesByPlugin, UserSession.get());
}
- public void deleteProfile() {
- // Delete alerts, activeRules, activeRuleParams, activeRuleNotes, Projects
- throw new UnsupportedOperationException();
- }
-
- public void renameProfile(Integer profileId, String newName) {
+ public void renameProfile(int profileId, String newName) {
QualityProfileDto qualityProfile = validateRenameProfile(profileId, newName);
operations.renameProfile(qualityProfile, newName, UserSession.get());
}
- public void setDefaultProfile(Integer profileId) {
+ public void setDefaultProfile(int profileId) {
QualityProfileDto qualityProfile = findNotNull(profileId);
operations.setDefaultProfile(qualityProfile, UserSession.get());
}
operations.setDefaultProfile(qualityProfile, UserSession.get());
}
- public void copyProfile() {
- throw new UnsupportedOperationException();
- }
-
- public void exportProfile(Integer profileId) {
- throw new UnsupportedOperationException();
- }
-
- public void exportProfile(Integer profileId, String plugin) {
- throw new UnsupportedOperationException();
- }
-
- public void restoreProfile() {
- throw new UnsupportedOperationException();
- }
-
- // INHERITANCE
-
- public void inheritance() {
- throw new UnsupportedOperationException();
- }
-
- public void inherit(Integer profileId, Integer parentProfileId) {
- throw new UnsupportedOperationException();
- }
-
- // CHANGELOG
-
- public void changelog(Integer profileId) {
- throw new UnsupportedOperationException();
- }
-
// PROJECTS
- public QProfileProjects projects(Integer profileId) {
+ public QProfileProjects projects(int profileId) {
Validation.checkMandatoryParameter(profileId, "profile");
QualityProfileDto qualityProfile = findNotNull(profileId);
return projectService.projects(qualityProfile);
/**
* Used in /project/profile
*/
- public QProfile profile(Integer projectId) {
+ public QProfile profile(int projectId) {
throw new UnsupportedOperationException();
}
- public void addProject(Integer profileId, Long projectId) {
+ public void addProject(int profileId, long projectId) {
Validation.checkMandatoryParameter(profileId, "profile");
Validation.checkMandatoryParameter(projectId, "project");
ComponentDto project = (ComponentDto) findNotNull(projectId);
projectService.addProject(qualityProfile, project, UserSession.get());
}
- public void removeProject(Integer profileId, Long projectId) {
+ public void removeProject(int profileId, long projectId) {
Validation.checkMandatoryParameter(profileId, "profile");
QualityProfileDto qualityProfile = findNotNull(profileId);
ComponentDto project = (ComponentDto) findNotNull(projectId);
projectService.removeProject(qualityProfile, project, UserSession.get());
}
- public void removeProjectByLanguage(String language, Long projectId) {
+ public void removeProjectByLanguage(String language, long projectId) {
Validation.checkMandatoryParameter(language, "language");
ComponentDto project = (ComponentDto) findNotNull(projectId);
projectService.removeProject(language, project, UserSession.get());
}
- public void removeAllProjects(Integer profileId) {
+ public void removeAllProjects(int profileId) {
throw new UnsupportedOperationException();
}
return rules.countInactiveRules(query);
}
- public void activeRule(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- public void deactiveRule(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- public void updateParameters(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- public void activeNote(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- public void editNote(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- public void deleteNote(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- public void extendDescription(Integer profileId, RuleKey ruleKey) {
- throw new UnsupportedOperationException();
- }
-
- // TEMPLATE RULES
-
- public void createTemplateRule() {
- throw new UnsupportedOperationException();
- }
-
- public void editTemplateRule() {
- throw new UnsupportedOperationException();
- }
-
- public void deleteTemplateRule() {
- throw new UnsupportedOperationException();
- }
-
private void validateNewProfile(String name, String language) {
validateName(name);
Validation.checkMandatoryParameter(language, "language");
}
}
- private QualityProfileDto findNotNull(Integer id) {
+ private QualityProfileDto findNotNull(int id) {
QualityProfileDto qualityProfile = find(id);
return checkNotNull(qualityProfile);
}
return checkNotNull(qualityProfile);
}
- private Component findNotNull(Long projectId) {
+ private Component findNotNull(long projectId) {
Component component = resourceDao.findById(projectId);
if (component == null) {
throw new NotFoundException("This project does not exists.");
}
@CheckForNull
- private QualityProfileDto find(Integer id) {
+ private QualityProfileDto find(int id) {
return qualityProfileDao.selectById(id);
}
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.core.component.ComponentDto;
-import org.sonar.core.qualityprofile.db.ActiveRuleDao;
import org.sonar.core.qualityprofile.db.QualityProfileDao;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.core.resource.ResourceDao;
@Mock
QualityProfileDao qualityProfileDao;
- @Mock
- ActiveRuleDao activeRuleDao;
-
@Mock
ResourceDao resourceDao;
@Before
public void setUp() throws Exception {
- qProfiles = new QProfiles(qualityProfileDao, activeRuleDao, resourceDao, projectService, search, service, rules);
+ qProfiles = new QProfiles(qualityProfileDao, resourceDao, projectService, search, service, rules);
}
@Test
verify(search).searchProfiles();
}
- @Test(expected = UnsupportedOperationException.class)
- public void testSearchProfile() throws Exception {
- qProfiles.searchProfile(null);
- }
-
@Test
public void create_new_profile() throws Exception {
Map<String, String> xmlProfilesByPlugin = newHashMap();
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void testDeleteProfile() throws Exception {
- qProfiles.deleteProfile();
- }
-
@Test
public void rename_profile() throws Exception {
QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("Default").setLanguage("java");
verify(service).setDefaultProfile(eq(qualityProfile), any(UserSession.class));
}
- @Test(expected = UnsupportedOperationException.class)
- public void testCopyProfile() throws Exception {
- qProfiles.copyProfile();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testExportProfile() throws Exception {
- qProfiles.exportProfile(1);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testExportProfileByPlugin() throws Exception {
- qProfiles.exportProfile(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testRestoreProfile() throws Exception {
- qProfiles.restoreProfile();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testInheritance() throws Exception {
- qProfiles.inheritance();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testInherit() throws Exception {
- qProfiles.inherit(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testChangelog() throws Exception {
- qProfiles.changelog(null);
- }
-
@Test
public void projects() throws Exception {
QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
verify(projectService).removeProject(eq("java"), eq(project), any(UserSession.class));
}
- @Test(expected = UnsupportedOperationException.class)
- public void testRemoveAllProjects() throws Exception {
- qProfiles.removeAllProjects(null);
- }
-
+ @Test
public void testSearchActiveRules() throws Exception {
final int profileId = 42;
- ProfileRuleQuery query = ProfileRuleQuery.create(profileId );
+ ProfileRuleQuery query = ProfileRuleQuery.create(profileId);
Paging paging = Paging.create(20, 1);
QProfileRuleResult result = mock(QProfileRuleResult.class);
when(rules.searchActiveRules(query, paging)).thenReturn(result);
@Test(expected = UnsupportedOperationException.class)
public void testSearchInactiveRules() throws Exception {
final int profileId = 42;
- ProfileRuleQuery query = ProfileRuleQuery.create(profileId );
+ ProfileRuleQuery query = ProfileRuleQuery.create(profileId);
Paging paging = Paging.create(20, 1);
qProfiles.searchInactiveRules(query, paging);
}
- @Test(expected = UnsupportedOperationException.class)
- public void testActiveRule() throws Exception {
- qProfiles.activeRule(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testDeactiveRule() throws Exception {
- qProfiles.deactiveRule(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void updateParameters() {
- qProfiles.updateParameters(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void activeNote() {
- qProfiles.activeNote(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void editNote() {
- qProfiles.editNote(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void deleteNote() {
- qProfiles.deleteNote(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void extendDescription() {
- qProfiles.extendDescription(null, null);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void createTemplateRule() throws Exception {
- qProfiles.createTemplateRule();;
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void editTemplateRule() throws Exception {
- qProfiles.editTemplateRule();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void deleteTemplateRule() throws Exception {
- qProfiles.deleteTemplateRule();
- }
}