Fix SonarQube issues (3) (#2206)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-20 17:04:07 +02:00
committed by GitHub
parent 5dabe9117a
commit e317a38d6d
12 changed files with 77 additions and 333 deletions

View File

@@ -28,7 +28,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; 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.DdiActivateAutoConfirmation;
import org.eclipse.hawkbit.ddi.json.model.DdiConfirmationFeedback; import org.eclipse.hawkbit.ddi.json.model.DdiConfirmationFeedback;
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants; import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
@@ -507,7 +506,7 @@ class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
final Target target, final Action action, final Target target, final Action action,
final DdiConfirmationFeedback.Confirmation confirmation, Integer code, String message) throws Exception { final DdiConfirmationFeedback.Confirmation confirmation, Integer code, String message) throws Exception {
if (message == null) { if (message == null) {
message = RandomStringUtils.randomAlphanumeric(1000); message = randomString(1000);
} }
final String feedback = getJsonConfirmationFeedback(confirmation, code, Collections.singletonList(message)); final String feedback = getJsonConfirmationFeedback(confirmation, code, Collections.singletonList(message));

View File

@@ -10,9 +10,7 @@
package org.eclipse.hawkbit.ddi.rest.resource; package org.eclipse.hawkbit.ddi.rest.resource;
import static org.assertj.core.api.Assertions.assertThat; 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.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.eclipse.hawkbit.im.authentication.SpPermission.TENANT_CONFIGURATION;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@@ -37,7 +35,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; 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.DdiResult;
import org.eclipse.hawkbit.ddi.json.model.DdiStatus; import org.eclipse.hawkbit.ddi.json.model.DdiStatus;
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants; import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
@@ -48,10 +45,8 @@ import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; 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.ActionUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; 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.DistributionSetUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent; 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.SoftwareModuleUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
@@ -692,7 +687,7 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
@Test @Test
@Description("The system should not create a new target because of a too long controller id.") @Description("The system should not create a new target because of a too long controller id.")
void rootRsWithInvalidControllerId() throws Exception { 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)) mvc.perform(get(CONTROLLER_BASE, tenantAware.getCurrentTenant(), invalidControllerId))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
@@ -735,7 +730,7 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
finished = "none"; finished = "none";
} }
if (message == null) { if (message == null) {
message = RandomStringUtils.randomAlphanumeric(1000); message = randomString(1000);
} }
final String feedback = getJsonActionFeedback(DdiStatus.ExecutionStatus.valueOf(execution.toUpperCase()), final String feedback = getJsonActionFeedback(DdiStatus.ExecutionStatus.valueOf(execution.toUpperCase()),

View File

@@ -41,7 +41,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
@@ -1068,8 +1067,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
final DistributionSet toLongName = testdataFactory final DistributionSet toLongName = testdataFactory.generateDistributionSet(randomString(NamedEntity.NAME_MAX_SIZE + 1));
.generateDistributionSet(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1));
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(toLongName))) mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())

View File

@@ -33,7 +33,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
@@ -628,8 +627,10 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
final DistributionSetType toLongName = entityFactory.distributionSetType().create().key("test123") final DistributionSetType toLongName = entityFactory.distributionSetType().create()
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build(); .key("test123")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))
.build();
mvc.perform(post("/rest/v1/distributionsettypes") mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Collections.singletonList(toLongName))) .content(JsonBuilder.distributionSetTypes(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))

View File

@@ -31,7 +31,6 @@ import com.jayway.jsonpath.JsonPath;
import io.qameta.allure.Description; import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -413,8 +412,10 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create().key("test123") final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create()
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build(); .key("test123")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))
.build();
mvc.perform( mvc.perform(
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Collections.singletonList(toLongName))) post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))

View File

@@ -31,7 +31,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import jakarta.validation.ConstraintViolationException; import jakarta.validation.ConstraintViolationException;
@@ -40,7 +39,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission;
@@ -805,7 +803,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("register target with too long controllerId should fail") .as("register target with too long controllerId should fail")
.isThrownBy(() -> controllerManagement.findOrRegisterTargetIfItDoesNotExist( .isThrownBy(() -> controllerManagement.findOrRegisterTargetIfItDoesNotExist(
RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1), LOCALHOST)); randomString(Target.CONTROLLER_ID_MAX_SIZE + 1), LOCALHOST));
} }
@Test @Test

View File

