Remove use of deprecated RandomStringUtils method (#2207)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-21 09:10:57 +02:00
committed by GitHub
parent e317a38d6d
commit d71a159db2
8 changed files with 42 additions and 65 deletions

View File

@@ -26,7 +26,6 @@ import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.ArtifactManagement;
@@ -117,8 +116,6 @@ public abstract class AbstractIntegrationTest {
protected static final URI LOCALHOST = URI.create("http://127.0.0.1");
protected static final int DEFAULT_TEST_WEIGHT = 500;
protected static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
/**
* Number of {@link DistributionSetType}s that exist in every test case. One
* generated by using
@@ -296,11 +293,11 @@ public abstract class AbstractIntegrationTest {
}
protected static String randomString(final int len) {
return RANDOM_STRING_UTILS.next(len, true, false);
return TestdataFactory.randomString(len);
}
protected static byte[] randomBytes(final int len) {
return randomString(len).getBytes();
return TestdataFactory.randomBytes(len);
}
protected DistributionSetAssignmentResult assignDistributionSet(final long dsID, final String controllerId) {

View File

@@ -9,12 +9,13 @@
*/
package org.eclipse.hawkbit.repository.test.util;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
/**
* Holds all database related configuration
*/
@Getter
@Slf4j
public class DatasourceContext {
@@ -23,19 +24,19 @@ public class DatasourceContext {
public static final String SPRING_DATABASE_USERNAME_KEY = "spring.datasource.username";
public static final String SPRING_DATABASE_PASSWORD_KEY = "spring.datasource.password";
public static final String DATABASE_PREFIX_KEY = "spring.database.random.prefix";
private static final String RANDOM_DB_PREFIX = System.getProperty(DATABASE_PREFIX_KEY, "HAWKBIT_TEST_");
private final String database;
private final String datasourceUrl;
private final String username;
private final String password;
private final String randomSchemaName = RANDOM_DB_PREFIX + RandomStringUtils.randomAlphanumeric(10);
private final String randomSchemaName = RANDOM_DB_PREFIX + TestdataFactory.randomString(10);
/**
* Constructor
*/
public DatasourceContext(final String database, final String datasourceUrl, final String username,
final String password) {
public DatasourceContext(final String database, final String datasourceUrl, final String username, final String password) {
this.database = database;
this.datasourceUrl = datasourceUrl;
this.username = username;
@@ -47,36 +48,14 @@ public class DatasourceContext {
*/
public DatasourceContext() {
database = System.getProperty(SPRING_DATABASE_KEY, System.getProperty(upperCaseVariant(SPRING_DATABASE_KEY)));
datasourceUrl = System.getProperty(SPRING_DATASOURCE_URL_KEY,
System.getProperty(upperCaseVariant(SPRING_DATASOURCE_URL_KEY)));
username = System.getProperty(SPRING_DATABASE_USERNAME_KEY,
System.getProperty(upperCaseVariant(SPRING_DATABASE_USERNAME_KEY)));
password = System.getProperty(SPRING_DATABASE_PASSWORD_KEY,
System.getProperty(upperCaseVariant(SPRING_DATABASE_PASSWORD_KEY)));
}
public String getDatabase() {
return database;
}
public String getDatasourceUrl() {
return datasourceUrl;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getRandomSchemaName() {
return randomSchemaName;
datasourceUrl = System.getProperty(SPRING_DATASOURCE_URL_KEY, System.getProperty(upperCaseVariant(SPRING_DATASOURCE_URL_KEY)));
username = System.getProperty(SPRING_DATABASE_USERNAME_KEY, System.getProperty(upperCaseVariant(SPRING_DATABASE_USERNAME_KEY)));
password = System.getProperty(SPRING_DATABASE_PASSWORD_KEY, System.getProperty(upperCaseVariant(SPRING_DATABASE_PASSWORD_KEY)));
}
public boolean isNotProperlyConfigured() {
log.debug("Datasource environment variables: [database: {}, username: {}, password: {}, datasourceUrl: {}]",
log.debug(
"Datasource environment variables: [database: {}, username: {}, password: {}, datasourceUrl: {}]",
database, username, password, datasourceUrl);
return database == null || datasourceUrl == null || username == null || password == null;
@@ -85,4 +64,4 @@ public class DatasourceContext {
private static String upperCaseVariant(final String key) {
return key.toUpperCase().replace('.', '_');
}
}
}

View File

@@ -138,6 +138,8 @@ public class TestdataFactory {
public static final String DEFAULT_COLOUR = "#000000";
public static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
private static final String SPACE_AND_DESCRIPTION = " description";
@Autowired
@@ -191,8 +193,16 @@ public class TestdataFactory {
@Autowired
private QuotaManagement quotaManagement;
public static String randomString(final int len) {
return RANDOM_STRING_UTILS.next(len, true, false);
}
public static byte[] randomBytes(final int len) {
return randomString(len).getBytes();
}
public Action performAssignment(final DistributionSet distributionSet) {
final Target target = createTarget(RandomStringUtils.randomAlphanumeric(5));
final Target target = createTarget(randomString(5));
final DeploymentRequest deploymentRequest = new DeploymentRequest(target.getControllerId(),
distributionSet.getId(), ActionType.FORCED, 0, null, null, null, null, false);
deploymentManagement.assignDistributionSets(Collections.singletonList(deploymentRequest));
@@ -1090,7 +1100,7 @@ public class TestdataFactory {
* @return created {@link Rollout}
*/
public Rollout createRollout() {
final String prefix = RandomStringUtils.randomAlphanumeric(5);
final String prefix = randomString(5);
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
prefix);
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
@@ -1158,7 +1168,7 @@ public class TestdataFactory {
public Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
final int amountOtherTargets, final int amountOfGroups, final String successCondition,
final String errorCondition, final ActionType actionType, final Integer weight) {
final String suffix = RandomStringUtils.randomAlphanumeric(5);
final String suffix = randomString(5);
final DistributionSet rolloutDS = createDistributionSet("rolloutDS-" + suffix);
createTargets(amountTargetsForRollout, "rollout-" + suffix + "-", "rollout");
createTargets(amountOtherTargets, "others-" + suffix + "-", "rollout");
@@ -1256,15 +1266,11 @@ public class TestdataFactory {
}
private static String randomDescriptionShort() {
return randomText(100);
return randomString(100);
}
private static String randomDescriptionLong() {
return randomText(200);
}
private static String randomText(final int len) {
return RandomStringUtils.randomAlphanumeric(len);
return randomString(200);
}
private void addTestModuleMetadata(final SoftwareModule module) {