}
public void deleteProfile(int profileId) {
- // TODO should support deletion of profile with children
RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
- if (profile != null && !profile.getProvided()) {
+ if (profile != null && !profile.getProvided() && getChildren(profile).isEmpty()) {
String hql = "UPDATE " + ResourceModel.class.getSimpleName() + " o SET o.rulesProfile=null WHERE o.rulesProfile=:rulesProfile";
getSession().createQuery(hql).setParameter("rulesProfile", profile).executeUpdate();
getSession().remove(profile);
assertThat(profilesManager.isCycle(level2, level3), is(true));
}
+ @Test
+ public void shouldNotDeleteInheritedProfile() {
+ setupData("shouldCheckCycles");
+ profilesManager.deleteProfile(1);
+ checkTables("shouldNotDeleteInheritedProfile", "rules_profiles");
+ }
+
@Test
public void shouldSetParent() {
setupData("shouldSetParent");
--- /dev/null
+<dataset>
+
+ <rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
+ plugin_rule_key="checkstyle.rule1" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
+
+ <rules_profiles id="1" provided="false" name="level1" default_profile="0" language="java" parent_name="[null]"/>
+
+ <rules_profiles id="2" provided="false" name="level2" default_profile="0" language="java" parent_name="level1"/>
+
+ <rules_profiles id="3" provided="false" name="level3" default_profile="0" language="java" parent_name="level2"/>
+
+</dataset>