Abstract RepositoryManagement test (#2631)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-08-28 12:56:16 +03:00
parent 42b0bc06a9
commit 4f0a8893c7
52 changed files with 1901 additions and 3042 deletions

View File

@@ -156,7 +156,7 @@ public class JpaRepositoryConfiguration {
* @return the {@link MethodValidationPostProcessor}
*/
@Bean
public MethodValidationPostProcessor methodValidationPostProcessor() {
public static MethodValidationPostProcessor methodValidationPostProcessor() {
final MethodValidationPostProcessor processor = new MethodValidationPostProcessor();
// ValidatorFactory shall NOT be closed because after closing the generated Validator
// methods shall not be called - we need the validator in future
@@ -170,7 +170,7 @@ public class JpaRepositoryConfiguration {
}
@Bean
public BeanPostProcessor entityManagerBeanPostProcessor(
public static BeanPostProcessor entityManagerBeanPostProcessor(
@Autowired(required = false) final AccessController<JpaArtifact> artifactAccessController,
@Autowired(required = false) final AccessController<JpaSoftwareModuleType> softwareModuleTypeAccessController,
@Autowired(required = false) final AccessController<JpaSoftwareModule> softwareModuleAccessController,

View File

@@ -431,8 +431,8 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action registerRetrieved(final long actionId, final String message) {
return handleRegisterRetrieved(actionId, message);
public void registerRetrieved(final long actionId, final String message) {
handleRegisterRetrieved(actionId, message);
}
@Override
@@ -895,10 +895,8 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
*
* @param actionId to the handle status for
* @param message for the status
* @return the updated action in case the status has been changed to
* {@link Status#RETRIEVED}
*/
private Action handleRegisterRetrieved(final Long actionId, final String message) {
private void handleRegisterRetrieved(final Long actionId, final String message) {
final JpaAction action = actionRepository.getById(actionId);
// do a manual query with CriteriaBuilder to avoid unnecessary field queries and an extra
// count query made by spring-data when using pageable requests, we don't need an extra count
@@ -910,8 +908,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
.multiselect(actionStatusRoot.get(AbstractJpaBaseEntity_.id), actionStatusRoot.get(JpaActionStatus_.status))
.where(cb.equal(actionStatusRoot.get(JpaActionStatus_.action).get(AbstractJpaBaseEntity_.id), actionId))
.orderBy(cb.desc(actionStatusRoot.get(AbstractJpaBaseEntity_.id)));
final List<Object[]> resultList = entityManager.createQuery(query).setFirstResult(0).setMaxResults(1)
.getResultList();
final List<Object[]> resultList = entityManager.createQuery(query).setFirstResult(0).setMaxResults(1).getResultList();
// if the latest status is not in retrieve state then we add a retrieved state again, we want
// to document a deployment retrieved status and a cancel retrieved status, but multiple
@@ -919,8 +916,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
// case controller retrieves a action multiple times.
if (resultList.isEmpty() || (Status.RETRIEVED != resultList.get(0)[1])) {
// document that the status has been retrieved
actionStatusRepository
.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message));
actionStatusRepository.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message));
// don't change the action status itself in case the action is in
// canceling state otherwise
@@ -928,10 +924,8 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
// cancel job anymore.
if (!action.isCancelingOrCanceled()) {
action.setStatus(Status.RETRIEVED);
return actionRepository.save(action);
}
}
return action;
}
private void cancelAssignDistributionSetEvent(final Action action) {

View File

@@ -316,16 +316,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
return actionStatusRepository.findByActionId(pageable, actionId);
}
@Override
public long countActionStatusByAction(final long actionId) {
assertActionExistsAndAccessible(actionId);
return actionStatusRepository.countByActionId(actionId);
}
// action is already got and there are checked read permissions - do not check
// permissions
// and UI which is to be removed
// action is already got and there are checked read permissions - do not check permissions and UI which is to be removed
@Override
public Page<String> findMessagesByActionStatusId(final long actionStatusId, final Pageable pageable) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();

View File

@@ -153,13 +153,6 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
return JpaManagementHelper.convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable);
}
@Override
public long countByRollout(final long rolloutId) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
return rolloutGroupRepository.countByRolloutId(rolloutId);
}
@Override
public Page<Target> findTargetsOfRolloutGroup(final long rolloutGroupId, final Pageable page) {
final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.getById(rolloutGroupId);

View File

@@ -271,11 +271,6 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
return tenantMetaDataRepository.save(data);
}
@Override
public TenantMetaData getTenantMetadata(final long tenantId) {
return tenantMetaDataRepository.findById(tenantId).orElseThrow(() -> new EntityNotFoundException(TenantMetaData.class, tenantId));
}
private static boolean isPostgreSql(final JpaProperties properties) {
return Database.POSTGRESQL == properties.getDatabase();
}

View File

@@ -30,6 +30,7 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeException;
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
@@ -114,13 +115,12 @@ class JpaTargetFilterQueryManagement
}
@Override
public boolean verifyTargetFilterQuerySyntax(final String query) {
public void verifyTargetFilterQuerySyntax(final String query) {
try {
RsqlUtility.getInstance().validateRsqlFor(query, TargetFields.class, JpaTarget.class);
return true;
} catch (final RSQLParserException | RSQLParameterUnsupportedFieldException e) {
log.debug("The RSQL query '{}}' is invalid.", query, e);
return false;
throw new RSQLParameterSyntaxException("Cannot create a Rollout with an empty target query filter!");
}
}

View File

@@ -464,7 +464,7 @@ public class JpaTargetManagement
// get the modifiable metadata map
final Map<String, String> metadata = target.getMetadata();
if (!metadata.containsKey(key)) {
throw new EntityNotFoundException("Target metadata", controllerId + ":" + key);
assertMetadataQuota(target.getId(), metadata.size() + 1);
}
metadata.put(key, value);

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serial;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
@@ -119,7 +120,7 @@ public class JpaDistributionSet
foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_metadata_ds"))
@MapKeyColumn(name = "meta_key", length = DistributionSet.METADATA_MAX_KEY_SIZE)
@Column(name = "meta_value", length = DistributionSet.METADATA_MAX_VALUE_SIZE)
private Map<String, String> metadata;
private Map<String, String> metadata = new HashMap<>();
@Column(name = "complete")
private boolean complete;

View File

@@ -119,22 +119,9 @@ public class JpaSoftwareModule
@ManyToMany(mappedBy = "modules", targetEntity = JpaDistributionSet.class, fetch = FetchType.LAZY)
private List<DistributionSet> assignedTo;
/**
* Parameterized constructor.
*/
public JpaSoftwareModule(final SoftwareModuleType type, final String name, final String version) {
this(type, name, version, null, null, false);
}
/**
* Parameterized constructor.
*/
public JpaSoftwareModule(final SoftwareModuleType type, final String name, final String version,
final String description, final String vendor, final boolean encrypted) {
super(name, version, description);
this.vendor = vendor;
super(name, version, null);
this.type = (JpaSoftwareModuleType) type;
this.encrypted = encrypted;
}
@Override