Spring Boot 2.0 (#721)

* Migration to Boot 2.0.

Signed-off-by: Kai Zimmermann <kai.zimmermann@microsoft.com>
This commit is contained in:
Kai Zimmermann
2019-01-31 07:29:27 +01:00
committed by GitHub
parent b42b009f9e
commit d52a720480
263 changed files with 2874 additions and 2692 deletions

View File

@@ -47,7 +47,7 @@ public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest
@Before
public void setup() throws Exception {
final BusJacksonAutoConfiguration autoConfiguration = new BusJacksonAutoConfiguration();
this.jacksonMessageConverter = autoConfiguration.busJsonConverter();
this.jacksonMessageConverter = autoConfiguration.busJsonConverter(null);
ReflectionTestUtils.setField(jacksonMessageConverter, "packagesToScan",
new String[] { "org.eclipse.hawkbit.repository.event.remote",
ClassUtils.getPackageName(RemoteApplicationEvent.class) });

View File

@@ -26,23 +26,25 @@ import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.test.TestConfiguration;
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
import org.eclipse.hawkbit.repository.test.util.RolloutTestApprovalStrategy;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
@SpringApplicationConfiguration(classes = {
org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration.class })
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class,
TestSupportBinderAutoConfiguration.class })
@TestPropertySource(locations = "classpath:/jpa-test.properties")
public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
protected static final String INVALID_TEXT_HTML = "</noscript><br><script>";
protected static final String NOT_EXIST_ID = "1234";
protected static final String NOT_EXIST_ID = "12345678990";
protected static final long NOT_EXIST_IDL = Long.parseLong(NOT_EXIST_ID);
@PersistenceContext

View File

@@ -82,8 +82,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
NOT_EXIST_IDL, "xxx", null, null, false, null, artifactSize)),
"SoftwareModule");
verifyThrownExceptionBy(() -> artifactManagement.create(
new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"), 1234L, "xxx", false, artifactSize)),
verifyThrownExceptionBy(
() -> artifactManagement.create(new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"),
NOT_EXIST_IDL, "xxx", null, null, false, null, artifactSize)),
"SoftwareModule");
verifyThrownExceptionBy(() -> artifactManagement.delete(NOT_EXIST_IDL), "Artifact");
@@ -120,7 +121,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1);
createArtifactForSoftwareModule("file11", sm.getId(), artifactSize, inputStream2);
createArtifactForSoftwareModule("file12", sm.getId(), artifactSize, inputStream3);
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream4);
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize,
inputStream4);
assertThat(artifact1).isInstanceOf(Artifact.class);
assertThat(artifact1.getSoftwareModule().getId()).isEqualTo(sm.getId());
@@ -152,9 +154,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
final long smID = softwareModuleRepository
.save(new JpaSoftwareModule(osType, "smIllegalFilenameTest", "1.0", null, null)).getId();
assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(() -> artifactManagement.create(
new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"), smID, illegalFilename, false,
artifactSize)));
assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
() -> artifactManagement.create(new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"), smID,
illegalFilename, false, artifactSize)));
assertThat(softwareModuleManagement.get(smID).get().getArtifacts()).hasSize(0);
}
@@ -284,7 +286,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
final InputStream inputStream2 = new RandomGeneratedInputStream(artifactSize)) {
final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1);
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream2);
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize,
inputStream2);
assertThat(artifactRepository.findAll()).hasSize(2);
@@ -292,16 +295,18 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
assertThat(artifact2.getId()).isNotNull();
assertThat(((JpaArtifact) artifact1).getSha1Hash()).isNotEqualTo(((JpaArtifact) artifact2).getSha1Hash());
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNotNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNotNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact2.getSha1Hash()))
.isNotNull();
artifactManagement.delete(artifact1.getId());
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact2.getSha1Hash()))
.isNotNull();
@@ -331,22 +336,26 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
try (final InputStream inputStream1 = new ByteArrayInputStream(randomBytes);
final InputStream inputStream2 = new ByteArrayInputStream(randomBytes)) {
final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1);
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream2);
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize,
inputStream2);
assertThat(artifactRepository.findAll()).hasSize(2);
assertThat(artifact1.getId()).isNotNull();
assertThat(artifact2.getId()).isNotNull();
assertThat(((JpaArtifact) artifact1).getSha1Hash()).isEqualTo(((JpaArtifact) artifact2).getSha1Hash());
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNotNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNotNull();
artifactManagement.delete(artifact1.getId());
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNotNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNotNull();
artifactManagement.delete(artifact2.getId());
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNull();
assertThat(
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
.isNull();
}
}

View File

