Reduce dependency on Guava (#1589)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-02-02 22:21:46 +02:00
committed by GitHub
parent 0ee916e8cb
commit bce69676d2
63 changed files with 222 additions and 332 deletions

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
@@ -33,7 +34,6 @@ import org.springframework.util.MimeTypeUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
/**
* Test the remote entity events.
@@ -57,13 +57,13 @@ public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest
}
private Message<?> createProtoStuffMessage(final TenantAwareEvent event) {
final Map<String, Object> headers = Maps.newLinkedHashMap();
final Map<String, Object> headers = new LinkedHashMap<>();
headers.put(MessageHeaders.CONTENT_TYPE, BusProtoStuffMessageConverter.APPLICATION_BINARY_PROTOSTUFF);
return busProtoStuffMessageConverter.toMessage(event, new MutableMessageHeaders(headers));
}
private Message<String> createJsonMessage(final Object event) {
final Map<String, MimeType> headers = Maps.newLinkedHashMap();
final Map<String, MimeType> headers = new LinkedHashMap<>();
headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
try {
final String json = new ObjectMapper().writeValueAsString(event);
@@ -76,7 +76,7 @@ public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest
}
protected Message<?> createMessageWithImmutableHeader(final TenantAwareEvent event) {
final Map<String, Object> headers = Maps.newLinkedHashMap();
final Map<String, Object> headers = new LinkedHashMap<>();
return busProtoStuffMessageConverter.toMessage(event, new MessageHeaders(headers));
}

View File

@@ -9,9 +9,13 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@@ -63,8 +67,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import static org.assertj.core.api.Assertions.assertThat;
@ContextConfiguration(classes = {
@@ -143,7 +145,7 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
@Transactional(readOnly = true)
protected List<Action> findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) {
return Lists.newArrayList(actionRepository.findByRolloutIdAndStatus(PAGE, rollout.getId(), actionStatus));
return toList(actionRepository.findByRolloutIdAndStatus(PAGE, rollout.getId(), actionStatus));
}
protected static void verifyThrownExceptionBy(final ThrowingCallable tc, final String objectType) {
@@ -205,4 +207,17 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
protected JpaRolloutGroup refresh(final RolloutGroup group) {
return rolloutGroupRepository.findById(group.getId()).get();
}
protected static <T> List<T> toList(final Iterable<? extends T> it) {
return StreamSupport.stream(it.spliterator(), false).map(e -> (T)e).toList();
}
protected static <T> T[] toArray(final Iterable<? extends T> it, final Class<T> type) {
final List<T> list = toList(it);
final T[] array = (T[])Array.newInstance(type, list.size());
for (int i = 0; i < array.length; i++) {
array[i] = list.get(i);
}
return array;
}
}

View File

@@ -19,6 +19,8 @@ import java.io.InputStream;
import java.net.URISyntaxException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HexFormat;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;
@@ -54,9 +56,6 @@ import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@@ -185,7 +184,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
// now create artifacts for this module until the quota is exceeded
final long maxArtifacts = quotaManagement.getMaxArtifactsPerSoftwareModule();
final List<Long> artifactIds = Lists.newArrayList();
final List<Long> artifactIds = new ArrayList<>();
final int artifactSize = 5 * 1024;
for (int i = 0; i < maxArtifacts; ++i) {
artifactIds.add(createArtifactForSoftwareModule("file" + i, smId, artifactSize).getId());
@@ -213,7 +212,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
// create as many small artifacts as possible w/o violating the storage
// quota
final long maxBytes = quotaManagement.getMaxArtifactStorage();
final List<Long> artifactIds = Lists.newArrayList();
final List<Long> artifactIds = new ArrayList<>();
// choose an artifact size which does not violate the max file size
final int artifactSize = Math.toIntExact(quotaManagement.getMaxArtifactSize() / 10);
@@ -591,7 +590,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
private String toBase16Hash(final String algorithm, final byte[] input) throws NoSuchAlgorithmException {
final MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
messageDigest.update(input);
return BaseEncoding.base16().lowerCase().encode(messageDigest.digest());
return HexFormat.of().withLowerCase().formatHex(messageDigest.digest());
}
private Artifact createArtifactForSoftwareModule(final String filename, final long moduleId, final int artifactSize)

View File

@@ -86,9 +86,6 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.ConcurrencyFailureException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
@@ -156,7 +153,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> controllerManagement.registerRetrieved(NOT_EXIST_IDL, "test message"), "Action");
verifyThrownExceptionBy(
() -> controllerManagement.updateControllerAttributes(NOT_EXIST_ID, Maps.newHashMap(), null), "Target");
() -> controllerManagement.updateControllerAttributes(NOT_EXIST_ID, new HashMap<>(), null), "Target");
}
@Test
@@ -973,7 +970,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Step
private void addAttributeAndVerify(final String controllerId) {
final Map<String, String> testData = Maps.newHashMapWithExpectedSize(1);
final Map<String, String> testData = new HashMap<>(1);
testData.put("test1", "testdata1");
controllerManagement.updateControllerAttributes(controllerId, testData, null);
@@ -983,7 +980,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Step
private void addSecondAttributeAndVerify(final String controllerId) {
final Map<String, String> testData = Maps.newHashMapWithExpectedSize(2);
final Map<String, String> testData = new HashMap<>(2);
testData.put("test2", "testdata20");
controllerManagement.updateControllerAttributes(controllerId, testData, null);
@@ -994,7 +991,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Step
private void updateAttributeAndVerify(final String controllerId) {
final Map<String, String> testData = Maps.newHashMapWithExpectedSize(2);
final Map<String, String> testData = new HashMap<>(2);
testData.put("test1", "testdata12");
controllerManagement.updateControllerAttributes(controllerId, testData, null);
@@ -1141,7 +1138,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
private void writeAttributes(final String controllerId, final int allowedAttributes, final String keyPrefix,
final String valuePrefix) {
final Map<String, String> testData = Maps.newHashMapWithExpectedSize(allowedAttributes);
final Map<String, String> testData = new HashMap<>(allowedAttributes);
for (int i = 0; i < allowedAttributes; i++) {
testData.put(keyPrefix + i, valuePrefix);
}
@@ -1212,13 +1209,13 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
.status(Action.Status.RUNNING).occurredAt(System.currentTimeMillis())
.messages(Lists.newArrayList("proceeding message 1")));
.messages(List.of("proceeding message 1")));
final long createTime = System.currentTimeMillis();
waitNextMillis();
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
.status(Action.Status.RUNNING).occurredAt(System.currentTimeMillis())
.messages(Lists.newArrayList("proceeding message 2")));
.messages(List.of("proceeding message 2")));
final List<String> messages = controllerManagement.getActionHistoryMessages(actionId, 2);
@@ -1279,7 +1276,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assignDistributionSet(testdataFactory.createDistributionSet("ds1"), testdataFactory.createTargets(1)));
assertThat(actionId).isNotNull();
final List<String> messages = Lists.newArrayList();
final List<String> messages = new ArrayList<>();
IntStream.range(0, maxMessages).forEach(i -> messages.add(i, "msg"));
assertThat(controllerManagement.addInformationalActionStatus(

View File

@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -90,10 +91,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort.Direction;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@@ -259,7 +256,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that tag to distribution set assignment that does not exist will cause EntityNotFoundException.")
void assignDistributionSetToTagThatDoesNotExistThrowsException() {
final List<Long> assignDS = Lists.newArrayListWithExpectedSize(5);
final List<Long> assignDS = new ArrayList<>(5);
for (int i = 0; i < 4; i++) {
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
}
@@ -730,9 +727,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet createdDs = testdataFactory.createDistributionSet();
final String[] knownTargetIdsArray = { "1", "2" };
final List<String> knownTargetIds = Lists.newArrayList(knownTargetIdsArray);
testdataFactory.createTargets(knownTargetIdsArray);
final List<String> knownTargetIds = new ArrayList<>();
knownTargetIds.add( "1");
knownTargetIds.add("2");
testdataFactory.createTargets(knownTargetIds.toArray(new String[0]));
// add not existing target to targets
knownTargetIds.add(notExistingId);
@@ -1055,9 +1053,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets)
.containsAll(savedNakedTargets);
assertThat(savedDeployedTargets).as("saved target are wrong")
.doesNotContain(Iterables.toArray(savedNakedTargets, Target.class));
.doesNotContain(toArray(savedNakedTargets, Target.class));
assertThat(savedNakedTargets).as("saved target are wrong")
.doesNotContain(Iterables.toArray(savedDeployedTargets, Target.class));
.doesNotContain(toArray(savedDeployedTargets, Target.class));
for (final Target myt : savedNakedTargets) {
final Target t = targetManagement.getByControllerID(myt.getControllerId()).get();
@@ -1101,7 +1099,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.isThrownBy(() -> assignDistributionSet(incomplete, targets));
final DistributionSet nowComplete = distributionSetManagement.assignSoftwareModules(incomplete.getId(),
Sets.newHashSet(os.getId()));
Set.of(os.getId()));
assertThat(assignDistributionSet(nowComplete, targets).getAssigned()).as("assign ds doesn't work")
.isEqualTo(10);
@@ -1165,9 +1163,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(deployedTargetsFromDB).as("content of deployed target is wrong")
.usingElementComparator(controllerIdComparator()).containsAll(savedDeployedTargets)
.doesNotContain(Iterables.toArray(undeployedTargetsFromDB, JpaTarget.class));
.doesNotContain(toArray(undeployedTargetsFromDB, JpaTarget.class));
assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong").containsAll(savedNakedTargets)
.doesNotContain(Iterables.toArray(deployedTargetsFromDB, JpaTarget.class));
.doesNotContain(toArray(deployedTargetsFromDB, JpaTarget.class));
}
@Test
@@ -1710,9 +1708,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final Iterable<DistributionSet> dss, final String deployedTargetPrefix,
final String undeployedTargetPrefix, final String distributionSetPrefix) {
Iterables.addAll(deployedTargets, deployedTs);
Iterables.addAll(undeployedTargets, undeployedTs);
Iterables.addAll(distributionSets, dss);
deployedTargets.addAll(toList(deployedTs));
undeployedTargets.addAll(toList(undeployedTs));
distributionSets.addAll(toList(dss));
deployedTargets.forEach(t -> deployedTargetIDs.add(t.getId()));

View File

@@ -18,10 +18,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -70,9 +72,6 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
@@ -324,7 +323,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Description("Verifies that multiple DS are of default type if not specified explicitly at creation time.")
void createMultipleDistributionSetsWithImplicitType() {
final List<DistributionSetCreate> creates = Lists.newArrayListWithExpectedSize(10);
final List<DistributionSetCreate> creates = new ArrayList<>(10);
for (int i = 0; i < 10; i++) {
creates.add(entityFactory.distributionSet().create().name("newtypesoft" + i).version("1" + i));
}
@@ -406,7 +405,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag.")
void assignAndUnassignDistributionSetToTag() {
final List<Long> assignDS = Lists.newArrayListWithExpectedSize(4);
final List<Long> assignDS = new ArrayList<>(4);
for (int i = 0; i < 4; i++) {
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
}
@@ -450,7 +449,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule os2 = testdataFactory.createSoftwareModuleOs();
// update is allowed as it is still not assigned to a target
ds = distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(ah2.getId()));
ds = distributionSetManagement.assignSoftwareModules(ds.getId(), Set.of(ah2.getId()));
// assign target
assignDistributionSet(ds.getId(), target.getControllerId());
@@ -458,7 +457,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final Long dsId = ds.getId();
// not allowed as it is assigned now
assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(dsId, Sets.newHashSet(os2.getId())))
assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(dsId, Set.of(os2.getId())))
.isInstanceOf(EntityReadOnlyException.class);
// not allowed as it is assigned now
@@ -482,7 +481,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// update data
assertThatThrownBy(
() -> distributionSetManagement.assignSoftwareModules(set.getId(), Sets.newHashSet(module.getId())))
() -> distributionSetManagement.assignSoftwareModules(set.getId(), Set.of(module.getId())))
.isInstanceOf(UnsupportedSoftwareModuleForThisDistributionSetException.class);
}
@@ -495,7 +494,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// update data
// legal update of module addition
distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os.getId()));
distributionSetManagement.assignSoftwareModules(ds.getId(), Set.of(os.getId()));
ds = getOrThrow(distributionSetManagement.getWithDetails(ds.getId()));
assertThat(getOrThrow(ds.findFirstModuleByType(osType))).isEqualTo(os);
@@ -531,7 +530,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// create some software modules
final int maxModules = quotaManagement.getMaxSoftwareModulesPerDistributionSet();
final List<Long> modules = Lists.newArrayList();
final List<Long> modules = new ArrayList<>();
for (int i = 0; i < maxModules + 1; ++i) {
modules.add(testdataFactory.createSoftwareModuleApp("sm" + i).getId());
}

View File

@@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import jakarta.validation.ConstraintViolationException;
@@ -41,8 +42,6 @@ import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Sets;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
@@ -206,13 +205,13 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
// add OS
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(osType.getId()));
Set.of(osType.getId()));
assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType);
// add JVM
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(runtimeType.getId()));
Set.of(runtimeType.getId()));
assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType, runtimeType);
@@ -228,7 +227,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
final int quota = quotaManagement.getMaxSoftwareModuleTypesPerDistributionSetType();
// create software module types
final List<Long> moduleTypeIds = Lists.newArrayList();
final List<Long> moduleTypeIds = new ArrayList<>();
for (int i = 0; i < quota + 1; ++i) {
final SoftwareModuleTypeCreate smCreate = entityFactory.softwareModuleType().create().name("smType_" + i)
.description("smType_" + i).maxAssignments(1).colour("blue").key("smType_" + i);
@@ -290,7 +289,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs();
assertThatThrownBy(() -> distributionSetTypeManagement
.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Sets.newHashSet(osType.getId())))
.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Set.of(osType.getId())))
.isInstanceOf(EntityReadOnlyException.class);
}
@@ -311,7 +310,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()));
Set.of(osType.getId()));
distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft").version("1")
.type(nonUpdatableType.getKey()));

View File

@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
@@ -29,7 +30,6 @@ import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.RandomGeneratedInputStream;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
@@ -56,9 +56,6 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@@ -309,7 +306,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
// [STEP2]: Assign SoftwareModule to DistributionSet
testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule));
testdataFactory.createDistributionSet(Set.of(assignedModule));
// [STEP3]: Delete the assigned SoftwareModule
softwareModuleManagement.delete(assignedModule.getId());
@@ -345,7 +342,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
// [STEP2]: Assign SoftwareModule to DistributionSet
final DistributionSet disSet = testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule));
final DistributionSet disSet = testdataFactory.createDistributionSet(Set.of(assignedModule));
// [STEP3]: Assign DistributionSet to a Device
assignDistributionSet(disSet, Collections.singletonList(target));
@@ -446,11 +443,11 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
final DistributionSet disSetX = testdataFactory.createDistributionSet(Sets.newHashSet(moduleX), "X");
final DistributionSet disSetX = testdataFactory.createDistributionSet(Set.of(moduleX), "X");
assignDistributionSet(disSetX, Collections.singletonList(target));
// [STEP4]: Assign SoftwareModuleY to DistributionSet and to target
final DistributionSet disSetY = testdataFactory.createDistributionSet(Sets.newHashSet(moduleY), "Y");
final DistributionSet disSetY = testdataFactory.createDistributionSet(Set.of(moduleY), "Y");
assignDistributionSet(disSetY, Collections.singletonList(target));
// [STEP5]: Delete SoftwareModuleX
@@ -549,8 +546,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e");
final DistributionSet set = distributionSetManagement
.create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists
.newArrayList(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
.create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(
List.of(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
softwareModuleManagement.delete(deleted.getId());
// with filter on name, version and module type
@@ -610,8 +607,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e");
distributionSetManagement
.create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists
.newArrayList(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
.create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(
List.of(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
softwareModuleManagement.delete(deleted.getId());
// test

View File

@@ -643,9 +643,9 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final Long[] overdueMix = { lastTargetQueryAlwaysOverdue, lastTargetQueryNotOverdue,
lastTargetQueryAlwaysOverdue, lastTargetNull, lastTargetQueryAlwaysOverdue };
final List<Target> notAssigned = Lists.newArrayListWithExpectedSize(overdueMix.length);
List<Target> targAssigned = Lists.newArrayListWithExpectedSize(overdueMix.length);
List<Target> targInstalled = Lists.newArrayListWithExpectedSize(overdueMix.length);
final List<Target> notAssigned = new ArrayList<>(overdueMix.length);
List<Target> targAssigned = new ArrayList<>(overdueMix.length);
List<Target> targInstalled = new ArrayList<>(overdueMix.length);
for (int i = 0; i < overdueMix.length; i++) {
notAssigned.add(targetManagement

View File

@@ -54,7 +54,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
import org.eclipse.hawkbit.repository.model.Action;
@@ -79,8 +78,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import com.google.common.collect.Iterables;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
@@ -674,7 +671,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
final int numberToDelete = 50;
final Collection<Target> targetsToDelete = firstList.subList(0, numberToDelete);
final Target[] deletedTargets = Iterables.toArray(targetsToDelete, Target.class);
final Target[] deletedTargets = toArray(targetsToDelete, Target.class);
final List<Long> targetsIdsToDelete = targetsToDelete.stream().map(Target::getId).collect(Collectors.toList());
targetManagement.delete(targetsIdsToDelete);
@@ -708,14 +705,14 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT1Tags).containsAll(t1Tags);
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
.hasSize(noT1Tags).doesNotContain(toArray(t2Tags, TargetTag.class));
final Target t21 = targetManagement.getByControllerID(t2.getControllerId())
.orElseThrow(IllegalStateException::new);
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT2Tags).containsAll(t2Tags);
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
.hasSize(noT2Tags).doesNotContain(toArray(t1Tags, TargetTag.class));
}
@Test
@@ -758,16 +755,16 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
final List<Target> targetWithTagC = new ArrayList<>();
// storing target lists to enable easy evaluation
Iterables.addAll(targetWithTagA, tagATargets);
Iterables.addAll(targetWithTagA, tagABTargets);
Iterables.addAll(targetWithTagA, tagABCTargets);
targetWithTagA.addAll(tagATargets);
targetWithTagA.addAll(tagABTargets);
targetWithTagA.addAll(tagABCTargets);
Iterables.addAll(targetWithTagB, tagBTargets);
Iterables.addAll(targetWithTagB, tagABTargets);
Iterables.addAll(targetWithTagB, tagABCTargets);
targetWithTagB.addAll(tagBTargets);
targetWithTagB.addAll(tagABTargets);
targetWithTagB.addAll(tagABCTargets);
Iterables.addAll(targetWithTagC, tagCTargets);
Iterables.addAll(targetWithTagC, tagABCTargets);
targetWithTagC.addAll(tagCTargets);
targetWithTagC.addAll(tagABCTargets);
// check the target lists as returned by assignTag
checkTargetHasTags(false, targetWithTagA, tagA);

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
@@ -24,8 +25,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import com.google.common.collect.Lists;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@@ -42,7 +41,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
softwareModuleId = softwareModule.getId();
final List<SoftwareModuleMetadataCreate> metadata = Lists.newArrayListWithExpectedSize(5);
final List<SoftwareModuleMetadataCreate> metadata = new ArrayList<>(5);
for (int i = 0; i < 5; i++) {
metadata.add(
entityFactory.softwareModuleMetadata().create(softwareModule.getId()).key("" + i).value("" + i));