Skip to content

Commit

Permalink
Improve reliability of SupportPrivateProjectInDefaultPermissionTempla…
Browse files Browse the repository at this point in the history
…teTest

There were some false-positives due to generated random values
that are not unique.
  • Loading branch information
Simon Brandhof committed May 5, 2017
1 parent 64ef4f0 commit 788e9ef
Showing 1 changed file with 5 additions and 5 deletions.
Expand Up @@ -20,9 +20,9 @@
package org.sonar.server.platform.db.migration.version.v64;

import java.sql.SQLException;
import java.util.Random;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -241,7 +241,7 @@ private void insertOrganization(String uuid, @Nullable Integer defaultGroupId, @
}

private int insertGroup(String organizationUuid) {
String name = "name" + new Random().nextInt(122);
String name = "name" + RandomStringUtils.random(20);
db.executeInsert(
"GROUPS",
"ORGANIZATION_UUID", organizationUuid,
Expand All @@ -251,12 +251,12 @@ private int insertGroup(String organizationUuid) {
}

private IdAndUuid insertPermissionTemplate(String organizationUuid) {
int i = new Random().nextInt(1222);
String uuid = "ptUuid" + i;
String random = RandomStringUtils.random(20);
String uuid = "ptUuid" + random;
db.executeInsert(
"PERMISSION_TEMPLATES",
"ORGANIZATION_UUID", organizationUuid,
"NAME", "name" + i,
"NAME", "name" + random,
"KEE", uuid);
return new IdAndUuid(
((Long) db.selectFirst("select id as \"ID\" from permission_templates where kee='" + uuid + "'").get("ID")).intValue(),
Expand Down

0 comments on commit 788e9ef

Please sign in to comment.