@@ -688,8 +688,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// populated;
final List<JpaTarget> allFoundTargets = targetRepository.findAll();
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAll(deployedTargetIDs);
final List<JpaTarget> undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs);
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAllById(deployedTargetIDs);
final List<JpaTarget> undeployedTargetsFromDB = targetRepository.findAllById(undeployedTargetIDs);
// test that number of Targets
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown()).as("number of target is wrong")
@@ -721,7 +721,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
+ "from target/controller. Expected behaviour is that in case of OK finished update the target will go to "
+ "IN_SYNC status and installed DS is set to the assigned DS entry.")
public void assignDistributionSetAndAddFinishedActionStatus() {
final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName());
final PageRequest pageRequest = PageRequest.of(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName());
final DeploymentResult deployResWithDsA = prepareComplexRepo("undep-A-T", 2, "dep-A-T", 4, 1, "dsA");
final DeploymentResult deployResWithDsB = prepareComplexRepo("undep-B-T", 3, "dep-B-T", 5, 1, "dsB");
@@ -815,7 +815,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
+ "if the DS is assigned to a target and a hard delete if the DS is not in use at all.")
public void deleteDistributionSet() {
final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, "id");
final PageRequest pageRequest = PageRequest.of(0, 100, Direction.ASC, "id");
final String undeployedTargetPrefix = "undep-T";
final int noOfUndeployedTargets = 2;

View File

@@ -868,10 +868,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
}
final Page<DistributionSetMetadata> metadataOfDs1 = distributionSetManagement
.findMetaDataByDistributionSetId(new PageRequest(0, 100), ds1.getId());
.findMetaDataByDistributionSetId(PageRequest.of(0, 100), ds1.getId());
final Page<DistributionSetMetadata> metadataOfDs2 = distributionSetManagement
.findMetaDataByDistributionSetId(new PageRequest(0, 100), ds2.getId());
.findMetaDataByDistributionSetId(PageRequest.of(0, 100), ds2.getId());
assertThat(metadataOfDs1.getNumberOfElements()).isEqualTo(10);
assertThat(metadataOfDs1.getTotalElements()).isEqualTo(10);

View File

