hawkBit repository uses Optional on single entity find/get requests (#435)

* Repo returns optionals.
* Improved exception handling for collection usage in repo queries.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-02-16 10:09:14 +01:00
committed by GitHub
parent d21af83804
commit 804522f966
232 changed files with 2104 additions and 2377 deletions

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.event.remote;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.lang.reflect.Constructor;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.event.remote;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.model.Action;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.event.remote.entity;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.lang.reflect.Constructor;

View File

@@ -44,6 +44,7 @@ public class ActionEventTest extends AbstractRemoteEntityEventTest<Action> {
generateAction.setActionType(ActionType.FORCED);
final Target target = testdataFactory.createTarget("Test");
generateAction.setTarget(target);
generateAction.setDistributionSet(testdataFactory.createDistributionSet());
return actionRepository.save(generateAction);
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.event.remote.entity;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.UUID;
@@ -56,7 +56,7 @@ public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest<Rollout
10, new RolloutGroupConditionBuilder().withDefaults()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build());
return rolloutManagement.findRolloutById(entity.getId()).getRolloutGroups().get(0);
return rolloutManagement.findRolloutById(entity.getId()).get().getRolloutGroups().get(0);
}
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.event.remote.entity;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.model.Target;
import org.junit.Test;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.model.Action.ActionType;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -60,16 +60,13 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
assertThat(softwareModuleRepository.findAll()).hasSize(0);
assertThat(artifactRepository.findAll()).hasSize(0);
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareModuleRepository.save(sm);
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
"version 2", null, null);
JpaSoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
sm2 = softwareModuleRepository.save(sm2);
JpaSoftwareModule sm3 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 3",
"version 3", null, null);
JpaSoftwareModule sm3 = new JpaSoftwareModule(osType, "name 3", "version 3", null, null);
sm3 = softwareModuleRepository.save(sm3);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -91,22 +88,21 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
assertThat(result).isNotEqualTo(result2);
assertThat(((JpaArtifact) result).getSha1Hash()).isEqualTo(((JpaArtifact) result2).getSha1Hash());
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getSha1Hash())
assertThat(artifactManagement.findArtifactByFilename("file1").get().getSha1Hash())
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getMd5Hash())
assertThat(artifactManagement.findArtifactByFilename("file1").get().getMd5Hash())
.isEqualTo(HashGeneratorUtils.generateMD5(random));
assertThat(artifactRepository.findAll()).hasSize(4);
assertThat(softwareModuleRepository.findAll()).hasSize(3);
assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts()).hasSize(3);
assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(3);
}
@Test
@Description("Tests hard delete directly on repository.")
public void hardDeleteSoftwareModule() throws NoSuchAlgorithmException, IOException {
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareModuleRepository.save(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -129,12 +125,10 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests the deletion of a local artifact including metadata.")
public void deleteArtifact() throws NoSuchAlgorithmException, IOException {
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareModuleRepository.save(sm);
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
"version 2", null, null);
JpaSoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
sm2 = softwareModuleRepository.save(sm2);
assertThat(artifactRepository.findAll()).isEmpty();
@@ -168,12 +162,10 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Description("Test the deletion of an artifact metadata where the binary is still linked to another "
+ "metadata element. The expected result is that the metadata is deleted but the binary kept.")
public void deleteDuplicateArtifacts() throws NoSuchAlgorithmException, IOException {
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareModuleRepository.save(sm);
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
"version 2", null, null);
JpaSoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
sm2 = softwareModuleRepository.save(sm2);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -202,7 +194,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024),
testdataFactory.createSoftwareModuleOs().getId(), "file1", false);
assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result);
assertThat(artifactManagement.findArtifact(result.getId()).get()).isEqualTo(result);
}
@Test
@@ -250,12 +242,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
public void findByFilenameAndSoftwareModule() {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty();
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isFalse();
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).hasSize(1);
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isTrue();
}
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
@@ -241,8 +241,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
final Long dsId = testdataFactory.createDistributionSet().getId();
testdataFactory.createTarget();
assignDistributionSet(dsId, TestdataFactory.DEFAULT_CONTROLLER_ID);
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
return deploymentManagement.findActiveActionsByTarget(TestdataFactory.DEFAULT_CONTROLLER_ID).get(0).getId();
}
@@ -296,10 +296,10 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
private void assertActionStatus(final Long actionId, final String controllerId,
final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus,
final Action.Status expectedActionStatus, final boolean actionActive) {
final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).getTargetInfo()
.getUpdateStatus();
final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).get()
.getTargetInfo().getUpdateStatus();
assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus);
final Action action = deploymentManagement.findAction(actionId);
final Action action = deploymentManagement.findAction(actionId).get();
assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus);
assertThat(action.isActive()).isEqualTo(actionActive);
final List<ActionStatus> actionStatusList = deploymentManagement.findActionStatusByAction(pageReq, actionId)
@@ -326,9 +326,9 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
// create two artifacts with identical SHA1 hash
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
ds.findFirstModuleByType(osType).get().getId(), "file1", false);
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds2.findFirstModuleByType(osType).getId(), "file1", false);
ds2.findFirstModuleByType(osType).get().getId(), "file1", false);
assertThat(artifact.getSha1Hash()).isEqualTo(artifact2.getSha1Hash());
assertThat(
@@ -462,8 +462,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING));
// nothing changed as "feedback after close" is disabled
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
@@ -487,8 +487,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING));
// nothing changed as "feedback after close" is disabled
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
// however, additional action status has been stored
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
@@ -514,7 +514,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
testData.put("test1", "testdata1");
controllerManagament.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
.isEqualTo(testData);
}
@@ -525,7 +525,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
testData.put("test2", "testdata20");
controllerManagament.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
testData.put("test1", "testdata1");
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
.isEqualTo(testData);
@@ -538,7 +538,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
controllerManagament.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
testData.put("test2", "testdata20");
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
.isEqualTo(testData);

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
@@ -92,7 +92,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final List<Target> testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
final Action action = deploymentManagement.findActionWithDetails(actionId);
final Action action = deploymentManagement.findActionWithDetails(actionId).get();
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
assertThat(action.getTarget()).as("Target in action").isNotNull();
@@ -109,7 +109,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final List<Target> testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Action action = deploymentManagement
.findActionWithDetails(assignDistributionSet(testDs, testTarget).getActions().get(0));
.findActionWithDetails(assignDistributionSet(testDs, testTarget).getActions().get(0)).get();
// save 2 action status
actionStatusRepository.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis()));
actionStatusRepository.save(new JpaActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
@@ -123,15 +123,34 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag. Not exists distribution set will be ignored for the assignment.")
public void assignAndUnassignDistributionSetToTag() {
final List<Long> assignDS = new ArrayList<>();
@Description("Ensures that tag to distribution set assignment that does not exist will cause EntityNotFoundException.")
public void assignDistributionSetToTagThatDoesNotExistThrowsException() {
final List<Long> assignDS = Lists.newArrayListWithExpectedSize(5);
for (int i = 0; i < 4; i++) {
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", new ArrayList<DistributionSetTag>())
.getId());
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
}
// not exists
assignDS.add(Long.valueOf(100));
final DistributionSetTag tag = tagManagement
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
try {
distributionSetManagement.assignTag(assignDS, tag.getId());
fail("It should not be possible to assign a DS that does not exist");
} catch (final EntityNotFoundException e) {
// Ok
}
}
@Test
@Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag.")
public void assignAndUnassignDistributionSetToTag() {
final List<Long> assignDS = Lists.newArrayListWithExpectedSize(4);
for (int i = 0; i < 4; i++) {
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
}
final DistributionSetTag tag = tagManagement
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
@@ -139,7 +158,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4);
assignedDS.forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1));
DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
assertThat(assignedDS.size()).as("assigned ds has wrong size")
.isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
@@ -147,13 +166,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
findDistributionSetTag.getId());
assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0));
assertThat(unAssignDS.getTags().size()).as("unassigned ds has wrong tag size").isEqualTo(0);
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag ds has wrong ds size")
.isEqualTo(3);
final List<DistributionSet> unAssignTargets = distributionSetManagement
.unAssignAllDistributionSetsByTag(findDistributionSetTag.getId());
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag has wrong ds size")
.isEqualTo(0);
assertThat(unAssignTargets.size()).as("unassigned target has wrong size").isEqualTo(3);
@@ -194,7 +213,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsInstalled = action.getDistributionSet();
// check initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("target has update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
// assign the two sets in a row
@@ -206,26 +225,26 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// we cancel second -> back to first
deploymentManagement.cancelAction(secondAction.getId());
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId()).get();
// confirm cancellation
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).as("wrong ds")
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet()).as("wrong ds")
.isEqualTo(dsFirst);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
// we cancel first -> back to installed
deploymentManagement.cancelAction(firstAction.getId());
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId()).get();
// confirm cancellation
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
}
@@ -241,7 +260,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsInstalled = action.getDistributionSet();
// check initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
// assign the two sets in a row
@@ -254,28 +273,28 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// we cancel first -> second is left
deploymentManagement.cancelAction(firstAction.getId());
// confirm cancellation
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId()).get();
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsSecond);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
// we cancel second -> remain assigned until finished cancellation
deploymentManagement.cancelAction(secondAction.getId());
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId()).get();
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(8);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsSecond);
// confirm cancellation
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
// cancelled success -> back to dsInstalled
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong installed ds").isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
}
@@ -289,7 +308,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
// verify initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
Action assigningAction = assignSet(target, ds);
@@ -298,21 +317,21 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(2);
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
target = targetManagement.findTargetByControllerID(target.getControllerId());
target = targetManagement.findTargetByControllerID(target.getControllerId()).get();
// force quit assignment
deploymentManagement.cancelAction(assigningAction.getId());
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId()).get();
deploymentManagement.forceQuitAction(assigningAction.getId());
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId()).get();
// verify
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong target update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
}
@@ -325,7 +344,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
// verify initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
final Action assigningAction = assignSet(target, ds);
@@ -344,11 +363,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
private JpaAction assignSet(final Target target, final DistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(ds);
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(ds);
final JpaAction action = actionRepository
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
.get(0);
@@ -396,13 +415,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.doesNotContain(Iterables.toArray(savedDeployedTargets, Target.class));
for (final Target myt : savedNakedTargets) {
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get();
assertThat(deploymentManagement.countActionsByTarget(t.getControllerId())).as("action should be empty")
.isEqualTo(0L);
}
for (final Target myt : savedDeployedTargets) {
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get();
final List<Action> activeActionsByTarget = deploymentManagement
.findActiveActionsByTarget(t.getControllerId());
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
@@ -546,20 +565,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verifying the correctness of the assignments
for (final Target t : deployResWithDsA.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).as("assignment is not correct").isEqualTo(dsA.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
}
for (final Target t : deployResWithDsB.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).as("assigned ds is wrong").isEqualTo(dsB.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
}
for (final Target t : deployResWithDsC.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsC.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should not be null").isNull();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
}
final List<Target> updatedTsDsA = testdataFactory
@@ -570,12 +589,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verify, that dsA is deployed correctly
assertThat(updatedTsDsA).as("ds is not deployed correctly").isEqualTo(deployResWithDsA.getDeployedTargets());
for (final Target t_ : updatedTsDsA) {
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId()))
.as("no actions should be active").hasSize(0);
}
@@ -596,12 +615,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
for (final Target t_ : deployed2DS) {
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
}
}
@@ -630,16 +649,16 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets,
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
DistributionSet dsA = testdataFactory.createDistributionSet("");
final DistributionSet dsA = testdataFactory.createDistributionSet("");
distributionSetManagement.deleteDistributionSet(dsA.getId());
dsA = distributionSetManagement.findDistributionSetById(dsA.getId());
assertThat(dsA).as("ds should be null").isNull();
assertThat(distributionSetManagement.findDistributionSetById(dsA.getId()).isPresent()).isFalse();
// // verify that the ds is not physically deleted
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
distributionSetManagement.deleteDistributionSet(ds.getId());
final DistributionSet foundDS = distributionSetManagement.findDistributionSetById(ds.getId());
final DistributionSet foundDS = distributionSetManagement.findDistributionSetById(ds.getId()).get();
assertThat(foundDS).as("founded should not be null").isNotNull();
assertThat(foundDS.isDeleted()).as("found ds should be deleted").isTrue();
}
@@ -711,13 +730,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// doing the assignment
targs = assignDistributionSet(dsA, targs).getAssignedEntity();
Target targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId());
Target targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId()).get();
// checking the revisions of the created entities
// verifying that the revision of the object and the revision within the
// DB has not changed
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
// verifying that the assignment is correct
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size())
@@ -736,7 +755,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
controllerManagament.addUpdateActionStatus(
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
targ = targetManagement.findTargetByControllerID(targ.getControllerId());
targ = targetManagement.findTargetByControllerID(targ.getControllerId()).get();
assertEquals("active target actions are wrong", 0,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
@@ -754,11 +773,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertEquals("active actions are wrong", 1,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
targetManagement.findTargetByControllerID(targ.getControllerId()).getTargetInfo().getUpdateStatus());
assertEquals("target status is wrong", TargetUpdateStatus.PENDING, targetManagement
.findTargetByControllerID(targ.getControllerId()).get().getTargetInfo().getUpdateStatus());
assertEquals("wrong assigned ds", dsB, targ.getAssignedDistributionSet());
assertEquals("Installed ds is wrong", dsA.getId(),
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).getTargetInfo()
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet().getId());
assertEquals("Active ds is wrong", dsB,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet());
@@ -774,12 +793,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final Target targ = testdataFactory.createTarget("target-id-A");
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
assignDistributionSet(dsA, Lists.newArrayList(targ));
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
}
@Test
@@ -793,16 +812,17 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
ds.getId(), ActionType.SOFT,
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
Lists.newArrayList(target.getControllerId()));
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0))
.get();
// verify preparation
Action findAction = deploymentManagement.findAction(action.getId());
Action findAction = deploymentManagement.findAction(action.getId()).get();
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.SOFT);
// test
deploymentManagement.forceTargetAction(action.getId());
// verify test
findAction = deploymentManagement.findAction(action.getId());
findAction = deploymentManagement.findAction(action.getId()).get();
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
}
@@ -817,9 +837,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
ds.getId(), ActionType.FORCED,
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
Lists.newArrayList(target.getControllerId()));
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0))
.get();
// verify perparation
Action findAction = deploymentManagement.findAction(action.getId());
Action findAction = deploymentManagement.findAction(action.getId()).get();
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
// test
@@ -827,7 +848,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verify test
assertThat(forceTargetAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
findAction = deploymentManagement.findAction(action.getId());
findAction = deploymentManagement.findAction(action.getId()).get();
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
}
@@ -896,7 +917,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(event.getActionId()).as("Action id in database and event do not match")
.isEqualTo(activeActionsByTarget.get(0).getId());
assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId())
assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId()).get()
.getModules()).as("softwaremodule size is not correct")
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@@ -18,6 +18,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.assertj.core.api.Condition;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
@@ -39,7 +40,6 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.fest.assertions.core.Condition;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -64,25 +64,29 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
public void updateUnassignedDistributionSetTypeModules() {
DistributionSetType updatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.isEmpty();
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
// add OS
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(osType.getId()));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.containsOnly(osType);
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType);
// add JVM
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(runtimeType.getId()));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.containsOnly(osType, runtimeType);
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType, runtimeType);
// remove OS
updatableType = distributionSetManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.containsOnly(runtimeType);
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(runtimeType);
}
@Test
@@ -90,17 +94,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
public void updateAssignedDistributionSetTypeMetaData() {
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(entityFactory
.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.isEmpty();
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
distributionSetManagement.updateDistributionSetType(
entityFactory.distributionSetType().update(nonUpdatableType.getId()).description("a new description"));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getDescription())
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getDescription())
.isEqualTo("a new description");
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getColour())
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getColour())
.isEqualTo("test123");
}
@@ -109,8 +114,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
public void addModuleToAssignedDistributionSetTypeFails() {
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.isEmpty();
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
@@ -129,8 +135,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
public void removeModuleToAssignedDistributionSetTypeFails() {
DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
.isEmpty();
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
nonUpdatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()));
@@ -170,7 +177,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey()));
distributionSetManagement.deleteDistributionSetType(softDelete.getId());
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").get().isDeleted())
.isEqualTo(true);
}
@Test
@@ -251,7 +259,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// assign target
assignDistributionSet(ds.getId(), target.getControllerId());
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
// not allowed as it is assigned now
try {
@@ -264,7 +272,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// not allowed as it is assigned now
try {
ds = distributionSetManagement.unassignSoftwareModule(ds.getId(),
ds.findFirstModuleByType(appType).getId());
ds.findFirstModuleByType(appType).get().getId());
fail("Expected EntityReadOnlyException");
} catch (final EntityReadOnlyException e) {
@@ -303,19 +311,19 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// update data
// legal update of module addition
distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os.getId()));
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
assertThat(ds.findFirstModuleByType(osType)).isEqualTo(os);
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
assertThat(ds.findFirstModuleByType(osType).get()).isEqualTo(os);
// legal update of module removal
distributionSetManagement.unassignSoftwareModule(ds.getId(), ds.findFirstModuleByType(appType).getId());
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
assertThat(ds.findFirstModuleByType(appType)).isNull();
distributionSetManagement.unassignSoftwareModule(ds.getId(), ds.findFirstModuleByType(appType).get().getId());
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
assertThat(ds.findFirstModuleByType(appType).isPresent()).isFalse();
// Update description
distributionSetManagement
.updateDistributionSet(entityFactory.distributionSet().update(ds.getId()).name("a new name")
.description("a new description").version("a new version").requiredMigrationStep(true));
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
assertThat(ds.getDescription()).isEqualTo("a new description");
assertThat(ds.getName()).isEqualTo("a new name");
assertThat(ds.getVersion()).isEqualTo("a new version");
@@ -338,7 +346,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// create an DS meta data entry
createDistributionSetMetadata(ds.getId(), new JpaDistributionSetMetadata(knownKey, ds, knownValue));
DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId());
DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()).get();
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2);
Thread.sleep(100);
@@ -349,7 +357,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// we are updating the sw meta data so also modifying the base software
// module so opt lock
// revision must be three
changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId());
changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()).get();
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(3);
assertThat(changedLockRevisionDS.getLastModifiedAt()).isGreaterThan(0L);
@@ -435,14 +443,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
distributionSetManagement.deleteDistributionSet(dsDeleted.getId());
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId());
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId()).get();
ds100Group1 = toggleTagAssignment(ds100Group1, dsTagA).getAssignedEntity();
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get();
ds100Group1 = toggleTagAssignment(ds100Group1, dsTagB).getAssignedEntity();
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get();
ds100Group2 = toggleTagAssignment(ds100Group2, dsTagA).getAssignedEntity();
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get();
// check setup
assertThat(distributionSetRepository.findAll()).hasSize(203);
@@ -655,11 +663,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Deltes a DS that is no in use. Expected behaviour is a hard delete on the database.")
public void deleteUnassignedDistributionSet() {
DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
final DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
testdataFactory.createDistributionSet("ds-2");
// delete a ds
assertThat(distributionSetRepository.findAll()).hasSize(2);
@@ -707,17 +712,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Description("Deletes a DS that is in use by either target assignment or rollout. Expected behaviour is a soft delete on the database, i.e. only marked as "
+ "deleted, kept as reference but unavailable for future use..")
public void deleteAssignedDistributionSet() {
DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
testdataFactory.createDistributionSet("ds-1");
testdataFactory.createDistributionSet("ds-2");
final DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
final DistributionSet dsToRolloutAssigned = testdataFactory.createDistributionSet("ds-4");
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
// create assigned DS
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
dsToTargetAssigned.getVersion());
final Target savedTarget = testdataFactory.createTarget();
assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
@@ -739,11 +739,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verify that the DistributionSetAssignmentResult not contains already assigned targets.")
public void verifyDistributionSetAssignmentResultNotContainsAlreadyAssignedTargets() {
DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
final DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
// create assigned DS
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
dsToTargetAssigned.getVersion());
final Target savedTarget = testdataFactory.createTarget();
DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(),
savedTarget.getControllerId());

