Merge branch 'master' into Multiple_VHost_Connection
Conflicts: hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
*/
|
||||
public class ListReportSeries extends AbstractReportSeries {
|
||||
|
||||
private final List<Number> data = new ArrayList<Number>();
|
||||
private final List<Number> data = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
||||
@@ -37,19 +37,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public interface ActionRepository extends BaseEntityRepository<Action, Long>, JpaSpecificationExecutor<Action> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
Iterable<Action> findAll();
|
||||
|
||||
/**
|
||||
* Retrieves an Action with all lazy attributes.
|
||||
*
|
||||
*
|
||||
* @param actionId
|
||||
* the ID of the action
|
||||
* @return the found {@link Action}
|
||||
@@ -67,13 +57,12 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* the {@link DistributionSet} on which will be filtered
|
||||
* @return the found {@link Action}s
|
||||
*/
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
Page<Action> findByDistributionSet(final Pageable pageable, final DistributionSet ds);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are referring the given
|
||||
* {@link Target}.
|
||||
*
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param target
|
||||
@@ -84,8 +73,9 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are active and referring the given
|
||||
* {@link Target} in a specified order.
|
||||
*
|
||||
* {@link Target} in a specified order. Loads also the lazy
|
||||
* {@link Action#getDistributionSet()} field.
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param target
|
||||
@@ -125,14 +115,13 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* @return the found {@link UpdateAction}s
|
||||
*/
|
||||
@Query("Select a from Action a where a.target = :target and a.distributionSet = :ds order by a.id")
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
Page<Action> findByTargetAndDistributionSet(final Pageable pageable, @Param("target") final Target target,
|
||||
@Param("ds") DistributionSet ds);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s of a specific target, without pagination
|
||||
* ordered by action ID.
|
||||
*
|
||||
*
|
||||
* @param target
|
||||
* to search for
|
||||
* @return a list of actions according to the searched target
|
||||
@@ -143,7 +132,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Retrieves all {@link Action}s of a specific target and given active flag
|
||||
* ordered by action ID.
|
||||
*
|
||||
*
|
||||
* @param pageable
|
||||
* the pagination parameter
|
||||
* @param target
|
||||
@@ -159,8 +148,9 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s of a specific target and given active flag
|
||||
* ordered by action ID.
|
||||
*
|
||||
* ordered by action ID. Loads also the lazy
|
||||
* {@link Action#getDistributionSet()} field.
|
||||
*
|
||||
* @param target
|
||||
* to search for
|
||||
* @param active
|
||||
@@ -174,7 +164,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Updates all {@link Action} to inactive for all targets with given ID.
|
||||
*
|
||||
*
|
||||
* @param keySet
|
||||
* the list of actions to set inactive
|
||||
* @param targetsIds
|
||||
@@ -190,7 +180,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* Switches the status of actions from one specific status into another,
|
||||
* only if the actions are in a specific status. This should be a atomar
|
||||
* operation.
|
||||
*
|
||||
*
|
||||
* @param statusToSet
|
||||
* the new status the actions should get
|
||||
* @param targetIds
|
||||
@@ -210,7 +200,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* Switches the status of actions from one specific status into another,
|
||||
* only if the actions are in a specific status. This should be a atomar
|
||||
* operation.
|
||||
*
|
||||
*
|
||||
* @param statusToSet
|
||||
* the new status the actions should get
|
||||
* @param rollout
|
||||
@@ -227,7 +217,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
@Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Retrieves all {@link Action}s which are active and referring to the given
|
||||
* target Ids and distribution set required migration step.
|
||||
*
|
||||
@@ -243,36 +233,24 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given target.
|
||||
*
|
||||
*
|
||||
* @param target
|
||||
* the target to count the {@link Action}s
|
||||
* @return the count of actions referring to the given target
|
||||
*/
|
||||
Long countByTarget(Target target);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.CrudRepository#save(java.lang.
|
||||
* Iterable)
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
|
||||
<S extends Action> List<S> save(Iterable<S> entities);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.repository.CrudRepository#save(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
|
||||
<S extends Action> S save(S entity);
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given DistributionSet.
|
||||
*
|
||||
*
|
||||
* @param distributionSet
|
||||
* DistributionSet to count the {@link Action}s from
|
||||
* @return the count of actions referring to the given distributionSet
|
||||
@@ -281,7 +259,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given rollout.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout to count the {@link Action}s from
|
||||
* @return the count of actions referring to the given rollout
|
||||
@@ -293,7 +271,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* are currently not in the given status. An in-clause statement does not
|
||||
* work with the spring-data, so this is specific usecase regarding to the
|
||||
* rollout-management to find out actions which are not in specific states.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout the actions are belong to
|
||||
* @param rolloutGroup
|
||||
@@ -312,7 +290,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all actions referring to a given rollout and rolloutgroup.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout the actions belong to
|
||||
* @param rolloutGroup
|
||||
@@ -323,7 +301,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all actions referring to a given rollout, rolloutgroup and status.
|
||||
*
|
||||
*
|
||||
* @param rolloutId
|
||||
* the ID of rollout the actions belong to
|
||||
* @param rolloutGroupId
|
||||
@@ -338,7 +316,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Retrieving all actions referring to a given rollout with a specific
|
||||
* action as parent reference and a specific status.
|
||||
*
|
||||
*
|
||||
* Finding all actions of a specific rolloutgroup parent relation.
|
||||
*
|
||||
* @param rollout
|
||||
@@ -355,7 +333,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Retrieves all actions for a specific rollout and in a specific status.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout the actions beglong to
|
||||
* @param actionStatus
|
||||
@@ -367,7 +345,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout.
|
||||
*
|
||||
*
|
||||
* @param rolloutId
|
||||
* id of {@link Rollout}
|
||||
* @return list of objects with status and target count
|
||||
@@ -378,7 +356,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout.
|
||||
*
|
||||
*
|
||||
* @param rolloutId
|
||||
* id of {@link Rollout}
|
||||
* @return list of objects with status and target count
|
||||
@@ -389,7 +367,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout group.
|
||||
*
|
||||
*
|
||||
* @param rolloutGroupId
|
||||
* id of {@link RolloutGroup}
|
||||
* @return list of objects with status and target count
|
||||
@@ -400,7 +378,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout group.
|
||||
*
|
||||
*
|
||||
* @param rolloutGroupId
|
||||
* list of id of {@link RolloutGroup}
|
||||
* @return list of objects with status and target count
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -212,14 +211,9 @@ public class ControllerManagement implements EnvironmentAware {
|
||||
@Modifying
|
||||
@Transactional
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
public Target findOrRegisterTargetIfItDoesNotexist(@NotNull final String targetid, final URI address) {
|
||||
final Specification<Target> spec = new Specification<Target>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
return cb.equal(targetRoot.get(Target_.controllerId), targetid);
|
||||
}
|
||||
};
|
||||
public Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty final String targetid, final URI address) {
|
||||
final Specification<Target> spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(Target_.controllerId),
|
||||
targetid);
|
||||
|
||||
Target target = targetRepository.findOne(spec);
|
||||
|
||||
@@ -229,9 +223,9 @@ public class ControllerManagement implements EnvironmentAware {
|
||||
target.setName(targetid);
|
||||
return targetManagement.createTarget(target, TargetUpdateStatus.REGISTERED, System.currentTimeMillis(),
|
||||
address);
|
||||
} else {
|
||||
return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
|
||||
}
|
||||
|
||||
return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -330,7 +330,7 @@ public class DeploymentManagement {
|
||||
// one we have been switched to canceling state because for targets
|
||||
// which we have changed to
|
||||
// canceling we don't want to publish the new action update event.
|
||||
final Set<Long> targetIdsCancellList = new HashSet<Long>();
|
||||
final Set<Long> targetIdsCancellList = new HashSet<>();
|
||||
targetIds.forEach(ids -> targetIdsCancellList.addAll(overrideObsoleteUpdateActions(ids)));
|
||||
|
||||
// cancel all scheduled actions which are in-active, these actions were
|
||||
@@ -378,11 +378,13 @@ public class DeploymentManagement {
|
||||
actionStatusRepository.save(actionStatus);
|
||||
});
|
||||
|
||||
// select updated targets in order to return them
|
||||
// flush to get action IDs
|
||||
entityManager.flush();
|
||||
// collect updated target and actions IDs in order to return them
|
||||
final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult(
|
||||
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(),
|
||||
controllerIDs.size() - targets.size(), Lists.newArrayList(targetIdsToActions.values()),
|
||||
targetManagement);
|
||||
controllerIDs.size() - targets.size(),
|
||||
targetIdsToActions.values().stream().map(Action::getId).collect(Collectors.toList()), targetManagement);
|
||||
|
||||
LOG.debug("assignDistribution({}) finished {}", set, result);
|
||||
|
||||
@@ -391,13 +393,16 @@ public class DeploymentManagement {
|
||||
// detaching as it is not necessary to persist the set itself
|
||||
entityManager.detach(set);
|
||||
|
||||
// send distribution set assignment event
|
||||
sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions, softwareModules);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sendDistributionSetAssignmentEvent(final List<Target> targets, final Set<Long> targetIdsCancellList,
|
||||
final Map<String, Action> targetIdsToActions, final List<SoftwareModule> softwareModules) {
|
||||
targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId()))
|
||||
.forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(),
|
||||
softwareModules));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -430,7 +435,7 @@ public class DeploymentManagement {
|
||||
*/
|
||||
private Set<Long> overrideObsoleteUpdateActions(final List<Long> targetsIds) {
|
||||
|
||||
final Set<Long> cancelledTargetIds = new HashSet<Long>();
|
||||
final Set<Long> cancelledTargetIds = new HashSet<>();
|
||||
|
||||
// Figure out if there are potential target/action combinations that
|
||||
// need to be considered
|
||||
@@ -709,8 +714,8 @@ public class DeploymentManagement {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Action} entity for given actionId with all lazy
|
||||
* attributes.
|
||||
* Get the {@link Action} entity for given actionId with all lazy attributes
|
||||
* (i.e. distributionSet, target, target.assignedDs).
|
||||
*
|
||||
* @param actionId
|
||||
* to be id of the action
|
||||
@@ -774,8 +779,7 @@ public class DeploymentManagement {
|
||||
multiselect.where(cb.equal(actionRoot.get(Action_.target), target));
|
||||
multiselect.orderBy(cb.desc(actionRoot.get(Action_.id)));
|
||||
multiselect.groupBy(actionRoot.get(Action_.id));
|
||||
final List<ActionWithStatusCount> resultList = entityManager.createQuery(multiselect).getResultList();
|
||||
return resultList;
|
||||
return entityManager.createQuery(multiselect).getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.AssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
@@ -19,14 +18,11 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
* information of an assignment and how much of the assignment has been done and
|
||||
* how much of the assignments had already been existed.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
|
||||
private final List<String> assignedTargets;
|
||||
private final List<Action> actions;
|
||||
private final List<Long> actions;
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
|
||||
@@ -48,7 +44,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
*
|
||||
*/
|
||||
public DistributionSetAssignmentResult(final List<String> assignedTargets, final int assigned,
|
||||
final int alreadyAssigned, final List<Action> actions, final TargetManagement targetManagement) {
|
||||
final int alreadyAssigned, final List<Long> actions, final TargetManagement targetManagement) {
|
||||
super(assigned, alreadyAssigned);
|
||||
this.assignedTargets = assignedTargets;
|
||||
this.actions = actions;
|
||||
@@ -63,9 +59,9 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actionId
|
||||
* @return the actionIds
|
||||
*/
|
||||
public List<Action> getActions() {
|
||||
public List<Long> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class NoCountPagingRepository {
|
||||
*/
|
||||
public <T, I extends Serializable> Slice<T> findAll(final Specification<T> spec, final Pageable pageable,
|
||||
final Class<T> domainClass) {
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<T, I>(domainClass, em);
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<>(domainClass, em);
|
||||
return noCountDao.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class NoCountPagingRepository {
|
||||
* org.springframework.data.domain.Pageable)
|
||||
*/
|
||||
public <T, I extends Serializable> Slice<T> findAll(final Pageable pageable, final Class<T> domainClass) {
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<T, I>(domainClass, em);
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<>(domainClass, em);
|
||||
return noCountDao.findAll(pageable);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class NoCountPagingRepository {
|
||||
|
||||
final List<T> content = query.getResultList();
|
||||
|
||||
return new PageImpl<T>(content, pageable, content.size());
|
||||
return new PageImpl<>(content, pageable, content.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,8 +245,9 @@ public class RolloutGroupManagement {
|
||||
JoinType.LEFT);
|
||||
|
||||
final Root<RolloutTargetGroup> countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class);
|
||||
countQuery
|
||||
.select(cb.count(countQueryFrom.join(RolloutTargetGroup_.target).join(Target_.actions, JoinType.LEFT)))
|
||||
countQueryFrom.join(RolloutTargetGroup_.target);
|
||||
countQueryFrom.join(RolloutTargetGroup_.actions, JoinType.LEFT);
|
||||
countQuery.select(cb.count(countQueryFrom))
|
||||
.where(cb.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup));
|
||||
final Long totalCount = entityManager.createQuery(countQuery).getSingleResult();
|
||||
|
||||
|
||||
@@ -552,7 +552,7 @@ public class RolloutManagement {
|
||||
if (updated == 0) {
|
||||
// nothing to check, maybe another instance already checked in
|
||||
// between
|
||||
LOGGER.info("No rolloutcheck necessary for current scheduled check {}, next check at {}", lastCheck,
|
||||
LOGGER.debug("No rolloutcheck necessary for current scheduled check {}, next check at {}", lastCheck,
|
||||
lastCheck + delayBetweenChecks);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class TagManagement {
|
||||
public void deleteTargetTag(@NotEmpty final String targetTagName) {
|
||||
final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName);
|
||||
|
||||
final List<Target> changed = new LinkedList<Target>();
|
||||
final List<Target> changed = new LinkedList<>();
|
||||
for (final Target target : targetRepository.findByTag(tag)) {
|
||||
target.getTags().remove(tag);
|
||||
changed.add(target);
|
||||
@@ -311,7 +311,7 @@ public class TagManagement {
|
||||
public void deleteDistributionSetTag(@NotEmpty final String tagName) {
|
||||
final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName);
|
||||
|
||||
final List<DistributionSet> changed = new LinkedList<DistributionSet>();
|
||||
final List<DistributionSet> changed = new LinkedList<>();
|
||||
for (final DistributionSet set : distributionSetRepository.findByTag(tag)) {
|
||||
set.getTags().remove(tag);
|
||||
changed.add(set);
|
||||
|
||||
@@ -24,6 +24,7 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.NamedEntityGraphs;
|
||||
import javax.persistence.NamedSubgraph;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
@@ -34,28 +35,22 @@ import org.eclipse.persistence.annotations.CascadeOnDelete;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Applicable transition changes of the software {@link SoftwareModule} state of
|
||||
* a {@link Target}, e.g. install, uninstall, update, start, stop, and
|
||||
* preparations for the transition change, i.e. download.
|
||||
* Applicable transition changes of the {@link SoftwareModule}s state of a
|
||||
* {@link Target}, e.g. install, uninstall, update and preparations for the
|
||||
* transition change, i.e. download.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Actions are managed by the SP server (SPS) and applied to the edge controller
|
||||
* by the SP controller (SPC). Actions may also be value added commands that are
|
||||
* nor directly related to SP, e.g. factory reset.
|
||||
* Actions are managed by the SP server and applied to the targets by the
|
||||
* client.
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"),
|
||||
@Index(name = "sp_idx_action_02", columnList = "tenant,target,active"),
|
||||
@Index(name = "sp_idx_action_prim", columnList = "tenant,id") })
|
||||
@NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }),
|
||||
@NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"),
|
||||
@NamedAttributeNode("target") }) })
|
||||
@NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet") ) ) })
|
||||
@Entity
|
||||
public class Action extends BaseEntity implements Comparable<Action> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ActionStatus extends BaseEntity {
|
||||
@CollectionTable(name = "sp_action_status_messages", joinColumns = @JoinColumn(name = "action_status_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_stat_msg_act_stat") ) , indexes = {
|
||||
@Index(name = "sp_idx_action_status_msgs_01", columnList = "action_status_id") })
|
||||
@Column(name = "detail_message", length = 512)
|
||||
private final List<String> messages = new ArrayList<String>();
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a new {@link ActionStatus} object.
|
||||
|
||||
@@ -32,6 +32,8 @@ import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SecurityChecker;
|
||||
@@ -74,6 +76,8 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "controller_id", length = 64)
|
||||
@Size(min = 1)
|
||||
@NotNull
|
||||
private String controllerId;
|
||||
|
||||
@Transient
|
||||
@@ -83,7 +87,7 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
||||
@JoinTable(name = "sp_target_target_tag", joinColumns = {
|
||||
@JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target") ) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "tag", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag") ) })
|
||||
private Set<TargetTag> tags = new HashSet<TargetTag>();
|
||||
private Set<TargetTag> tags = new HashSet<>();
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = { CascadeType.REMOVE })
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.MapJoin;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@@ -101,7 +102,7 @@ public final class RSQLUtility {
|
||||
*/
|
||||
public static <A extends Enum<A> & FieldNameProvider, T> Specification<T> parse(final String rsql,
|
||||
final Class<A> fieldNameProvider) {
|
||||
return new RSQLSpecification<>(rsql, fieldNameProvider);
|
||||
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,16 +461,46 @@ public final class RSQLUtility {
|
||||
singleList.add(cb.lessThanOrEqualTo(pathOfString(fieldPath), value));
|
||||
break;
|
||||
case "=in=":
|
||||
singleList.add(fieldPath.in(transformedValues));
|
||||
singleList.add(getInPredicate(transformedValues, fieldPath));
|
||||
break;
|
||||
case "=out=":
|
||||
singleList.add(cb.not(fieldPath.in(transformedValues)));
|
||||
singleList.add(getOutPredicate(transformedValues, fieldPath));
|
||||
break;
|
||||
default:
|
||||
LOGGER.info("operator symbol {} is either not supported or not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate getInPredicate(final List<Object> transformedValues, final Path<Object> fieldPath) {
|
||||
final List<String> inParams = new ArrayList<>();
|
||||
for (final Object param : transformedValues) {
|
||||
if (param instanceof String) {
|
||||
inParams.add(((String) param).toUpperCase());
|
||||
}
|
||||
}
|
||||
if (!inParams.isEmpty()) {
|
||||
return cb.upper(pathOfString(fieldPath)).in(inParams);
|
||||
} else {
|
||||
return fieldPath.in(transformedValues);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate getOutPredicate(final List<Object> transformedValues, final Path<Object> fieldPath) {
|
||||
final List<String> outParams = new ArrayList<>();
|
||||
for (final Object param : transformedValues) {
|
||||
if (param instanceof String) {
|
||||
outParams.add(((String) param).toUpperCase());
|
||||
}
|
||||
}
|
||||
if (!outParams.isEmpty()) {
|
||||
return cb.not(cb.upper(pathOfString(fieldPath)).in(outParams));
|
||||
} else {
|
||||
return cb.not(fieldPath.in(transformedValues));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Path<Object> getMapValueFieldPath(final A enumField, final Path<Object> fieldPath) {
|
||||
if (!enumField.isMap() || enumField.getValueFieldName() == null) {
|
||||
return fieldPath;
|
||||
@@ -477,6 +508,7 @@ public final class RSQLUtility {
|
||||
return fieldPath.get(enumField.getValueFieldName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Predicate mapToMapPredicate(final ComparisonNode node, final Path<Object> fieldPath,
|
||||
final A enumField) {
|
||||
if (!enumField.isMap()) {
|
||||
@@ -485,10 +517,12 @@ public final class RSQLUtility {
|
||||
final String[] graph = node.getSelector().split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR);
|
||||
final String keyValue = graph[graph.length - 1];
|
||||
if (fieldPath instanceof MapJoin) {
|
||||
return cb.equal(((MapJoin<?, ?, ?>) fieldPath).key(), keyValue);
|
||||
// Currently we support only string key .So below cast is safe.
|
||||
return cb.equal(cb.upper((Expression<String>) (((MapJoin<?, ?, ?>) fieldPath).key())),
|
||||
keyValue.toUpperCase());
|
||||
}
|
||||
|
||||
return cb.equal(fieldPath.get(enumField.getKeyFieldName()), keyValue);
|
||||
return cb.equal(cb.upper(fieldPath.get(enumField.getKeyFieldName())), keyValue.toUpperCase());
|
||||
}
|
||||
|
||||
private Predicate getEqualToPredicate(final Object transformedValue, final Path<Object> fieldPath) {
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra
|
||||
System.setProperty("spring.data.mongodb.port", String.valueOf(port));
|
||||
}
|
||||
|
||||
Version version = Version.V3_0_5;
|
||||
Version version = Version.V3_0_8;
|
||||
if (System.getProperty("inf.mongodb.version") != null) {
|
||||
version = Version
|
||||
.valueOf("V" + System.getProperty("inf.mongodb.version").trim().replaceAll("\\.", "_"));
|
||||
|
||||
@@ -54,7 +54,7 @@ public class MethodSecurityUtil {
|
||||
if (!METHOD_SECURITY_EXCLUSION.contains(method.getName()) && !method.isSynthetic()
|
||||
&& Modifier.isPublic(method.getModifiers())) {
|
||||
final PreAuthorize annotation = method.getAnnotation(PreAuthorize.class);
|
||||
assertThat(annotation).describedAs(
|
||||
assertThat(annotation).as(
|
||||
"The public method " + method.getName() + " is not annoated with @PreAuthorize, security leak?")
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@@ -150,14 +150,14 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
ExternalArtifact result = artifactManagement.createExternalArtifact(provider, null, sm.getId());
|
||||
|
||||
assertNotNull(result);
|
||||
assertNotNull("The result of an external artifact should not be null", result);
|
||||
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1);
|
||||
assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId());
|
||||
assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/{version}/");
|
||||
assertThat(result.getExternalArtifactProvider()).isEqualTo(provider);
|
||||
|
||||
result = artifactManagement.createExternalArtifact(provider, "/test", sm2.getId());
|
||||
assertNotNull(result);
|
||||
assertNotNull("The newly created external artifact should not be null", result);
|
||||
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(2);
|
||||
assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/test");
|
||||
assertThat(result.getExternalArtifactProvider()).isEqualTo(provider);
|
||||
@@ -176,7 +176,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
"https://fhghdfjgh", "/{version}/");
|
||||
|
||||
final ExternalArtifact result = artifactManagement.createExternalArtifact(provider, null, sm.getId());
|
||||
assertNotNull(result);
|
||||
assertNotNull("The newly created external artifact should not be null", result);
|
||||
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1);
|
||||
|
||||
artifactManagement.deleteExternalArtifact(result.getId());
|
||||
@@ -348,7 +348,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
final LocalArtifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
sm.getId(), "file1", false);
|
||||
|
||||
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random),
|
||||
assertTrue("The stored binary matches the given binary", IOUtils.contentEquals(new ByteArrayInputStream(random),
|
||||
artifactManagement.loadLocalArtifactBinary(result).getFileInputStream()));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
@@ -71,6 +74,24 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
.getNumberOfElements()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Register a controller which not exist")
|
||||
public void testfindOrRegisterTargetIfItDoesNotexist() {
|
||||
final Target target = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null);
|
||||
assertThat(target).as("target should not be null").isNotNull();
|
||||
|
||||
final Target sameTarget = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null);
|
||||
assertThat(target).as("Target should be the equals").isEqualTo(sameTarget);
|
||||
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
||||
|
||||
try {
|
||||
controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null);
|
||||
fail("target with empty controller id should not be registred");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Controller trys to finish an update process after it has been finished by an error action status.")
|
||||
public void tryToFinishUpdateProcessMoreThenOnce() {
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.Constants;
|
||||
@@ -66,6 +65,22 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Autowired
|
||||
private EventBus eventBus;
|
||||
|
||||
@Test
|
||||
@Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.")
|
||||
public void findActionWithLazyDetails() {
|
||||
final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement,
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
|
||||
// one action with one action status is generated
|
||||
final Long actionId = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
|
||||
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
|
||||
assertThat(action.getTarget()).as("Target in action").isNotNull();
|
||||
assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action")
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test verifies that the custom query to find all actions include the count of action status is working correctly")
|
||||
public void findActionsWithStatusCountByTarget() {
|
||||
@@ -73,7 +88,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
|
||||
// one action with one action status is generated
|
||||
final Action action = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(
|
||||
deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0));
|
||||
// save 2 action status
|
||||
actionStatusRepository.save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis()));
|
||||
actionStatusRepository.save(new ActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
|
||||
@@ -81,8 +97,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final List<ActionWithStatusCount> findActionsWithStatusCountByTarget = deploymentManagement
|
||||
.findActionsWithStatusCountByTargetOrderByIdDesc(testTarget.get(0));
|
||||
|
||||
assertThat(findActionsWithStatusCountByTarget).hasSize(1);
|
||||
assertThat(findActionsWithStatusCountByTarget.get(0).getActionStatusCount()).isEqualTo(3L);
|
||||
assertThat(findActionsWithStatusCountByTarget).as("wrong action size").hasSize(1);
|
||||
assertThat(findActionsWithStatusCountByTarget.get(0).getActionStatusCount()).as("wrong action status size")
|
||||
.isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,27 +115,32 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1"));
|
||||
|
||||
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag);
|
||||
assertThat(assignedDS.size()).isEqualTo(4);
|
||||
assignedDS.forEach(ds -> assertThat(ds.getTags().size()).isEqualTo(1));
|
||||
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");
|
||||
assertThat(assignedDS.size()).isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size")
|
||||
.isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
|
||||
|
||||
assertThat(distributionSetManagement.unAssignTag(Long.valueOf(100), findDistributionSetTag)).isNull();
|
||||
assertThat(distributionSetManagement.unAssignTag(Long.valueOf(100), findDistributionSetTag))
|
||||
.as("unassign tag result should be null").isNull();
|
||||
|
||||
final DistributionSet unAssignDS = distributionSetManagement.unAssignTag(assignDS.get(0),
|
||||
findDistributionSetTag);
|
||||
assertThat(unAssignDS.getId()).isEqualTo(assignDS.get(0));
|
||||
assertThat(unAssignDS.getTags().size()).isEqualTo(0);
|
||||
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");
|
||||
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).isEqualTo(3);
|
||||
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag ds has wrong ds size")
|
||||
.isEqualTo(3);
|
||||
|
||||
final List<DistributionSet> unAssignTargets = distributionSetManagement
|
||||
.unAssignAllDistributionSetsByTag(findDistributionSetTag);
|
||||
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
|
||||
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).isEqualTo(0);
|
||||
assertThat(unAssignTargets.size()).isEqualTo(3);
|
||||
unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0));
|
||||
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag has wrong ds size")
|
||||
.isEqualTo(0);
|
||||
assertThat(unAssignTargets.size()).as("unassigned target has wrong size").isEqualTo(3);
|
||||
unAssignTargets
|
||||
.forEach(target -> assertThat(target.getTags().size()).as("target has wrong tag size").isEqualTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +162,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
targetManagement.findAllTargetIds().forEach(targetIdName -> {
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(
|
||||
targetManagement.findTargetByControllerID(targetIdName.getControllerId()))).hasSize(2);
|
||||
targetManagement.findTargetByControllerID(targetIdName.getControllerId())))
|
||||
.as("active action has wrong size").hasSize(2);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,14 +186,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("target has update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
// assign the two sets in a row
|
||||
Action firstAction = assignSet(target, dsFirst);
|
||||
Action secondAction = assignSet(target, dsSecond);
|
||||
|
||||
assertThat(actionRepository.findAll()).hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of actions").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(2);
|
||||
|
||||
// we cancel second -> back to first
|
||||
deploymentManagement.cancelAction(secondAction,
|
||||
@@ -180,10 +203,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
secondAction.setStatus(Status.CANCELED);
|
||||
controllerManagement.addCancelActionStatus(
|
||||
new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()), secondAction);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(4);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(dsFirst);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(4);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).as("wrong ds")
|
||||
.isEqualTo(dsFirst);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel first -> back to installed
|
||||
deploymentManagement.cancelAction(firstAction,
|
||||
@@ -193,11 +217,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
firstAction.setStatus(Status.CANCELED);
|
||||
controllerManagement.addCancelActionStatus(
|
||||
new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()), firstAction);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(6);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(6);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.isEqualTo(dsInstalled);
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,14 +243,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
// assign the two sets in a row
|
||||
Action firstAction = assignSet(target, dsFirst);
|
||||
Action secondAction = assignSet(target, dsSecond);
|
||||
|
||||
assertThat(actionRepository.findAll()).hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of actions").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(2);
|
||||
|
||||
// we cancel first -> second is left
|
||||
deploymentManagement.cancelAction(firstAction,
|
||||
@@ -236,26 +260,28 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
firstAction.setStatus(Status.CANCELED);
|
||||
controllerManagement.addCancelActionStatus(
|
||||
new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()), firstAction);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(4);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(dsSecond);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
deploymentManagement.cancelAction(secondAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
secondAction = deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(5);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(dsSecond);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(5);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
// confirm cancellation
|
||||
secondAction.setStatus(Status.CANCELED);
|
||||
controllerManagement.addCancelActionStatus(
|
||||
new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()), secondAction);
|
||||
// cancelled success -> back to dsInstalled
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.isEqualTo(dsInstalled);
|
||||
.as("wrong installed ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,13 +300,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
Action assigningAction = assignSet(target, ds);
|
||||
|
||||
// verify assignment
|
||||
assertThat(actionRepository.findAll()).hasSize(1);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(1);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(1);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(1);
|
||||
|
||||
target = targetManagement.findTargetByControllerID(target.getControllerId());
|
||||
|
||||
@@ -293,11 +319,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||
|
||||
// verify
|
||||
assertThat(assigningAction.getStatus()).isEqualTo(Status.CANCELED);
|
||||
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.isEqualTo(dsInstalled);
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -316,13 +342,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
final Action assigningAction = assignSet(target, ds);
|
||||
|
||||
// verify assignment
|
||||
assertThat(actionRepository.findAll()).hasSize(1);
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(1);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(1);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(1);
|
||||
|
||||
// force quit assignment
|
||||
try {
|
||||
@@ -337,11 +363,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() });
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
|
||||
.isEqualTo(ds);
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
|
||||
assertThat(action).isNotNull();
|
||||
assertThat(action).as("action should not be null").isNotNull();
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -349,7 +375,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
* test a simple deployment by calling the
|
||||
* {@link TargetRepository#assignDistributionSet(DistributionSet, Iterable)}
|
||||
* and checking the active action and the action history of the targets.
|
||||
*
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
@@ -373,26 +399,30 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
deploymentManagement.assignDistributionSet(ds, savedDeployedTargets);
|
||||
|
||||
// verify that one Action for each assignDistributionSet
|
||||
assertThat(actionRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(20);
|
||||
assertThat(actionRepository.findAll(pageReq).getNumberOfElements()).as("wrong size of actions").isEqualTo(20);
|
||||
|
||||
final Iterable<Target> allFoundTargets = targetManagement.findTargetsAll(pageReq).getContent();
|
||||
|
||||
assertThat(allFoundTargets).containsAll(savedDeployedTargets).containsAll(savedNakedTargets);
|
||||
assertThat(savedDeployedTargets).doesNotContain(Iterables.toArray(savedNakedTargets, Target.class));
|
||||
assertThat(savedNakedTargets).doesNotContain(Iterables.toArray(savedDeployedTargets, Target.class));
|
||||
assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets)
|
||||
.containsAll(savedNakedTargets);
|
||||
assertThat(savedDeployedTargets).as("saved target are wrong")
|
||||
.doesNotContain(Iterables.toArray(savedNakedTargets, Target.class));
|
||||
assertThat(savedNakedTargets).as("saved target are wrong")
|
||||
.doesNotContain(Iterables.toArray(savedDeployedTargets, Target.class));
|
||||
|
||||
for (final Target myt : savedNakedTargets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
|
||||
assertThat(deploymentManagement.findActionsByTarget(t)).isEmpty();
|
||||
assertThat(deploymentManagement.findActionsByTarget(t)).as("action should be empty").isEmpty();
|
||||
}
|
||||
|
||||
for (final Target myt : savedDeployedTargets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(t);
|
||||
assertThat(activeActionsByTarget).isNotEmpty();
|
||||
assertThat(t.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
|
||||
assertThat(t.getTargetInfo().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
for (final Action ua : activeActionsByTarget) {
|
||||
assertThat(ua.getDistributionSet()).isEqualTo(ds);
|
||||
assertThat(ua.getDistributionSet()).as("action has wrong ds").isEqualTo(ds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,12 +461,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// give some chance to receive events asynchronously
|
||||
Thread.sleep(300);
|
||||
final List<TargetAssignDistributionSetEvent> events = eventHandlerMock.getEvents(1, TimeUnit.MILLISECONDS);
|
||||
assertThat(events).isEmpty();
|
||||
assertThat(events).as("events should be empty").isEmpty();
|
||||
|
||||
final EventHandlerMock eventHandlerMockAfterCompletionOfDs = new EventHandlerMock(10);
|
||||
eventBus.register(eventHandlerMockAfterCompletionOfDs);
|
||||
|
||||
assertThat(deploymentManagement.assignDistributionSet(nowComplete, targets).getAssigned()).isEqualTo(10);
|
||||
assertThat(deploymentManagement.assignDistributionSet(nowComplete, targets).getAssigned())
|
||||
.as("assign ds doesn't work").isEqualTo(10);
|
||||
assertTargetAssignDistributionSetEvents(targets, nowComplete,
|
||||
eventHandlerMockAfterCompletionOfDs.getEvents(10, TimeUnit.SECONDS));
|
||||
}
|
||||
@@ -476,7 +507,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// retrieving all Actions created by the assignDistributionSet call
|
||||
final Page<Action> page = actionRepository.findAll(pageReq);
|
||||
// and verify the number
|
||||
assertThat(page.getTotalElements()).isEqualTo(noOfDeployedTargets * noOfDistributionSets);
|
||||
assertThat(page.getTotalElements()).as("wrong size of actions")
|
||||
.isEqualTo(noOfDeployedTargets * noOfDistributionSets);
|
||||
|
||||
// only records retrieved from the DB can be evaluated to be sure that
|
||||
// all fields are
|
||||
@@ -487,17 +519,20 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final Iterable<Target> undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs);
|
||||
|
||||
// test that number of Targets
|
||||
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown())
|
||||
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown()).as("number of target is wrong")
|
||||
.isEqualTo(deployedTargetsFromDB.spliterator().getExactSizeIfKnown()
|
||||
+ undeployedTargetsFromDB.spliterator().getExactSizeIfKnown());
|
||||
assertThat(deployedTargetsFromDB.spliterator().getExactSizeIfKnown()).isEqualTo(noOfDeployedTargets);
|
||||
assertThat(undeployedTargetsFromDB.spliterator().getExactSizeIfKnown()).isEqualTo(noOfUndeployedTargets);
|
||||
assertThat(deployedTargetsFromDB.spliterator().getExactSizeIfKnown()).as("number of target is wrong")
|
||||
.isEqualTo(noOfDeployedTargets);
|
||||
assertThat(undeployedTargetsFromDB.spliterator().getExactSizeIfKnown()).as("number of target is wrong")
|
||||
.isEqualTo(noOfUndeployedTargets);
|
||||
|
||||
// test the content of different lists
|
||||
assertThat(allFoundTargets).containsAll(deployedTargetsFromDB).containsAll(undeployedTargetsFromDB);
|
||||
assertThat(deployedTargetsFromDB).containsAll(savedDeployedTargets)
|
||||
assertThat(allFoundTargets).as("content of founded target is wrong").containsAll(deployedTargetsFromDB)
|
||||
.containsAll(undeployedTargetsFromDB);
|
||||
assertThat(deployedTargetsFromDB).as("content of deployed target is wrong").containsAll(savedDeployedTargets)
|
||||
.doesNotContain(Iterables.toArray(undeployedTargetsFromDB, Target.class));
|
||||
assertThat(undeployedTargetsFromDB).containsAll(savedNakedTargets)
|
||||
assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong").containsAll(savedNakedTargets)
|
||||
.doesNotContain(Iterables.toArray(deployedTargetsFromDB, Target.class));
|
||||
|
||||
// For each of the 4 targets 1 distribution sets gets assigned
|
||||
@@ -525,42 +560,42 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final DistributionSet dsC = deployResWithDsC.getDistributionSets().get(0);
|
||||
|
||||
// retrieving the UpdateActions created by the assignments
|
||||
final Action updActA = actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(0);
|
||||
final Action updActB = actionRepository.findByDistributionSet(pageRequest, dsB).getContent().get(0);
|
||||
final Action updActC = actionRepository.findByDistributionSet(pageRequest, dsC).getContent().get(0);
|
||||
actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(0);
|
||||
actionRepository.findByDistributionSet(pageRequest, dsB).getContent().get(0);
|
||||
actionRepository.findByDistributionSet(pageRequest, dsC).getContent().get(0);
|
||||
|
||||
// verifying the correctness of the assignments
|
||||
for (final Target t : deployResWithDsA.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsA.getId());
|
||||
assertThat(t.getAssignedDistributionSet().getId()).as("assignment is not correct").isEqualTo(dsA.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
.getInstalledDistributionSet()).isNull();
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
}
|
||||
for (final Target t : deployResWithDsB.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsB.getId());
|
||||
assertThat(t.getAssignedDistributionSet().getId()).as("assigned ds is wrong").isEqualTo(dsB.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
.getInstalledDistributionSet()).isNull();
|
||||
.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()
|
||||
.getInstalledDistributionSet()).isNull();
|
||||
.getInstalledDistributionSet()).as("installed ds should not be null").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
}
|
||||
|
||||
final List<Target> updatedTsDsA = sendUpdateActionStatusToTargets(dsA, deployResWithDsA.getDeployedTargets(),
|
||||
Status.FINISHED, new String[] { "alles gut" });
|
||||
|
||||
// verify, that dsA is deployed correctly
|
||||
assertThat(updatedTsDsA).isEqualTo(deployResWithDsA.getDeployedTargets());
|
||||
assertThat(updatedTsDsA).as("ds is not deployed correctly").isEqualTo(deployResWithDsA.getDeployedTargets());
|
||||
for (final Target t_ : updatedTsDsA) {
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
|
||||
assertThat(t.getAssignedDistributionSet()).isEqualTo(dsA);
|
||||
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
.getInstalledDistributionSet()).isEqualTo(dsA);
|
||||
.getInstalledDistributionSet()).as("installed ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t)).hasSize(0);
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t)).as("no actions should be active").hasSize(0);
|
||||
}
|
||||
|
||||
// deploy dsA to the target which already have dsB deployed -> must
|
||||
@@ -569,18 +604,18 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// UpdateAction for dsA
|
||||
final Iterable<Target> deployed2DS = deploymentManagement
|
||||
.assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedTargets();
|
||||
final Action updActA2 = actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1);
|
||||
actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1);
|
||||
|
||||
assertThat(deployed2DS).containsAll(deployResWithDsB.getDeployedTargets());
|
||||
assertThat(deployed2DS).hasSameSizeAs(deployResWithDsB.getDeployedTargets());
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsB.getDeployedTargets());
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsB.getDeployedTargets());
|
||||
|
||||
for (final Target t_ : deployed2DS) {
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
|
||||
assertThat(t.getAssignedDistributionSet()).isEqualTo(dsA);
|
||||
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
.getInstalledDistributionSet()).isNull();
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -613,22 +648,22 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(dsA.getId());
|
||||
dsA = distributionSetManagement.findDistributionSetById(dsA.getId());
|
||||
assertThat(dsA).isNull();
|
||||
assertThat(dsA).as("ds should be null").isNull();
|
||||
|
||||
// // 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());
|
||||
assertThat(foundDS).isNotNull();
|
||||
assertThat(foundDS.isDeleted()).isTrue();
|
||||
assertThat(foundDS).as("founded should not be null").isNotNull();
|
||||
assertThat(foundDS.isDeleted()).as("founded ds should be deleted").isTrue();
|
||||
}
|
||||
|
||||
// verify that deleted attribute is used correctly
|
||||
List<DistributionSet> allFoundDS = distributionSetManagement.findDistributionSetsAll(pageReq, false, true)
|
||||
.getContent();
|
||||
assertThat(allFoundDS.size()).isEqualTo(0);
|
||||
assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0);
|
||||
allFoundDS = distributionSetManagement.findDistributionSetsAll(pageRequest, true, true).getContent();
|
||||
assertThat(allFoundDS).hasSize(noOfDistributionSets);
|
||||
assertThat(allFoundDS).as("wrong size of founded ds").hasSize(noOfDistributionSets);
|
||||
|
||||
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
|
||||
sendUpdateActionStatusToTargets(ds, deploymentResult.getDeployedTargets(), Status.FINISHED,
|
||||
@@ -642,9 +677,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// successfully and no activeAction is referring to created distribution
|
||||
// sets
|
||||
allFoundDS = distributionSetManagement.findDistributionSetsAll(pageRequest, false, true).getContent();
|
||||
assertThat(allFoundDS.size()).isEqualTo(0);
|
||||
assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0);
|
||||
allFoundDS = distributionSetManagement.findDistributionSetsAll(pageRequest, true, true).getContent();
|
||||
assertThat(allFoundDS).hasSize(noOfDistributionSets);
|
||||
assertThat(allFoundDS).as("size of founded ds is wrong").hasSize(noOfDistributionSets);
|
||||
|
||||
}
|
||||
|
||||
@@ -668,15 +703,15 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
"blabla alles gut");
|
||||
}
|
||||
|
||||
assertThat(targetManagement.countTargetsAll()).isNotZero();
|
||||
assertThat(actionStatusRepository.count()).isNotZero();
|
||||
assertThat(targetManagement.countTargetsAll()).as("size of targets is wrong").isNotZero();
|
||||
assertThat(actionStatusRepository.count()).as("size of action status is wrong").isNotZero();
|
||||
|
||||
targetManagement
|
||||
.deleteTargets(deploymentResult.getUndeployedTargetIDs().toArray(new Long[noOfUndeployedTargets]));
|
||||
targetManagement.deleteTargets(deploymentResult.getDeployedTargetIDs().toArray(new Long[noOfDeployedTargets]));
|
||||
|
||||
assertThat(targetManagement.countTargetsAll()).isZero();
|
||||
assertThat(actionStatusRepository.count()).isZero();
|
||||
assertThat(targetManagement.countTargetsAll()).as("size of targets should be zero").isZero();
|
||||
assertThat(actionStatusRepository.count()).as("size of action status is wrong").isZero();
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
@@ -727,7 +762,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// 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()).isEqualTo(
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
|
||||
// verifying that the assignment is correct
|
||||
@@ -778,12 +813,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
public void checkThatDsRevisionsIsNotChangedWithTargetAssignment() {
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet dsB = TestDataUtil.generateDistributionSet("b", softwareManagement,
|
||||
distributionSetManagement);
|
||||
TestDataUtil.generateDistributionSet("b", softwareManagement, distributionSetManagement);
|
||||
Target targ = targetManagement
|
||||
.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).isEqualTo(
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
|
||||
final List<Target> targs = new ArrayList<Target>();
|
||||
@@ -791,7 +825,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final Iterable<Target> savedTargs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedTargets();
|
||||
targ = savedTargs.iterator().next();
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).isEqualTo(
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
}
|
||||
|
||||
@@ -805,17 +839,17 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
|
||||
.assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, target.getControllerId());
|
||||
final Action action = assignDistributionSet.getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
|
||||
// verify preparation
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
assertThat(findAction.getActionType()).isEqualTo(ActionType.SOFT);
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.SOFT);
|
||||
|
||||
// test
|
||||
deploymentManagement.forceTargetAction(action.getId());
|
||||
|
||||
// verify test
|
||||
findAction = deploymentManagement.findAction(action.getId());
|
||||
assertThat(findAction.getActionType()).isEqualTo(ActionType.FORCED);
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -828,18 +862,18 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
|
||||
.assignDistributionSet(ds.getId(), ActionType.FORCED, Action.NO_FORCE_TIME, target.getControllerId());
|
||||
final Action action = assignDistributionSet.getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
|
||||
// verify perparation
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
assertThat(findAction.getActionType()).isEqualTo(ActionType.FORCED);
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
|
||||
// test
|
||||
final Action forceTargetAction = deploymentManagement.forceTargetAction(action.getId());
|
||||
|
||||
// verify test
|
||||
assertThat(forceTargetAction.getActionType()).isEqualTo(ActionType.FORCED);
|
||||
assertThat(forceTargetAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
findAction = deploymentManagement.findAction(action.getId());
|
||||
assertThat(findAction.getActionType()).isEqualTo(ActionType.FORCED);
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -848,7 +882,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
* <p>
|
||||
* <b>All created distribution sets are assigned to all targets of the
|
||||
* target list deployedTargets.</b>
|
||||
*
|
||||
*
|
||||
* @param undeployedTargetPrefix
|
||||
* prefix to be used as target controller prefix
|
||||
* @param noOfUndeployedTargets
|
||||
@@ -901,14 +935,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
if (event.getControllerId().equals(myt.getControllerId())) {
|
||||
found = true;
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(myt);
|
||||
assertThat(activeActionsByTarget).isNotEmpty();
|
||||
assertThat(event.getActionId()).isEqualTo(activeActionsByTarget.get(0).getId())
|
||||
.as("Action id in database and event do not match");
|
||||
assertThat(event.getSoftwareModules())
|
||||
assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty();
|
||||
assertThat(event.getActionId()).as("Action id in database and event do not match")
|
||||
.isEqualTo(activeActionsByTarget.get(0).getId());
|
||||
assertThat(event.getSoftwareModules()).as("softwaremodule size is not correct")
|
||||
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
|
||||
}
|
||||
}
|
||||
assertThat(found).isTrue().as("No event found for controller " + myt.getControllerId());
|
||||
assertThat(found).as("No event found for controller " + myt.getControllerId()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,42 +961,19 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
private final List<Target> deployedTargets = new ArrayList<Target>();
|
||||
private final List<DistributionSet> distributionSets = new ArrayList<DistributionSet>();
|
||||
|
||||
private final String undeployedTargetPrefix;
|
||||
private final String deployedTargetPrefix;
|
||||
private final String distributionSetPrefix;
|
||||
|
||||
public DeploymentResult(final Iterable<Target> deployedTs, final Iterable<Target> undeployedTs,
|
||||
final Iterable<DistributionSet> dss, final String deployedTargetPrefix,
|
||||
final String undeployedTargetPrefix, final String distributionSetPrefix) {
|
||||
|
||||
this.undeployedTargetPrefix = undeployedTargetPrefix;
|
||||
this.deployedTargetPrefix = deployedTargetPrefix;
|
||||
this.distributionSetPrefix = distributionSetPrefix;
|
||||
|
||||
Iterables.addAll(deployedTargets, deployedTs);
|
||||
Iterables.addAll(undeployedTargets, undeployedTs);
|
||||
Iterables.addAll(distributionSets, dss);
|
||||
|
||||
deployedTargets.forEach(new Consumer<Target>() {
|
||||
@Override
|
||||
public void accept(final Target t) {
|
||||
deployedTargetIDs.add(t.getId());
|
||||
}
|
||||
});
|
||||
deployedTargets.forEach(t -> deployedTargetIDs.add(t.getId()));
|
||||
|
||||
undeployedTargets.forEach(new Consumer<Target>() {
|
||||
@Override
|
||||
public void accept(final Target t) {
|
||||
undeployedTargetIDs.add(t.getId());
|
||||
}
|
||||
});
|
||||
undeployedTargets.forEach(t -> undeployedTargetIDs.add(t.getId()));
|
||||
|
||||
distributionSets.forEach(new Consumer<DistributionSet>() {
|
||||
@Override
|
||||
public void accept(final DistributionSet ds) {
|
||||
distributionSetIDs.add(ds.getId());
|
||||
}
|
||||
});
|
||||
distributionSets.forEach(ds -> distributionSetIDs.add(ds.getId()));
|
||||
|
||||
}
|
||||
|
||||
@@ -1001,27 +1012,6 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
return deployedTargets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the noOfUndeployedTargets
|
||||
*/
|
||||
public int getNoOfUndeployedTargets() {
|
||||
return undeployedTargetIDs.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the noOfDeployedTargets
|
||||
*/
|
||||
public int getNoOfDeployedTargets() {
|
||||
return deployedTargetIDs.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the noOfDistributionSets
|
||||
*/
|
||||
public int getNoOfDistributionSets() {
|
||||
return distributionSets.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the undeployedTargetIDs
|
||||
*/
|
||||
@@ -1029,26 +1019,6 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
return undeployedTargetIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the undeployedTargetPrefix
|
||||
*/
|
||||
public String getUndeployedTargetPrefix() {
|
||||
return undeployedTargetPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deployedTargetPrefix
|
||||
*/
|
||||
public String getDeployedTargetPrefix() {
|
||||
return deployedTargetPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the distributionSetPrefix
|
||||
*/
|
||||
public String getDistributionSetPrefix() {
|
||||
return distributionSetPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
private static class EventHandlerMock {
|
||||
@@ -1073,9 +1043,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
latch.await(timeout, unit);
|
||||
final List<TargetAssignDistributionSetEvent> handledEvents = new LinkedList<TargetAssignDistributionSetEvent>(
|
||||
events);
|
||||
assertThat(handledEvents).hasSize(expectedNumberOfEvents)
|
||||
.as("Did not receive the expected amount of events (" + expectedNumberOfEvents
|
||||
+ ") within timeout. Received events are " + handledEvents);
|
||||
assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents
|
||||
+ ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents);
|
||||
|
||||
return handledEvents;
|
||||
}
|
||||
}
|
||||
@@ -1101,9 +1071,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
throws InterruptedException {
|
||||
latch.await(timeout, unit);
|
||||
final List<CancelTargetAssignmentEvent> handledEvents = new LinkedList<CancelTargetAssignmentEvent>(events);
|
||||
assertThat(handledEvents).hasSize(expectedNumberOfEvents)
|
||||
.as("Did not receive the expected amount of events (" + expectedNumberOfEvents
|
||||
+ ") within timeout. Received events are " + handledEvents);
|
||||
assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents
|
||||
+ ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents);
|
||||
return handledEvents;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
@@ -96,10 +95,11 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
// +1 because we go back #maxMonthBackAmountReportTargets but in the
|
||||
// report the current month
|
||||
// is included for sure, so from this month we go back
|
||||
assertThat(targetsCreatedOverPeriod.getData()).hasSize(maxMonthBackAmountReportTargets + 1);
|
||||
assertThat(targetsCreatedOverPeriod.getData()).as("created over period has wrong size")
|
||||
.hasSize(maxMonthBackAmountReportTargets + 1);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) {
|
||||
// only one target is created for each month
|
||||
assertThat(reportItem.getData().intValue()).isEqualTo(1);
|
||||
assertThat(reportItem.getData().intValue()).as("Target for each month").isEqualTo(1);
|
||||
}
|
||||
|
||||
// check cache evict
|
||||
@@ -109,7 +109,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
targetsCreatedOverPeriod = reportManagement.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) {
|
||||
assertThat(reportItem.getData().intValue()).isEqualTo(2);
|
||||
assertThat(reportItem.getData().intValue()).as("Target for each month").isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final Target createTarget = targetManagement.createTarget(new Target("t" + month));
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
|
||||
Lists.newArrayList(createTarget));
|
||||
controllerManagament.registerRetrieved(result.getActions().get(0),
|
||||
controllerManagament.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
}
|
||||
DataReportSeries<LocalDate> feedbackReceivedOverTime = reportManagement
|
||||
@@ -146,10 +147,11 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
// +1 because we go back #maxMonthBackAmountReportTargets but in the
|
||||
// report the current month
|
||||
// is included for sure, so from this month we go back
|
||||
assertThat(feedbackReceivedOverTime.getData()).hasSize(maxMonthBackAmountReportTargets + 1);
|
||||
assertThat(feedbackReceivedOverTime.getData()).as("feedback receiver has wrong data size")
|
||||
.hasSize(maxMonthBackAmountReportTargets + 1);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : feedbackReceivedOverTime.getData()) {
|
||||
// only one target feedback is created for each month
|
||||
assertThat(reportItem.getData().intValue()).isEqualTo(1);
|
||||
assertThat(reportItem.getData().intValue()).as("data size is wrong").isEqualTo(1);
|
||||
}
|
||||
|
||||
// check cache evict
|
||||
@@ -158,12 +160,13 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final Target createTarget = targetManagement.createTarget(new Target("t2" + month));
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
|
||||
Lists.newArrayList(createTarget));
|
||||
controllerManagament.registerRetrieved(result.getActions().get(0),
|
||||
controllerManagament.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
}
|
||||
feedbackReceivedOverTime = reportManagement.feedbackReceivedOverTime(DateTypes.perMonth(), from, to);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : feedbackReceivedOverTime.getData()) {
|
||||
assertThat(reportItem.getData().intValue()).isEqualTo(2);
|
||||
assertThat(reportItem.getData().intValue()).as("report item has wrong data size").isEqualTo(2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -221,21 +224,26 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
// total count of three because ds1 has two different versions
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(3L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Version/Item type of DistributionSet 1 in statistics")
|
||||
.isEqualTo(3L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList()))
|
||||
.contains("0.0.0", "0.0.1");
|
||||
.as("versio item contains wrong version").contains("0.0.0", "0.0.1");
|
||||
} else if (dataReportSeriesItem.getType().equals("ds2")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(1L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Version/Item type of DistributionSet 2 in statistics")
|
||||
.isEqualTo(1L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.2");
|
||||
|
||||
assertThat(outerData).as("Version/Item type has wrong size").hasSize(1);
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 2 in statistics")
|
||||
.isEqualTo("0.0.2");
|
||||
} else if (dataReportSeriesItem.getType().equals("ds3")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(0L);
|
||||
|
||||
assertThat(dataReportSeriesItem.getData()).as("Version/Item type of DistributionSet 3 in statistics")
|
||||
.isEqualTo(0L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.3");
|
||||
assertThat(outerData).as("Version/Item type has wrong size").hasSize(1);
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 3 in statistics")
|
||||
.isEqualTo("0.0.3");
|
||||
} else {
|
||||
fail("no assertion count for distribution set " + dataReportSeriesItem.getType());
|
||||
}
|
||||
@@ -251,8 +259,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(4L);
|
||||
|
||||
assertThat(dataReportSeriesItem.getData()).as("Data report item number").isEqualTo(4L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,19 +285,23 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
switch (reportItem.getType()) {
|
||||
case ERROR:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownErrorCount);
|
||||
assertThat(reportItem.getData()).as("ERROR count for targets in statistics").isEqualTo(knownErrorCount);
|
||||
break;
|
||||
case IN_SYNC:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownSyncCount);
|
||||
assertThat(reportItem.getData()).as("IN_SYNC count for targets in statistics")
|
||||
.isEqualTo(knownSyncCount);
|
||||
break;
|
||||
case PENDING:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownPendingCount);
|
||||
assertThat(reportItem.getData()).as("PENDING count for targets in statistics")
|
||||
.isEqualTo(knownPendingCount);
|
||||
break;
|
||||
case REGISTERED:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownRegCount);
|
||||
assertThat(reportItem.getData()).as("REGISTERED count for targets in statistics")
|
||||
.isEqualTo(knownRegCount);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownUnknownCount);
|
||||
assertThat(reportItem.getData()).as("UNKNOWN count for targets in statistics")
|
||||
.isEqualTo(knownUnknownCount);
|
||||
break;
|
||||
default:
|
||||
fail("missing case for unknown target update status " + reportItem.getType());
|
||||
@@ -309,19 +320,24 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
switch (reportItem.getType()) {
|
||||
case ERROR:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownErrorCount * 2);
|
||||
assertThat(reportItem.getData()).as("ERROR count for targets in statistics")
|
||||
.isEqualTo(knownErrorCount * 2);
|
||||
break;
|
||||
case IN_SYNC:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownSyncCount * 2);
|
||||
assertThat(reportItem.getData()).as("IN_SYNC count for targets in statistics")
|
||||
.isEqualTo(knownSyncCount * 2);
|
||||
break;
|
||||
case PENDING:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownPendingCount * 2);
|
||||
assertThat(reportItem.getData()).as("PENDING count for targets in statistics")
|
||||
.isEqualTo(knownPendingCount * 2);
|
||||
break;
|
||||
case REGISTERED:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownRegCount * 2);
|
||||
assertThat(reportItem.getData()).as("REGISTERED count for targets in statistics")
|
||||
.isEqualTo(knownRegCount * 2);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownUnknownCount * 2);
|
||||
assertThat(reportItem.getData()).as("UNKNOWN count for targets in statistics")
|
||||
.isEqualTo(knownUnknownCount * 2);
|
||||
break;
|
||||
default:
|
||||
fail("missing case for unknown target update status " + reportItem.getType());
|
||||
@@ -373,22 +389,30 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
|
||||
// total count of three because ds1 has two different versions
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(3L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 1 in statistics")
|
||||
.isEqualTo(3L);
|
||||
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList()))
|
||||
.contains("0.0.0", "0.0.1");
|
||||
.as("Out series contains wrong version").contains("0.0.0", "0.0.1");
|
||||
|
||||
} else if (dataReportSeriesItem.getType().equals("ds2")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(1L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 2 in statistics")
|
||||
.isEqualTo(1L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.2");
|
||||
assertThat(outerData).as("out series has wrong size").hasSize(1);
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 2 in statistics")
|
||||
.isEqualTo("0.0.2");
|
||||
|
||||
} else if (dataReportSeriesItem.getType().equals("ds3")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(0L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 3 in statistics")
|
||||
.isEqualTo(0L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.3");
|
||||
assertThat(outerData).as("out series has wrong size").hasSize(1);
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 3 in statistics")
|
||||
.isEqualTo("0.0.3");
|
||||
} else {
|
||||
fail("no assertion count for distribution set " + dataReportSeriesItem.getType());
|
||||
}
|
||||
@@ -402,7 +426,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(4L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 1 in statistics")
|
||||
.isEqualTo(4L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,29 +460,24 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
DataReportSeries<SeriesTime> targetsNotLastPoll = reportManagement.targetsLastPoll();
|
||||
DataReportSeriesItem<SeriesTime>[] data = targetsNotLastPoll.getData();
|
||||
|
||||
// for( final DataReportSeriesItem<SeriesTime> dataReportSeriesItem :
|
||||
// data ) {
|
||||
// System.out.println( dataReportSeriesItem.getData() );
|
||||
// }
|
||||
|
||||
// --- Verfiy ---
|
||||
|
||||
// verify hour
|
||||
assertThat(data[0].getType()).isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).isEqualTo((long) knownTargetsPollLastHour);
|
||||
assertThat(data[0].getType()).as("Series time").isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).as("Targets poll last hour").isEqualTo((long) knownTargetsPollLastHour);
|
||||
// verify day
|
||||
assertThat(data[1].getType()).isEqualTo(SeriesTime.DAY);
|
||||
assertThat(data[1].getData()).isEqualTo((long) knownTargetsPollLastDay);
|
||||
assertThat(data[1].getType()).as("Series time").isEqualTo(SeriesTime.DAY);
|
||||
assertThat(data[1].getData()).as("Targets poll last day").isEqualTo((long) knownTargetsPollLastDay);
|
||||
// verify week
|
||||
assertThat(data[2].getType()).isEqualTo(SeriesTime.WEEK);
|
||||
assertThat(data[2].getData()).isEqualTo((long) knownTargetsPollLastWeek);
|
||||
assertThat(data[2].getType()).as("Series time").isEqualTo(SeriesTime.WEEK);
|
||||
assertThat(data[2].getData()).as("Targets poll last week").isEqualTo((long) knownTargetsPollLastWeek);
|
||||
|
||||
// test cache evict
|
||||
createTargets("hourPoll2", knownTargetsPollLastHour, now.minusMinutes(59));
|
||||
targetsNotLastPoll = reportManagement.targetsLastPoll();
|
||||
data = targetsNotLastPoll.getData();
|
||||
assertThat(data[0].getType()).isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).isEqualTo((long) knownTargetsPollLastHour * 2);
|
||||
assertThat(data[0].getType()).as("Series time").isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).as("Targets poll last hour").isEqualTo((long) knownTargetsPollLastHour * 2);
|
||||
|
||||
}
|
||||
|
||||
@@ -468,33 +488,26 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final int targetCreateAmount = 10;
|
||||
|
||||
// create targets for another tenant
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", "anotherTenant"), new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
for (int index = 0; index < targetCreateAmount; index++) {
|
||||
targetManagement.createTarget(new Target("t" + index));
|
||||
}
|
||||
return null;
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", "anotherTenant"), () -> {
|
||||
for (int index = 0; index < targetCreateAmount; index++) {
|
||||
targetManagement.createTarget(new Target("t" + index));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// ensure targets has been created for 'anotherTenant'
|
||||
final Slice<Target> targetsForAnotherTenant = securityRule.runAs(
|
||||
WithSpringAuthorityRule.withUserAndTenant("user", "anotherTenant"), new Callable<Slice<Target>>() {
|
||||
@Override
|
||||
public Slice<Target> call() throws Exception {
|
||||
return targetManagement.findTargetsAll(new PageRequest(0, 1000));
|
||||
}
|
||||
});
|
||||
assertThat(targetsForAnotherTenant).hasSize(targetCreateAmount);
|
||||
WithSpringAuthorityRule.withUserAndTenant("user", "anotherTenant"),
|
||||
() -> targetManagement.findTargetsAll(new PageRequest(0, 1000)));
|
||||
assertThat(targetsForAnotherTenant).as("targets has wrong size").hasSize(targetCreateAmount);
|
||||
|
||||
final LocalDateTime to = LocalDateTime.now();
|
||||
final LocalDateTime from = to.minusMonths(targetCreateAmount);
|
||||
// now retrieve the report for the 'mytenant'
|
||||
final DataReportSeries<LocalDate> targetsCreatedOverPeriod = reportManagement
|
||||
.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to);
|
||||
// final no targets should final be created for this tenant
|
||||
assertThat(targetsCreatedOverPeriod.getData()).hasSize(0);
|
||||
assertThat(targetsCreatedOverPeriod.getData()).as("final no targets should final be created for this tenant")
|
||||
.hasSize(0);
|
||||
|
||||
}
|
||||
|
||||
@@ -555,7 +568,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.data.auditing.DateTimeProvider#getNow()
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -159,10 +159,10 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
public void hardDeleteOfNotAssignedArtifact() {
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX with Artifacts
|
||||
SoftwareModule unassignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
|
||||
Iterator<Artifact> artifactsIt = unassignedModule.getArtifacts().iterator();
|
||||
Artifact artifact1 = artifactsIt.next();
|
||||
Artifact artifact2 = artifactsIt.next();
|
||||
final SoftwareModule unassignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
|
||||
final Iterator<Artifact> artifactsIt = unassignedModule.getArtifacts().iterator();
|
||||
final Artifact artifact1 = artifactsIt.next();
|
||||
final Artifact artifact2 = artifactsIt.next();
|
||||
|
||||
// [STEP2]: Delete unassigned SoftwareModule
|
||||
softwareManagement.deleteSoftwareModule(unassignedModule);
|
||||
@@ -185,7 +185,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
public void softDeleteOfAssignedArtifact() {
|
||||
|
||||
// Init DistributionSet
|
||||
DistributionSet disSet = distributionSetManagement
|
||||
final DistributionSet disSet = distributionSetManagement
|
||||
.createDistributionSet(new DistributionSet("ds1", "v1.0", "test ds", standardDsType, null));
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX with ArtifactX
|
||||
@@ -200,14 +200,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: assignedModule is marked as deleted
|
||||
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId());
|
||||
assertTrue(assignedModule.isDeleted());
|
||||
assertTrue("The module should be flagged as deleted", assignedModule.isDeleted());
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||
|
||||
// verify: binary data is deleted
|
||||
Iterator<Artifact> artifactsIt = assignedModule.getArtifacts().iterator();
|
||||
Artifact artifact1 = artifactsIt.next();
|
||||
Artifact artifact2 = artifactsIt.next();
|
||||
final Iterator<Artifact> artifactsIt = assignedModule.getArtifacts().iterator();
|
||||
final Artifact artifact1 = artifactsIt.next();
|
||||
final Artifact artifact2 = artifactsIt.next();
|
||||
assertArtfiactNull(artifact1, artifact2);
|
||||
|
||||
// verify: artifact meta data is still available
|
||||
@@ -221,7 +221,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
// Init target and DistributionSet
|
||||
final Target target = targetManagement.createTarget(new Target("test123"));
|
||||
DistributionSet disSet = distributionSetManagement
|
||||
final DistributionSet disSet = distributionSetManagement
|
||||
.createDistributionSet(new DistributionSet("ds1", "v1.0", "test ds", standardDsType, null));
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX and include the new ArtifactX
|
||||
@@ -242,14 +242,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: assignedModule is marked as deleted
|
||||
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId());
|
||||
assertTrue(assignedModule.isDeleted());
|
||||
assertTrue("The found module should be flagged deleted", assignedModule.isDeleted());
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||
|
||||
// verify: binary data is deleted
|
||||
Iterator<Artifact> artifactsIt = assignedModule.getArtifacts().iterator();
|
||||
Artifact artifact1 = artifactsIt.next();
|
||||
Artifact artifact2 = artifactsIt.next();
|
||||
final Iterator<Artifact> artifactsIt = assignedModule.getArtifacts().iterator();
|
||||
final Artifact artifact1 = artifactsIt.next();
|
||||
final Artifact artifact2 = artifactsIt.next();
|
||||
assertArtfiactNull(artifact1, artifact2);
|
||||
|
||||
// verify: artifact meta data is still available
|
||||
@@ -265,7 +265,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(operations.find(new Query())).hasSize(0);
|
||||
|
||||
// Init artifact binary data, target and DistributionSets
|
||||
byte[] source = RandomUtils.nextBytes(1024);
|
||||
final byte[] source = RandomUtils.nextBytes(1024);
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX and add a new ArtifactX
|
||||
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
|
||||
@@ -273,7 +273,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// [STEP2]: Create newArtifactX and add it to SoftwareModuleX
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId());
|
||||
Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP3]: Create SoftwareModuleY and add the same ArtifactX
|
||||
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
|
||||
@@ -281,7 +281,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// [STEP4]: Assign the same ArtifactX to SoftwareModuleY
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId());
|
||||
Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
// verify: that only one entry was created in mongoDB
|
||||
assertThat(operations.find(new Query())).hasSize(1);
|
||||
@@ -325,14 +325,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId());
|
||||
Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP2]: Create SoftwareModuleY and add the same ArtifactX
|
||||
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId());
|
||||
Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
// verify: that only one entry was created in mongoDB
|
||||
assertThat(operations.find(new Query())).hasSize(1);
|
||||
@@ -358,8 +358,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// verify: SoftwareModuleX and SofwtareModule are marked as deleted
|
||||
assertThat(moduleX).isNotNull();
|
||||
assertThat(moduleY).isNotNull();
|
||||
assertTrue(moduleX.isDeleted());
|
||||
assertTrue(moduleY.isDeleted());
|
||||
assertTrue("The module should be flagged deleted", moduleX.isDeleted());
|
||||
assertTrue("The module should be flagged deleted", moduleY.isDeleted());
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(2);
|
||||
|
||||
@@ -370,10 +370,10 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(artifactRepository.findOne(artifactY.getId())).isNotNull();
|
||||
}
|
||||
|
||||
private SoftwareModule createSoftwareModuleWithArtifacts(SoftwareModuleType type, String name, String version,
|
||||
int numberArtifacts) {
|
||||
private SoftwareModule createSoftwareModuleWithArtifacts(final SoftwareModuleType type, final String name,
|
||||
final String version, final int numberArtifacts) {
|
||||
|
||||
long countSoftwareModule = softwareModuleRepository.count();
|
||||
final long countSoftwareModule = softwareModuleRepository.count();
|
||||
|
||||
// create SoftwareModule
|
||||
SoftwareModule softwareModule = softwareManagement
|
||||
@@ -388,7 +388,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
softwareModule = softwareManagement.findSoftwareModuleWithDetails(softwareModule.getId());
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1);
|
||||
|
||||
List<Artifact> artifacts = softwareModule.getArtifacts();
|
||||
final List<Artifact> artifacts = softwareModule.getArtifacts();
|
||||
|
||||
assertThat(artifacts).hasSize(numberArtifacts);
|
||||
if (numberArtifacts != 0) {
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -26,6 +25,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.Query;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
@@ -65,6 +65,24 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that a target with empty controller id cannot be created")
|
||||
public void createTargetWithNoControllerId() {
|
||||
try {
|
||||
targetManagement.createTarget(new Target(""));
|
||||
fail("target with empty controller id should not be created");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
try {
|
||||
targetManagement.createTarget(new Target(null));
|
||||
fail("target with empty controller id should not be created");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that targets can assigned and unassigned to a target tag. Not exists target will be ignored for the assignment.")
|
||||
public void assignAndUnassignTargetsToTag() {
|
||||
@@ -156,7 +174,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(set.getId(), "4711");
|
||||
|
||||
final Action action = result.getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(result.getActions().get(0));
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
|
||||
@@ -203,7 +221,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
* verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted
|
||||
* that the target have additional tags assigned to them which are not
|
||||
* contained within parameter tags.
|
||||
*
|
||||
*
|
||||
* @param strict
|
||||
* if true, the given targets MUST contain EXACTLY ALL given
|
||||
* tags, AND NO OTHERS. If false, the given targets MUST contain
|
||||
@@ -226,10 +244,10 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
}
|
||||
if (strict) {
|
||||
fail();
|
||||
fail("Target does not contain all tags");
|
||||
}
|
||||
}
|
||||
fail();
|
||||
fail("Target does not contain any tags or the expected tag was not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,7 +258,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : t.getTags()) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
fail();
|
||||
fail("Target should have no tags");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,30 +274,33 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final Target target = TestDataUtil.buildTargetFixture(myCtrlID, "the description!");
|
||||
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
assertNotNull(savedTarget);
|
||||
assertNotNull("The target should not be null", savedTarget);
|
||||
final Long createdAt = savedTarget.getCreatedAt();
|
||||
Long modifiedAt = savedTarget.getLastModifiedAt();
|
||||
assertEquals(createdAt, modifiedAt);
|
||||
assertNotNull(savedTarget.getCreatedAt());
|
||||
assertNotNull(savedTarget.getLastModifiedAt());
|
||||
assertEquals(target, savedTarget);
|
||||
|
||||
assertThat(createdAt).as("CreatedAt compared with modifiedAt").isEqualTo(modifiedAt);
|
||||
assertNotNull("The createdAt attribut of the target should no be null", savedTarget.getCreatedAt());
|
||||
assertNotNull("The lastModifiedAt attribut of the target should no be null", savedTarget.getLastModifiedAt());
|
||||
assertThat(target).as("Target compared with saved target").isEqualTo(savedTarget);
|
||||
|
||||
savedTarget.setDescription("changed description");
|
||||
Thread.sleep(1);
|
||||
savedTarget = targetManagement.updateTarget(savedTarget);
|
||||
|
||||
assertNotNull(savedTarget.getLastModifiedAt());
|
||||
assertNotEquals(createdAt, savedTarget.getLastModifiedAt());
|
||||
assertNotEquals(modifiedAt, savedTarget.getLastModifiedAt());
|
||||
assertNotNull("The lastModifiedAt attribute of the target should not be null", savedTarget.getLastModifiedAt());
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
modifiedAt = savedTarget.getLastModifiedAt();
|
||||
|
||||
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId());
|
||||
|
||||
assertNotNull(foundTarget);
|
||||
assertEquals(myCtrlID, foundTarget.getControllerId());
|
||||
assertEquals(savedTarget, foundTarget);
|
||||
assertEquals(createdAt, foundTarget.getCreatedAt());
|
||||
assertEquals(modifiedAt, foundTarget.getLastModifiedAt());
|
||||
assertNotNull("The target should not be null", foundTarget);
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
|
||||
.isEqualTo(foundTarget.getControllerId());
|
||||
assertThat(savedTarget).as("Target compared with saved target").isEqualTo(foundTarget);
|
||||
assertThat(createdAt).as("CreatedAt compared with saved createdAt").isEqualTo(foundTarget.getCreatedAt());
|
||||
assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(foundTarget.getLastModifiedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,8 +317,11 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final Target savedExtra = targetManagement.createTarget(extra);
|
||||
|
||||
Iterable<Target> allFound = targetRepository.findAll();
|
||||
assertEquals(firstList.size(), firstSaved.spliterator().getExactSizeIfKnown());
|
||||
assertEquals(firstList.size() + 1, allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
assertThat(Long.valueOf(firstList.size())).as("List size of targets")
|
||||
.isEqualTo(firstSaved.spliterator().getExactSizeIfKnown());
|
||||
assertThat(Long.valueOf(firstList.size() + 1)).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
// change the objects and save to again to trigger a change on
|
||||
// lastModifiedAt
|
||||
@@ -308,18 +332,23 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
_founds: for (final Target foundTarget : allFound) {
|
||||
for (final Target changedTarget : firstSaved) {
|
||||
if (changedTarget.getControllerId().equals(foundTarget.getControllerId())) {
|
||||
assertEquals(changedTarget.getDescription(), foundTarget.getDescription());
|
||||
assertTrue(changedTarget.getName().startsWith(foundTarget.getName()));
|
||||
assertTrue(changedTarget.getName().endsWith("changed"));
|
||||
assertEquals(changedTarget.getCreatedAt(), foundTarget.getCreatedAt());
|
||||
assertThat(changedTarget.getLastModifiedAt()).isNotEqualTo(changedTarget.getCreatedAt());
|
||||
|
||||
assertThat(changedTarget.getDescription())
|
||||
.as("Description of changed target compared with description saved target")
|
||||
.isEqualTo(foundTarget.getDescription());
|
||||
assertThat(changedTarget.getName()).as("Name of changed target starts with name of saved target")
|
||||
.startsWith(foundTarget.getName());
|
||||
assertThat(changedTarget.getName()).as("Name of changed target ends with 'changed'")
|
||||
.endsWith("changed");
|
||||
assertThat(changedTarget.getCreatedAt()).as("CreatedAt compared with saved createdAt")
|
||||
.isEqualTo(foundTarget.getCreatedAt());
|
||||
assertThat(changedTarget.getLastModifiedAt()).as("LastModifiedAt compared with saved createdAt")
|
||||
.isNotEqualTo(changedTarget.getCreatedAt());
|
||||
continue _founds;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundTarget.getControllerId().equals(savedExtra.getControllerId())) {
|
||||
fail();
|
||||
fail("The controllerId of the found target is not equal to the controllerId of the saved target");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,8 +370,8 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
targetManagement.deleteTargets(deletedTargetIDs);
|
||||
|
||||
allFound = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent();
|
||||
assertEquals(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del,
|
||||
allFound.spliterator().getExactSizeIfKnown());
|
||||
assertThat(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del).as("Size of splited list")
|
||||
.isEqualTo(allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
// verify that all undeleted are still found
|
||||
assertThat(allFound).doesNotContain(deletedTargets);
|
||||
@@ -376,15 +405,26 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
final Query qry = entityManager.createNativeQuery("select * from sp_target_attributes ta");
|
||||
final List result = qry.getResultList();
|
||||
assertEquals(attribs.size() * ts.spliterator().getExactSizeIfKnown(), result.size());
|
||||
|
||||
assertThat(attribs.size() * ts.spliterator().getExactSizeIfKnown()).as("Amount of all target attributes")
|
||||
.isEqualTo(result.size());
|
||||
|
||||
for (final Target myT : ts) {
|
||||
final Target t = targetManagement.findTargetByControllerIDWithDetails(myT.getControllerId());
|
||||
assertEquals(attribs.size(), t.getTargetInfo().getControllerAttributes().size());
|
||||
assertThat(attribs.size()).as("Amount of target attributes per target")
|
||||
.isEqualTo(t.getTargetInfo().getControllerAttributes().size());
|
||||
|
||||
for (final Entry<String, String> ca : t.getTargetInfo().getControllerAttributes().entrySet()) {
|
||||
assertTrue(attribs.containsKey(ca.getKey()));
|
||||
assertTrue("Attributes list does not contain target attribute key", attribs.containsKey(ca.getKey()));
|
||||
// has the same value: see string concatenation above
|
||||
assertEquals(String.format("%s-%s", attribs.get(ca.getKey()), t.getControllerId()), ca.getValue());
|
||||
// assertThat(String.format("%s-%s",
|
||||
// attribs.get(ca.getKey()))).as("Value of string
|
||||
// concatenation")
|
||||
// .isEqualTo(ca.getValue());
|
||||
|
||||
assertEquals("The value of the string concatenation is not equal to the value of the target attributes",
|
||||
String.format("%s-%s", attribs.get(ca.getKey()), t.getControllerId()), ca.getValue());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,9 +696,8 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final List<Target> targetsListWithNoTag = targetManagement
|
||||
.findTargetByFilters(new PageRequest(0, 500), null, null, null, Boolean.TRUE, tagNames).getContent();
|
||||
|
||||
// Total targets
|
||||
assertEquals(50, targetManagement.findAllTargetIds().size());
|
||||
// Targets with no tag
|
||||
assertEquals(25, targetsListWithNoTag.size());
|
||||
assertThat(50).as("Total targets").isEqualTo(targetManagement.findAllTargetIds().size());
|
||||
assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class RSQLActionFieldsTest extends AbstractIntegrationTest {
|
||||
|
||||
try {
|
||||
assertRSQLQuery(ActionFields.STATUS.name() + "==true", 5);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterUnsupportedFieldException because status cannot be compared with 'true'");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +114,9 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest {
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "!=pending", 3);
|
||||
try {
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "==noExist*", 0);
|
||||
fail();
|
||||
fail("RSQLParameterUnsupportedFieldException was expected since update status unknown");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
// test ok - exception was excepted
|
||||
}
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=in=(pending,error)", 1);
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=out=(pending,error)", 3);
|
||||
|
||||
@@ -63,7 +63,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterSyntaxException e) {
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing an expected RSQLParameterUnsupportedFieldException because of unknown RSQL field");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, DistributionSetFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class RSQLUtilityTest {
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,13 +199,14 @@ public final class RepositoryDataGenerator {
|
||||
|
||||
}
|
||||
|
||||
private void createActionStatusHistory(final List<Action> actions, final int sizeMultiplikator) {
|
||||
private void createActionStatusHistory(final List<Long> actions, final int sizeMultiplikator) {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
int index = 0;
|
||||
for (final Action actionGiven : actions) {
|
||||
for (final Long actionGiven : actions) {
|
||||
// retrieved
|
||||
Action action = controllerManagement.registerRetrieved(actionGiven,
|
||||
Action action = controllerManagement.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(actionGiven),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
// download
|
||||
@@ -260,10 +261,11 @@ public final class RepositoryDataGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private void createSimpleActionStatusHistory(final List<Action> actions) {
|
||||
for (final Action actionGiven : actions) {
|
||||
private void createSimpleActionStatusHistory(final List<Long> actions) {
|
||||
for (final Long actionGiven : actions) {
|
||||
// retrieved
|
||||
Action action = controllerManagement.registerRetrieved(actionGiven,
|
||||
Action action = controllerManagement.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(actionGiven),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
// close
|
||||
|
||||
Reference in New Issue
Block a user