import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.configuration.Property;
+import org.sonar.core.properties.PropertyDto;
import org.sonar.server.platform.PersistentSettings;
import java.util.List;
public void exportXml(SonarConfig sonarConfig) {
List<Property> xmlProperties = Lists.newArrayList();
- for (Map.Entry<String, String> entry : persistentSettings.getProperties().entrySet()) {
+ for (PropertyDto property : persistentSettings.getGlobalProperties()){
// "sonar.core.id" must never be restored, it is unique for a server and it created once at the 1rst server startup
- if (!CoreProperties.SERVER_ID.equals(entry.getKey())) {
- xmlProperties.add(new Property(entry.getKey(), entry.getValue()));
+ if (!CoreProperties.SERVER_ID.equals(property.getKey())) {
+ xmlProperties.add(new Property(property.getKey(), property.getValue()));
}
}
sonarConfig.setProperties(xmlProperties);
import org.sonar.core.properties.PropertyDto;
import javax.annotation.Nullable;
+
+import java.util.List;
import java.util.Map;
/**
public void start() {
Map<String, String> databaseProperties = Maps.newHashMap();
- for (PropertyDto property : propertiesDao.selectGlobalProperties()) {
+ for (PropertyDto property : getGlobalProperties()) {
databaseProperties.put(property.getKey(), property.getValue());
}
settings.activateDatabaseSettings(databaseProperties);
public Settings getSettings() {
return settings;
}
+
+ public List<PropertyDto> getGlobalProperties(){
+ return propertiesDao.selectGlobalProperties();
+ }
}
package org.sonar.server.configuration;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import org.hamcrest.collection.IsMapContaining;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.configuration.Property;
+import org.sonar.core.properties.PropertyDto;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import org.sonar.server.platform.PersistentSettings;
}
@Test
- public void export_properties() {
- when(persistentSettings.getProperties()).thenReturn(ImmutableMap.of("key1", "value1", "key2", "value2"));
+ public void shouldExportProperties() {
+ when(persistentSettings.getGlobalProperties()).thenReturn(Lists.newArrayList(new PropertyDto().setKey("key1").setValue("value1"), new PropertyDto().setKey("key2").setValue("value2")));
SonarConfig config = new SonarConfig();
backup.exportXml(config);
}
@Test
- public void do_not_export_server_id() {
- when(persistentSettings.getProperties()).thenReturn(ImmutableMap.of(CoreProperties.SERVER_ID, "111"));
+ public void shouldNotExportServerId() {
+ when(persistentSettings.getGlobalProperties()).thenReturn(Lists.newArrayList(new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue("111"), new PropertyDto().setKey("key").setValue("value")));
SonarConfig config = new SonarConfig();
backup.exportXml(config);
- assertThat(config.getProperties()).isEmpty();
+ assertThat(config.getProperties()).containsOnly(new Property("key", "value"));
}
@Test
- public void import_backup_of_properties() {
+ public void shouldImportBackupOfProperties() {
SonarConfig config = new SonarConfig();
config.setProperties(Arrays.asList(new Property("key1", "value1")));
}
@Test
- public void do_not_import_server_id() {
+ public void shouldNotImportServerId() {
// initial server id
when(persistentSettings.getString(CoreProperties.SERVER_ID)).thenReturn("111");