]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8857 fix quality flaws
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Fri, 17 Mar 2017 16:30:35 +0000 (17:30 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 23 Mar 2017 16:38:34 +0000 (17:38 +0100)
* deprecate quality profile dao methods without org parameter
* remove unused fields in RenameAction
* change access to wsSupport to static
* source format
* reduce complexity of method
* use constants instead of literals
* remove redundantly overridden method
* remove method QProfileFactory.find
* fix QualityProfileDao.sqlQueryString

13 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/CachingRuleActivatorContextFactory.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileFactoryTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java

index 7af73c840798ac6ff0fcc3e79a2fa8ccb53b61c2..a27579265b59ad41b7906ba49192dbb706198787 100644 (file)
@@ -176,10 +176,18 @@ public class QualityProfileDao implements Dao {
     return executeLargeInputs(languageKeys, input -> mapper(session).selectByNameAndLanguages(organization.getUuid(), name, input));
   }
 
+  /**
+   * @deprecated provide organization
+   */
+  @Deprecated
   public List<ComponentDto> selectProjects(String profileName, String language, DbSession session) {
     return mapper(session).selectProjects(profileName, language);
   }
 
+  /**
+   * @deprecated provide organization
+   */
+  @Deprecated
   public Map<String, Long> countProjectsByProfileKey(DbSession dbSession) {
     Map<String, Long> countByKey = new HashMap<>();
     QualityProfileMapper mapper = mapper(dbSession);
@@ -220,8 +228,11 @@ public class QualityProfileDao implements Dao {
     return mapper(session).selectProjectAssociations(profileKey, nameQuery);
   }
 
-  private String sqlQueryString(@Nullable String query) {
-    return query == null ? "%" : "%" + query.toUpperCase(Locale.ENGLISH) + "%";
+  private static String sqlQueryString(@Nullable String query) {
+    if (query == null) {
+      return "%";
+    }
+    return "%" + query.toUpperCase(Locale.ENGLISH) + "%";
   }
 
   private static QualityProfileMapper mapper(DbSession session) {
index d038eaee306b22a79206cd7ff8a185f8536b3a16..f4b2770e2687ddee78e321d1c86407c46bd586e7 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.qualityprofile;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
@@ -33,7 +32,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
-import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.rule.RuleDto;
 
 public class CachingRuleActivatorContextFactory extends RuleActivatorContextFactory implements Startable {
@@ -82,9 +80,4 @@ public class CachingRuleActivatorContextFactory extends RuleActivatorContextFact
     return dbClient.activeRuleDao().selectByProfileKey(session, profileKey).stream()
       .collect(Collectors.uniqueIndex(dto -> dto.getKey().ruleKey()));
   }
-
-  @Override
-  List<ActiveRuleParamDto> getActiveRuleParams(DbSession session, ActiveRuleDto activeRuleDto) {
-    return super.getActiveRuleParams(session, activeRuleDto);
-  }
 }
index 80ce9142bb44ccab1bbab7c92b84a188641d6cb3..ec35da3305869ecd19cd0f2a1fb6eaa10fecc1f1 100644 (file)
@@ -56,6 +56,21 @@ public class QProfileBackuperImpl implements QProfileBackuper {
 
   private static final Joiner RULE_KEY_JOINER = Joiner.on(", ").skipNulls();
 
+  private static final String ATTRIBUTE_PROFILE = "profile";
+  private static final String ATTRIBUTE_NAME = "name";
+  private static final String ATTRIBUTE_LANGUAGE = "language";
+
+  private static final String ATTRIBUTE_RULES = "rules";
+  private static final String ATTRIBUTE_RULE = "rule";
+  private static final String ATTRIBUTE_REPOSITORY_KEY = "repositoryKey";
+  private static final String ATTRIBUTE_KEY = "key";
+  private static final String ATTRIBUTE_PRIORITY = "priority";
+
+  private static final String ATTRIBUTE_PARAMETERS = "parameters";
+  private static final String ATTRIBUTE_PARAMETER = "parameter";
+  private static final String ATTRIBUTE_PARAMETER_KEY = "key";
+  private static final String ATTRIBUTE_PARAMETER_VALUE = "value";
+
   private final DbClient db;
   private final QProfileReset profileReset;
   private final QProfileFactory profileFactory;
@@ -75,28 +90,28 @@ public class QProfileBackuperImpl implements QProfileBackuper {
 
   private void writeXml(DbSession dbSession, Writer writer, QualityProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
     XmlWriter xml = XmlWriter.of(writer).declaration();
-    xml.begin("profile");
-    xml.prop("name", profile.getName());
-    xml.prop("language", profile.getLanguage());
-    xml.begin("rules");
+    xml.begin(ATTRIBUTE_PROFILE);
+    xml.prop(ATTRIBUTE_NAME, profile.getName());
+    xml.prop(ATTRIBUTE_LANGUAGE, profile.getLanguage());
+    xml.begin(ATTRIBUTE_RULES);
     while (activeRules.hasNext()) {
       ActiveRuleDto activeRule = activeRules.next();
-      xml.begin("rule");
-      xml.prop("repositoryKey", activeRule.getKey().ruleKey().repository());
-      xml.prop("key", activeRule.getKey().ruleKey().rule());
-      xml.prop("priority", activeRule.getSeverityString());
-      xml.begin("parameters");
+      xml.begin(ATTRIBUTE_RULE);
+      xml.prop(ATTRIBUTE_REPOSITORY_KEY, activeRule.getKey().ruleKey().repository());
+      xml.prop(ATTRIBUTE_KEY, activeRule.getKey().ruleKey().rule());
+      xml.prop(ATTRIBUTE_PRIORITY, activeRule.getSeverityString());
+      xml.begin(ATTRIBUTE_PARAMETERS);
       for (ActiveRuleParamDto param : db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
         xml
-          .begin("parameter")
-          .prop("key", param.getKey())
-          .prop("value", param.getValue())
+          .begin(ATTRIBUTE_PARAMETER)
+          .prop(ATTRIBUTE_PARAMETER_KEY, param.getKey())
+          .prop(ATTRIBUTE_PARAMETER_VALUE, param.getValue())
           .end();
       }
-      xml.end("parameters");
-      xml.end("rule");
+      xml.end(ATTRIBUTE_PARAMETERS);
+      xml.end(ATTRIBUTE_RULE);
     }
-    xml.end("rules").end("profile").close();
+    xml.end(ATTRIBUTE_RULES).end(ATTRIBUTE_PROFILE).close();
   }
 
   @Override
@@ -133,13 +148,13 @@ public class QProfileBackuperImpl implements QProfileBackuper {
       SMInputCursor cursor = rootC.childElementCursor();
       while (cursor.getNext() != null) {
         String nodeName = cursor.getLocalName();
-        if (StringUtils.equals("name", nodeName)) {
+        if (StringUtils.equals(ATTRIBUTE_NAME, nodeName)) {
           profileName = StringUtils.trim(cursor.collectDescendantText(false));
 
-        } else if (StringUtils.equals("language", nodeName)) {
+        } else if (StringUtils.equals(ATTRIBUTE_LANGUAGE, nodeName)) {
           profileLang = StringUtils.trim(cursor.collectDescendantText(false));
 
-        } else if (StringUtils.equals("rules", nodeName)) {
+        } else if (StringUtils.equals(ATTRIBUTE_RULES, nodeName)) {
           SMInputCursor rulesCursor = cursor.childElementCursor("rule");
           ruleActivations = parseRuleActivations(rulesCursor);
         }
@@ -166,17 +181,17 @@ public class QProfileBackuperImpl implements QProfileBackuper {
       Map<String, String> parameters = Maps.newHashMap();
       while (ruleCursor.getNext() != null) {
         String nodeName = ruleCursor.getLocalName();
-        if (StringUtils.equals("repositoryKey", nodeName)) {
+        if (StringUtils.equals(ATTRIBUTE_REPOSITORY_KEY, nodeName)) {
           repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false));
 
-        } else if (StringUtils.equals("key", nodeName)) {
+        } else if (StringUtils.equals(ATTRIBUTE_KEY, nodeName)) {
           key = StringUtils.trim(ruleCursor.collectDescendantText(false));
 
-        } else if (StringUtils.equals("priority", nodeName)) {
+        } else if (StringUtils.equals(ATTRIBUTE_PRIORITY, nodeName)) {
           severity = StringUtils.trim(ruleCursor.collectDescendantText(false));
 
-        } else if (StringUtils.equals("parameters", nodeName)) {
-          SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter");
+        } else if (StringUtils.equals(ATTRIBUTE_PARAMETERS, nodeName)) {
+          SMInputCursor propsCursor = ruleCursor.childElementCursor(ATTRIBUTE_PARAMETER);
           readParameters(propsCursor, parameters);
         }
       }
@@ -204,9 +219,9 @@ public class QProfileBackuperImpl implements QProfileBackuper {
       String value = null;
       while (propCursor.getNext() != null) {
         String nodeName = propCursor.getLocalName();
-        if (StringUtils.equals("key", nodeName)) {
+        if (StringUtils.equals(ATTRIBUTE_PARAMETER_KEY, nodeName)) {
           key = StringUtils.trim(propCursor.collectDescendantText(false));
-        } else if (StringUtils.equals("value", nodeName)) {
+        } else if (StringUtils.equals(ATTRIBUTE_PARAMETER_VALUE, nodeName)) {
           value = StringUtils.trim(propCursor.collectDescendantText(false));
         }
       }
index 08db76df84b3b4925e139b8db42fd0db75a8c100..28739708f17c886a8d6620b8b96607a8259fd774 100644 (file)
@@ -34,10 +34,8 @@ import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.qualityprofile.ws.QProfileReference;
 
 import static org.sonar.server.qualityprofile.ActiveRuleChange.Type.DEACTIVATED;
-import static org.sonar.server.ws.WsUtils.checkFound;
 import static org.sonar.server.ws.WsUtils.checkRequest;
 
 /**
@@ -144,29 +142,6 @@ public class QProfileFactory {
 
   // ------------- DEFAULT PROFILE
 
-  /**
-   * @deprecated replaced by {@link org.sonar.server.qualityprofile.ws.QProfileWsSupport#getProfile(DbSession, QProfileReference)}
-   */
-  @Deprecated
-  public QualityProfileDto find(DbSession dbSession, QProfileRef ref) {
-    if (ref.hasKey()) {
-      return findByKey(dbSession, ref.getKey());
-    }
-    return findByName(dbSession, ref.getLanguage(), ref.getName());
-  }
-
-  private QualityProfileDto findByKey(DbSession dbSession, String profileKey) {
-    QualityProfileDto profile;
-    profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
-    return checkFound(profile, "Unable to find a profile for with key '%s'", profileKey);
-  }
-
-  private QualityProfileDto findByName(DbSession dbSession, String language, String profileName) {
-    QualityProfileDto profile;
-    profile = db.qualityProfileDao().selectByNameAndLanguage(profileName, language, dbSession);
-    return checkFound(profile, "Unable to find a profile for language '%s' with name '%s'", language, profileName);
-  }
-
   private static void checkNotDefault(QualityProfileDto p) {
     if (p.isDefault()) {
       throw BadRequestException.create("The profile marked as default can not be deleted: " + p.getKey());
index caf56c4d4e097c27ba97fd8db102310706854332..8c2bdd41424a1e8b83574399f464a4ada72ebf36 100644 (file)
@@ -78,24 +78,28 @@ public class QProfileResetImpl implements QProfileReset {
       List<RuleActivation> activations = Lists.newArrayList();
       for (RulesProfile def : entry.getValue()) {
         for (ActiveRule activeRule : def.getActiveRules()) {
-          RuleActivation activation = new RuleActivation(RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()));
-          activation.setSeverity(activeRule.getSeverity().name());
-          if (!activeRule.getActiveRuleParams().isEmpty()) {
-            for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
-              activation.setParameter(param.getParamKey(), param.getValue());
-            }
-          } else {
-            for (RuleParamDto param : db.ruleDao().selectRuleParamsByRuleKey(dbSession, activeRule.getRule().ruleKey())) {
-              activation.setParameter(param.getName(), param.getDefaultValue());
-            }
-          }
-          activations.add(activation);
+          activations.add(getRuleActivation(dbSession, activeRule));
         }
       }
       reset(dbSession, profile, activations);
     }
   }
 
+  private RuleActivation getRuleActivation(DbSession dbSession, ActiveRule activeRule) {
+    RuleActivation activation = new RuleActivation(RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()));
+    activation.setSeverity(activeRule.getSeverity().name());
+    if (!activeRule.getActiveRuleParams().isEmpty()) {
+      for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
+        activation.setParameter(param.getParamKey(), param.getValue());
+      }
+    } else {
+      for (RuleParamDto param : db.ruleDao().selectRuleParamsByRuleKey(dbSession, activeRule.getRule().ruleKey())) {
+        activation.setParameter(param.getName(), param.getDefaultValue());
+      }
+    }
+    return activation;
+  }
+
   @Override
   public BulkChangeResult reset(DbSession dbSession, QualityProfileDto profile, Collection<RuleActivation> activations) {
     requireNonNull(profile.getId(), "Quality profile must be persisted");
index fabf8f240661993ab41a16b5f10a7c1ca2c00eb7..4d1813112b7c897e3128fdf5a3264c667effcdae 100644 (file)
@@ -88,7 +88,7 @@ public class CreateAction implements QProfileWsAction {
       .setResponseExample(getClass().getResource("example-create.json"))
       .setHandler(this);
 
-    qProfileWsSupport
+    QProfileWsSupport
       .createOrganizationParam(create)
       .setSince("6.4");
 
index c63a67d457d23e8f6dcd2b119196ea21e0c87366..25e2904d302885d747c7033dbed77fc2ff3284bc 100644 (file)
@@ -57,7 +57,7 @@ public class DeleteAction implements QProfileWsAction {
       .setPost(true)
       .setHandler(this);
 
-    qProfileWsSupport.createOrganizationParam(action)
+    QProfileWsSupport.createOrganizationParam(action)
       .setSince("6.4");
 
     QProfileReference.defineParams(action, languages);
index 1221609c3b945a35e945433277d207b94a2a22a4..80915b6745308abc3ecdd5a4e5e6974f168521d1 100644 (file)
@@ -88,7 +88,7 @@ public class OldRestoreAction implements WsAction {
       checkArgument(backup != null, "A backup file must be provided");
       reader = new InputStreamReader(backup, StandardCharsets.UTF_8);
       OrganizationDto defaultOrg = qProfileWsSupport.getOrganizationByKey(dbSession, null);
-      QProfileRestoreSummary result = backuper.restore(dbSession, reader, defaultOrg,null);
+      QProfileRestoreSummary result = backuper.restore(dbSession, reader, defaultOrg, null);
       writeResponse(response.newJsonWriter(), result);
     } finally {
       IOUtils.closeQuietly(reader);
@@ -98,20 +98,20 @@ public class OldRestoreAction implements WsAction {
 
   private void writeResponse(JsonWriter json, QProfileRestoreSummary result) {
     QualityProfileDto profile = result.getProfile();
-      String languageKey = profile.getLanguage();
-      Language language = languages.get(languageKey);
+    String languageKey = profile.getLanguage();
+    Language language = languages.get(languageKey);
 
-      JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
-      jsonProfile
-        .prop("key", profile.getKey())
-        .prop("name", profile.getName())
-        .prop("language", languageKey)
-        .prop("isDefault", false)
-        .prop("isInherited", false);
-      if (language != null) {
-        jsonProfile.prop("languageName", language.getName());
-      }
-      jsonProfile.endObject();
+    JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
+    jsonProfile
+      .prop("key", profile.getKey())
+      .prop("name", profile.getName())
+      .prop("language", languageKey)
+      .prop("isDefault", false)
+      .prop("isInherited", false);
+    if (language != null) {
+      jsonProfile.prop("languageName", language.getName());
+    }
+    jsonProfile.endObject();
 
     BulkChangeResult ruleChanges = result.getRuleChanges();
     json.prop("ruleSuccesses", ruleChanges.countSucceeded());
index 59769f2c9e39d1a0954ff2e2b51b0117ce7d6fd8..cca053e4d01f5cde089c658182f25e9626410c28 100644 (file)
@@ -33,7 +33,6 @@ import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.user.UserSession;
 
 import static java.lang.String.format;
@@ -47,14 +46,10 @@ public class RenameAction implements QProfileWsAction {
   private static final String PARAM_PROFILE_KEY = "key";
   private static final int MAXIMUM_NAME_LENGTH = 100;
 
-  private final QProfileFactory profileFactory;
-  private final QProfileWsSupport qProfileWsSupport;
   private final DbClient dbClient;
   private final UserSession userSession;
 
-  public RenameAction(QProfileFactory profileFactory, QProfileWsSupport qProfileWsSupport, DbClient dbClient, UserSession userSession) {
-    this.profileFactory = profileFactory;
-    this.qProfileWsSupport = qProfileWsSupport;
+  public RenameAction(DbClient dbClient, UserSession userSession) {
     this.dbClient = dbClient;
     this.userSession = userSession;
   }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java
deleted file mode 100644 (file)
index 4f641b7..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.qualityprofile;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactoryImpl;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.db.qualityprofile.QualityProfileTesting;
-import org.sonar.server.exceptions.NotFoundException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class QProfileFactoryTest {
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private DbSession dbSession = dbTester.getSession();
-  private QProfileFactory underTest = new QProfileFactory(dbTester.getDbClient(), UuidFactoryImpl.INSTANCE, System2.INSTANCE);
-
-  @Before
-  public void setUp() throws Exception {
-    QualityProfileDto dto = QualityProfileTesting.newQualityProfileDto().setKey("sw").setName("Sonar way").setLanguage("js");
-    dbTester.getDbClient().qualityProfileDao().insert(dbSession, dto);
-    dbTester.commit();
-  }
-
-  @Test
-  public void find_profile_by_key() {
-    QualityProfileDto profile = underTest.find(dbSession, QProfileRef.fromKey("sw"));
-    assertThat(profile.getKey()).isEqualTo("sw");
-    assertThat(profile.getLanguage()).isEqualTo("js");
-    assertThat(profile.getName()).isEqualTo("Sonar way");
-  }
-
-  @Test
-  public void find_profile_by_name() {
-    QualityProfileDto profile = underTest.find(dbSession, QProfileRef.fromName("js", "Sonar way"));
-    assertThat(profile.getKey()).isEqualTo("sw");
-    assertThat(profile.getLanguage()).isEqualTo("js");
-    assertThat(profile.getName()).isEqualTo("Sonar way");
-  }
-
-  @Test
-  public void throw_NFE_if_profile_key_does_not_exist() {
-    expectedException.expect(NotFoundException.class);
-
-    underTest.find(dbSession, QProfileRef.fromKey("missing"));
-  }
-
-  @Test
-  public void throw_NFE_if_profile_name_does_not_exist() {
-    expectedException.expect(NotFoundException.class);
-
-    underTest.find(dbSession, QProfileRef.fromName("js", "Missing"));
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileFactoryTest.java
deleted file mode 100644 (file)
index f4cc36c..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.qualityprofile.ws;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.db.qualityprofile.QualityProfileTesting;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.qualityprofile.QProfileFactory;
-import org.sonar.server.qualityprofile.QProfileRef;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class QProfileFactoryTest {
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-  private DbSession dbSession = dbTester.getSession();
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private QProfileFactory underTest = new QProfileFactory(dbTester.getDbClient(), UuidFactoryFast.getInstance(), System2.INSTANCE);
-
-  @Before
-  public void setUp() throws Exception {
-    QualityProfileDto dto = QualityProfileTesting.newQualityProfileDto().setKey("sw").setName("Sonar way").setLanguage("js");
-    dbTester.getDbClient().qualityProfileDao().insert(dbSession, dto);
-    dbTester.commit();
-  }
-
-  @Test
-  public void find_profile_by_key() {
-    QualityProfileDto profile = underTest.find(dbSession, QProfileRef.fromKey("sw"));
-    assertThat(profile.getKey()).isEqualTo("sw");
-    assertThat(profile.getLanguage()).isEqualTo("js");
-    assertThat(profile.getName()).isEqualTo("Sonar way");
-  }
-
-  @Test
-  public void find_profile_by_name() {
-    QualityProfileDto profile = underTest.find(dbSession, QProfileRef.fromName("js", "Sonar way"));
-    assertThat(profile.getKey()).isEqualTo("sw");
-    assertThat(profile.getLanguage()).isEqualTo("js");
-    assertThat(profile.getName()).isEqualTo("Sonar way");
-  }
-
-  @Test
-  public void throw_NFE_if_profile_key_does_not_exist() {
-    expectedException.expect(NotFoundException.class);
-
-    underTest.find(dbSession, QProfileRef.fromKey("missing"));
-  }
-
-  @Test
-  public void throw_NFE_if_profile_name_does_not_exist() {
-    expectedException.expect(NotFoundException.class);
-
-    underTest.find(dbSession, QProfileRef.fromName("js", "Missing"));
-  }
-}
index 27fd4af542f085edac05ac6d32d98fc4d373c9d9..f464b7ac8d132f4ac9930c62add8ba0e80039520 100644 (file)
@@ -74,7 +74,7 @@ public class QProfilesWsTest {
       new DeleteAction(languages, null, null, userSessionRule, wsSupport),
       new ExportersAction(),
       new InheritanceAction(null, null, null, null, languages),
-      new RenameAction(null, wsSupport, dbClient, userSessionRule))).controller(QProfilesWs.API_ENDPOINT);
+      new RenameAction(dbClient, userSessionRule))).controller(QProfilesWs.API_ENDPOINT);
   }
 
   private ProfileImporter[] createImporters(Languages languages) {
index eae88cdb03fa7a56c4e590795e6c59f8cf481329..aef0b81d79da4798beb207eb24cd4368af8be9a9 100644 (file)
@@ -24,7 +24,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
@@ -35,7 +34,6 @@ import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
-import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
@@ -65,8 +63,6 @@ public class RenameActionTest {
     TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
     QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSessionRule, defaultOrganizationProvider);
     underTest = new RenameAction(
-      new QProfileFactory(dbClient, UuidFactoryFast.getInstance(), System2.INSTANCE),
-      wsSupport,
       dbClient,
       userSessionRule);
     tester = new WsTester(new QProfilesWs(