@@ -59,15 +59,12 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
@ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag");
verifyThrownExceptionBy(
() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
verifyThrownExceptionBy(() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
"DistributionSetTag");
}
@@ -82,16 +79,11 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
final Collection<DistributionSet> dsBCs = testdataFactory.createDistributionSets("DS-BC", 13);
final Collection<DistributionSet> dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9);
final DistributionSetTag tagA = distributionSetTagManagement
.create(entityFactory.tag().create().name("A"));
final DistributionSetTag tagB = distributionSetTagManagement
.create(entityFactory.tag().create().name("B"));
final DistributionSetTag tagC = distributionSetTagManagement
.create(entityFactory.tag().create().name("C"));
final DistributionSetTag tagX = distributionSetTagManagement
.create(entityFactory.tag().create().name("X"));
final DistributionSetTag tagY = distributionSetTagManagement
.create(entityFactory.tag().create().name("Y"));
final DistributionSetTag tagA = distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
final DistributionSetTag tagB = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
final DistributionSetTag tagC = distributionSetTagManagement.create(entityFactory.tag().create().name("C"));
final DistributionSetTag tagX = distributionSetTagManagement.create(entityFactory.tag().create().name("X"));
final DistributionSetTag tagY = distributionSetTagManagement.create(entityFactory.tag().create().name("Y"));
toggleTagAssignment(dsAs, tagA);
toggleTagAssignment(dsBs, tagB);
@@ -210,8 +202,8 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
assertThat(result.getAssigned()).isEqualTo(0);
assertThat(result.getAssignedEntity()).isEmpty();
assertThat(result.getUnassigned()).isEqualTo(40);
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.get(
concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement
.get(concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
}
@@ -219,15 +211,15 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Ensures that a created tag is persisted in the repository as defined.")
public void createDistributionSetTag() {
final Tag tag = distributionSetTagManagement.create(
entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
final Tag tag = distributionSetTagManagement
.create(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found")
.isEqualTo("kai2");
assertThat(distributionSetTagManagement.getByName("kai1").get().getColour()).as("wrong tag found")
.isEqualTo("colour");
assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour())
.as("wrong tag found").isEqualTo("colour");
assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour()).as("wrong tag found")
.isEqualTo("colour");
}
@Test
@@ -238,7 +230,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
final DistributionSetTag toDelete = tags.iterator().next();
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong tag found")
assertThat(distributionSetRepository.findById(set.getId()).get().getTags()).as("Wrong tag found")
.contains(toDelete);
}
@@ -246,12 +238,13 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
distributionSetTagManagement.delete(tags.iterator().next().getName());
// check
assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull();
assertThat(distributionSetTagManagement.findAll(PAGE).getContent())
.as("Wrong size of tags after deletion").hasSize(19);
assertThat(distributionSetTagRepository.findById(toDelete.getId())).as("Deleted tag should be null")
.isNotPresent();
assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of tags after deletion")
.hasSize(19);
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong found tags")
assertThat(distributionSetRepository.findById(set.getId()).get().getTags()).as("Wrong found tags")
.doesNotContain(toDelete);
}
}
@@ -272,8 +265,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
public void failedDuplicateDsTagNameExceptionAfterUpdate() {
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
final DistributionSetTag tag = distributionSetTagManagement
.create(entityFactory.tag().create().name("B"));
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
try {
distributionSetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A"));
@@ -294,14 +286,13 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
final DistributionSetTag savedAssigned = tags.iterator().next();
// persist
distributionSetTagManagement
.update(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
distributionSetTagManagement.update(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
// check data
assertThat(distributionSetTagManagement.findAll(PAGE).getContent())
.as("Wrong size of ds tags").hasSize(tags.size());
assertThat(distributionSetTagRepository.findOne(savedAssigned.getId()).getName()).as("Wrong ds tag found")
.isEqualTo("test123");
assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of ds tags")
.hasSize(tags.size());
assertThat(distributionSetTagRepository.findById(savedAssigned.getId()).get().getName())
.as("Wrong ds tag found").isEqualTo("test123");
}
@Test

View File

@@ -72,7 +72,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(1234L,
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(NOT_EXIST_IDL,
Arrays.asList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)),

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutCreatedEvent;
@@ -20,8 +22,6 @@ import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;

View File

@@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -1547,41 +1548,40 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Creating a rollout with approval role or approval engine disabled results in the rollout being in " +
"READY state.")
@Description("Creating a rollout with approval role or approval engine disabled results in the rollout being in "
+ "READY state.")
public void createdRolloutWithApprovalRoleOrApprovalDisabledTransitionsToReadyState() {
approvalStrategy.setApprovalNeeded(false);
final String successCondition = "50";
final String errorCondition = "80";
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
5, successCondition, errorCondition);
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
errorCondition);
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.READY);
}
@Test
@Description("Creating a rollout without approver role and approval enabled leads to transition to " +
"WAITING_FOR_APPROVAL state.")
@Description("Creating a rollout without approver role and approval enabled leads to transition to "
+ "WAITING_FOR_APPROVAL state.")
public void createdRolloutWithoutApprovalRoleTransitionsToWaitingForApprovalState() {
approvalStrategy.setApprovalNeeded(true);
final String successCondition = "50";
final String errorCondition = "80";
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
5, successCondition, errorCondition);
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
errorCondition);
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.WAITING_FOR_APPROVAL);
}
@Test
@Description("Approving a rollout leads to transition to READY state.")
public void approvedRolloutTransitionsToReadyState() {
approvalStrategy.setApprovalNeeded(true);
final String successCondition = "50";
final String errorCondition = "80";
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
5, successCondition, errorCondition);
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
errorCondition);
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.WAITING_FOR_APPROVAL);
rolloutManagement.approveOrDeny(rollout.getId(), Rollout.ApprovalDecision.APPROVED);
final Rollout resultingRollout = rolloutRepository.findOne(rollout.getId());
final Rollout resultingRollout = rolloutRepository.findById(rollout.getId()).get();
assertThat(resultingRollout.getStatus()).isEqualTo(Rollout.RolloutStatus.READY);
}
@@ -1591,11 +1591,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
approvalStrategy.setApprovalNeeded(true);
final String successCondition = "50";
final String errorCondition = "80";
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
5, successCondition, errorCondition);
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
errorCondition);
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.WAITING_FOR_APPROVAL);
rolloutManagement.approveOrDeny(rollout.getId(), Rollout.ApprovalDecision.DENIED);
final Rollout resultingRollout = rolloutRepository.findOne(rollout.getId());
final Rollout resultingRollout = rolloutRepository.findById(rollout.getId()).get();
assertThat(resultingRollout.getStatus()).isEqualTo(RolloutStatus.APPROVAL_DENIED);
}
@@ -1622,8 +1622,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.handleRollouts();
// verify
final JpaRollout deletedRollout = rolloutRepository.findOne(createdRollout.getId());
assertThat(deletedRollout).isNull();
final Optional<JpaRollout> deletedRollout = rolloutRepository.findById(createdRollout.getId());
assertThat(deletedRollout).isNotPresent();
assertThat(rolloutGroupRepository.count()).isZero();
assertThat(rolloutTargetGroupRepository.count()).isZero();
}
@@ -1663,7 +1663,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.handleRollouts();
// verify
final JpaRollout deletedRollout = rolloutRepository.findOne(createdRollout.getId());
final JpaRollout deletedRollout = rolloutRepository.findById(createdRollout.getId()).get();
assertThat(deletedRollout).isNotNull();
assertThat(deletedRollout.getStatus()).isEqualTo(RolloutStatus.DELETED);

View File

