]> source.dussan.org Git - sonarqube.git/commitdiff
Fix false-positives with randomly generated strings for DB
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 8 Jun 2017 17:01:09 +0000 (19:01 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 8 Jun 2017 17:01:09 +0000 (19:01 +0200)
Only characters with supported encoding should be used by DB tests.

server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDbTester.java
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTesting.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/PopulateOrganizationMembersTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SupportPrivateProjectInDefaultPermissionTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistComponentsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java

index 0b6c234cdd744c1c286e8ae40247a92083f108e6..7ba24919da691f0d0be2f116314bb1b157983e77 100644 (file)
@@ -21,12 +21,12 @@ package org.sonar.db.rule;
 
 import java.util.Arrays;
 import java.util.function.Consumer;
-import org.apache.commons.lang.RandomStringUtils;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
 
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.sonar.db.rule.RuleTesting.newRule;
 import static org.sonar.db.rule.RuleTesting.newRuleDto;
 
@@ -125,7 +125,7 @@ public class RuleDbTester {
   public RuleParamDto insertRuleParam(RuleDto rule) {
     RuleParamDto param = new RuleParamDto();
     param.setRuleId(rule.getId());
-    param.setName(RandomStringUtils.random(10));
+    param.setName(randomAlphabetic(10));
     param.setType(RuleParamType.STRING.type());
     db.getDbClient().ruleDao().insertRuleParam(db.getSession(), rule.getDefinition(), param);
     db.commit();
index 86c659636b817db6585d9637d6bf5ac87f201ec9..696644b8705fe64ae1d4b1d648c4585ae11242ab 100644 (file)
@@ -35,7 +35,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.collect.ImmutableSet.copyOf;
 import static com.google.common.collect.Sets.newHashSet;
 import static java.util.Objects.requireNonNull;
-import static org.apache.commons.lang.RandomStringUtils.random;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.apache.commons.lang.math.RandomUtils.nextInt;
@@ -252,7 +251,7 @@ public class RuleTesting {
   }
 
   public static RuleKey randomRuleKeyOfMaximumLength() {
-    return RuleKey.of(random(255), random(200));
+    return RuleKey.of(randomAlphabetic(255), randomAlphabetic(200));
   }
 
   public static Consumer<RuleDefinitionDto> setRepositoryKey(String repositoryKey) {
index 7b1c5f1271e0bc048ebe8727d55f17aa6a66338a..f6b80803ea6077aa762f2cf84ebf8f192891fb29 100644 (file)
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import javax.annotation.Nullable;
-import org.apache.commons.lang.RandomStringUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -35,6 +34,7 @@ import org.sonar.db.CoreDbTester;
 import org.sonar.server.platform.db.migration.version.v63.DefaultOrganizationUuidProviderImpl;
 
 import static java.lang.String.format;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.apache.commons.lang.math.RandomUtils.nextLong;
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -279,7 +279,7 @@ public class PopulateOrganizationMembersTableTest {
   }
 
   private int insertNewGroup(String organizationUuid) {
-    String groupName = RandomStringUtils.random(10);
+    String groupName = randomAlphabetic(10);
     db.executeInsert("GROUPS", "NAME", groupName, "ORGANIZATION_UUID", organizationUuid);
     return ((Long) db.selectFirst(format("select ID from groups where name='%s' and organization_uuid='%s'", groupName, organizationUuid)).get("ID")).intValue();
   }
index daac2f09ec5a8c096018baec3a323d681df88fdd..637faab973f174573c8dfeae685b6ae6025b9dab 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.db.CoreDbTester;
 import org.sonar.server.platform.db.migration.version.v63.DefaultOrganizationUuidProviderImpl;
 
 import static java.lang.String.valueOf;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.apache.commons.lang.math.RandomUtils.nextLong;
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -241,7 +242,7 @@ public class SupportPrivateProjectInDefaultPermissionTemplateTest {
   }
 
   private int insertGroup(String organizationUuid) {
-    String name = "name" + RandomStringUtils.random(20);
+    String name = "name" + randomAlphabetic(20);
     db.executeInsert(
       "GROUPS",
       "ORGANIZATION_UUID", organizationUuid,
index f31a4a0342ad6ea7a1f38427c67b7ee6de6e27bd..0dfe390aaed1e09d488941067d0e24f1797666ec 100644 (file)
@@ -62,7 +62,7 @@ import static java.util.Optional.ofNullable;
 import static java.util.stream.Collectors.joining;
 import static java.util.stream.IntStream.range;
 import static java.util.stream.Stream.of;
-import static org.apache.commons.lang.RandomStringUtils.random;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.groups.Tuple.tuple;
 import static org.mockito.Mockito.doReturn;
@@ -570,7 +570,7 @@ public class SuggestionsActionTest {
 
   @Test
   public void should_only_provide_project_for_certain_qualifiers() throws Exception {
-    String query = random(10);
+    String query = randomAlphabetic(10);
 
     ComponentDto view = db.components().insertView(organization, v -> v.setName(query));
     ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubView(view).setName(query));
index eca5ea07c004b5a2d827b472ef84b80ed1a2e5a3..b6998f59d1618697f43c9eed00020ec5239ebbb1 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.server.computation.task.projectanalysis.component.MutableDisabl
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 
 import static java.util.Collections.emptyList;
-import static org.apache.commons.lang.RandomStringUtils.random;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doReturn;
@@ -51,7 +51,7 @@ public class PersistComponentsStepTest {
     Component component = mock(Component.class);
     DbClient dbClient = mock(DbClient.class);
     ComponentDao componentDao = mock(ComponentDao.class);
-    String projectKey = random(20);
+    String projectKey = randomAlphabetic(20);
 
     doReturn(component).when(treeRootHolder).getRoot();
     doReturn(projectKey).when(component).getKey();
index 1866cabae52b676fc02478b0d23e2c3cb4f96be7..bbb79fb205fee4e6f473128f30e081c8d2dac966 100644 (file)
  */
 package org.sonar.server.qualityprofile.index;
 
-import org.apache.commons.lang.RandomStringUtils;
 import org.sonar.api.rule.Severity;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.rule.RuleTesting;
 
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+
 public class ActiveRuleDocTesting {
 
   public static ActiveRuleDoc newDoc() {
@@ -32,7 +33,7 @@ public class ActiveRuleDocTesting {
 
   public static ActiveRuleDoc newDoc(ActiveRuleKey key) {
     return new ActiveRuleDoc(key)
-      .setOrganizationUuid(RandomStringUtils.random(40))
+      .setOrganizationUuid(randomAlphabetic(40))
       .setSeverity(Severity.CRITICAL)
       .setInheritance(null).setCreatedAt(150000000L)
       .setUpdatedAt(160000000L);