private Boolean provided = Boolean.FALSE;
@Column(name = "enabled", updatable = true, nullable = false)
- private boolean enabled = true;
+ private Boolean enabled = Boolean.TRUE;
@Column(name = "language", updatable = true, nullable = false)
private String language;
this.provided = b;
}
- public boolean isEnabled() {
+ public Boolean getEnabled() {
return enabled;
}
- public RulesProfile setEnabled(boolean b) {
+ public boolean isEnabled() {
+ return enabled==Boolean.TRUE;
+ }
+
+ public RulesProfile setEnabled(Boolean b) {
this.enabled = b;
return this;
}
*/
package org.sonar.server.configuration;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.measures.Metric;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.*;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.test.TestUtils;
+import java.io.IOException;
import java.util.Arrays;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.collection.IsCollectionContaining.hasItem;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
public class ProfilesBackupTest extends AbstractDbUnitTestCase {
}
@Test
- public void testExportWithNoProfiles() {
-
+ public void shouldImportProvidedProfiles() {
RulesProfile profileProvided = new RulesProfile("test provided", "lang", false, true);
RulesProfile profileNotProvided = new RulesProfile("test not provided", "lang", false, false);
getSession().save(profileProvided, profileNotProvided);
}
@Test
- public void testExportWithProfilesAndAlerts() {
-
+ public void shouldImportProfiles() {
RulesProfile profileProvided = new RulesProfile("test provided", "lang", false, true);
RulesProfile profileNotProvided = new RulesProfile("test not provided", "lang", false, false);
getSession().save(profileProvided, profileNotProvided);
assertEquals(2, newProfile.getActiveRules().size());
assertEquals(1, newProfile.getActiveRules(RulePriority.MAJOR).get(0).getActiveRuleParams().size());
assertEquals(2, newProfile.getAlerts().size());
+ }
+
+ /**
+ * The field <profile><enabled> has been added in version 2.6. Profiles imported from backup of previous releases must
+ * be considered as enabled.
+ */
+ @Test
+ public void shouldSupportMissingEnabledField() throws IOException {
+ Backup backup = new Backup(getSession());
+ backup.doImportXml(FileUtils.readFileToString(TestUtils.getResource(getClass(), "shouldSupportMissingEnabledField.xml")));
+
+ RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "name", "Missing enabled field");
+ assertThat(profile.getEnabled(), is(Boolean.TRUE));
+ }
+
+ @Test
+ public void shouldSupportEnabledField() throws IOException {
+ Backup backup = new Backup(getSession());
+ backup.doImportXml(FileUtils.readFileToString(TestUtils.getResource(getClass(), "shouldSupportEnabledField.xml")));
+
+ RulesProfile enabledProfile = getSession().getSingleResult(RulesProfile.class, "name", "Enabled");
+ assertThat(enabledProfile.getEnabled(), is(Boolean.TRUE));
+ RulesProfile disabledProfile = getSession().getSingleResult(RulesProfile.class, "name", "Disabled");
+ assertThat(disabledProfile.getEnabled(), is(Boolean.FALSE));
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<sonar-config>
+ <version><![CDATA[59]]></version>
+ <date><![CDATA[2009-02-19]]></date>
+ <metrics/>
+ <profiles>
+ <profile>
+ <name><![CDATA[Disabled]]></name>
+ <default-profile><![CDATA[false]]></default-profile>
+ <provided><![CDATA[false]]></provided>
+ <language><![CDATA[java]]></language>
+ <enabled><![CDATA[false]]></enabled>
+ <active-rules>
+ </active-rules>
+ <alerts/>
+ </profile>
+ <profile>
+ <name><![CDATA[Enabled]]></name>
+ <default-profile><![CDATA[false]]></default-profile>
+ <provided><![CDATA[false]]></provided>
+ <language><![CDATA[java]]></language>
+ <enabled><![CDATA[true]]></enabled>
+ <active-rules>
+ </active-rules>
+ <alerts/>
+ </profile>
+ </profiles>
+</sonar-config>