@@ -284,8 +284,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertArtifactNull(artifact1, artifact2);
// verify: meta data of artifact is deleted
assertThat(artifactRepository.findOne(artifact1.getId())).isNull();
assertThat(artifactRepository.findOne(artifact2.getId())).isNull();
assertThat(artifactRepository.findById(artifact1.getId())).isNotPresent();
assertThat(artifactRepository.findById(artifact2.getId())).isNotPresent();
}
@Test
@@ -315,8 +315,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertArtifactNull(artifact1, artifact2);
// verify: artifact meta data is still available
assertThat(artifactRepository.findOne(artifact1.getId())).isNotNull();
assertThat(artifactRepository.findOne(artifact2.getId())).isNotNull();
assertThat(artifactRepository.findById(artifact1.getId())).isNotNull();
assertThat(artifactRepository.findById(artifact2.getId())).isNotNull();
}
@Test
@@ -355,8 +355,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertArtifactNull(artifact1, artifact2);
// verify: artifact meta data is still available
assertThat(artifactRepository.findOne(artifact1.getId())).isNotNull();
assertThat(artifactRepository.findOne(artifact2.getId())).isNotNull();
assertThat(artifactRepository.findById(artifact1.getId())).isNotNull();
assertThat(artifactRepository.findById(artifact2.getId())).isNotNull();
}
@Test
@@ -398,10 +398,11 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertArtifactNotNull(artifactY);
// verify: meta data of artifactX is deleted
assertThat(artifactRepository.findOne(artifactX.getId())).isNull();
assertThat(artifactRepository.findById(artifactX.getId())).isNotPresent();
// verify: meta data of artifactY is not deleted
assertThat(artifactRepository.findOne(artifactY.getId())).isNotNull();
assertThat(artifactRepository.findById(artifactY.getId())).isPresent();
}
@Test
@@ -459,7 +460,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertArtifactNull(artifactX, artifactY);
// verify: meta data of artifactX and artifactY is not deleted
assertThat(artifactRepository.findOne(artifactY.getId())).isNotNull();
assertThat(artifactRepository.findById(artifactY.getId())).isNotNull();
}
private SoftwareModule createSoftwareModuleWithArtifacts(final SoftwareModuleType type, final String name,
@@ -488,7 +489,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertArtifactNotNull(artifacts.toArray(new Artifact[artifacts.size()]));
}
artifacts.forEach(artifact -> assertThat(artifactRepository.findOne(artifact.getId())).isNotNull());
artifacts.forEach(artifact -> assertThat(artifactRepository.findById(artifact.getId())).isNotNull());
return softwareModule;
}
@@ -791,13 +792,15 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
ah = softwareModuleManagement.get(ah.getId()).get();
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId())
.getContent()).as("Contains the created metadata element")
assertThat(
softwareModuleManagement.findMetaDataBySoftwareModuleId(PageRequest.of(0, 10), ah.getId()).getContent())
.as("Contains the created metadata element")
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
softwareModuleManagement.deleteMetaData(ah.getId(), knownKey1);
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId())
.getContent()).as("Metadata elemenets are").isEmpty();
assertThat(
softwareModuleManagement.findMetaDataBySoftwareModuleId(PageRequest.of(0, 10), ah.getId()).getContent())
.as("Metadata elemenets are").isEmpty();
}
@Test
@@ -835,10 +838,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
}
Page<SoftwareModuleMetadata> metadataSw1 = softwareModuleManagement
.findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw1.getId());
.findMetaDataBySoftwareModuleId(PageRequest.of(0, 100), sw1.getId());
Page<SoftwareModuleMetadata> metadataSw2 = softwareModuleManagement
.findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw2.getId());
.findMetaDataBySoftwareModuleId(PageRequest.of(0, 100), sw2.getId());
assertThat(metadataSw1.getNumberOfElements()).isEqualTo(metadataCountSw1);
assertThat(metadataSw1.getTotalElements()).isEqualTo(metadataCountSw1);
@@ -846,10 +849,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertThat(metadataSw2.getNumberOfElements()).isEqualTo(metadataCountSw2);
assertThat(metadataSw2.getTotalElements()).isEqualTo(metadataCountSw2);
metadataSw1 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(new PageRequest(0, 100),
metadataSw1 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(PageRequest.of(0, 100),
sw1.getId());
metadataSw2 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(new PageRequest(0, 100),
metadataSw2 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(PageRequest.of(0, 100),
sw2.getId());
assertThat(metadataSw1.getNumberOfElements()).isEqualTo(metadataCountSw1);

View File

@@ -49,20 +49,18 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL), "SoftwareModuleType");
verifyThrownExceptionBy(
() -> softwareModuleTypeManagement
.update(entityFactory.softwareModuleType().update(1234L)),
() -> softwareModuleTypeManagement.update(entityFactory.softwareModuleType().update(NOT_EXIST_IDL)),
"SoftwareModuleType");
}
@Test
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
public void updateNothingResultsInUnchangedRepositoryForType() {
final SoftwareModuleType created = softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
final SoftwareModuleType created = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
final SoftwareModuleType updated = softwareModuleTypeManagement
.update(entityFactory.softwareModuleType().update(created.getId()));
@@ -75,8 +73,8 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Calling update for changed fields results in change in the repository.")
public void updateSoftareModuleTypeFieldsToNewValue() {
final SoftwareModuleType created = softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
final SoftwareModuleType created = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
final SoftwareModuleType updated = softwareModuleTypeManagement.update(
entityFactory.softwareModuleType().update(created.getId()).description("changed").colour("changed"));
@@ -106,39 +104,34 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType,
runtimeType, appType);
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
SoftwareModuleType type = softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
SoftwareModuleType type = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType,
runtimeType, appType, type);
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type);
// delete unassigned
softwareModuleTypeManagement.delete(type.getId());
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType,
runtimeType, appType);
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType);
type = softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
type = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType,
runtimeType, appType, type);
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type);
softwareModuleManagement.create(
entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
softwareModuleManagement
.create(entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
// delete assigned
softwareModuleTypeManagement.delete(type.getId());
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType,
runtimeType, appType);
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType,
softwareModuleTypeRepository.findOne(type.getId()));
softwareModuleTypeRepository.findById(type.getId()).get());
}
@Test
@@ -147,21 +140,19 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
testdataFactory.createSoftwareModuleOs();
final SoftwareModuleType found = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
assertThat(softwareModuleTypeManagement.getByName("thename").get())
.as("Type with given name").isEqualTo(found);
assertThat(softwareModuleTypeManagement.getByName("thename").get()).as("Type with given name").isEqualTo(found);
}
@Test
@Description("Verfies that it is not possible to create a type that alrady exists.")
public void createSoftwareModuleTypeFailsWithExistingEntity() {
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
@@ -172,11 +163,10 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Verfies that it is not possible to create a list of types where one already exists.")
public void createSoftwareModuleTypesFailsWithExistingEntity() {
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareModuleTypeManagement.create(
Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
softwareModuleTypeManagement
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
entityFactory.softwareModuleType().create().key("anothertype").name("anothername")));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
@@ -188,8 +178,8 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
try {
softwareModuleTypeManagement.create(
entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0));
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0));
fail("should not have worked as max assignment is invalid. Should be greater than 0.");
} catch (final ConstraintViolationException e) {
@@ -199,13 +189,12 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Verfies that multiple types are created as requested.")
public void createMultipleSoftwareModuleTypes() {
final List<SoftwareModuleType> created = softwareModuleTypeManagement.create(
Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
final List<SoftwareModuleType> created = softwareModuleTypeManagement
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
entityFactory.softwareModuleType().create().key("thetype2").name("thename2")));
assertThat(created.size()).as("Number of created types").isEqualTo(2);
assertThat(softwareModuleTypeManagement.count()).as("Number of types in repository")
.isEqualTo(5);
assertThat(softwareModuleTypeManagement.count()).as("Number of types in repository").isEqualTo(5);
}
}

