Spring Boot 2.0 (#721)

* Migration to Boot 2.0.

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

View File

@@ -42,12 +42,9 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.cloud.bus.ConditionalOnBusEnabled;
import org.springframework.cloud.bus.ServiceMatcher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
@@ -65,7 +62,6 @@ import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;
import org.springframework.security.concurrent.DelegatingSecurityContextScheduledExecutorService;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.util.AntPathMatcher;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -128,8 +124,9 @@ public class TestConfiguration implements AsyncConfigurer {
@Bean
TenantAwareCacheManager cacheManager() {
return new TenantAwareCacheManager(new GuavaCacheManager(), tenantAware());
return new TenantAwareCacheManager(new CaffeineCacheManager(), tenantAware());
}
/**
* Bean for the download id cache.
*
@@ -206,15 +203,6 @@ public class TestConfiguration implements AsyncConfigurer {
return new VirtualPropertyResolver();
}
@Bean
@ConditionalOnMissingBean
ServiceMatcher serviceMatcher(final ApplicationContext applicationContext) {
final ServiceMatcher serviceMatcher = new ServiceMatcher();
serviceMatcher.setMatcher(new AntPathMatcher(":"));
serviceMatcher.setApplicationContext(applicationContext);
return serviceMatcher;
}
@Bean
RolloutApprovalStrategy rolloutApprovalStrategy() {
return new RolloutTestApprovalStrategy();

View File

@@ -37,8 +37,8 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Sets;
import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.core.ConditionTimeoutException;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionTimeoutException;
/**
* Test rule to setup and verify the event count for a method.

View File

@@ -17,9 +17,7 @@ import java.net.URI;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
@@ -71,7 +69,7 @@ import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.bus.ServiceMatcher;
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
import org.springframework.context.ApplicationEventPublisher;
@@ -80,18 +78,22 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.hateoas.MediaTypes;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringJUnit4ClassRunner.class)
import com.google.common.io.Files;
@RunWith(SpringRunner.class)
@ActiveProfiles({ "test" })
@WithUser(principal = "bumlux", allSpPermissions = true, authorities = { CONTROLLER_ROLE, SYSTEM_ROLE })
@SpringApplicationConfiguration(classes = { TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
@SpringBootTest
@ContextConfiguration(classes = { TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
// destroy the context after each test class because otherwise we get problem
// when context is
// refreshed we e.g. get two instances of CacheManager which leads to very
@@ -102,19 +104,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
// important!
@TestExecutionListeners(inheritListeners = true, listeners = { EventVerifier.class, CleanupTestExecutionListener.class,
MySqlTestDatabase.class, MsSqlTestDatabase.class }, mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
@TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true")
public abstract class AbstractIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(AbstractIntegrationTest.class);
protected static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
protected static final Pageable PAGE = PageRequest.of(0, 400, new Sort(Direction.ASC, "id"));
protected static final URI LOCALHOST = URI.create("http://127.0.0.1");
/**
* Constant for MediaType HAL with encoding UTF-8. Necessary since Spring
* version 4.3.2 @see https://jira.spring.io/browse/SPR-14577
*/
protected static final String APPLICATION_JSON_HAL_UTF = MediaTypes.HAL_JSON + ";charset=UTF-8";
/**
* Number of {@link DistributionSetType}s that exist in every test case. One
* generated by using
@@ -362,7 +359,8 @@ public abstract class AbstractIntegrationTest {
}
private static String artifactDirectory = "./artifactrepo/" + RandomStringUtils.randomAlphanumeric(20);
private static String artifactDirectory = Files.createTempDir().getAbsolutePath() + "/"
+ RandomStringUtils.randomAlphanumeric(20);
@After
public void cleanUp() {
@@ -416,20 +414,4 @@ public abstract class AbstractIntegrationTest {
final ZonedDateTime currentTime = ZonedDateTime.now();
return currentTime.getOffset().getId().replace("Z", "+00:00");
}
protected static Map<String, String> getMaintenanceWindow(final String schedule, final String duration,
final String timezone) {
final Map<String, String> maintenanceWindowMap = new HashMap<>();
maintenanceWindowMap.put("schedule", schedule);
maintenanceWindowMap.put("duration", duration);
maintenanceWindowMap.put("timezone", timezone);
return maintenanceWindowMap;
}
protected static Map<String, String> getMaintenanceWindowWithNextStart(final String schedule, final String duration,
final String timezone, final long nextStartAt) {
final Map<String, String> maintenanceWindowMap = getMaintenanceWindow(schedule, duration, timezone);
maintenanceWindowMap.put("nextStartAt", String.valueOf(nextStartAt));
return maintenanceWindowMap;
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.data.domain.Sort.Direction;
public class JpaTestRepositoryManagement {
private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class);
private static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
private static final Pageable PAGE = PageRequest.of(0, 400, new Sort(Direction.ASC, "id"));
private final TenantAwareCacheManager cacheManager;

View File

@@ -886,7 +886,8 @@ public class TestdataFactory {
final String descriptionPrefix, final Long lastTargetQuery) {
return targetManagement.create(IntStream.range(0, numberOfTargets)
.mapToObj(i -> entityFactory.target().create().controllerId(controllerIdPrefix + i)
.mapToObj(i -> entityFactory.target().create()
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery))
.collect(Collectors.toList()));
}
@@ -973,7 +974,7 @@ public class TestdataFactory {
final List<Action> result = new ArrayList<>();
for (final Target target : targets) {
final List<Action> findByTarget = deploymentManagement
.findActionsByTarget(target.getControllerId(), new PageRequest(0, 400)).getContent();
.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent();
for (final Action action : findByTarget) {
result.add(sendUpdateActionStatusToTarget(status, action, msgs));
}

View File

@@ -17,9 +17,6 @@ import java.lang.annotation.Target;
/**
* Annotation to run test classes or test methods with a specific user with
* specific permissions.
*
*
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })

View File

@@ -20,10 +20,6 @@ spring.jpa.properties.eclipselink.logging.parameters=true
# Test utility properties for easier fault investigation - END
# Default properties for test that can be overridden during test run - START
## JPA Repository - START
spring.datasource.url=jdbc:h2:mem:sp-db;DB_CLOSE_ON_EXIT=FALSE
## JPA Repository - END
# Enforce persistence of targetpolls for test predictability.
hawkbit.server.repository.eagerPollPersistence=true