Skip to content

Commit

Permalink
Fix SonarQube issues (3)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Jan 20, 2025
1 parent 5dabe91 commit 4400f1f
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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.ddi.json.model.DdiActivateAutoConfirmation;
import org.eclipse.hawkbit.ddi.json.model.DdiConfirmationFeedback;
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
Expand Down Expand Up @@ -507,7 +506,7 @@ private ResultActions sendConfirmationFeedback(
final Target target, final Action action,
final DdiConfirmationFeedback.Confirmation confirmation, Integer code, String message) throws Exception {
if (message == null) {
message = RandomStringUtils.randomAlphanumeric(1000);
message = randomString(1000);
}

final String feedback = getJsonConfirmationFeedback(confirmation, code, Collections.singletonList(message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
package org.eclipse.hawkbit.ddi.rest.resource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.SYSTEM_ROLE;
import static org.eclipse.hawkbit.im.authentication.SpPermission.TENANT_CONFIGURATION;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -37,7 +35,6 @@
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.ddi.json.model.DdiResult;
import org.eclipse.hawkbit.ddi.json.model.DdiStatus;
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
Expand All @@ -48,10 +45,8 @@
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTypeCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleTypeCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
Expand Down Expand Up @@ -692,7 +687,7 @@ void earliestActionIsExposedToControllerInMultiAssignMode() throws Exception {
@Test
@Description("The system should not create a new target because of a too long controller id.")
void rootRsWithInvalidControllerId() throws Exception {
final String invalidControllerId = RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1);
final String invalidControllerId = randomString(Target.CONTROLLER_ID_MAX_SIZE + 1);
mvc.perform(get(CONTROLLER_BASE, tenantAware.getCurrentTenant(), invalidControllerId))
.andExpect(status().isBadRequest());
}
Expand Down Expand Up @@ -735,7 +730,7 @@ private ResultActions sendDeploymentActionFeedback(final Target target, final Ac
finished = "none";
}
if (message == null) {
message = RandomStringUtils.randomAlphanumeric(1000);
message = randomString(1000);
}

final String feedback = getJsonActionFeedback(DdiStatus.ExecutionStatus.valueOf(execution.toUpperCase()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
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.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
Expand Down Expand Up @@ -1068,8 +1067,7 @@ public void invalidRequestsOnDistributionSetsResource() throws Exception {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());

final DistributionSet toLongName = testdataFactory
.generateDistributionSet(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1));
final DistributionSet toLongName = testdataFactory.generateDistributionSet(randomString(NamedEntity.NAME_MAX_SIZE + 1));
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
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.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
Expand Down Expand Up @@ -628,8 +627,10 @@ void invalidRequestsOnDistributionSetTypesResource() throws Exception {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());

final DistributionSetType toLongName = entityFactory.distributionSetType().create().key("test123")
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
final DistributionSetType toLongName = entityFactory.distributionSetType().create()
.key("test123")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))
.build();
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
Expand Down Expand Up @@ -413,8 +412,10 @@ public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());

final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create().key("test123")
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create()
.key("test123")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))
.build();
mvc.perform(
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import jakarta.validation.ConstraintViolationException;
Expand All @@ -40,7 +39,6 @@
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.assertj.core.api.Assertions;
import org.eclipse.hawkbit.im.authentication.SpPermission;
Expand Down Expand Up @@ -805,7 +803,7 @@ void findOrRegisterTargetIfItDoesNotExistThrowsExceptionForInvalidControllerIdPa
assertThatExceptionOfType(ConstraintViolationException.class)
.as("register target with too long controllerId should fail")
.isThrownBy(() -> controllerManagement.findOrRegisterTargetIfItDoesNotExist(
RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1), LOCALHOST));
randomString(Target.CONTROLLER_ID_MAX_SIZE + 1), LOCALHOST));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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.Condition;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties;
Expand Down Expand Up @@ -978,7 +977,7 @@ private void createAndUpdateDistributionSetWithInvalidDescription(final Distribu
assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long description should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version("a").description(RandomStringUtils.randomAlphanumeric(513))));
.version("a").description(randomString(513))));

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with invalid description should not be created")
Expand All @@ -988,7 +987,7 @@ private void createAndUpdateDistributionSetWithInvalidDescription(final Distribu
assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long description should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.description(RandomStringUtils.randomAlphanumeric(513))));
.description(randomString(513))));

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement
Expand All @@ -1000,8 +999,9 @@ private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long name should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a")
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create()
.version("a")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too short name should not be created").isThrownBy(() -> distributionSetManagement
Expand All @@ -1015,7 +1015,7 @@ private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet
assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement
Expand All @@ -1033,7 +1033,7 @@ private void createAndUpdateDistributionSetWithInvalidVersion(final Distribution
assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long version should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version(RandomStringUtils.randomAlphanumeric(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too short version should not be created").isThrownBy(() -> distributionSetManagement
Expand All @@ -1042,7 +1042,7 @@ private void createAndUpdateDistributionSetWithInvalidVersion(final Distribution
assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long version should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.version(RandomStringUtils.randomAlphanumeric(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));

assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too short version should not be updated").isThrownBy(() -> distributionSetManagement
Expand Down
Loading

0 comments on commit 4400f1f

Please sign in to comment.