View File

@@ -81,7 +81,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
verifyThrownExceptionBy(
() -> targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> targetFilterQueryManagement.updateAutoAssignDS(1234L, set.getId()),
verifyThrownExceptionBy(() -> targetFilterQueryManagement.updateAutoAssignDS(NOT_EXIST_IDL, set.getId()),
"TargetFilterQuery");
verifyThrownExceptionBy(
() -> targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL),
@@ -123,7 +123,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
entityFactory.targetFilterQuery().create().name("someOtherFilter").query("name==PendingTargets002"));
final List<TargetFilterQuery> results = targetFilterQueryManagement
.findByRsql(new PageRequest(0, 10), "name==" + filterName).getContent();
.findByRsql(PageRequest.of(0, 10), "name==" + filterName).getContent();
assertEquals("Search result should have 1 result", 1, results.size());
assertEquals("Retrieved newly created custom target filter", targetFilterQuery, results.get(0));
}
@@ -132,7 +132,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Description("Test searching a target filter query with an invalid filter.")
public void searchTargetFilterQueryInvalidField() {
// Should throw an exception
targetFilterQueryManagement.findByRsql(new PageRequest(0, 10), "unknownField==testValue").getContent();
targetFilterQueryManagement.findByRsql(PageRequest.of(0, 10), "unknownField==testValue").getContent();
}
@@ -316,7 +316,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
assertEquals(4L, targetFilterQueryManagement.count());
// check if find works
Page<TargetFilterQuery> tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500),
Page<TargetFilterQuery> tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(PageRequest.of(0, 500),
distributionSet.getId(), null);
assertThat(1L).as("Target filter query").isEqualTo(tfqList.getTotalElements());
@@ -325,22 +325,22 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
targetFilterQueryManagement.updateAutoAssignDS(tfq2.getId(), distributionSet.getId());
// check if find works for two
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500),
distributionSet.getId(), null);
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(PageRequest.of(0, 500), distributionSet.getId(),
null);
assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
Iterator<TargetFilterQuery> iterator = tfqList.iterator();
assertEquals("Returns correct target filter query 1", tfq.getId(), iterator.next().getId());
assertEquals("Returns correct target filter query 2", tfq2.getId(), iterator.next().getId());
// check if find works with name filter
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500),
distributionSet.getId(), "name==" + filterName);
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(PageRequest.of(0, 500), distributionSet.getId(),
"name==" + filterName);
assertThat(1L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
assertEquals("Returns correct target filter query", tfq2.getId(), tfqList.iterator().next().getId());
// check if find works for all with auto assign DS
tfqList = targetFilterQueryManagement.findWithAutoAssignDS(new PageRequest(0, 500));
tfqList = targetFilterQueryManagement.findWithAutoAssignDS(PageRequest.of(0, 500));
assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
iterator = tfqList.iterator();
assertEquals("Returns correct target filter query 1", tfq.getId(), iterator.next().getId());

View File

@@ -419,8 +419,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
target = createTargetWithAttributes("4711");
assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1);
assertThat(targetManagement.existsByControllerId("4711")).isTrue();
targetManagement.delete(Collections.singletonList(target.getId()));
assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(0);
assertThat(targetManagement.existsByControllerId("4711")).isFalse();
final List<Long> targets = new ArrayList<>();
for (int i = 0; i < 5; i++) {
@@ -664,7 +666,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
targetManagement.delete(targetsIdsToDelete);
final List<Target> targetsLeft = targetManagement.findAll(new PageRequest(0, 200)).getContent();
final List<Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent();
assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of split list")
.isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown());
@@ -905,12 +907,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verify that the flag for requesting controller attributes is set correctly.")
public void verifyRequestControllerAttributes() {
final String knownTargetId = "KnownControllerId";
createTargetWithAttributes(knownTargetId);
final String knownControllerId = "KnownControllerId";
final Target target = createTargetWithAttributes(knownControllerId);
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isFalse();
targetManagement.requestControllerAttributes(knownTargetId);
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isTrue();
assertThat(targetManagement.findByControllerAttributesRequested(PAGE)).isEmpty();
assertThat(targetManagement.isControllerAttributesRequested(knownControllerId)).isFalse();
targetManagement.requestControllerAttributes(knownControllerId);
final Target updated = targetManagement.getByControllerID(knownControllerId).get();
assertThat(target.isRequestControllerAttributes()).isFalse();
assertThat(targetManagement.findByControllerAttributesRequested(PAGE).getContent()).contains(updated);
assertThat(targetManagement.isControllerAttributesRequested(knownControllerId)).isTrue();
}

