From 4724663d3f743928d171f9743779d9161e2250ed Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 20 Jun 2014 14:25:13 +0200 Subject: [PATCH] SONAR-5007 do not display the profile version in the widget "description" The concept of profile version was dropped. --- .../plugins/core/widgets/description.html.erb | 5 +- .../rule/QProfileEventsDecoratorTest.java | 314 ++++++------------ 2 files changed, 109 insertions(+), 210 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb index 646b9e08a92..20b6dad36b8 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb @@ -30,15 +30,14 @@

<% else - profile_measure=@snapshot.measure(Metric::PROFILE) + profile_measure=@snapshot.measure('profile') if profile_measure %>

<%= message('widget.description.profile') -%>: - <%= link_to profile_measure.data, {:controller => '/profiles', :action => 'show', :id => profile_measure.value.to_i}, :class => 'widget-link', :id => 'profile_link' -%> + <%= link_to profile_measure.data, {:controller => 'profiles', :action => 'show', :id => profile_measure.value.to_i}, :class => 'widget-link', :id => 'profile_link' -%> - (<%= message('widget.description.profile_version_x', :params => format_measure('profile_version', :default => '1')) -%>)

<% end end %> diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java index c2be9665707..fa97b20289e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java @@ -18,212 +18,112 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* -* SonarQube, open source software quality management tool. -* Copyright (C) 2008-2014 SonarSource -* mailto:contact AT sonarsource DOT com -* -* SonarQube 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. -* -* SonarQube 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 this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.batch.rule; -//import org.junit.Test; -//import org.sonar.api.batch.DecoratorContext; -//import org.sonar.api.batch.Event; -//import org.sonar.api.batch.TimeMachine; -//import org.sonar.api.batch.TimeMachineQuery; -//import org.sonar.api.measures.CoreMetrics; -//import org.sonar.api.measures.Measure; -//import org.sonar.api.resources.Java; -//import org.sonar.api.resources.Languages; -//import org.sonar.api.resources.Project; -//import org.sonar.core.qualityprofile.db.QualityProfileDao; -//import org.sonar.core.qualityprofile.db.QualityProfileDto; -// -//import java.util.Arrays; -//import java.util.Collections; -//import java.util.Date; -// -//import static org.fest.assertions.Assertions.assertThat; -//import static org.mockito.Matchers.any; -//import static org.mockito.Matchers.anyString; -//import static org.mockito.Matchers.eq; -//import static org.mockito.Matchers.same; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -//public class QProfileEventsDecoratorTest { -// -// Project project = new Project("myProject"); -// DecoratorContext decoratorContext = mock(DecoratorContext.class); -// TimeMachine timeMachine = mock(TimeMachine.class); -// Languages languages = mock(Languages.class); -// QProfileEventsDecorator decorator = new QProfileEventsDecorator(timeMachine, languages); -// -// @Test -// public void shouldExecuteOnProjects() { -// assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); -// } -// -// @Test -// public void shouldDoNothingIfNoProfileChange() { -// Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]"); -// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]"); -// -// when(timeMachine.getMeasures(any(TimeMachineQuery.class))) -// .thenReturn(Arrays.asList(previousMeasure)); -// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -// -// decorator.decorate(project, decoratorContext); -// -// verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class)); -// } -// -// @Test -// public void shouldDoNothingIfNoProfileChange_fallbackOldProfileMeasure() { -// mockTMWithDeprecatedProfileMeasures(2, "Java Two", 20); -// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"key\":\"p2\",\"name\":\"Java Two\",\"language\":\"java\"}]"); -// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -// -// when(languages.get("java")).thenReturn(Java.INSTANCE); -// -// decorator.decorate(project, decoratorContext); -// -// verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class)); -// } -// -// @Test -// public void shouldCreateEventIfProfileChange() { -// Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]"); -// // Different profile -// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":3,\"name\":\"Java Other\",\"version\":1,\"language\":\"java\"}]"); -// -// when(timeMachine.getMeasures(any(TimeMachineQuery.class))) -// .thenReturn(Arrays.asList(previousMeasure)); -// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -// -// when(languages.get("java")).thenReturn(Java.INSTANCE); -// -// decorator.decorate(project, decoratorContext); -// -// verify(decoratorContext).createEvent( -// eq("Use Java Other version 1 (Java)"), -// eq("Java Other version 1 used for Java"), -// same(Event.CATEGORY_PROFILE), any(Date.class)); -// } -//// -//// @Test -//// public void shouldCreateEventIfProfileChange_fallbackOldProfileMeasure() { -//// mockTMWithDeprecatedProfileMeasures(2, "Java Two", 20); -//// when(qualityProfileDao.getById(20)).thenReturn(new QualityProfileDto().setLanguage("java")); -//// // Different profile -//// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":3,\"name\":\"Java Other\",\"version\":1,\"language\":\"java\"}]"); -//// -//// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -//// -//// when(languages.get("java")).thenReturn(Java.INSTANCE); -//// -//// decorator.decorate(project, decoratorContext); -//// -//// verify(decoratorContext).createEvent( -//// eq("Use Java Other version 1 (Java)"), -//// eq("Java Other version 1 used for Java"), -//// same(Event.CATEGORY_PROFILE), any(Date.class)); -//// } -//// -//// @Test -//// public void shouldCreateEventIfProfileVersionChange() { -//// Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":20,\"language\":\"java\"}]"); -//// // Same profile, different version -//// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]"); -//// -//// when(timeMachine.getMeasures(any(TimeMachineQuery.class))) -//// .thenReturn(Arrays.asList(previousMeasure)); -//// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -//// -//// when(languages.get("java")).thenReturn(Java.INSTANCE); -//// -//// decorator.decorate(project, decoratorContext); -//// -//// verify(decoratorContext).createEvent( -//// eq("Use Java Two version 21 (Java)"), -//// eq("Java Two version 21 used for Java"), -//// same(Event.CATEGORY_PROFILE), any(Date.class)); -//// } -//// -//// @Test -//// public void shouldCreateEventIfProfileVersionChange_fallbackOldProfileMeasure() { -//// mockTMWithDeprecatedProfileMeasures(2, "Java Two", 20); -//// when(qualityProfileDao.getById(20)).thenReturn(new QualityProfileDto().setLanguage("java")); -//// // Same profile, different version -//// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]"); -//// -//// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -//// -//// when(languages.get("java")).thenReturn(Java.INSTANCE); -//// -//// decorator.decorate(project, decoratorContext); -//// -//// verify(decoratorContext).createEvent( -//// eq("Use Java Two version 21 (Java)"), -//// eq("Java Two version 21 used for Java"), -//// same(Event.CATEGORY_PROFILE), any(Date.class)); -//// } -//// -//// @Test -//// public void shouldCreateEventIfProfileVersionChange_fallbackOldProfileMeasure_noVersion() { -//// mockTMWithDeprecatedProfileMeasures(2, "Java Two", null); -//// when(qualityProfileDao.getById(20)).thenReturn(new QualityProfileDto().setLanguage("java")); -//// // Same profile, different version -//// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]"); -//// -//// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -//// -//// when(languages.get("java")).thenReturn(Java.INSTANCE); -//// -//// decorator.decorate(project, decoratorContext); -//// -//// verify(decoratorContext).createEvent( -//// eq("Use Java Two version 21 (Java)"), -//// eq("Java Two version 21 used for Java"), -//// same(Event.CATEGORY_PROFILE), any(Date.class)); -//// } -// -// @Test -// public void shouldNotCreateEventIfFirstAnalysis() { -// Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[{\"id\":2,\"name\":\"Java Two\",\"version\":21,\"language\":\"java\"}]"); -// -// when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); -// -// when(languages.get("java")).thenReturn(Java.INSTANCE); -// -// decorator.decorate(project, decoratorContext); -// -// verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class)); -// } -// -// private void mockTMWithDeprecatedProfileMeasures(double profileId, String profileName, Integer versionValue) { -// mockTM(new Measure(CoreMetrics.QUALITY_PROFILES, profileId, profileName), versionValue == null ? null : new Measure(CoreMetrics.PROFILE_VERSION, Double.valueOf(versionValue))); -// } -// -// private void mockTM(Measure result1, Measure result2) { -// when(timeMachine.getMeasures(any(TimeMachineQuery.class))) -// .thenReturn(Collections.emptyList()) -// .thenReturn(result1 == null ? Collections.emptyList() : Arrays.asList(result1)) -// .thenReturn(result2 == null ? Collections.emptyList() : Arrays.asList(result2)); -// -// } -//} +import org.junit.Ignore; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.batch.Event; +import org.sonar.api.batch.TimeMachine; +import org.sonar.api.batch.TimeMachineQuery; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Java; +import org.sonar.api.resources.Languages; +import org.sonar.api.resources.Project; + +import java.util.Arrays; +import java.util.Date; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class QProfileEventsDecoratorTest { + + static final String JAVA_V1_JSON = "{\"key\":\"J1\",\"language\":\"java\",\"name\":\"Java One\"}"; + static final String JAVA_V2_JSON = "{\"key\":\"J1\",\"language\":\"java\",\"name\":\"Java One\"}"; + + Project project = new Project("myProject"); + DecoratorContext decoratorContext = mock(DecoratorContext.class); + TimeMachine timeMachine = mock(TimeMachine.class); + Languages languages = mock(Languages.class); + QProfileEventsDecorator decorator = new QProfileEventsDecorator(timeMachine, languages); + + @Test + public void shouldExecuteOnProjects() { + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void shouldDoNothingIfNoProfileChange() { + Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]"); + Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]"); + + when(timeMachine.getMeasures(any(TimeMachineQuery.class))) + .thenReturn(Arrays.asList(previousMeasure)); + when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); + + decorator.decorate(project, decoratorContext); + + verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class)); + } + + @Test + @Ignore + public void shouldCreateEventIfProfileChange() { + Measure previousMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]"); + // Different profile + Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V2_JSON + "]"); + + when(timeMachine.getMeasures(any(TimeMachineQuery.class))) + .thenReturn(Arrays.asList(previousMeasure)); + when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); + + when(languages.get("java")).thenReturn(Java.INSTANCE); + + decorator.decorate(project, decoratorContext); + + verify(decoratorContext).createEvent( + eq("Use Java Other version 1 (Java)"), + eq("Java Other version 1 used for Java"), + same(Event.CATEGORY_PROFILE), any(Date.class)); + } + + @Test + public void shouldNotCreateEventIfFirstAnalysis() { + Measure newMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_V1_JSON + "]"); + + when(decoratorContext.getMeasure(CoreMetrics.QUALITY_PROFILES)).thenReturn(newMeasure); + + when(languages.get("java")).thenReturn(Java.INSTANCE); + + decorator.decorate(project, decoratorContext); + + verify(decoratorContext, never()).createEvent(anyString(), anyString(), anyString(), any(Date.class)); + } +} -- 2.39.5