@@ -19,88 +19,17 @@ | |||
*/ | |||
package org.sonar.core.qualitymodel; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.database.DatabaseSession; | |||
import org.sonar.api.qualitymodel.Model; | |||
import org.sonar.api.qualitymodel.ModelDefinition; | |||
import org.sonar.api.qualitymodel.ModelFinder; | |||
import org.sonar.api.utils.Logs; | |||
import org.sonar.api.utils.SonarException; | |||
import org.sonar.jpa.session.DatabaseSessionFactory; | |||
import javax.persistence.Query; | |||
public class DefaultModelFinder implements ModelFinder { | |||
private ModelDefinition[] definitions; | |||
private DatabaseSessionFactory sessionFactory; | |||
public DefaultModelFinder(DatabaseSessionFactory sessionFactory, ModelDefinition[] definitions) { | |||
this.sessionFactory = sessionFactory; | |||
this.definitions = definitions; | |||
} | |||
/** | |||
* This constructor is used when there are no templates | |||
*/ | |||
public DefaultModelFinder(DatabaseSessionFactory sessionFactory) { | |||
this.sessionFactory = sessionFactory; | |||
this.definitions = new ModelDefinition[0]; | |||
} | |||
/** | |||
* Executed when the server starts | |||
*/ | |||
public void registerDefinitions() { | |||
DatabaseSession session = sessionFactory.getSession(); | |||
for (ModelDefinition definition : definitions) { | |||
if (StringUtils.isNotBlank(definition.getName()) && !exists(session, definition.getName())) { | |||
Logs.INFO.info("Register quality model: " + definition.getName()); | |||
Model model = definition.create(); | |||
if (StringUtils.isBlank(model.getName())) { | |||
model.setName(definition.getName()); | |||
} | |||
insert(session, model); | |||
session.commit(); | |||
} | |||
} | |||
} | |||
public Model reset(String name) { | |||
ModelDefinition definition = findDefinitionByName(name); | |||
if (definition == null) { | |||
throw new SonarException("Can not reset quality model. Definition not found: " + name); | |||
} | |||
LoggerFactory.getLogger(getClass()).info("Reset quality model: " + name); | |||
Model model = definition.create(); | |||
return reset(model); | |||
} | |||
Model reset(Model model) { | |||
DatabaseSession session = sessionFactory.getSession(); | |||
try { | |||
delete(session, model.getName()); | |||
model = insert(session, model); | |||
session.commit(); | |||
return model; | |||
} catch (RuntimeException e) { | |||
session.rollback(); | |||
throw e; | |||
} | |||
} | |||
public ModelDefinition findDefinitionByName(String name) { | |||
for (ModelDefinition definition : definitions) { | |||
if (StringUtils.equals(name, definition.getName())) { | |||
return definition; | |||
} | |||
} | |||
return null; | |||
} | |||
public Model findByName(String name) { | |||
@@ -108,22 +37,4 @@ public class DefaultModelFinder implements ModelFinder { | |||
return session.getSingleResult(Model.class, "name", name); | |||
} | |||
public static void delete(DatabaseSession session, String name) { | |||
Model model = session.getSingleResult(Model.class, "name", name); | |||
if (model != null) { | |||
session.removeWithoutFlush(model); | |||
session.commit(); | |||
} | |||
} | |||
public static Model insert(DatabaseSession session, Model model) { | |||
return (Model) session.saveWithoutFlush(model); | |||
} | |||
public static boolean exists(DatabaseSession session, String name) { | |||
Query query = session.getEntityManager().createQuery("SELECT COUNT(qm) FROM " + Model.class.getSimpleName() + " qm WHERE qm.name=:name"); | |||
query.setParameter("name", name); | |||
Number count = (Number) query.getSingleResult(); | |||
return count.intValue() > 0; | |||
} | |||
} |
@@ -20,38 +20,14 @@ | |||
package org.sonar.core.qualitymodel; | |||
import org.junit.Test; | |||
import org.sonar.api.qualitymodel.Characteristic; | |||
import org.sonar.api.qualitymodel.Model; | |||
import org.sonar.api.qualitymodel.ModelDefinition; | |||
import org.sonar.jpa.test.AbstractDbUnitTestCase; | |||
import java.util.List; | |||
import static org.hamcrest.CoreMatchers.is; | |||
import static org.junit.Assert.*; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
public class DefaultModelFinderTest extends AbstractDbUnitTestCase { | |||
@Test | |||
public void reset() { | |||
setupData("shared"); | |||
DefaultModelFinder provider = new DefaultModelFinder(getSessionFactory()); | |||
Model model = Model.createByName("M1"); | |||
Characteristic c1 = model.createCharacteristicByName("NEWM1C1"); | |||
Characteristic c1a = model.createCharacteristicByName("NEWM1C1A"); | |||
c1.addChild(c1a); | |||
model.createCharacteristicByName("NEWM1C2"); | |||
model = provider.reset(model); | |||
model = getSession().getSingleResult(Model.class, "name", "M1"); | |||
assertNotNull(model); | |||
assertThat(model.getCharacteristics().size(), is(3)); | |||
assertThat(model.getCharacteristicByName("NEWM1C1A").getParents().size(), is(1)); | |||
assertNotNull(model.getCharacteristicByName("NEWM1C1A").getParent("NEWM1C1")); | |||
} | |||
@Test | |||
public void findByName() { | |||
setupData("shared"); | |||
@@ -67,55 +43,4 @@ public class DefaultModelFinderTest extends AbstractDbUnitTestCase { | |||
DefaultModelFinder provider = new DefaultModelFinder(getSessionFactory()); | |||
assertNull(provider.findByName("UNKNOWN")); | |||
} | |||
@Test | |||
public void noDefinitionsToRegister() { | |||
setupData("shared"); | |||
DefaultModelFinder provider = new DefaultModelFinder(getSessionFactory()); | |||
provider.registerDefinitions(); | |||
// same state | |||
List<Model> models = getSession().getResults(Model.class); | |||
assertThat(models.size(), is(2)); | |||
} | |||
@Test | |||
public void registerOnlyNewDefinitions() { | |||
setupData("shared"); | |||
ModelDefinition existingDefinition = new FakeDefinition("M1"); | |||
ModelDefinition newDefinition = new FakeDefinition("NEWMODEL"); | |||
ModelDefinition[] definitions = new ModelDefinition[]{existingDefinition, newDefinition}; | |||
DefaultModelFinder provider = new DefaultModelFinder(getSessionFactory(), definitions); | |||
provider.registerDefinitions(); | |||
List<Model> models = getSession().getResults(Model.class); | |||
assertThat(models.size(), is(3)); // 2 existing + one new | |||
} | |||
@Test | |||
public void exists() { | |||
setupData("shared"); | |||
assertTrue(DefaultModelFinder.exists(getSession(), "M1")); | |||
} | |||
@Test | |||
public void notExists() { | |||
setupData("shared"); | |||
assertFalse(DefaultModelFinder.exists(getSession(), "UNKNOWN")); | |||
} | |||
} | |||
class FakeDefinition extends ModelDefinition { | |||
public FakeDefinition(String name) { | |||
super(name); | |||
} | |||
@Override | |||
public Model create() { | |||
return Model.create(); | |||
} | |||
} |
@@ -240,19 +240,38 @@ public final class Characteristic implements Comparable<Characteristic> { | |||
} | |||
public CharacteristicProperty setProperty(String key, String value) { | |||
return createProperty(key).setValue(value); | |||
return addProperty(CharacteristicProperty.create(key).setValue(value)); | |||
} | |||
public CharacteristicProperty setProperty(String key, double value) { | |||
return createProperty(key).setValue(value); | |||
return addProperty(CharacteristicProperty.create(key).setValue(value)); | |||
} | |||
public CharacteristicProperty createProperty(String key) { | |||
CharacteristicProperty property = new CharacteristicProperty(this, key); | |||
public CharacteristicProperty addProperty(CharacteristicProperty property) { | |||
property.setCharacteristic(this); | |||
properties.add(property); | |||
return property; | |||
} | |||
public CharacteristicProperty getProperty(String key) { | |||
for (CharacteristicProperty property : properties) { | |||
if (StringUtils.equals(key, property.getKey())) { | |||
return property; | |||
} | |||
} | |||
return null; | |||
} | |||
public String getPropertyValueAsString(String key) { | |||
CharacteristicProperty property = getProperty(key); | |||
return property != null ? property.getValue() : null; | |||
} | |||
public Double getPropertyValueAsDouble(String key) { | |||
CharacteristicProperty property = getProperty(key); | |||
return property != null ? property.getValueAsDouble() : null; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) { |
@@ -46,9 +46,14 @@ public final class CharacteristicProperty { | |||
@JoinColumn(name = "characteristic_id", updatable = true, nullable = false) | |||
private Characteristic characteristic; | |||
CharacteristicProperty(Characteristic characteristic, String key) { | |||
this.characteristic = characteristic; | |||
this.key = key; | |||
/** | |||
* Use the factory method create() | |||
*/ | |||
CharacteristicProperty() { | |||
} | |||
public static CharacteristicProperty create(String key) { | |||
return new CharacteristicProperty().setKey(key); | |||
} | |||
public Integer getId() { |
@@ -32,11 +32,4 @@ public interface ModelFinder extends BatchComponent, ServerComponent { | |||
*/ | |||
Model findByName(String name); | |||
/** | |||
* @return null if the name is not found | |||
*/ | |||
ModelDefinition findDefinitionByName(String name); | |||
Model reset(String name); | |||
} |
@@ -0,0 +1,64 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2009 SonarSource SA | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar 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. | |||
* | |||
* Sonar 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 Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.api.qualitymodel; | |||
import org.junit.Test; | |||
import static junit.framework.Assert.assertTrue; | |||
import static org.hamcrest.CoreMatchers.notNullValue; | |||
import static org.hamcrest.core.Is.is; | |||
import static org.hamcrest.core.IsNull.nullValue; | |||
import static org.junit.Assert.assertThat; | |||
public class CharacteristicTest { | |||
@Test | |||
public void testStringProperties() { | |||
Characteristic characteristic = new Characteristic(); | |||
characteristic.setProperty("foo", "bar"); | |||
assertThat(characteristic.getProperty("foo"), notNullValue()); | |||
assertThat(characteristic.getPropertyValueAsString("foo"), is("bar")); | |||
assertThat(characteristic.getPropertyValueAsDouble("foo"), nullValue()); | |||
assertThat(characteristic.getProperty("unknown"), nullValue()); | |||
assertThat(characteristic.getPropertyValueAsString("unknown"), nullValue()); | |||
} | |||
@Test | |||
public void testDoubleProperties() { | |||
Characteristic characteristic = new Characteristic(); | |||
characteristic.setProperty("foo", 3.1); | |||
assertThat(characteristic.getProperty("foo"), notNullValue()); | |||
assertThat(characteristic.getPropertyValueAsDouble("foo"), is(3.1)); | |||
assertThat(characteristic.getPropertyValueAsString("foo"), nullValue()); | |||
} | |||
@Test | |||
public void addProperty() { | |||
Characteristic characteristic = new Characteristic(); | |||
characteristic.addProperty(CharacteristicProperty.create("foo")); | |||
CharacteristicProperty property = characteristic.getProperty("foo"); | |||
assertThat(property, notNullValue()); | |||
assertTrue(property.getCharacteristic()==characteristic); | |||
} | |||
} |
@@ -49,6 +49,7 @@ import org.sonar.server.database.JndiDatabaseConnector; | |||
import org.sonar.server.filters.FilterExecutor; | |||
import org.sonar.server.mavendeployer.MavenRepository; | |||
import org.sonar.server.plugins.*; | |||
import org.sonar.server.qualitymodel.DefaultModelManager; | |||
import org.sonar.server.rules.*; | |||
import org.sonar.server.startup.*; | |||
import org.sonar.server.ui.AuthenticatorFactory; | |||
@@ -155,6 +156,7 @@ public final class Platform { | |||
pluginRepository.registerPlugins(servicesContainer); | |||
servicesContainer.as(Characteristics.CACHE).addComponent(DefaultModelFinder.class); // depends on plugins | |||
servicesContainer.as(Characteristics.CACHE).addComponent(DefaultModelManager.class); | |||
servicesContainer.as(Characteristics.CACHE).addComponent(Plugins.class); | |||
servicesContainer.as(Characteristics.CACHE).addComponent(ChartFactory.class); | |||
servicesContainer.as(Characteristics.CACHE).addComponent(Languages.class); |
@@ -0,0 +1,124 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2009 SonarSource SA | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar 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. | |||
* | |||
* Sonar 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 Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.server.qualitymodel; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.database.DatabaseSession; | |||
import org.sonar.api.qualitymodel.Model; | |||
import org.sonar.api.qualitymodel.ModelDefinition; | |||
import org.sonar.api.utils.Logs; | |||
import org.sonar.api.utils.SonarException; | |||
import org.sonar.jpa.session.DatabaseSessionFactory; | |||
import javax.persistence.Query; | |||
public final class DefaultModelManager implements ServerComponent, ModelManager { | |||
private ModelDefinition[] definitions; | |||
private DatabaseSessionFactory sessionFactory; | |||
public DefaultModelManager(DatabaseSessionFactory sessionFactory, ModelDefinition[] definitions) { | |||
this.sessionFactory = sessionFactory; | |||
this.definitions = definitions; | |||
} | |||
/** | |||
* This constructor is used when there are no templates | |||
*/ | |||
public DefaultModelManager(DatabaseSessionFactory sessionFactory) { | |||
this.sessionFactory = sessionFactory; | |||
this.definitions = new ModelDefinition[0]; | |||
} | |||
/** | |||
* Executed when the server starts | |||
*/ | |||
public ModelManager registerDefinitions() { | |||
DatabaseSession session = sessionFactory.getSession(); | |||
for (ModelDefinition definition : definitions) { | |||
if (StringUtils.isNotBlank(definition.getName()) && !exists(session, definition.getName())) { | |||
Logs.INFO.info("Register quality model: " + definition.getName()); | |||
Model model = definition.create(); | |||
if (StringUtils.isBlank(model.getName())) { | |||
model.setName(definition.getName()); | |||
} | |||
insert(session, model); | |||
session.commit(); | |||
} | |||
} | |||
return this; | |||
} | |||
public Model reset(String name) { | |||
ModelDefinition definition = findDefinitionByName(name); | |||
if (definition == null) { | |||
throw new SonarException("Can not reset quality model. Definition not found: " + name); | |||
} | |||
LoggerFactory.getLogger(getClass()).info("Reset quality model: " + name); | |||
Model model = definition.create(); | |||
return reset(model); | |||
} | |||
Model reset(Model model) { | |||
DatabaseSession session = sessionFactory.getSession(); | |||
try { | |||
delete(session, model.getName()); | |||
model = insert(session, model); | |||
session.commit(); | |||
return model; | |||
} catch (RuntimeException e) { | |||
session.rollback(); | |||
throw e; | |||
} | |||
} | |||
public ModelDefinition findDefinitionByName(String name) { | |||
for (ModelDefinition definition : definitions) { | |||
if (StringUtils.equals(name, definition.getName())) { | |||
return definition; | |||
} | |||
} | |||
return null; | |||
} | |||
public static void delete(DatabaseSession session, String name) { | |||
Model model = session.getSingleResult(Model.class, "name", name); | |||
if (model != null) { | |||
session.removeWithoutFlush(model); | |||
session.commit(); | |||
} | |||
} | |||
public static Model insert(DatabaseSession session, Model model) { | |||
return (Model) session.saveWithoutFlush(model); | |||
} | |||
public static boolean exists(DatabaseSession session, String name) { | |||
Query query = session.getEntityManager().createQuery("SELECT COUNT(qm) FROM " + Model.class.getSimpleName() + " qm WHERE qm.name=:name"); | |||
query.setParameter("name", name); | |||
Number count = (Number) query.getSingleResult(); | |||
return count.intValue() > 0; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2009 SonarSource SA | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar 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. | |||
* | |||
* Sonar 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 Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.server.qualitymodel; | |||
import org.sonar.api.qualitymodel.Model; | |||
import org.sonar.api.qualitymodel.ModelDefinition; | |||
public interface ModelManager { | |||
ModelManager registerDefinitions(); | |||
Model reset(String name); | |||
ModelDefinition findDefinitionByName(String name); | |||
} |
@@ -20,25 +20,23 @@ | |||
package org.sonar.server.startup; | |||
import org.sonar.api.utils.TimeProfiler; | |||
import org.sonar.core.qualitymodel.DefaultModelFinder; | |||
import org.sonar.server.qualitymodel.ModelManager; | |||
public final class RegisterQualityModels { | |||
private DefaultModelFinder provider; | |||
private ModelManager manager; | |||
/** | |||
* | |||
* @param provider | |||
* @param registerRulesBeforeModels used only to be started after the creation of check templates | |||
*/ | |||
// NOSONAR the parameter registerRulesBeforeModels is only used to provide the execution order by picocontainer | |||
public RegisterQualityModels(DefaultModelFinder provider, RegisterRules registerRulesBeforeModels) { | |||
this.provider = provider; | |||
public RegisterQualityModels(ModelManager manager, RegisterRules registerRulesBeforeModels) { | |||
this.manager = manager; | |||
} | |||
public void start() { | |||
TimeProfiler profiler = new TimeProfiler().start("Register quality models"); | |||
provider.registerDefinitions(); | |||
manager.registerDefinitions(); | |||
profiler.stop(); | |||
} | |||
} |
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; | |||
import org.sonar.api.Plugin; | |||
import org.sonar.api.Plugins; | |||
import org.sonar.api.Property; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.profiles.ProfileExporter; | |||
import org.sonar.api.profiles.ProfileImporter; | |||
import org.sonar.api.resources.Language; | |||
@@ -52,7 +53,7 @@ import org.sonar.updatecenter.common.Version; | |||
import java.util.Collection; | |||
import java.util.List; | |||
public class JRubyFacade { | |||
public final class JRubyFacade implements ServerComponent { | |||
public FilterResult executeFilter(Filter filter) { | |||
return getContainer().getComponent(FilterExecutor.class).execute(filter); |
@@ -0,0 +1,121 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2009 SonarSource SA | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar 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. | |||
* | |||
* Sonar 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 Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.server.qualitymodel; | |||
import org.junit.Test; | |||
import org.sonar.api.qualitymodel.Characteristic; | |||
import org.sonar.api.qualitymodel.Model; | |||
import org.sonar.api.qualitymodel.ModelDefinition; | |||
import org.sonar.jpa.test.AbstractDbUnitTestCase; | |||
import java.util.List; | |||
import static org.hamcrest.CoreMatchers.is; | |||
import static org.junit.Assert.*; | |||
public class DefaultModelManagerTest extends AbstractDbUnitTestCase { | |||
@Test | |||
public void reset() { | |||
setupData("shared"); | |||
DefaultModelManager manager = new DefaultModelManager(getSessionFactory()); | |||
Model model = Model.createByName("M1"); | |||
Characteristic c1 = model.createCharacteristicByName("NEWM1C1"); | |||
Characteristic c1a = model.createCharacteristicByName("NEWM1C1A"); | |||
c1.addChild(c1a); | |||
model.createCharacteristicByName("NEWM1C2"); | |||
manager.reset(model); | |||
model = getSession().getSingleResult(Model.class, "name", "M1"); | |||
assertNotNull(model); | |||
assertThat(model.getCharacteristics().size(), is(3)); | |||
assertThat(model.getCharacteristicByName("NEWM1C1A").getParents().size(), is(1)); | |||
assertNotNull(model.getCharacteristicByName("NEWM1C1A").getParent("NEWM1C1")); | |||
} | |||
@Test | |||
public void noDefinitionsToRegister() { | |||
setupData("shared"); | |||
ModelManager provider = new DefaultModelManager(getSessionFactory()); | |||
provider.registerDefinitions(); | |||
// same state | |||
List<Model> models = getSession().getResults(Model.class); | |||
assertThat(models.size(), is(2)); | |||
} | |||
@Test | |||
public void registerOnlyNewDefinitions() { | |||
setupData("shared"); | |||
ModelDefinition existingDefinition = new FakeDefinition("M1", Model.create()); | |||
ModelDefinition newDefinition = new FakeDefinition("NEWMODEL", Model.create()); | |||
ModelDefinition[] definitions = new ModelDefinition[]{existingDefinition, newDefinition}; | |||
ModelManager manager = new DefaultModelManager(getSessionFactory(), definitions); | |||
manager.registerDefinitions(); | |||
List<Model> models = getSession().getResults(Model.class); | |||
assertThat(models.size(), is(3)); // 2 existing + one new | |||
} | |||
@Test | |||
public void registerModelProperties() { | |||
Model model = Model.create(); | |||
Characteristic characteristic = model.createCharacteristicByName("Usability"); | |||
characteristic.setProperty("factor", 2.0); | |||
characteristic.setProperty("severity", "BLOCKER"); | |||
setupData("shared"); | |||
ModelDefinition def = new FakeDefinition("with-properties", model); | |||
ModelManager manager = new DefaultModelManager(getSessionFactory(), new ModelDefinition[]{def}); | |||
manager.registerDefinitions(); | |||
checkTables("registerModelProperties", "quality_models", "characteristics", "characteristic_properties"); | |||
} | |||
@Test | |||
public void exists() { | |||
setupData("shared"); | |||
assertTrue(DefaultModelManager.exists(getSession(), "M1")); | |||
} | |||
@Test | |||
public void notExists() { | |||
setupData("shared"); | |||
assertFalse(DefaultModelManager.exists(getSession(), "UNKNOWN")); | |||
} | |||
} | |||
class FakeDefinition extends ModelDefinition { | |||
private final Model model; | |||
public FakeDefinition(String name, Model model) { | |||
super(name); | |||
this.model = model; | |||
} | |||
@Override | |||
public Model create() { | |||
return model; | |||
} | |||
} |
@@ -20,7 +20,7 @@ | |||
package org.sonar.server.startup; | |||
import org.junit.Test; | |||
import org.sonar.core.qualitymodel.DefaultModelFinder; | |||
import org.sonar.server.qualitymodel.ModelManager; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
@@ -29,9 +29,9 @@ public class RegisterQualityModelsTest { | |||
@Test | |||
public void isASimpleBridgeOverProvider() { | |||
DefaultModelFinder provider = mock(DefaultModelFinder.class); | |||
RegisterQualityModels startup = new RegisterQualityModels(provider, null); | |||
ModelManager manager = mock(ModelManager.class); | |||
RegisterQualityModels startup = new RegisterQualityModels(manager, null); | |||
startup.start(); | |||
verify(provider).registerDefinitions(); | |||
verify(manager).registerDefinitions(); | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
<dataset> | |||
<quality_models id="1" name="M1" /> | |||
<quality_models id="2" name="M2" /> | |||
<quality_models id="3" name="with-properties" /> | |||
<characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" /> | |||
<characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true" /> | |||
<characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/> | |||
<characteristics id="4" kee="USABILITY" name="Usability" quality_model_id="3" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/> | |||
<characteristic_edges child_id="2" parent_id="1"/> | |||
<characteristic_properties id="1" characteristic_id="1" kee="foo" value="[null]" text_value="bar" /> | |||
<characteristic_properties id="2" characteristic_id="4" kee="factor" value="2.0" text_value="[null]" /> | |||
<characteristic_properties id="3" characteristic_id="4" kee="severity" value="[null]" text_value="BLOCKER" /> | |||
</dataset> |
@@ -0,0 +1,12 @@ | |||
<dataset> | |||
<quality_models id="1" name="M1" /> | |||
<quality_models id="2" name="M2" /> | |||
<characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" /> | |||
<characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true" /> | |||
<characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/> | |||
<characteristic_edges child_id="2" parent_id="1"/> | |||
<characteristic_properties id="1" characteristic_id="1" kee="foo" value="[null]" text_value="bar" /> | |||
</dataset> |