Remove use of deprecated RandomStringUtils method (#2207)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -53,7 +53,6 @@ import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
@@ -554,7 +553,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Description("Ensures that target update request fails is updated value fails against a constraint.")
|
||||
void updateTargetDescriptionFailsIfInvalidLength() throws Exception {
|
||||
final String knownControllerId = "123";
|
||||
final String knownNewDescription = RandomStringUtils.randomAlphabetic(513);
|
||||
final String knownNewDescription = randomString(513);
|
||||
final String knownNameNotModify = "nameNotModify";
|
||||
final String body = new JSONObject().put("description", knownNewDescription).toString();
|
||||
|
||||
@@ -869,7 +868,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a target creation with empty name and a controllerId that exceeds the name length limitation is successful and the name gets truncated.")
|
||||
void createTargetWithEmptyNameAndLongControllerId() throws Exception {
|
||||
final String randomString = RandomStringUtils.randomAlphanumeric(JpaTarget.CONTROLLER_ID_MAX_SIZE);
|
||||
final String randomString = randomString(JpaTarget.CONTROLLER_ID_MAX_SIZE);
|
||||
|
||||
final Target target = entityFactory.target().create().controllerId(randomString).build();
|
||||
|
||||
@@ -950,7 +949,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Description("Verifies that a properties of new targets are validated as in allowed size range.")
|
||||
void createTargetWithInvalidPropertyBadRequest() throws Exception {
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1")
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
|
||||
|
||||
@@ -34,7 +34,6 @@ import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
@@ -510,7 +509,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final TargetType tooLongName = entityFactory.targetType().create()
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(tooLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
|
||||
@@ -23,7 +23,6 @@ import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
|
||||
@@ -33,7 +33,6 @@ import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.awaitility.Awaitility;
|
||||
@@ -1869,7 +1868,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that returned result considers provided sort parameter.")
|
||||
void findAllRolloutsConsidersSorting() {
|
||||
final String randomString = RandomStringUtils.randomAlphanumeric(5);
|
||||
final String randomString = randomString(5);
|
||||
final DistributionSet testDs = testdataFactory.createDistributionSet(randomString + "-testDs");
|
||||
testdataFactory.createTargets(10, randomString + "-testTarget-");
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
@@ -31,7 +31,6 @@ import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.SpRole;
|
||||
@@ -1231,7 +1230,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long description should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
|
||||
.description(RandomStringUtils.randomAlphanumeric(513))));
|
||||
.description(randomString(513))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be created").isThrownBy(() -> targetManagement
|
||||
@@ -1240,7 +1239,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long description should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId())
|
||||
.description(RandomStringUtils.randomAlphanumeric(513))));
|
||||
.description(randomString(513))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be updated").isThrownBy(() -> targetManagement.update(
|
||||
@@ -1253,7 +1252,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long name should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be created").isThrownBy(() -> targetManagement
|
||||
@@ -1262,7 +1261,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId())
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be updated").isThrownBy(() -> targetManagement
|
||||
@@ -1280,7 +1279,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long token should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
|
||||
.securityToken(RandomStringUtils.randomAlphanumeric(Target.SECURITY_TOKEN_MAX_SIZE + 1))));
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be created").isThrownBy(() -> targetManagement
|
||||
@@ -1289,7 +1288,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId())
|
||||
.securityToken(RandomStringUtils.randomAlphanumeric(Target.SECURITY_TOKEN_MAX_SIZE + 1))));
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be updated").isThrownBy(() -> targetManagement.update(
|
||||
@@ -1306,7 +1305,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long address should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
|
||||
.address(RandomStringUtils.randomAlphanumeric(513))));
|
||||
.address(randomString(513))));
|
||||
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class).as("target with invalid should not be created")
|
||||
.isThrownBy(() -> targetManagement
|
||||
@@ -1315,7 +1314,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long address should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId())
|
||||
.address(RandomStringUtils.randomAlphanumeric(513))));
|
||||
.address(randomString(513))));
|
||||
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid address should not be updated").isThrownBy(() -> targetManagement
|
||||
@@ -1335,7 +1334,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create()
|
||||
.controllerId(RandomStringUtils.randomAlphanumeric(Target.CONTROLLER_ID_MAX_SIZE + 1))));
|
||||
.controllerId(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid controller id should not be created").isThrownBy(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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('.', '_');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user