View File

@@ -245,7 +245,7 @@ public class TargetTagManagementTest extends AbstractJpaIntegrationTest {
assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent())
.doesNotContain(toDelete);
}
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();
assertThat(targetTagRepository.findById(toDelete.getId())).as("No tag should be found").isNotPresent();
assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(19);
}
@@ -262,9 +262,9 @@ public class TargetTagManagementTest extends AbstractJpaIntegrationTest {
// check data
assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(tags.size());
assertThat(targetTagRepository.findOne(savedAssigned.getId()).getName()).as("wrong target tag is saved")
assertThat(targetTagRepository.findById(savedAssigned.getId()).get().getName()).as("wrong target tag is saved")
.isEqualTo("test123");
assertThat(targetTagRepository.findOne(savedAssigned.getId()).getOptLockRevision())
assertThat(targetTagRepository.findById(savedAssigned.getId()).get().getOptLockRevision())
.as("wrong target tag is saved").isEqualTo(2);
}

View File

@@ -34,7 +34,7 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.EventListener;
@@ -44,7 +44,7 @@ import io.qameta.allure.Story;
@Feature("Component Tests - Repository")
@Story("Entity Events")
@SpringApplicationConfiguration(classes = RepositoryTestConfiguration.class)
@SpringBootTest(classes = { RepositoryTestConfiguration.class })
public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
@Autowired

View File

@@ -90,7 +90,7 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
final Slice<Action> findEnitity = deploymentManagement.findActionsByTarget(rsqlParam, target.getControllerId(),
new PageRequest(0, 100));
PageRequest.of(0, 100));
final long countAllEntities = deploymentManagement.countActionsByTarget(rsqlParam, target.getControllerId());
assertThat(findEnitity).isNotNull();
assertThat(countAllEntities).isEqualTo(expectedEntities);

View File

@@ -145,7 +145,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
}
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
final Page<DistributionSet> find = distributionSetManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
final Page<DistributionSet> find = distributionSetManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
final long countAll = find.getTotalElements();
assertThat(find).as("Founded entity is should not be null").isNotNull();
assertThat(countAll).as("Founded entity size is wrong").isEqualTo(excpectedEntity);

View File

@@ -73,7 +73,7 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegratio
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
final Page<DistributionSetMetadata> findEnitity = distributionSetManagement
.findMetaDataByDistributionSetIdAndRsql(new PageRequest(0, 100), distributionSetId, rsqlParam);
.findMetaDataByDistributionSetIdAndRsql(PageRequest.of(0, 100), distributionSetId, rsqlParam);
final long countAllEntities = findEnitity.getTotalElements();
assertThat(findEnitity).isNotNull();
assertThat(countAllEntities).isEqualTo(expectedEntities);

View File