View File

@@ -8,8 +8,8 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.time.LocalDate;
import java.time.LocalDateTime;

View File

@@ -8,8 +8,8 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.ArrayList;
import java.util.HashMap;
@@ -196,7 +196,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// Run here, because scheduler is disabled during tests
rolloutManagement.checkStartingRollouts(0);
return rolloutManagement.findRolloutById(createdRollout.getId());
return rolloutManagement.findRolloutById(createdRollout.getId()).get();
}
@Step("Finish three actions of the rollout group and delete two targets")
@@ -249,7 +249,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).getStatus())
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus())
.isEqualTo(RolloutStatus.FINISHED);
}
@@ -284,7 +284,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// and should execute the error action
rolloutManagement.checkRunningRollouts(0);
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId());
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
// the rollout itself should be in paused based on the error action
assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED);
@@ -324,7 +324,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// and should execute the error action
rolloutManagement.checkRunningRollouts(0);
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId());
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
// the rollout itself should be in paused based on the error action
assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED);
@@ -337,7 +337,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.resumeRollout(createdRollout.getId());
// the rollout should be running again
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).getStatus())
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus())
.isEqualTo(RolloutStatus.RUNNING);
// checking rollouts again
@@ -370,7 +370,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.checkRunningRollouts(0);
// finish running actions, 2 actions should be finished
assertThat(changeStatusForAllRunningActions(createdRollout, Status.FINISHED)).isEqualTo(2);
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).getStatus())
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus())
.isEqualTo(RolloutStatus.RUNNING);
}
@@ -385,7 +385,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.FINISHED));
// verify that rollout itself is in finished state
final Rollout findRolloutById = rolloutManagement.findRolloutById(createdRollout.getId());
final Rollout findRolloutById = rolloutManagement.findRolloutById(createdRollout.getId()).get();
assertThat(findRolloutById.getStatus()).isEqualTo(RolloutStatus.FINISHED);
}
@@ -508,7 +508,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// round(7/3)=2 targets running (Group 3)
// round(5/2)=3 targets SCHEDULED (Group 3)
// round(2/1)=2 targets SCHEDULED (Group 4)
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId());
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
@@ -542,7 +542,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
successCondition, errorCondition);
final DistributionSet ds = createdRollout.getDistributionSet();
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId());
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
// 5 targets are running
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
assertThat(runningActions.size()).isEqualTo(5);
@@ -584,7 +584,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
successCondition, errorCondition);
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo");
@@ -626,7 +626,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
successCondition, errorCondition);
final DistributionSet distributionSet = rolloutOne.getDistributionSet();
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
rolloutManagement.checkRunningRollouts(0);
@@ -643,7 +643,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.ERROR, 6L);
validateRolloutActionStatus(rolloutOne.getId(), expectedTargetCountStatus);
// rollout is finished
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
assertThat(rolloutOne.getStatus()).isEqualTo(RolloutStatus.FINISHED);
final int amountGroupsForRolloutTwo = 1;
@@ -655,7 +655,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// Run here, because scheduler is disabled during tests
rolloutManagement.checkStartingRollouts(0);
rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId());
rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId()).get();
// 6 error targets are know running
expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 6L);
@@ -684,7 +684,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
successCondition, errorCondition);
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
rolloutManagement.checkRunningRollouts(0);
@@ -708,13 +708,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
successCondition, errorCondition);
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
rolloutManagement.checkRunningRollouts(0);
// verify: 40% error and 60% finished -> should not move to next group
// because successCondition 80%
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
final List<RolloutGroup> rolloutGruops = rolloutOne.getRolloutGroups();
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L);
@@ -733,12 +733,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
successCondition, errorCondition);
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
rolloutManagement.checkRunningRollouts(0);
// verify: 40% error -> should pause because errorCondition is 20%
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
assertThat(RolloutStatus.PAUSED).isEqualTo(rolloutOne.getStatus());
}
@@ -896,7 +896,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final Rollout rolloutCreated = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout,
amountGroups, successCondition, errorCondition, rolloutName, "RolloutA");
final Rollout rolloutFound = rolloutManagement.findRolloutByName(rolloutName);
final Rollout rolloutFound = rolloutManagement.findRolloutByName(rolloutName).get();
assertThat(rolloutCreated).isEqualTo(rolloutFound);
}
@@ -919,7 +919,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
changeStatusForRunningActions(myRollout, Status.FINISHED, 2);
rolloutManagement.checkRunningRollouts(0);
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
float percent = rolloutManagement.getFinishedPercentForRunningGroup(myRollout.getId(),
myRollout.getRolloutGroups().get(0).getId());
@@ -963,7 +963,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// Run here, because scheduler is disabled during tests
rolloutManagement.checkStartingRollouts(0);
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
final List<RolloutGroup> rolloutGroups = myRollout.getRolloutGroups();
Page<Target> targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
@@ -1070,7 +1070,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
conditionRolloutStatus, 15000, 500)).as("Rollout status").isNotNull();
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 1L);
@@ -1099,7 +1099,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.checkReadyRollouts(0);
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
rolloutManagement.startRollout(myRollout.getId());
@@ -1112,7 +1112,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 100L);
@@ -1144,15 +1144,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.checkReadyRollouts(0);
// rollout should not have been started
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
// schedule to now
rolloutManagement.updateRollout(
entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis()));
rolloutManagement
.updateRollout(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis()));
rolloutManagement.checkReadyRollouts(0);
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.STARTING);
// Run here, because scheduler is disabled during tests
@@ -1163,7 +1163,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 100L);
@@ -1200,7 +1200,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutGroups.add(generateRolloutGroup(2, percentTargetsInGroup3, null));
Rollout myRollout = rolloutManagement.createRollout(rolloutcreate, rolloutGroups, conditions);
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
for (final RolloutGroup group : myRollout.getRolloutGroups()) {
@@ -1214,7 +1214,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.fillRolloutGroupsWithTargets(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1);
@@ -1318,7 +1318,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
.set(distributionSet);
Rollout myRollout = rolloutManagement.createRollout(rolloutToCreate, amountGroups, conditions);
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
@@ -1351,13 +1351,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup,
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement
.findRolloutGroupWithDetailedStatus(rolloutGroup.getId());
.findRolloutGroupWithDetailedStatus(rolloutGroup.getId()).get();
validateStatus(rolloutGroupWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus);
}
private void validateRolloutActionStatus(final Long rolloutId,
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
final Rollout rolloutWithDetail = rolloutManagement.findRolloutWithDetailedStatus(rolloutId);
final Rollout rolloutWithDetail = rolloutManagement.findRolloutWithDetailedStatus(rolloutId).get();
validateStatus(rolloutWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus);
}
@@ -1447,7 +1447,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Override
public RolloutStatus call() throws Exception {
final Rollout myRollout = rolloutManagement.findRolloutById(rolloutId);
final Rollout myRollout = rolloutManagement.findRolloutById(rolloutId).get();
return myRollout.getStatus();
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -23,7 +23,6 @@ import javax.validation.ConstraintViolationException;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
@@ -187,11 +186,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
.isEqualTo(ds);
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
.isEqualTo(ds);
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
assertThat(action).isNotNull();
return action;
@@ -290,7 +289,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModule is deleted
assertThat(softwareModuleRepository.findAll()).hasSize(0);
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId())).isNull();
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId()).isPresent()).isFalse();
// verify: binary data of artifact is deleted
assertArtfiactNull(artifact1, artifact2);
@@ -315,7 +314,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [VERIFY EXPECTED RESULT]:
// verify: assignedModule is marked as deleted
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId());
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
assertTrue("The module should be flagged as deleted", assignedModule.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(1);
@@ -355,7 +354,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [VERIFY EXPECTED RESULT]:
// verify: assignedModule is marked as deleted
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId());
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
assertTrue("The found module should be flagged deleted", assignedModule.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(1);
@@ -383,7 +382,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [STEP2]: Create newArtifactX and add it to SoftwareModuleX
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
// [STEP3]: Create SoftwareModuleY and add the same ArtifactX
@@ -391,7 +390,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [STEP4]: Assign the same ArtifactX to SoftwareModuleY
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId());
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
// [STEP5]: Delete SoftwareModuleX
@@ -400,8 +399,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModuleX is deleted, and ModuelY still exists
assertThat(softwareModuleRepository.findAll()).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId())).isNull();
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId())).isNotNull();
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId()).isPresent()).isFalse();
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId()).isPresent()).isTrue();
// verify: binary data of artifact is not deleted
assertArtfiactNotNull(artifactY);
@@ -425,14 +424,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
// [STEP2]: Create SoftwareModuleY and add the same ArtifactX
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId());
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
@@ -450,8 +449,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
softwareManagement.deleteSoftwareModule(moduleY.getId());
// [VERIFY EXPECTED RESULT]:
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId());
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
// verify: SoftwareModuleX and SofwtareModule are marked as deleted
assertThat(moduleX).isNotNull();
@@ -483,7 +482,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
}
// Verify correct Creation of SoftwareModule and corresponding artifacts
softwareModule = softwareManagement.findSoftwareModuleById(softwareModule.getId());
softwareModule = softwareManagement.findSoftwareModuleById(softwareModule.getId()).get();
assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1);
final List<Artifact> artifacts = softwareModule.getArtifacts();
@@ -623,7 +622,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename")).as("Type with given name")
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename").get()).as("Type with given name")
.isEqualTo(found);
}
@@ -718,7 +717,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareManagement
.createSoftwareModuleMetadata(ah.getId(), Lists.newArrayList(swMetadata1, swMetadata2));
final SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
final SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
assertThat(softwareModuleMetadata).hasSize(2);
@@ -770,7 +769,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// base software module should have now the opt lock revision one
// because we are modifying the
// base software module
SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
// update the software module metadata
@@ -780,7 +779,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// we are updating the sw meta data so also modiying the base software
// module so opt lock
// revision must be two
changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(3);
// verify updated meta data contains the updated value
@@ -823,12 +822,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
.getSoftwareModule();
try {
softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist");
fail("should not have worked as module metadata with that key does not exist");
} catch (final EntityNotFoundException e) {
}
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist").isPresent()).isFalse();
}
@Test