@@ -31,7 +31,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.assertj.core.api.Condition; import org.assertj.core.api.Condition;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties; import org.eclipse.hawkbit.repository.RepositoryProperties;
@@ -978,7 +977,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long description should not be created") .as("entity with too long description should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a") .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version("a").description(RandomStringUtils.randomAlphanumeric(513)))); .version("a").description(randomString(513))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with invalid description should not be created") .as("entity with invalid description should not be created")
@@ -988,7 +987,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long description should not be updated") .as("entity with too long description should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.description(RandomStringUtils.randomAlphanumeric(513)))); .description(randomString(513))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement .as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement
@@ -1000,8 +999,9 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long name should not be created") .as("entity with too long name should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a") .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create()
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)))); .version("a")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too short name should not be created").isThrownBy(() -> distributionSetManagement .as("entity with too short name should not be created").isThrownBy(() -> distributionSetManagement
@@ -1015,7 +1015,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long name should not be updated") .as("entity with too long name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .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) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement .as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement
@@ -1033,7 +1033,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long version should not be created") .as("entity with too long version should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a") .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) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too short version should not be created").isThrownBy(() -> distributionSetManagement .as("entity with too short version should not be created").isThrownBy(() -> distributionSetManagement
@@ -1042,7 +1042,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long version should not be updated") .as("entity with too long version should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .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) assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too short version should not be updated").isThrownBy(() -> distributionSetManagement .as("entity with too short version should not be updated").isThrownBy(() -> distributionSetManagement

View File

@@ -25,7 +25,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
@@ -50,13 +49,13 @@ import org.junit.jupiter.api.Test;
*/ */
@Feature("Component Tests - Repository") @Feature("Component Tests - Repository")
@Story("DistributionSet Management") @Story("DistributionSet Management")
public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest { class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description("Verifies that management get access react as specfied on calls for non existing entities by means " @Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.") + "of Optional not present.")
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) }) @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() { void nonExistingEntityAccessReturnsNotPresent() {
assertThat(distributionSetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(distributionSetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent();
assertThat(distributionSetTypeManagement.findByKey(NOT_EXIST_ID)).isNotPresent(); assertThat(distributionSetTypeManagement.findByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetTypeManagement.findByName(NOT_EXIST_ID)).isNotPresent(); assertThat(distributionSetTypeManagement.findByName(NOT_EXIST_ID)).isNotPresent();
@@ -68,7 +67,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@ExpectEvents({ @ExpectEvents({
@Expect(type = DistributionSetCreatedEvent.class, count = 0), @Expect(type = DistributionSetCreatedEvent.class, count = 0),
@Expect(type = DistributionSetTypeCreatedEvent.class, count = 1) }) @Expect(type = DistributionSetTypeCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() { void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final List<Long> softwareModuleTypes = Collections.singletonList(osType.getId()); final List<Long> softwareModuleTypes = Collections.singletonList(osType.getId());
@@ -98,7 +97,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 0) }) @Expect(type = DistributionSetUpdatedEvent.class, count = 0) })
public void createAndUpdateDistributionSetWithInvalidFields() { void createAndUpdateDistributionSetWithInvalidFields() {
final DistributionSet set = testdataFactory.createDistributionSet(); final DistributionSet set = testdataFactory.createDistributionSet();
createAndUpdateDistributionSetWithInvalidDescription(set); createAndUpdateDistributionSetWithInvalidDescription(set);
@@ -108,7 +107,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Tests the successful module update of unused distribution set type which is in fact allowed.") @Description("Tests the successful module update of unused distribution set type which is in fact allowed.")
public void updateUnassignedDistributionSetTypeModules() { void updateUnassignedDistributionSetTypeModules() {
final DistributionSetType updatableType = distributionSetTypeManagement final DistributionSetType updatableType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); .create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty(); assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
@@ -133,7 +132,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Verifies that the quota for software module types per distribution set type is enforced as expected.") @Description("Verifies that the quota for software module types per distribution set type is enforced as expected.")
public void quotaMaxSoftwareModuleTypes() { void quotaMaxSoftwareModuleTypes() {
final int quota = quotaManagement.getMaxSoftwareModuleTypesPerDistributionSetType(); final int quota = quotaManagement.getMaxSoftwareModuleTypesPerDistributionSetType();
// create software module types // create software module types
final List<Long> moduleTypeIds = new ArrayList<>(); final List<Long> moduleTypeIds = new ArrayList<>();
@@ -180,7 +179,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Tests the successfull update of used distribution set type meta data which is in fact allowed.") @Description("Tests the successfull update of used distribution set type meta data which is in fact allowed.")
public void updateAssignedDistributionSetTypeMetaData() { void updateAssignedDistributionSetTypeMetaData() {
final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs(); final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs();
distributionSetTypeManagement.update( distributionSetTypeManagement.update(
@@ -193,7 +192,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Tests the unsuccessfull update of used distribution set type (module addition).") @Description("Tests the unsuccessfull update of used distribution set type (module addition).")
public void addModuleToAssignedDistributionSetTypeFails() { void addModuleToAssignedDistributionSetTypeFails() {
final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs(); final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs();
assertThatThrownBy(() -> distributionSetTypeManagement assertThatThrownBy(() -> distributionSetTypeManagement
@@ -203,7 +202,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Tests the unsuccessfull update of used distribution set type (module removal).") @Description("Tests the unsuccessfull update of used distribution set type (module removal).")
public void removeModuleToAssignedDistributionSetTypeFails() { void removeModuleToAssignedDistributionSetTypeFails() {
DistributionSetType nonUpdatableType = distributionSetTypeManagement DistributionSetType nonUpdatableType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); .create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty(); assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
@@ -220,7 +219,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Tests the successfull deletion of unused (hard delete) distribution set types.") @Description("Tests the successfull deletion of unused (hard delete) distribution set types.")
public void deleteUnassignedDistributionSetType() { void deleteUnassignedDistributionSetType() {
final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetTypeManagement final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("delete").name("to be deleted")); .create(entityFactory.distributionSetType().create().key("delete").name("to be deleted"));
@@ -232,7 +231,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Tests the successfull deletion of used (soft delete) distribution set types.") @Description("Tests the successfull deletion of used (soft delete) distribution set types.")
public void deleteAssignedDistributionSetType() { void deleteAssignedDistributionSetType() {
final int existing = (int) distributionSetTypeManagement.count(); final int existing = (int) distributionSetTypeManagement.count();
final JpaDistributionSetType toBeDeleted = (JpaDistributionSetType) distributionSetTypeManagement final JpaDistributionSetType toBeDeleted = (JpaDistributionSetType) distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted")); .create(entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted"));
@@ -252,7 +251,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
@Test @Test
@Description("Verifies that when no SoftwareModules are assigned to a Distribution then the DistributionSet is not complete.") @Description("Verifies that when no SoftwareModules are assigned to a Distribution then the DistributionSet is not complete.")
public void shouldFailWhenDistributionSetHasNoSoftwareModulesAssigned() { void shouldFailWhenDistributionSetHasNoSoftwareModulesAssigned() {
final JpaDistributionSetType jpaDistributionSetType = (JpaDistributionSetType) distributionSetTypeManagement final JpaDistributionSetType jpaDistributionSetType = (JpaDistributionSetType) distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("newType").name("new Type")); .create(entityFactory.distributionSetType().create().key("newType").name("new Type"));
@@ -271,7 +270,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long description should not be created") .as("set with too long description should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a") .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version("a").description(RandomStringUtils.randomAlphanumeric(513)))); .version("a").description(randomString(513))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set invalid description text should not be created") .as("set invalid description text should not be created")
@@ -281,7 +280,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long description should not be updated") .as("set with too long description should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.description(RandomStringUtils.randomAlphanumeric(513)))); .description(randomString(513))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid description should not be updated").isThrownBy(() -> distributionSetManagement .as("set with invalid description should not be updated").isThrownBy(() -> distributionSetManagement
@@ -294,7 +293,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be created") assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a") .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a")
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)))); .name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class).as("set with invalid name should not be created") assertThatExceptionOfType(ConstraintViolationException.class).as("set with invalid name should not be created")
.isThrownBy(() -> distributionSetManagement .isThrownBy(() -> distributionSetManagement
@@ -310,7 +309,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be updated") assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .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("set with invalid name should not be updated") assertThatExceptionOfType(ConstraintViolationException.class).as("set with invalid name should not be updated")
.isThrownBy(() -> distributionSetManagement .isThrownBy(() -> distributionSetManagement
@@ -327,7 +326,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long version should not be created") .as("set with too long version should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a") .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) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid version should not be created").isThrownBy(() -> distributionSetManagement .as("set with invalid version should not be created").isThrownBy(() -> distributionSetManagement
@@ -344,7 +343,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long version should not be updated") .as("set with too long version should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .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) assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid version should not be updated").isThrownBy(() -> distributionSetManagement .as("set with invalid version should not be updated").isThrownBy(() -> distributionSetManagement

View File

@@ -27,7 +27,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
@@ -239,7 +238,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with too long description should not be created") .as("tag with too long description should not be created")
.isThrownBy(() -> targetTagManagement.create( .isThrownBy(() -> targetTagManagement.create(
entityFactory.tag().create().name("a").description(RandomStringUtils.randomAlphanumeric(513)))); entityFactory.tag().create().name("a").description(randomString(513))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with invalid description should not be created").isThrownBy(() -> targetTagManagement .as("tag with invalid description should not be created").isThrownBy(() -> targetTagManagement
.create(entityFactory.tag().create().name("a").description(INVALID_TEXT_HTML))); .create(entityFactory.tag().create().name("a").description(INVALID_TEXT_HTML)));
@@ -247,7 +246,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
.as("tag with too long description should not be updated") .as("tag with too long description should not be updated")
.isThrownBy(() -> targetTagManagement.update( .isThrownBy(() -> targetTagManagement.update(
entityFactory.tag().update(tag.getId()) entityFactory.tag().update(tag.getId())
.description(RandomStringUtils.randomAlphanumeric(513)))); .description(randomString(513))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with invalid description should not be updated") .as("tag with invalid description should not be updated")
.isThrownBy(() -> targetTagManagement .isThrownBy(() -> targetTagManagement
@@ -259,14 +258,14 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with too long colour should not be created") .as("tag with too long colour should not be created")
.isThrownBy(() -> targetTagManagement.create( .isThrownBy(() -> targetTagManagement.create(
entityFactory.tag().create().name("a").colour(RandomStringUtils.randomAlphanumeric(17)))); entityFactory.tag().create().name("a").colour(randomString(17))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with invalid colour should not be created").isThrownBy(() -> targetTagManagement .as("tag with invalid colour should not be created").isThrownBy(() -> targetTagManagement
.create(entityFactory.tag().create().name("a").colour(INVALID_TEXT_HTML))); .create(entityFactory.tag().create().name("a").colour(INVALID_TEXT_HTML)));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with too long colour should not be updated") .as("tag with too long colour should not be updated")
.isThrownBy(() -> targetTagManagement.update( .isThrownBy(() -> targetTagManagement.update(
entityFactory.tag().update(tag.getId()).colour(RandomStringUtils.randomAlphanumeric(17)))); entityFactory.tag().update(tag.getId()).colour(randomString(17))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with invalid colour should not be updated").isThrownBy(() -> targetTagManagement .as("tag with invalid colour should not be updated").isThrownBy(() -> targetTagManagement
.update(entityFactory.tag().update(tag.getId()).colour(INVALID_TEXT_HTML))); .update(entityFactory.tag().update(tag.getId()).colour(INVALID_TEXT_HTML)));
@@ -277,16 +276,14 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with too long name should not be created") .as("tag with too long name should not be created")
.isThrownBy(() -> targetTagManagement .isThrownBy(() -> targetTagManagement
.create(entityFactory.tag().create().name(RandomStringUtils.randomAlphanumeric( .create(entityFactory.tag().create().name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with invalidname should not be created") .as("tag with invalidname should not be created")
.isThrownBy(() -> targetTagManagement.create(entityFactory.tag().create().name(INVALID_TEXT_HTML))); .isThrownBy(() -> targetTagManagement.create(entityFactory.tag().create().name(INVALID_TEXT_HTML)));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("tag with too long name should not be updated") .as("tag with too long name should not be updated")
.isThrownBy(() -> targetTagManagement .isThrownBy(() -> targetTagManagement
.update(entityFactory.tag().update(tag.getId()).name(RandomStringUtils.randomAlphanumeric( .update(entityFactory.tag().update(tag.getId()).name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class).as("tag with invalid name should not be updated") assertThatExceptionOfType(ConstraintViolationException.class).as("tag with invalid name should not be updated")
.isThrownBy(() -> targetTagManagement .isThrownBy(() -> targetTagManagement
.update(entityFactory.tag().update(tag.getId()).name(INVALID_TEXT_HTML))); .update(entityFactory.tag().update(tag.getId()).name(INVALID_TEXT_HTML)));

View File

@@ -22,7 +22,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Step; import io.qameta.allure.Step;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTypeCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTypeCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTypeUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTypeUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
@@ -78,8 +77,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long description should not be created") .as("targetType with too long description should not be created")
.isThrownBy(() -> targetTypeManagement.create( .isThrownBy(() -> targetTypeManagement.create(
entityFactory.targetType().create().name("a").description( entityFactory.targetType().create().name("a").description(randomString(TargetType.DESCRIPTION_MAX_SIZE + 1))));
RandomStringUtils.randomAlphanumeric(TargetType.DESCRIPTION_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid description should not be created").isThrownBy(() -> targetTypeManagement .as("targetType with invalid description should not be created").isThrownBy(() -> targetTypeManagement
@@ -88,8 +86,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long description should not be updated") .as("targetType with too long description should not be updated")
.isThrownBy(() -> targetTypeManagement.update( .isThrownBy(() -> targetTypeManagement.update(
entityFactory.targetType().update(targetType.getId()).description( entityFactory.targetType().update(targetType.getId()).description(randomString(TargetType.DESCRIPTION_MAX_SIZE + 1))));
RandomStringUtils.randomAlphanumeric(TargetType.DESCRIPTION_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid description should not be updated") .as("targetType with invalid description should not be updated")
@@ -213,8 +210,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long colour should not be created") .as("targetType with too long colour should not be created")
.isThrownBy(() -> targetTypeManagement.create( .isThrownBy(() -> targetTypeManagement.create(
entityFactory.targetType().create().name("a") entityFactory.targetType().create().name("a").colour(randomString(Type.COLOUR_MAX_SIZE + 1))));
.colour(RandomStringUtils.randomAlphanumeric(Type.COLOUR_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid colour should not be created").isThrownBy(() -> targetTypeManagement .as("targetType with invalid colour should not be created").isThrownBy(() -> targetTypeManagement
@@ -223,8 +219,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long colour should not be updated") .as("targetType with too long colour should not be updated")
.isThrownBy(() -> targetTypeManagement.update( .isThrownBy(() -> targetTypeManagement.update(
entityFactory.targetType().update(targetType.getId()) entityFactory.targetType().update(targetType.getId()).colour(randomString(Type.COLOUR_MAX_SIZE + 1))));
.colour(RandomStringUtils.randomAlphanumeric(Type.COLOUR_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid colour should not be updated").isThrownBy(() -> targetTypeManagement .as("targetType with invalid colour should not be updated").isThrownBy(() -> targetTypeManagement
@@ -235,9 +230,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
private void createTargetTypeWithInvalidKey() { private void createTargetTypeWithInvalidKey() {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long key should not be created") .as("targetType with too long key should not be created")
.isThrownBy(() -> targetTypeManagement .isThrownBy(() -> targetTypeManagement.create(entityFactory.targetType().create().name(randomString(Type.KEY_MAX_SIZE + 1))));
.create(entityFactory.targetType().create().name(RandomStringUtils.randomAlphanumeric(
Type.KEY_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid key should not be created").isThrownBy( .as("targetType with invalid key should not be created").isThrownBy(
@@ -249,8 +242,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long name should not be created") .as("targetType with too long name should not be created")
.isThrownBy(() -> targetTypeManagement .isThrownBy(() -> targetTypeManagement
.create(entityFactory.targetType().create().name(RandomStringUtils.randomAlphanumeric( .create(entityFactory.targetType().create().name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid name should not be created").isThrownBy( .as("targetType with invalid name should not be created").isThrownBy(
@@ -259,8 +251,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with too long name should not be updated") .as("targetType with too long name should not be updated")
.isThrownBy(() -> targetTypeManagement .isThrownBy(() -> targetTypeManagement
.update(entityFactory.targetType().update(targetType.getId()).name(RandomStringUtils.randomAlphanumeric( .update(entityFactory.targetType().update(targetType.getId()).name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid name should not be updated").isThrownBy(() -> targetTypeManagement .as("targetType with invalid name should not be updated").isThrownBy(() -> targetTypeManagement

View File

@@ -107,7 +107,8 @@ import org.springframework.test.context.TestPropertySource;
// Cleaning repository will fire "delete" events. We won't count them to the // Cleaning repository will fire "delete" events. We won't count them to the
// test execution. So, the order execution between EventVerifier and Cleanup is // test execution. So, the order execution between EventVerifier and Cleanup is
// important! // important!
@TestExecutionListeners(listeners = { EventVerifier.class, CleanupTestExecutionListener.class }, @TestExecutionListeners(
listeners = { EventVerifier.class, CleanupTestExecutionListener.class },
mergeMode = MergeMode.MERGE_WITH_DEFAULTS) mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
@TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true") @TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true")
public abstract class AbstractIntegrationTest { public abstract class AbstractIntegrationTest {

View File

@@ -14,9 +14,10 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomStringUtils; import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
@@ -35,18 +36,19 @@ import org.springframework.util.CollectionUtils;
/** /**
* Builder class for building certain json strings. * Builder class for building certain json strings.
*/ */
public abstract class JsonBuilder { @NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
public class JsonBuilder {
public static String ids(final Collection<Long> ids) throws JSONException { public static String ids(final Collection<Long> ids) throws JSONException {
final JSONArray list = new JSONArray(); final JSONArray list = new JSONArray();
for (final Long smID : ids) { for (final Long smID : ids) {
list.put(new JSONObject().put("id", smID)); list.put(new JSONObject().put("id", smID));
} }
return list.toString(); return list.toString();
} }
public static <T> String toArray(final Collection<T> ids) throws JSONException { public static <T> String toArray(final Collection<T> ids) {
final JSONArray list = new JSONArray(); final JSONArray list = new JSONArray();
for (final T smID : ids) { for (final T smID : ids) {
list.put(smID); list.put(smID);
@@ -66,20 +68,15 @@ public abstract class JsonBuilder {
builder.append(","); builder.append(",");
} }
} }
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
public static String tag(final Tag tag) throws JSONException { public static String tag(final Tag tag) throws JSONException {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
createTagLine(builder, tag); createTagLine(builder, tag);
return builder.toString(); return builder.toString();
} }
public static String softwareModules(final List<SoftwareModule> modules) throws JSONException { public static String softwareModules(final List<SoftwareModule> modules) throws JSONException {
@@ -98,42 +95,9 @@ public abstract class JsonBuilder {
builder.append(","); builder.append(",");
} }
} }
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
}
public static String softwareModulesCreatableFieldsOnly(final List<SoftwareModule> modules) throws JSONException {
final StringBuilder builder = new StringBuilder();
builder.append("[");
int i = 0;
for (final SoftwareModule module : modules) {
builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription())
.put("type", module.getType().getKey()).put("vendor", module.getVendor())
.put("version", module.getVersion()).toString());
if (++i < modules.size()) {
builder.append(",");
}
}
builder.append("]");
return builder.toString();
}
public static String softwareModuleUpdatableFieldsOnly(final SoftwareModule module) throws JSONException {
final StringBuilder builder = new StringBuilder();
builder.append(new JSONObject().put("description", module.getDescription()).put("vendor", module.getVendor())
.toString());
return builder.toString();
} }
public static String softwareModuleTypes(final List<SoftwareModuleType> types) throws JSONException { public static String softwareModuleTypes(final List<SoftwareModuleType> types) throws JSONException {
@@ -151,81 +115,21 @@ public abstract class JsonBuilder {
builder.append(","); builder.append(",");
} }
} }
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
}
public static String softwareModuleTypesCreatableFieldsOnly(final List<SoftwareModuleType> types)
throws JSONException {
final StringBuilder builder = new StringBuilder();
builder.append("[");
int i = 0;
for (final SoftwareModuleType module : types) {
builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription())
.put("colour", module.getColour()).put("key", module.getKey())
.put("maxAssignments", module.getMaxAssignments()).toString());
if (++i < types.size()) {
builder.append(",");
}
}
builder.append("]");
return builder.toString();
}
/**
* Build an invalid request body with missing result for feedback message.
*
* @param id id of the action
* @param execution the execution
* @param message the message
* @return a invalid request body
* @throws JSONException
*/
public static String missingResultInFeedback(final String id, final String execution, final String message)
throws JSONException {
return new JSONObject().put("id", id).put("time", "20140511T121314")
.put("status",
new JSONObject().put("execution", execution).put("details", new JSONArray().put(message)))
.toString();
}
/**
* Build an invalid request body with missing finished result for feedback
* message.
*
* @param id id of the action
* @param execution the execution
* @param message the message
* @return a invalid request body
* @throws JSONException
*/
public static String missingFinishedResultInFeedback(final String id, final String execution, final String message)
throws JSONException {
return new JSONObject().put("id", id).put("time", "20140511T121314")
.put("status", new JSONObject().put("execution", execution).put("result", new JSONObject())
.put("details", new JSONArray().put(message)))
.toString();
} }
public static String distributionSetTypes(final List<DistributionSetType> types) throws JSONException { public static String distributionSetTypes(final List<DistributionSetType> types) throws JSONException {
final JSONArray result = new JSONArray(); final JSONArray result = new JSONArray();
for (final DistributionSetType type : types) { for (final DistributionSetType type : types) {
final JSONArray osmTypes = new JSONArray(); final JSONArray osmTypes = new JSONArray();
type.getOptionalModuleTypes().forEach(smt -> { type.getOptionalModuleTypes().forEach(smt -> {
try { try {
osmTypes.put(new JSONObject().put("id", smt.getId())); osmTypes.put(new JSONObject().put("id", smt.getId()));
} catch (final JSONException e1) { } catch (final JSONException e1) {
e1.printStackTrace(); log.error("JSONException (skip)", e1);
} }
}); });
@@ -234,7 +138,7 @@ public abstract class JsonBuilder {
try { try {
msmTypes.put(new JSONObject().put("id", smt.getId())); msmTypes.put(new JSONObject().put("id", smt.getId()));
} catch (final JSONException e) { } catch (final JSONException e) {
e.printStackTrace(); log.error("JSONException (skip)", e);
} }
}); });
@@ -249,47 +153,14 @@ public abstract class JsonBuilder {
return result.toString(); return result.toString();
} }
public static String distributionSetTypesCreateValidFieldsOnly(final List<DistributionSetType> types) { public static String distributionSets(final List<DistributionSet> sets) {
final JSONArray result = new JSONArray();
for (final DistributionSetType module : types) {
try {
final JSONArray osmTypes = new JSONArray();
module.getOptionalModuleTypes().forEach(smt -> {
try {
osmTypes.put(new JSONObject().put("id", smt.getId()));
} catch (final JSONException e) {
e.printStackTrace();
}
});
final JSONArray msmTypes = new JSONArray();
module.getMandatoryModuleTypes().forEach(smt -> {
try {
msmTypes.put(new JSONObject().put("id", smt.getId()));
} catch (final JSONException e) {
e.printStackTrace();
}
});
result.put(new JSONObject().put("name", module.getName()).put("description", module.getDescription())
.put("colour", module.getColour()).put("key", module.getKey()).put("optionalmodules", osmTypes)
.put("mandatorymodules", msmTypes));
} catch (final JSONException e) {
e.printStackTrace();
}
}
return result.toString();
}
public static String distributionSets(final List<DistributionSet> sets) throws JSONException {
final JSONArray setsJson = new JSONArray(); final JSONArray setsJson = new JSONArray();
sets.forEach(set -> { sets.forEach(set -> {
try { try {
setsJson.put(distributionSet(set)); setsJson.put(distributionSet(set));
} catch (final JSONException e) { } catch (final JSONException e) {
e.printStackTrace(); log.error("JSONException (skip)", e);
} }
}); });
@@ -297,62 +168,15 @@ public abstract class JsonBuilder {
} }
public static String distributionSetsCreateValidFieldsOnly(final List<DistributionSet> sets) throws JSONException {
final JSONArray result = new JSONArray();
for (final DistributionSet set : sets) {
result.put(distributionSetCreateValidFieldsOnly(set));
}
return result.toString();
}
public static JSONObject distributionSetCreateValidFieldsOnly(final DistributionSet set) throws JSONException {
final List<JSONObject> modules = set.getModules().stream().map(module -> {
try {
return new JSONObject().put("id", module.getId());
} catch (final JSONException e) {
e.printStackTrace();
return null;
}
}).collect(Collectors.toList());
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
.put("type", set.getType() == null ? null : set.getType().getKey()).put("version", set.getVersion())
.put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", new JSONArray(modules));
}
public static String distributionSetUpdateValidFieldsOnly(final DistributionSet set) throws JSONException {
set.getModules().stream().map(module -> {
try {
return new JSONObject().put("id", module.getId());
} catch (final JSONException e) {
e.printStackTrace();
return null;
}
}).collect(Collectors.toList());
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
.put("version", set.getVersion()).put("requiredMigrationStep", set.isRequiredMigrationStep())
.toString();
}
public static JSONObject distributionSet(final DistributionSet set) throws JSONException { public static JSONObject distributionSet(final DistributionSet set) throws JSONException {
final List<JSONObject> modules = set.getModules().stream().map(module -> { final List<JSONObject> modules = set.getModules().stream().map(module -> {
try { try {
return new JSONObject().put("id", module.getId()); return new JSONObject().put("id", module.getId());
} catch (final JSONException e) { } catch (final JSONException e) {
e.printStackTrace(); log.error("JSONException (skip)", e);
return null; return null;
} }
}).collect(Collectors.toList()); }).toList();
return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
.put("type", set.getType() == null ? null : set.getType().getKey()).put("id", Long.MAX_VALUE) .put("type", set.getType() == null ? null : set.getType().getKey()).put("id", Long.MAX_VALUE)
@@ -387,15 +211,13 @@ public abstract class JsonBuilder {
return builder.toString(); return builder.toString();
} }
public static String targets(final List<Target> targets, final boolean withToken, final long targetTypeId) public static String targets(final List<Target> targets, final boolean withToken, final long targetTypeId) throws JSONException {
throws JSONException {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
builder.append("["); builder.append("[");
int i = 0; int i = 0;
for (final Target target : targets) { for (final Target target : targets) {
final String address = target.getAddress() != null ? target.getAddress().toString() : null; final String address = target.getAddress() != null ? target.getAddress().toString() : null;
final String type = target.getTargetType() != null ? target.getTargetType().getId().toString() : null;
final String token = withToken ? target.getSecurityToken() : null; final String token = withToken ? target.getSecurityToken() : null;
builder.append(new JSONObject().put("controllerId", target.getControllerId()) builder.append(new JSONObject().put("controllerId", target.getControllerId())
@@ -423,7 +245,7 @@ public abstract class JsonBuilder {
try { try {
dsTypes.put(new JSONObject().put("id", dsType.getId())); dsTypes.put(new JSONObject().put("id", dsType.getId()));
} catch (final JSONException e1) { } catch (final JSONException e1) {
e1.printStackTrace(); log.error("JSONException (skip)", e1);
} }
}); });
@@ -437,46 +259,12 @@ public abstract class JsonBuilder {
return result.toString(); return result.toString();
} }
public static String targetTypesCreatableFieldsOnly(final List<TargetType> types) throws JSONException {
final JSONArray result = new JSONArray();
for (final TargetType type : types) {
final JSONArray dsTypes = new JSONArray();
type.getCompatibleDistributionSetTypes().forEach(dsType -> {
try {
dsTypes.put(new JSONObject().put("id", dsType.getId()));
} catch (final JSONException e1) {
e1.printStackTrace();
}
});
final JSONObject json = new JSONObject().put("name", type.getName())
.put("description", type.getDescription()).put("colour", type.getColour());
if (dsTypes.length() != 0) {
json.put("compatibledistributionsettypes", dsTypes);
}
result.put(json);
}
return result.toString();
}
public static String rollout(final String name, final String description, final int groupSize, public static String rollout(final String name, final String description, final int groupSize,
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions) { final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions) {
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null, null, null, return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null, null, null,
null, null, null); null, null, null);
} }
public static String rollout(final String name, final String description, final Integer groupSize,
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
final String type) {
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null, type,
null, null, null, null);
}
public static String rolloutWithGroups(final String name, final String description, final Integer groupSize, public static String rolloutWithGroups(final String name, final String description, final Integer groupSize,
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions, final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
final List<RolloutGroup> groups) { final List<RolloutGroup> groups) {
@@ -488,9 +276,9 @@ public abstract class JsonBuilder {
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions, final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
final List<RolloutGroup> groups, final String type, final Integer weight, final List<RolloutGroup> groups, final String type, final Integer weight,
final Boolean confirmationRequired) { final Boolean confirmationRequired) {
final List<String> rolloutGroupsJson = groups.stream().map(JsonBuilder::rolloutGroup) final List<String> rolloutGroupsJson = groups.stream().map(JsonBuilder::rolloutGroup).toList();
.collect(Collectors.toList()); return rollout(
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, name, description, groupSize, distributionSetId, targetFilterQuery, conditions,
rolloutGroupsJson, type, weight, System.currentTimeMillis(), null, confirmationRequired); rolloutGroupsJson, type, weight, System.currentTimeMillis(), null, confirmationRequired);
} }
@@ -578,7 +366,7 @@ public abstract class JsonBuilder {
} }
} catch (final JSONException e) { } catch (final JSONException e) {
e.printStackTrace(); log.error("JSONException (skip)", e);
} }
return json.toString(); return json.toString();
@@ -635,48 +423,24 @@ public abstract class JsonBuilder {
} }
} catch (final JSONException e) { } catch (final JSONException e) {
e.printStackTrace(); log.error("JSONException (skip)", e);
fail("Cannot parse JSON for rollout group."); fail("Cannot parse JSON for rollout group.");
} }
return jsonGroup.toString(); return jsonGroup.toString();
} }
public static String cancelActionFeedback(final String id, final String execution) throws JSONException {
return cancelActionFeedback(id, execution, null, RandomStringUtils.randomAlphanumeric(1000));
}
public static String cancelActionFeedback(final String id, final String execution, final String message)
throws JSONException {
return cancelActionFeedback(id, execution, null, message);
}
public static String cancelActionFeedback(final String id, final String execution, final Integer code,
final String message) throws JSONException {
final JSONObject statusJson = new JSONObject().put("execution", execution)
.put("result", new JSONObject().put("finished", "success"))
.put("details", new JSONArray().put(message));
if (code != null) {
statusJson.put("code", code);
}
return new JSONObject().put("id", id).put("status", statusJson).toString();
}
public static JSONObject configData(final Map<String, String> attributes) throws JSONException { public static JSONObject configData(final Map<String, String> attributes) throws JSONException {
return configData(attributes, null); return configData(attributes, null);
} }
public static JSONObject configData(final Map<String, String> attributes, final String mode) throws JSONException { public static JSONObject configData(final Map<String, String> attributes, final String mode) throws JSONException {
final JSONObject data = new JSONObject(); final JSONObject data = new JSONObject();
attributes.entrySet().forEach(entry -> { attributes.forEach((key, value) -> {
try { try {
data.put(entry.getKey(), entry.getValue()); data.put(key, value);
} catch (final JSONException e) { } catch (final JSONException e) {
e.printStackTrace(); log.error("JSONException (skip)", e);
} }
}); });