JPA Refactoring (3) (#2109)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-02 13:50:06 +02:00
committed by GitHub
parent 794f26bea2
commit a9f3d1491a
37 changed files with 151 additions and 246 deletions

View File

@@ -27,11 +27,13 @@ import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
import org.eclipse.hawkbit.im.authentication.SpRole;
import org.eclipse.hawkbit.repository.RolloutApprovalStrategy;
import org.eclipse.hawkbit.repository.RolloutStatusCache;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
import org.eclipse.hawkbit.repository.test.util.RolloutTestApprovalStrategy;
import org.eclipse.hawkbit.repository.test.util.SystemManagementHolder;
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
import org.eclipse.hawkbit.security.DdiSecurityProperties;
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
@@ -131,6 +133,16 @@ public class TestConfiguration implements AsyncConfigurer {
return new ArtifactFilesystemRepository(artifactFilesystemProperties);
}
/**
* @return the {@link org.eclipse.hawkbit.repository.test.util.SystemManagementHolder} singleton bean which holds the
* current {@link SystemManagement} service and make it accessible in
* beans which cannot access the service directly, e.g. JPA entities.
*/
@Bean
SystemManagementHolder systemManagementHolder() {
return SystemManagementHolder.getInstance();
}
@Bean
TestdataFactory testdataFactory() {
return new TestdataFactory();

View File

@@ -18,7 +18,6 @@ import java.util.Objects;
import java.util.concurrent.Callable;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder;
import org.eclipse.hawkbit.tenancy.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.tenancy.TenantAwareUser;
import org.springframework.security.authentication.TestingAuthenticationToken;
@@ -29,6 +28,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
public class SecurityContextSwitch {
public static final String DEFAULT_TENANT = "DEFAULT";
private static final WithUser PRIVILEDGED_USER =
createWithUser("bumlux", DEFAULT_TENANT, false, true, false, "ROLE_CONTROLLER", "ROLE_SYSTEM_CODE");

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.test.util;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A singleton bean which holds {@link SystemManagement} service and makes it
* accessible to beans which are not managed by spring, e.g. JPA entities.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SystemManagementHolder {
private static final SystemManagementHolder INSTANCE = new SystemManagementHolder();
@Getter
@Setter
@Autowired
private SystemManagement systemManagement;
/**
* @return the singleton {@link SystemManagementHolder} instance
*/
public static SystemManagementHolder getInstance() {
return INSTANCE;
}
}