View File

@@ -8,15 +8,15 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Random;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
@@ -131,9 +131,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
}
private void createTestArtifact(final byte[] random) {
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -72,18 +72,18 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
toggleTagAssignment(dsBs, tagB);
toggleTagAssignment(dsCs, tagC);
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()));
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()));
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()).get());
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()).get());
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()));
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()));
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()).get());
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()).get());
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()));
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()));
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()).get());
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()).get());
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()));
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()));
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()));
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()).get());
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()).get());
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()).get());
DistributionSetFilterBuilder distributionSetFilterBuilder;
@@ -259,9 +259,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final Tag tag = tagManagement
.createTargetTag(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
assertThat(targetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag ed").isEqualTo("kai2");
assertThat(tagManagement.findTargetTag("kai1").getColour()).as("wrong tag found").isEqualTo("colour");
assertThat(tagManagement.findTargetTagById(tag.getId()).getColour()).as("wrong tag found").isEqualTo("colour");
assertThat(targetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag ed")
.isEqualTo("kai2");
assertThat(tagManagement.findTargetTag("kai1").get().getColour()).as("wrong tag found").isEqualTo("colour");
assertThat(tagManagement.findTargetTagById(tag.getId()).get().getColour()).as("wrong tag found")
.isEqualTo("colour");
}
@Test
@@ -273,7 +275,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final TargetTag toDelete = tags.iterator().next();
for (final Target target : targetRepository.findAll()) {
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getTags())
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
.contains(toDelete);
}
@@ -282,7 +284,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
// check
for (final Target target : targetRepository.findAll()) {
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getTags())
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
.doesNotContain(toDelete);
}
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();
@@ -314,10 +316,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final Tag tag = tagManagement.createDistributionSetTag(
entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
assertThat(distributionSetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag found")
assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found")
.isEqualTo("kai2");
assertThat(tagManagement.findDistributionSetTag("kai1").getColour()).as("wrong tag found").isEqualTo("colour");
assertThat(tagManagement.findDistributionSetTagById(tag.getId()).getColour()).as("wrong tag found")
assertThat(tagManagement.findDistributionSetTag("kai1").get().getColour()).as("wrong tag found")
.isEqualTo("colour");
assertThat(tagManagement.findDistributionSetTagById(tag.getId()).get().getColour()).as("wrong tag found")
.isEqualTo("colour");
}
@@ -337,7 +340,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final DistributionSetTag toDelete = tags.iterator().next();
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags())
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags())
.as("Wrong tag found").contains(toDelete);
}
@@ -348,7 +351,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull();
assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of tags after deletion").hasSize(19);
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags())
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags())
.as("Wrong found tags").doesNotContain(toDelete);
}
}

