From 109d8cd5fd4e2781222e84228504913932decd78 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 14 Jul 2015 16:40:39 +0200 Subject: [PATCH] add a type validation module --- .../platformlevel/PlatformLevel4.java | 24 ++--------- .../server/util/TypeValidationModule.java | 40 +++++++++++++++++++ .../server/util/TypeValidationModuleTest.java | 35 ++++++++++++++++ 3 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/util/TypeValidationModule.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/util/TypeValidationModuleTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index c914209b90d..d5a674cc6ea 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -19,6 +19,7 @@ */ package org.sonar.server.platform.platformlevel; +import java.util.List; import org.sonar.api.config.EmailSettings; import org.sonar.api.issue.action.Actions; import org.sonar.api.profiles.AnnotationProfileParser; @@ -313,23 +314,13 @@ import org.sonar.server.user.ws.UserJsonWriter; import org.sonar.server.user.ws.UserPropertiesWs; import org.sonar.server.user.ws.UsersWs; import org.sonar.server.usergroups.ws.UserGroupsModule; -import org.sonar.server.util.BooleanTypeValidation; -import org.sonar.server.util.FloatTypeValidation; -import org.sonar.server.util.IntegerTypeValidation; -import org.sonar.server.util.LongTypeValidation; -import org.sonar.server.util.MetricLevelTypeValidation; -import org.sonar.server.util.StringListTypeValidation; -import org.sonar.server.util.StringTypeValidation; -import org.sonar.server.util.TextTypeValidation; -import org.sonar.server.util.TypeValidations; +import org.sonar.server.util.TypeValidationModule; import org.sonar.server.view.index.ViewIndex; import org.sonar.server.view.index.ViewIndexDefinition; import org.sonar.server.view.index.ViewIndexer; import org.sonar.server.ws.ListingWs; import org.sonar.server.ws.WebServiceEngine; -import java.util.List; - public class PlatformLevel4 extends PlatformLevel { private final List level4AddedComponents; @@ -705,16 +696,7 @@ public class PlatformLevel4 extends PlatformLevel { // Properties PropertiesWs.class, - // Type validation - TypeValidations.class, - IntegerTypeValidation.class, - FloatTypeValidation.class, - BooleanTypeValidation.class, - TextTypeValidation.class, - StringTypeValidation.class, - StringListTypeValidation.class, - LongTypeValidation.class, - MetricLevelTypeValidation.class, + TypeValidationModule.class, // System RestartAction.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidationModule.java b/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidationModule.java new file mode 100644 index 00000000000..020733659f6 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidationModule.java @@ -0,0 +1,40 @@ +/* + * 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.server.util; + +import org.sonar.core.platform.Module; + +public class TypeValidationModule extends Module { + @Override + protected void configureModule() { + add( + TypeValidations.class, + IntegerTypeValidation.class, + FloatTypeValidation.class, + BooleanTypeValidation.class, + TextTypeValidation.class, + StringTypeValidation.class, + StringListTypeValidation.class, + LongTypeValidation.class, + MetricLevelTypeValidation.class + ); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/TypeValidationModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/TypeValidationModuleTest.java new file mode 100644 index 00000000000..92731a740f9 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/util/TypeValidationModuleTest.java @@ -0,0 +1,35 @@ +/* + * 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.server.util; + +import org.junit.Test; +import org.sonar.core.platform.ComponentContainer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TypeValidationModuleTest { + @Test + public void verify_count_of_added_components() { + ComponentContainer container = new ComponentContainer(); + new TypeValidationModule().configure(container); + assertThat(container.size()).isEqualTo(11); + } +} -- 2.39.5