@@ -77,7 +77,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
}
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
final Page<RolloutGroup> findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(new PageRequest(0, 100),
final Page<RolloutGroup> findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(PageRequest.of(0, 100),
rollout.getId(), rsqlParam);
final long countTargetsAll = findTargetPage.getTotalElements();
assertThat(findTargetPage).isNotNull();

View File

@@ -116,7 +116,7 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
}
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
final Page<SoftwareModule> find = softwareModuleManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
final Page<SoftwareModule> find = softwareModuleManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
final long countAll = find.getTotalElements();
assertThat(find).isNotNull();
assertThat(countAll).isEqualTo(excpectedEntity);

View File

@@ -88,7 +88,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
final Page<SoftwareModuleMetadata> findEnitity = softwareModuleManagement
.findMetaDataByRsql(new PageRequest(0, 100), softwareModuleId, rsqlParam);
.findMetaDataByRsql(PageRequest.of(0, 100), softwareModuleId, rsqlParam);
final long countAllEntities = findEnitity.getTotalElements();
assertThat(findEnitity).isNotNull();
assertThat(countAllEntities).isEqualTo(expectedEntities);

View File

@@ -66,7 +66,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest
}
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
final Page<SoftwareModuleType> find = softwareModuleTypeManagement.findByRsql(new PageRequest(0, 100),
final Page<SoftwareModuleType> find = softwareModuleTypeManagement.findByRsql(PageRequest.of(0, 100),
rsqlParam);
final long countAll = find.getTotalElements();
assertThat(find).isNotNull();

View File

@@ -119,7 +119,7 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
private void assertRSQLQueryDistributionSet(final String rsqlParam, final long expectedEntities) {
final Page<DistributionSetTag> findEnitity = distributionSetTagManagement.findByRsql(new PageRequest(0, 100),
final Page<DistributionSetTag> findEnitity = distributionSetTagManagement.findByRsql(PageRequest.of(0, 100),
rsqlParam);
final long countAllEntities = findEnitity.getTotalElements();
assertThat(findEnitity).isNotNull();
@@ -128,7 +128,7 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
private void assertRSQLQueryTarget(final String rsqlParam, final long expectedEntities) {
final Page<TargetTag> findEnitity = targetTagManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
final Page<TargetTag> findEnitity = targetTagManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
final long countAllEntities = findEnitity.getTotalElements();
assertThat(findEnitity).isNotNull();
assertThat(countAllEntities).isEqualTo(expectedEntities);

View File

@@ -9,16 +9,15 @@
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@@ -33,11 +32,11 @@ import org.eclipse.hawkbit.repository.FieldNameProvider;
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.TimestampCalculator;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
@@ -45,18 +44,19 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.test.context.junit4.SpringRunner;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@RunWith(PowerMockRunner.class)
@RunWith(SpringRunner.class)
@Feature("Component Tests - Repository")
@Story("RSQL search utility")
@PrepareForTest(TimestampCalculator.class)
// TODO: fully document tests -> @Description for long text and reasonable
// method name as short text
public class RSQLUtilityTest {
@@ -64,7 +64,7 @@ public class RSQLUtilityTest {
@Spy
private final VirtualPropertyResolver macroResolver = new VirtualPropertyResolver();
@Mock
@MockBean
private TenantConfigurationManagement confMgmt;
@Mock
@@ -80,6 +80,14 @@ public class RSQLUtilityTest {
@Mock
private Attribute attribute;
@Configuration
static class Config {
@Bean
TenantConfigurationManagementHolder tenantConfigurationManagementHolder() {
return TenantConfigurationManagementHolder.getInstance();
}
}
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
.<String> builder().value("00:05:00").build();
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
@@ -179,7 +187,9 @@ public class RSQLUtilityTest {
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.get("version")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
.thenReturn(mock(Predicate.class));
@@ -197,7 +207,8 @@ public class RSQLUtilityTest {
final String correctRsql = "name!=abc";
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.notLike(any(Expression.class), anyString(), eq('\\')))
.thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
.thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
@@ -218,7 +229,7 @@ public class RSQLUtilityTest {
final String correctRsql = "name==a%";
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
.thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
@@ -239,11 +250,11 @@ public class RSQLUtilityTest {
final String correctRsql = "name==a%";
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
.thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
.thenReturn(mock(Predicate.class));
// test
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null, Database.SQL_SERVER)
@@ -261,7 +272,7 @@ public class RSQLUtilityTest {
final String correctRsql = "name=lt=abc";
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.lessThan(any(Expression.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
.thenReturn(mock(Predicate.class));
// test
@@ -279,7 +290,7 @@ public class RSQLUtilityTest {
final String correctRsql = "testfield==bumlux";
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) TestValueEnum.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.equal(any(Root.class), any(TestValueEnum.class))).thenReturn(mock(Predicate.class));
// test
RSQLUtility.parse(correctRsql, TestFieldEnum.class, null, testDb).toPredicate(baseSoftwareModuleRootMock,
@@ -317,7 +328,9 @@ public class RSQLUtilityTest {
final String correctRsql = "testfield=le=" + overduePropPlaceholder;
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class);
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
when(criteriaBuilderMock.<String> lessThanOrEqualTo(any(Expression.class), eq(overduePropPlaceholder)))
.thenReturn(mock(Predicate.class));
@@ -365,9 +378,6 @@ public class RSQLUtilityTest {
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
.thenReturn(TEST_POLLING_OVERDUE_TIME_INTERVAL);
mockStatic(TimestampCalculator.class);
when(TimestampCalculator.getTenantConfigurationManagement()).thenReturn(confMgmt);
return macroResolver;
}

View File

@@ -12,36 +12,35 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.TimestampCalculator;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@RunWith(SpringRunner.class)
@Feature("Unit Tests - Repository")
@Story("Placeholder resolution for virtual properties")
@RunWith(PowerMockRunner.class)
@PrepareForTest(TimestampCalculator.class)
public class VirtualPropertyResolverTest {
@Spy
private final VirtualPropertyResolver resolverUnderTest = new VirtualPropertyResolver();
@Mock
@MockBean
private TenantConfigurationManagement confMgmt;
private StrSubstitutor substitutor;
@@ -51,6 +50,14 @@ public class VirtualPropertyResolverTest {
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
.<String> builder().value("00:07:37").build();
@Configuration
static class Config {
@Bean
TenantConfigurationManagementHolder tenantConfigurationManagementHolder() {
return TenantConfigurationManagementHolder.getInstance();
}
}
@Before
public void before() {
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class))
@@ -58,9 +65,6 @@ public class VirtualPropertyResolverTest {
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
.thenReturn(TEST_POLLING_OVERDUE_TIME_INTERVAL);
mockStatic(TimestampCalculator.class);
when(TimestampCalculator.getTenantConfigurationManagement()).thenReturn(confMgmt);
substitutor = new StrSubstitutor(resolverUnderTest, StrSubstitutor.DEFAULT_PREFIX,
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE);
}

View File

@@ -9,9 +9,9 @@
package org.eclipse.hawkbit.repository.jpa.specifications;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -28,7 +28,6 @@ import javax.persistence.criteria.Root;
import org.junit.Test;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
@@ -41,20 +40,20 @@ public class SpecificationsBuilderTest {
@Test
@Description("Test the combination of specs on an empty list which returns null")
public void combineWithAndEmptyList() {
List<Specification<Object>> specList = Collections.emptyList();
final List<Specification<Object>> specList = Collections.emptyList();
assertThat(SpecificationsBuilder.combineWithAnd(specList)).isNull();
}
@Test
@Description("Test the combination of specs on an immutable list with one entry")
public void combineWithAndSingleImmutableList() {
Specification<Object> spec = (root, query, cb) -> cb.equal(root.get("field1"), "testValue");
List<Specification<Object>> specList = Collections.singletonList(spec);
Specifications<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
final Specification<Object> spec = (root, query, cb) -> cb.equal(root.get("field1"), "testValue");
final List<Specification<Object>> specList = Collections.singletonList(spec);
final Specification<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
assertThat(specifications).as("Specifications").isNotNull();
// mocks to call toPredicate on specifications
CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
final CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
final Path field1 = mock(Path.class);
final Predicate equalPredicate = mock(Predicate.class);
final CriteriaQuery<Object[]> query = mock(CriteriaQuery.class);
@@ -63,28 +62,27 @@ public class SpecificationsBuilderTest {
when(criteriaBuilder.equal(any(Expression.class), anyString())).thenReturn(equalPredicate);
when(root.get("field1")).thenReturn(field1);
Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
final Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
assertThat(predicate).isEqualTo(equalPredicate);
}
@Test
@Description("Test the combination of specs on a list with multiple entries")
public void combineWithAndList() {
Specification<Object> spec1 = (root, query, cb) -> cb.equal(root.get("field1"), "testValue1");
Specification<Object> spec2 = (root, query, cb) -> cb.equal(root.get("field2"), "testValue2");
final Specification<Object> spec1 = (root, query, cb) -> cb.equal(root.get("field1"), "testValue1");
final Specification<Object> spec2 = (root, query, cb) -> cb.equal(root.get("field2"), "testValue2");
List<Specification<Object>> specList = new ArrayList<>(2);
final List<Specification<Object>> specList = new ArrayList<>(2);
specList.add(spec1);
specList.add(spec2);
Specifications<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
final Specification<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
assertThat(specifications).as("Specifications").isNotNull();
// mocks to call toPredicate on specifications
CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
final CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
final Path field1 = mock(Path.class);
final Path field2 = mock(Path.class);
final Predicate equalPredicate1 = mock(Predicate.class);
@@ -99,7 +97,7 @@ public class SpecificationsBuilderTest {
when(root.get("field1")).thenReturn(field1);
when(root.get("field2")).thenReturn(field2);
Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
final Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
assertThat(predicate).as("Combined predicate").isEqualTo(combinedPredicate);