View File

@@ -8,8 +8,9 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -47,7 +48,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
assertEquals("Retrieved newly created custom target filter", targetFilterQuery,
targetFilterQueryManagement.findTargetFilterQueryByName(filterName));
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get());
}
@Test
@@ -98,8 +99,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
targetFilterQueryManagement.deleteTargetFilterQuery(targetFilterQuery.getId());
assertEquals("Returns null as the target filter is deleted", null,
targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId()));
assertFalse("Returns null as the target filter is deleted",
targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId()).isPresent());
}
@@ -114,7 +115,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
targetFilterQueryManagement.updateTargetFilterQuery(
entityFactory.targetFilterQuery().update(targetFilterQuery.getId()).query(newQuery));
assertEquals("Returns updated target filter query", newQuery,
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).getQuery());
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get().getQuery());
}
@@ -130,7 +131,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(),
distributionSet.getId());
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
@@ -149,13 +150,13 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
distributionSet.getId());
// Check if target filter query is there
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
distributionSetManagement.deleteDistributionSet(distributionSet.getId());
// Check if auto assign distribution set is null
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
assertNotNull("Returns target filter query", tfq);
assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet());
@@ -178,17 +179,17 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
.getId(), distributionSet.getId());
// Check if target filter query is there with the distribution set
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
distributionSetManagement.deleteDistributionSet(distributionSet.getId());
// Check if distribution set is still in the database with deleted flag
assertTrue("Distribution set should be deleted",
distributionSetManagement.findDistributionSetById(distributionSet.getId()).isDeleted());
distributionSetManagement.findDistributionSetById(distributionSet.getId()).get().isDeleted());
// Check if auto assign distribution set is null
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
assertNotNull("Returns target filter query", tfq);
assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet());

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Instant;
import java.util.ArrayList;
@@ -118,12 +118,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
verifyThatRepositoryContains400Targets();
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs);
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.findTargetByControllerID(assignedC));
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA,
targetManagement.findTargetByControllerID(assignedC).get());
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
verifyThat3TargetsHaveDSAssigned(setA,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA));
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA).get());
List<Target> expected = concat(targAs, targBs, targCs, targDs);
expected.removeAll(
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
@@ -133,26 +134,26 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
expected = concat(targAs);
expected.remove(targetManagement.findTargetByControllerID(assignedA));
expected.remove(targetManagement.findTargetByControllerID(assignedA).get());
verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected);
expected = concat(targBs);
expected.remove(targetManagement.findTargetByControllerID(assignedB));
expected.remove(targetManagement.findTargetByControllerID(assignedB).get());
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
verifyThat3TargetsAreInStatusPending(pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
targetManagement.findTargetByControllerID(assignedA));
targetManagement.findTargetByControllerID(assignedA).get());
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
targetManagement.findTargetByControllerID(assignedB));
targetManagement.findTargetByControllerID(assignedB).get());
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs));
verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
targetManagement.findTargetByControllerID(installedC));
targetManagement.findTargetByControllerID(installedC).get());
expected = concat(targBs, targCs);
expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));

