diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-10-28 17:03:15 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-10-30 11:25:31 +0100 |
commit | 86b031b91a3e6f96bb919666aa36ed85bd4af4e7 (patch) | |
tree | 2e476a8b6290f945b3676c00586d77958fd7cba5 | |
parent | 776130ebe8cfb26e84833b6e11efbf97fc35cbcf (diff) | |
download | sonarqube-86b031b91a3e6f96bb919666aa36ed85bd4af4e7.tar.gz sonarqube-86b031b91a3e6f96bb919666aa36ed85bd4af4e7.zip |
SONAR-6355 Default quality gate should used period 1
As the period 1 is now the leak period, the quality gate should then use this period
2 files changed, 36 insertions, 31 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java index 62bf899b166..67a7dff346a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java @@ -20,15 +20,25 @@ package org.sonar.server.qualitygate; import org.picocontainer.Startable; -import org.sonar.api.measures.CoreMetrics; import org.sonar.db.loadedtemplate.LoadedTemplateDao; import org.sonar.db.loadedtemplate.LoadedTemplateDto; -import org.sonar.db.qualitygate.QualityGateConditionDto; import org.sonar.db.qualitygate.QualityGateDto; +import static org.sonar.api.measures.CoreMetrics.NEW_BLOCKER_VIOLATIONS_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_CRITICAL_VIOLATIONS_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_SQALE_DEBT_RATIO_KEY; +import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_GREATER_THAN; +import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_LESS_THAN; + public class RegisterQualityGates implements Startable { private static final String BUILTIN_QUALITY_GATE = "SonarQube way"; + private static final int LEAK_PERIOD = 1; + private static final String NEW_BLOCKER_ISSUE_ERROR_THRESHOLD = "0"; + private static final String NEW_CRITICAL_ISSUE_ERROR_THRESHOLD = "0"; + private static final String DEBT_ON_NEW_CODE_ERROR_THRESHOLD = "5"; + private static final String NEW_COVERAGE_ERROR_THRESHOLD = "80"; private final QualityGates qualityGates; private final LoadedTemplateDao loadedTemplateDao; @@ -57,10 +67,10 @@ public class RegisterQualityGates implements Startable { private void createBuiltinQualityGate() { QualityGateDto builtin = qualityGates.create(BUILTIN_QUALITY_GATE); - qualityGates.createCondition(builtin.getId(), CoreMetrics.NEW_BLOCKER_VIOLATIONS_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "0", 3); - qualityGates.createCondition(builtin.getId(), CoreMetrics.NEW_CRITICAL_VIOLATIONS_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "0", 3); - qualityGates.createCondition(builtin.getId(), CoreMetrics.NEW_SQALE_DEBT_RATIO_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "5", 3); - qualityGates.createCondition(builtin.getId(), CoreMetrics.NEW_COVERAGE_KEY, QualityGateConditionDto.OPERATOR_LESS_THAN, null, "80", 3); + qualityGates.createCondition(builtin.getId(), NEW_BLOCKER_VIOLATIONS_KEY, OPERATOR_GREATER_THAN, null, NEW_BLOCKER_ISSUE_ERROR_THRESHOLD, LEAK_PERIOD); + qualityGates.createCondition(builtin.getId(), NEW_CRITICAL_VIOLATIONS_KEY, OPERATOR_GREATER_THAN, null, NEW_CRITICAL_ISSUE_ERROR_THRESHOLD, LEAK_PERIOD); + qualityGates.createCondition(builtin.getId(), NEW_SQALE_DEBT_RATIO_KEY, OPERATOR_GREATER_THAN, null, DEBT_ON_NEW_CODE_ERROR_THRESHOLD, LEAK_PERIOD); + qualityGates.createCondition(builtin.getId(), NEW_COVERAGE_KEY, OPERATOR_LESS_THAN, null, NEW_COVERAGE_ERROR_THRESHOLD, LEAK_PERIOD); qualityGates.setDefault(builtin.getId()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java index a1b8d7c8d79..c7fc97895de 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java @@ -19,55 +19,50 @@ */ package org.sonar.server.qualitygate; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; import org.sonar.db.loadedtemplate.LoadedTemplateDao; import org.sonar.db.loadedtemplate.LoadedTemplateDto; import org.sonar.db.qualitygate.QualityGateDto; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.times; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.sonar.api.measures.CoreMetrics.NEW_BLOCKER_VIOLATIONS_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_CRITICAL_VIOLATIONS_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_SQALE_DEBT_RATIO_KEY; +import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_GREATER_THAN; +import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_LESS_THAN; -@RunWith(MockitoJUnitRunner.class) public class RegisterQualityGatesTest { - @Mock - private QualityGates qualityGates; + static long QGATE_ID = 42L; - @Mock - private LoadedTemplateDao templateDao; - - private RegisterQualityGates task; - - @Before - public void setUp() { - task = new RegisterQualityGates(qualityGates, templateDao); - } + QualityGates qualityGates = mock(QualityGates.class); + LoadedTemplateDao templateDao = mock(LoadedTemplateDao.class); + RegisterQualityGates task = new RegisterQualityGates(qualityGates, templateDao); @Test - public void should_register_default_gate() { + public void register_default_gate() { String templateType = "QUALITY_GATE"; String templateName = "SonarQube way"; when(templateDao.countByTypeAndKey(templateType, templateName)).thenReturn(0); - when(qualityGates.create(templateName)).thenReturn(new QualityGateDto().setId(42L)); + when(qualityGates.create(templateName)).thenReturn(new QualityGateDto().setId(QGATE_ID)); task.start(); verify(templateDao).countByTypeAndKey(templateType, templateName); verify(qualityGates).create(templateName); - verify(qualityGates, times(4)).createCondition(anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt()); - verify(qualityGates).setDefault(anyLong()); + verify(qualityGates).createCondition(eq(QGATE_ID), eq(NEW_BLOCKER_VIOLATIONS_KEY), eq(OPERATOR_GREATER_THAN), eq((String) null), eq("0"), eq(1)); + verify(qualityGates).createCondition(eq(QGATE_ID), eq(NEW_CRITICAL_VIOLATIONS_KEY), eq(OPERATOR_GREATER_THAN), eq((String) null), eq("0"), eq(1)); + verify(qualityGates).createCondition(eq(QGATE_ID), eq(NEW_SQALE_DEBT_RATIO_KEY), eq(OPERATOR_GREATER_THAN), eq((String) null), eq("5"), eq(1)); + verify(qualityGates).createCondition(eq(QGATE_ID), eq(NEW_COVERAGE_KEY), eq(OPERATOR_LESS_THAN), eq((String) null), eq("80"), eq(1)); + verify(qualityGates).setDefault(eq(QGATE_ID)); ArgumentCaptor<LoadedTemplateDto> templateArg = ArgumentCaptor.forClass(LoadedTemplateDto.class); verify(templateDao).insert(templateArg.capture()); @@ -79,7 +74,7 @@ public class RegisterQualityGatesTest { } @Test - public void should_not_register_default_gate_if_already_present() { + public void does_not_register_default_gate_if_already_present() { String templateType = "QUALITY_GATE"; String templateName = "SonarQube way"; when(templateDao.countByTypeAndKey(templateType, templateName)).thenReturn(1); |