View File

@@ -12,7 +12,7 @@ import static com.google.common.collect.Iterables.limit;
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.stream.Collectors.toList;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -197,7 +197,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1));
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1");
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
.isEqualTo(findTargetTag.getAssignedToTargets().size());
@@ -207,11 +207,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
assertThat(unAssignTarget.getTags()).as("Tag size is wrong").isEmpty();
findTargetTag = tagManagement.findTargetTag("Tag1");
findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3);
final List<Target> unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag.getId());
findTargetTag = tagManagement.findTargetTag("Tag1");
findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty();
assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3);
unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0));
@@ -250,7 +250,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId));
controllerManagament.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
.isEqualTo(testData);
return target;
@@ -287,7 +287,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
entityFactory.actionStatus().create(result.getActions().get(0)).status(Status.FINISHED));
assignDistributionSet(set2.getId(), "4711");
target = targetManagement.findTargetByControllerIDWithDetails("4711");
target = targetManagement.findTargetByControllerIDWithDetails("4711").get();
// read data
assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong")
@@ -308,7 +308,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that repositoy returns null if given controller ID does not exist without exception.")
public void findTargetByControllerIDWithDetailsReturnsNullForNonexisting() {
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd")).as("Expected as").isNull();
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd").isPresent()).isFalse();
}
@Test
@@ -354,7 +354,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
*/
private void checkTargetHasTags(final boolean strict, final Iterable<Target> targets, final TargetTag... tags) {
_target: for (final Target tl : targets) {
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId());
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
for (final Tag tt : t.getTags()) {
for (final Tag tag : tags) {
@@ -372,7 +372,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
private void checkTargetHasNotTags(final Iterable<Target> targets, final TargetTag... tags) {
for (final Target tl : targets) {
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId());
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
for (final Tag tag : tags) {
for (final Tag tt : t.getTags()) {
@@ -412,7 +412,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
.isNotEqualTo(savedTarget.getLastModifiedAt());
modifiedAt = savedTarget.getLastModifiedAt();
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId());
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId()).get();
assertNotNull("The target should not be null", foundTarget);
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
.isEqualTo(foundTarget.getControllerId());
@@ -506,12 +506,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final List<TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId()));
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId());
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get();
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags);
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags)
.doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId());
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get();
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags).containsAll(t2Tags);
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags)
.doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
@@ -697,7 +697,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
controllerManagament.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1"));
securityRule.runAs(WithSpringAuthorityRule.withUser("bumlux", "READ_TARGET"), () -> {
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId);
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
.get();
assertThat(findTargetByControllerID).isNotNull();
assertThat(findTargetByControllerID.getTargetInfo()).isNotNull();
assertThat(findTargetByControllerID.getTargetInfo().getPollStatus()).isNotNull();

View File

@@ -8,8 +8,8 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.Serializable;
import java.time.Duration;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.autoassign;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.stream.Collectors;

View File

@@ -8,12 +8,13 @@
*/
package org.eclipse.hawkbit.repository.jpa.event;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleDeletedEvent;
@@ -28,7 +29,6 @@ import org.eclipse.hawkbit.repository.jpa.event.RepositoryEntityEventTest.Reposi
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.fest.assertions.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.model;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
@@ -54,7 +54,8 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
final Target targetToBeCreated = testdataFactory.createTarget("targetToBeCreated");
final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId());
final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId())
.get();
assertThat(postLoadEntityListener.getEntity()).isNotNull();
assertThat(postLoadEntityListener.getEntity()).isEqualTo(loadedTarget);
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.model;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import org.eclipse.hawkbit.repository.ActionFields;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.Arrays;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.RolloutGroupFields;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
@@ -39,7 +39,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
final DistributionSet dsA = testdataFactory.createDistributionSet("");
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
rollout = rolloutManagement.findRolloutById(rollout.getId());
rollout = rolloutManagement.findRolloutById(rollout.getId()).get();
this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId();
}
@@ -84,7 +84,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
final String targetFilterQuery) {
return rolloutManagement.createRollout(
entityFactory.rollout().create()
.set(distributionSetManagement.findDistributionSetById(distributionSetId)).name(name)
.set(distributionSetManagement.findDistributionSetById(distributionSetId).get()).name(name)
.targetFilterQuery(targetFilterQuery),
amountGroups, new RolloutGroupConditionBuilder().withDefaults()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.TagFields;
import org.eclipse.hawkbit.repository.builder.TagCreate;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.Arrays;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.List;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.specifications;
import static org.fest.assertions.Assertions.assertThat;
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;

View File

@@ -8,10 +8,12 @@
*/
package org.eclipse.hawkbit.repository.jpa.tenancy;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.Collection;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
@@ -126,7 +128,13 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
final Target createTargetForTenant = createTargetForTenant(controllerAnotherTenant, anotherTenant);
// ensure target cannot be deleted by 'mytenant'
targetManagement.deleteTargets(Lists.newArrayList(createTargetForTenant.getId()));
try {
targetManagement.deleteTargets(Lists.newArrayList(createTargetForTenant.getId()));
fail("mytenant should not have been able to delete target of anotherTenant");
} catch (final EntityNotFoundException ex) {
// ok
}
Slice<Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
assertThat(targetsForAnotherTenant).hasSize(1);