diff --git a/chaos-monkey-docs/src/main/asciidoc/changes.adoc b/chaos-monkey-docs/src/main/asciidoc/changes.adoc index 06e61419..dde22140 100644 --- a/chaos-monkey-docs/src/main/asciidoc/changes.adoc +++ b/chaos-monkey-docs/src/main/asciidoc/changes.adoc @@ -11,10 +11,11 @@ Built with Spring Boot {spring-boot-version} === New Features // - https://github.com/codecentric/chaos-monkey-spring-boot/pull/xxx[#xxx] Added example entry. Please don't remove. +- https://github.com/codecentric/chaos-monkey-spring-boot/pull/618[#618] Upgrade to Spring Boot 4 and Spring Cloud 2025.1 === Contributors This release was only possible because of these great humans ❤️: -// - https://github.com/octocat[@octocat] +- https://github.com/bmatthews68[@bmatthews68] Thank you for your support! diff --git a/chaos-monkey-docs/src/main/asciidoc/endpoints.adoc b/chaos-monkey-docs/src/main/asciidoc/endpoints.adoc index b6201231..608252af 100644 --- a/chaos-monkey-docs/src/main/asciidoc/endpoints.adoc +++ b/chaos-monkey-docs/src/main/asciidoc/endpoints.adoc @@ -11,8 +11,8 @@ https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html[Spr [source,txt,subs="verbatim,attributes",role="primary"] .application.properties: ---- -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=true +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=unrestricted # include all endpoints management.endpoints.web.exposure.include=* diff --git a/chaos-monkey-docs/src/main/asciidoc/getting-started.adoc b/chaos-monkey-docs/src/main/asciidoc/getting-started.adoc index d40655be..9004f550 100644 --- a/chaos-monkey-docs/src/main/asciidoc/getting-started.adoc +++ b/chaos-monkey-docs/src/main/asciidoc/getting-started.adoc @@ -90,7 +90,7 @@ Start your Spring Boot application, add Chaos Monkey for Spring Boot JAR and pro ---- java -cp your-app.jar -Dloader.path=chaos-monkey-spring-boot-{project-version}-jar-with-dependencies.jar - org.springframework.boot.loader.PropertiesLauncher + org.springframework.boot.loader.launch.PropertiesLauncher --spring.profiles.active=chaos-monkey --spring.config.location=file:./chaos-monkey.properties ---- diff --git a/chaos-monkey-spring-boot/pom.xml b/chaos-monkey-spring-boot/pom.xml index b5d1fe84..efc73512 100644 --- a/chaos-monkey-spring-boot/pom.xml +++ b/chaos-monkey-spring-boot/pom.xml @@ -48,14 +48,29 @@ org.aspectj aspectjweaver + + org.jspecify + jspecify + org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc provided - com.fasterxml.jackson.core + org.springframework.boot + spring-boot-starter-restclient + provided + + + org.springframework.boot + spring-boot-starter-webclient + provided + + + tools.jackson.core jackson-databind + 3.0.3 org.springframework.boot @@ -69,7 +84,7 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui ${spring-doc.version} provided @@ -120,6 +135,11 @@ spring-boot-starter-actuator true + + org.springframework.boot + spring-boot-health + true + org.springframework.boot spring-boot-starter-test @@ -146,6 +166,11 @@ unleash-client-java true + + org.springframework.boot + spring-boot-resttestclient + test + diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/assaults/KillAppAssault.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/assaults/KillAppAssault.java index 557ca599..34765e1d 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/assaults/KillAppAssault.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/assaults/KillAppAssault.java @@ -19,12 +19,12 @@ import de.codecentric.spring.boot.chaos.monkey.component.MetricType; import de.codecentric.spring.boot.chaos.monkey.configuration.AssaultProperties; import de.codecentric.spring.boot.chaos.monkey.configuration.ChaosMonkeySettings; +import org.jspecify.annotations.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.lang.NonNull; import java.util.concurrent.TimeUnit; diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultException.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultException.java index bb30b6b5..8e153967 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultException.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultException.java @@ -16,8 +16,7 @@ package de.codecentric.spring.boot.chaos.monkey.configuration; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.ObjectMapper; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; @@ -29,6 +28,8 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.util.ClassUtils; +import tools.jackson.core.JacksonException; +import tools.jackson.databind.exc.MismatchedInputException; @Data public class AssaultException { @@ -74,7 +75,7 @@ private Throwable getThrowable() { try { ThrowableCreator creator = getCreator(); instance = creator.create(getExceptionArgumentValues()); - } catch (ReflectiveOperationException | ClassCastException | JsonProcessingException e) { + } catch (ReflectiveOperationException | ClassCastException | JacksonException e) { Logger.warn("Failed to create custom exception. Fallback: Throw RuntimeException"); instance = new RuntimeException("Chaos Monkey - RuntimeException (Fallback)", e); } @@ -105,7 +106,7 @@ private List> getExceptionArgumentTypes() throws ClassNotFoundException return exceptionArgumentTypes; } - private List getExceptionArgumentValues() throws ClassNotFoundException, JsonProcessingException { + private List getExceptionArgumentValues() throws ClassNotFoundException, JacksonException { List exceptionArgumentValues = new ArrayList<>(); for (ExceptionArgument argument : arguments) { Class classType = argument.getClassType(); @@ -113,7 +114,7 @@ private List getExceptionArgumentValues() throws ClassNotFoundException, try { // this mostly works for primitive values and strings exceptionArgumentValues.add(objectMapper.convertValue(value, classType)); - } catch (IllegalArgumentException e) { + } catch (MismatchedInputException | IllegalArgumentException e) { // treat value as json encoded otherwise exceptionArgumentValues.add(objectMapper.readValue(value, classType)); } diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultProperties.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultProperties.java index 2f62d9b5..2f0f5aa8 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultProperties.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/AssaultProperties.java @@ -16,7 +16,7 @@ package de.codecentric.spring.boot.chaos.monkey.configuration; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.ObjectMapper; import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.AssaultPropertiesUpdate; import java.util.List; import java.util.concurrent.ThreadLocalRandom; diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyAdvisorConfiguration.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyAdvisorConfiguration.java index 1929e8ce..1df6448a 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyAdvisorConfiguration.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyAdvisorConfiguration.java @@ -29,7 +29,6 @@ import de.codecentric.spring.boot.chaos.monkey.watcher.advice.filter.RepositoryClassFilter; import de.codecentric.spring.boot.chaos.monkey.watcher.advice.filter.SpringHookMethodsFilter; import lombok.RequiredArgsConstructor; -import lombok.val; import org.springframework.aop.ClassFilter; import org.springframework.aop.support.ClassFilters; import org.springframework.aop.support.RootClassFilter; @@ -96,8 +95,7 @@ public ChaosMonkeyPointcutAdvisor componentPointcutAdvisor(ChaosMonkeyBaseClassF @ConditionalOnClass(name = "org.springframework.data.repository.Repository") public ChaosMonkeyPointcutAdvisor repositoryPointcutAdvisor(ChaosMonkeyBaseClassFilter baseClassFilter, ChaosMonkeyRequestScope requestScope, MetricEventPublisher eventPublisher) throws ClassNotFoundException { - @SuppressWarnings("unchecked") - val repositoryDefinition = (Class) Class.forName("org.springframework.data.repository.RepositoryDefinition"); + final var repositoryDefinition = (Class) Class.forName("org.springframework.data.repository.RepositoryDefinition"); ClassFilter[] filters = {new RepositoryClassFilter(), new RepositoryAnnotatedClassFilter(), new AnnotationClassFilter(repositoryDefinition)}; return new ChaosMonkeyPointcutAdvisor(baseClassFilter, @@ -107,12 +105,12 @@ public ChaosMonkeyPointcutAdvisor repositoryPointcutAdvisor(ChaosMonkeyBaseClass @Bean @ConditionalOnMissingBean(name = "healthIndicatorAdviceProvider") - @ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") + @ConditionalOnClass(name = "org.springframework.boot.health.contributor.HealthIndicator") public ChaosMonkeyPointcutAdvisor healthIndicatorAdviceProvider(ChaosMonkeyBaseClassFilter baseClassFilter, ChaosMonkeyRequestScope requestScope) throws ClassNotFoundException { - Class healthIndicatorClass = Class.forName("org.springframework.boot.actuate.health.HealthIndicator"); + Class healthIndicatorClass = Class.forName("org.springframework.boot.health.contributor.HealthIndicator"); return new ChaosMonkeyPointcutAdvisor(baseClassFilter, new ChaosMonkeyHealthIndicatorAdvice(requestScope, watcherProperties), - new RootClassFilter(healthIndicatorClass), new MethodNameFilter("getHealth")); + new RootClassFilter(healthIndicatorClass), new MethodNameFilter("health")); } @Bean diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyOpenApiConfiguration.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyOpenApiConfiguration.java index 7a6282ba..7293dfbd 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyOpenApiConfiguration.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyOpenApiConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package de.codecentric.spring.boot.chaos.monkey.configuration; -import org.springdoc.core.GroupedOpenApi; +import org.springdoc.core.models.GroupedOpenApi; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyProperties.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyProperties.java index 89e2afb2..35d57f27 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyProperties.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/configuration/ChaosMonkeyProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.Setter; +import org.jspecify.annotations.Nullable; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.lang.Nullable; @Data @NoArgsConstructor @@ -35,7 +35,6 @@ public class ChaosMonkeyProperties { private String togglePrefix = "chaos.monkey"; - @Nullable public void setEnabled(boolean enabled) { if (this.enabled != enabled) { lastEnabledToggleTimestamp = System.currentTimeMillis(); diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyJmxEndpoint.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyJmxEndpoint.java index b25b0d23..73ac04ed 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyJmxEndpoint.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyJmxEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,13 @@ import de.codecentric.spring.boot.chaos.monkey.configuration.WatcherProperties; import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.AssaultPropertiesUpdate; import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.ChaosMonkeyStatusResponseDto; +import org.springframework.boot.actuate.endpoint.Access; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; import org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpoint; /** @author Benjamin Wilms */ -@JmxEndpoint(enableByDefault = false, id = "chaosmonkeyjmx") +@JmxEndpoint(defaultAccess = Access.NONE, id = "chaosmonkeyjmx") public class ChaosMonkeyJmxEndpoint extends BaseChaosMonkeyEndpoint { public ChaosMonkeyJmxEndpoint(ChaosMonkeySettings chaosMonkeySettings) { diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpoint.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpoint.java index 4ce00135..d6381b54 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpoint.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.ChaosMonkeySettingsDto; import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.ChaosMonkeyStatusResponseDto; import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.WatcherPropertiesUpdate; +import org.springframework.boot.actuate.endpoint.Access; import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -30,7 +31,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; -@RestControllerEndpoint(enableByDefault = false, id = "chaosmonkey") +@RestControllerEndpoint(defaultAccess = Access.NONE, id = "chaosmonkey") public class ChaosMonkeyRestEndpoint extends BaseChaosMonkeyEndpoint { private final ChaosMonkeyRuntimeScope runtimeScope; diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdate.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdate.java index 35747dc2..682031a5 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdate.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdate.java @@ -16,8 +16,7 @@ package de.codecentric.spring.boot.chaos.monkey.endpoints.dto; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.ObjectMapper; import de.codecentric.spring.boot.chaos.monkey.configuration.AssaultException; import de.codecentric.spring.boot.chaos.monkey.configuration.AssaultProperties; import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.validation.AssaultExceptionConstraint; @@ -29,8 +28,9 @@ import jakarta.validation.constraints.Min; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; import org.springframework.validation.annotation.Validated; +import tools.jackson.databind.DatabindException; /** * Is used to update properties. Partial updates are allowed: i. e. @@ -133,7 +133,7 @@ public class AssaultPropertiesUpdate { public void applyTo(AssaultProperties t) { try { new ObjectMapper().updateValue(t, this); - } catch (JsonMappingException e) { + } catch (DatabindException e) { throw new IllegalArgumentException("cannot update values", e); } } diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/ChaosMonkeyStatusResponseDto.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/ChaosMonkeyStatusResponseDto.java index 6ebfb79d..528ad32f 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/ChaosMonkeyStatusResponseDto.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/ChaosMonkeyStatusResponseDto.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; @Data @NoArgsConstructor diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdate.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdate.java index c1f1a0c9..fe55622c 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdate.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdate.java @@ -16,13 +16,13 @@ package de.codecentric.spring.boot.chaos.monkey.endpoints.dto; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.ObjectMapper; import de.codecentric.spring.boot.chaos.monkey.configuration.WatcherProperties; import java.util.List; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; +import tools.jackson.databind.DatabindException; @Data @NoArgsConstructor @@ -62,7 +62,7 @@ public class WatcherPropertiesUpdate { public void applyTo(WatcherProperties t) { try { new ObjectMapper().updateValue(t, this); - } catch (JsonMappingException e) { + } catch (DatabindException e) { throw new IllegalArgumentException("cannot update values", e); } } diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/AbstractChaosMonkeyAdvice.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/AbstractChaosMonkeyAdvice.java index eb94570c..17bbfc48 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/AbstractChaosMonkeyAdvice.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/AbstractChaosMonkeyAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package de.codecentric.spring.boot.chaos.monkey.watcher.advice; -import lombok.val; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.aspectj.lang.ProceedingJoinPoint; @@ -28,7 +27,7 @@ public abstract class AbstractChaosMonkeyAdvice implements MethodInterceptor { @Override public final Object invoke(MethodInvocation invocation) throws Throwable { // this cast should always succeed within spring - val pjp = new MethodInvocationProceedingJoinPoint((ProxyMethodInvocation) invocation); + final var pjp = new MethodInvocationProceedingJoinPoint((ProxyMethodInvocation) invocation); return invoke(pjp); } diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyBeanPostProcessor.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyBeanPostProcessor.java index 1a873c4d..6110affb 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyBeanPostProcessor.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyBeanPostProcessor.java @@ -21,7 +21,6 @@ import de.codecentric.spring.boot.chaos.monkey.configuration.WatcherProperties; import de.codecentric.spring.boot.chaos.monkey.watcher.advice.filter.SpringHookMethodsFilter; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor; import org.springframework.aop.support.ComposablePointcut; import org.springframework.aop.support.DefaultPointcutAdvisor; @@ -38,8 +37,8 @@ public class ChaosMonkeyBeanPostProcessor extends AbstractAdvisingBeanPostProces public ChaosMonkeyBeanPostProcessor(WatcherProperties watcherProperties, ChaosMonkeyRequestScope requestScope, MetricEventPublisher eventPublisher) { this.watcherProperties = watcherProperties; - val advice = new ChaosMonkeyDefaultAdvice(requestScope, eventPublisher, ChaosTarget.BEAN, (pjp) -> { - val bean = pjp.getThis(); + final var advice = new ChaosMonkeyDefaultAdvice(requestScope, eventPublisher, ChaosTarget.BEAN, (pjp) -> { + final var bean = pjp.getThis(); return watcherProperties.getBeans().contains(activeBeanNameCache.get(bean)) || watcherProperties.getBeanClasses().stream().anyMatch(clazz -> clazz.isInstance(bean)); }); diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyHealthIndicatorAdvice.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyHealthIndicatorAdvice.java index 4f17959e..3bd2bc6b 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyHealthIndicatorAdvice.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/ChaosMonkeyHealthIndicatorAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.reflect.MethodSignature; -import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.health.contributor.Health; @RequiredArgsConstructor @Slf4j diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplateCustomizer.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplateCustomizer.java index afa6cfc3..3bb7c165 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplateCustomizer.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplateCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 the original author or authors. + * Copyright 2021-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ package de.codecentric.spring.boot.chaos.monkey.watcher.outgoing; import java.util.List; -import org.springframework.boot.web.client.RestTemplateCustomizer; + +import org.springframework.boot.restclient.RestTemplateCustomizer; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.web.client.RestTemplate; diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplatePostProcessor.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplatePostProcessor.java index 1e5bcb47..b6b9ab0e 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplatePostProcessor.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyRestTemplatePostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 the original author or authors. + * Copyright 2021-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ public ChaosMonkeyRestTemplatePostProcessor(ChaosMonkeyRestTemplateCustomizer re @Override public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { - if (bean instanceof RestTemplate) { - this.restTemplateCustomizer.customize((RestTemplate) bean); + if (bean instanceof RestTemplate template) { + this.restTemplateCustomizer.customize(template); } return bean; } diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientCustomizer.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientCustomizer.java index bbd43d6e..7bd6b74a 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientCustomizer.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 the original author or authors. + * Copyright 2021-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package de.codecentric.spring.boot.chaos.monkey.watcher.outgoing; -import org.springframework.boot.web.reactive.function.client.WebClientCustomizer; +import org.springframework.boot.webclient.WebClientCustomizer; import org.springframework.web.reactive.function.client.WebClient.Builder; public class ChaosMonkeyWebClientCustomizer implements WebClientCustomizer { diff --git a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientPostProcessor.java b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientPostProcessor.java index d7bf7e15..3022a031 100644 --- a/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientPostProcessor.java +++ b/chaos-monkey-spring-boot/src/main/java/de/codecentric/spring/boot/chaos/monkey/watcher/outgoing/ChaosMonkeyWebClientPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 the original author or authors. + * Copyright 2021-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,10 +31,10 @@ public ChaosMonkeyWebClientPostProcessor(final ChaosMonkeyWebClientWatcher filte @Override public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { final Object target; - if (bean instanceof WebClient) { + if (bean instanceof WebClient client) { // create a copy of WebClient whose settings are replicated from the current // WebClient. - target = ((WebClient) bean).mutate().filter(filter).build(); + target = client.mutate().filter(filter).build(); } else { target = bean; } diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/CPUAssaultIntegration.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/CPUAssaultIntegration.java index f5fca036..e567c1f0 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/CPUAssaultIntegration.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/CPUAssaultIntegration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 the original author or authors. + * Copyright 2021-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,21 +33,21 @@ abstract class CPUAssaultIntegration { @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.enabled-by-default=true", + "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.access.default=unrestricted", "chaos.monkey.assaults.cpuActive=true", "chaos.monkey.assaults.cpuLoadTargetFraction=0.3", "chaos.monkey.assaults.cpuMillisecondsHoldLoad=5000", "spring.profiles.active=chaos-monkey"}) static class LowCPUAssaultIntegration extends CPUAssaultIntegration { } @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.enabled-by-default=true", + "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.access.default=unrestricted", "chaos.monkey.assaults.cpuActive=true", "chaos.monkey.assaults.cpuLoadTargetFraction=0.8", "chaos.monkey.assaults.cpuMillisecondsHoldLoad=5000", "spring.profiles.active=chaos-monkey"}) static class HighCPUAssaultIntegration extends CPUAssaultIntegration { } @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.enabled-by-default=true", + "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.access.default=unrestricted", "chaos.monkey.assaults.cpuActive=true", "chaos.monkey.assaults.cpuLoadTargetFraction=1.0", "chaos.monkey.assaults.cpuMillisecondsHoldLoad=5000", "spring.profiles.active=chaos-monkey"}) static class MaxCPUAssaultIntegration extends CPUAssaultIntegration { diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/MemoryAssaultIntegrationTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/MemoryAssaultIntegrationTest.java index 52bc69ee..a4e2bffd 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/MemoryAssaultIntegrationTest.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/assaults/MemoryAssaultIntegrationTest.java @@ -30,18 +30,20 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.ResponseEntity; import org.springframework.util.unit.DataSize; /** @author Benjamin Wilms */ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.enabled-by-default=true", + "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.access.default=unrestricted", "chaos.monkey.assaults.memoryActive=true", "chaos.monkey.assaults.memoryFillTargetFraction=0.80", "chaos.monkey.assaults.memoryMillisecondsWaitNextIncrease=100", "chaos.monkey.assaults.memoryFillIncrementFraction=0.99", "chaos.monkey.assaults.memoryMillisecondsHoldFilledMemory=2000", "spring.profiles.active=chaos-monkey"}) +@AutoConfigureTestRestTemplate class MemoryAssaultIntegrationTest { @LocalServerPort diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointDisabledIntegrationTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointDisabledIntegrationTest.java index 065b045d..60f1bdd7 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointDisabledIntegrationTest.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointDisabledIntegrationTest.java @@ -21,8 +21,9 @@ import de.codecentric.spring.boot.demo.chaos.monkey.ChaosDemoApplication; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,6 +32,7 @@ /** @author Benjamin Wilms */ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource("classpath:test-chaos-monkey-endpoints-disabled.properties") +@AutoConfigureTestRestTemplate class ChaosMonkeyRequestScopeRestEndpointDisabledIntegrationTest { @Test diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointIntegrationTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointIntegrationTest.java index cfb3a9b3..b990bc31 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointIntegrationTest.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRequestScopeRestEndpointIntegrationTest.java @@ -16,8 +16,8 @@ package de.codecentric.spring.boot.chaos.monkey.endpoints; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import de.codecentric.spring.boot.chaos.monkey.assaults.KillAppAssault; import de.codecentric.spring.boot.chaos.monkey.configuration.AssaultException; import de.codecentric.spring.boot.chaos.monkey.configuration.AssaultProperties; @@ -34,16 +34,17 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.bean.override.mockito.MockitoBean; +import tools.jackson.core.JacksonException; +import tools.jackson.databind.json.JsonMapper; +import tools.jackson.databind.ObjectMapper; import java.time.OffsetDateTime; import java.util.Collections; @@ -56,9 +57,11 @@ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource("classpath:application-test-chaos-monkey-profile.properties") +@AutoConfigureTestRestTemplate class ChaosMonkeyRequestScopeRestEndpointIntegrationTest { - private final ObjectMapper objectMapper = new ObjectMapper(); + private final ObjectMapper objectMapper = JsonMapper.builder() + .changeDefaultPropertyInclusion(incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL)).build(); // NB: We don't want to kill the JVM the tests are running in @MockitoBean @@ -75,7 +78,6 @@ class ChaosMonkeyRequestScopeRestEndpointIntegrationTest { @BeforeEach void setUp(@LocalServerPort int serverPort) { baseUrl = "http://localhost:" + serverPort + "/actuator/chaosmonkey"; - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test @@ -157,7 +159,7 @@ void postWatcherConfigurationContainingClass() { // Assault Tests @Test - void getAssaultConfiguration() throws JsonProcessingException { + void getAssaultConfiguration() throws JacksonException { ResponseEntity result = testRestTemplate.getForEntity(baseUrl + "/assaults", AssaultPropertiesUpdate.class); assertEquals(HttpStatus.OK, result.getStatusCode()); diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpointTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpointTest.java index 91b5fb8d..ebd24d41 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpointTest.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/ChaosMonkeyRestEndpointTest.java @@ -28,9 +28,10 @@ import de.codecentric.spring.boot.demo.chaos.monkey.ChaosDemoApplication; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; @@ -39,8 +40,9 @@ @ActiveProfiles("chaos-monkey") @ContextConfiguration(classes = {ChaosDemoApplication.class}) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"management.endpoint.chaosmonkey.enabled=true", - "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.enabled-by-default=true"}) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"management.endpoint.chaosmonkey.access=unrestricted", + "management.endpoints.web.exposure.include=chaosmonkey", "management.endpoints.access.default=unrestricted"}) +@AutoConfigureTestRestTemplate public class ChaosMonkeyRestEndpointTest { @Autowired diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdateTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdateTest.java new file mode 100644 index 00000000..f1a89331 --- /dev/null +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/AssaultPropertiesUpdateTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.codecentric.spring.boot.chaos.monkey.endpoints.dto; + +import de.codecentric.spring.boot.chaos.monkey.configuration.AssaultProperties; +import org.junit.jupiter.api.Test; +import org.mockito.MockedConstruction; +import tools.jackson.databind.DatabindException; +import tools.jackson.databind.ObjectMapper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.*; + +class AssaultPropertiesUpdateTest { + + @Test + void handlesDatabindException() { + final AssaultProperties properties = new AssaultProperties(); + final AssaultPropertiesUpdate update = new AssaultPropertiesUpdate(); + try (final MockedConstruction mockedConstruction = mockConstruction(ObjectMapper.class, + (mock, context) -> when(mock.updateValue(properties, update)).thenThrow(DatabindException.class))) { + assertThatThrownBy(() -> update.applyTo(properties)).isInstanceOf(IllegalArgumentException.class); + } + } +} diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdateTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdateTest.java new file mode 100644 index 00000000..a766f28b --- /dev/null +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/endpoints/dto/WatcherPropertiesUpdateTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.codecentric.spring.boot.chaos.monkey.endpoints.dto; + +import de.codecentric.spring.boot.chaos.monkey.configuration.WatcherProperties; +import org.junit.jupiter.api.Test; +import org.mockito.MockedConstruction; +import tools.jackson.databind.DatabindException; +import tools.jackson.databind.ObjectMapper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mockConstruction; +import static org.mockito.Mockito.when; + +class WatcherPropertiesUpdateTest { + + @Test + void handlesDatabindException() { + final WatcherProperties properties = new WatcherProperties(); + final WatcherPropertiesUpdate update = new WatcherPropertiesUpdate(); + try (final MockedConstruction mockedConstruction = mockConstruction(ObjectMapper.class, + (mock, context) -> when(mock.updateValue(properties, update)).thenThrow(DatabindException.class))) { + assertThatThrownBy(() -> update.applyTo(properties)).isInstanceOf(IllegalArgumentException.class); + } + } +} diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/SpringBootHealthIndicatorAdviceIntegrationTest.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/SpringBootHealthIndicatorAdviceIntegrationTest.java index 7e84f7d0..10a4aef6 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/SpringBootHealthIndicatorAdviceIntegrationTest.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/chaos/monkey/watcher/advice/SpringBootHealthIndicatorAdviceIntegrationTest.java @@ -22,8 +22,9 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.health.contributor.Health; +import org.springframework.boot.health.contributor.HealthIndicator; +import org.springframework.boot.health.contributor.Status; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; @@ -40,8 +41,8 @@ class HealthIndicatorEnabledIntegrationTest { @Test public void testIndicatorsAreDown() { - healthIndicators.forEach( - healthIndicator -> assertThat(healthIndicator.getHealth(Boolean.TRUE).getStatus()).isEqualTo(Health.down().build().getStatus())); + healthIndicators.forEach(healthIndicator -> assertThat(healthIndicator.health(Boolean.TRUE)).isNotNull().extracting(Health::getStatus) + .isEqualTo(Status.DOWN)); } } @@ -56,8 +57,8 @@ class HealthIndicatorDisabledIntegrationTest { @Test public void testIndicatorsAreUp() { - healthIndicators.forEach( - healthIndicator -> assertThat(healthIndicator.getHealth(Boolean.TRUE).getStatus()).isEqualTo(Health.up().build().getStatus())); + healthIndicators.forEach(healthIndicator -> assertThat(healthIndicator.health(Boolean.TRUE)).isNotNull().extracting(Health::getStatus) + .isEqualTo(Status.UP)); } } } diff --git a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/demo/chaos/monkey/ChaosDemoApplication.java b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/demo/chaos/monkey/ChaosDemoApplication.java index ffea7dd6..87f88287 100644 --- a/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/demo/chaos/monkey/ChaosDemoApplication.java +++ b/chaos-monkey-spring-boot/src/test/java/de/codecentric/spring/boot/demo/chaos/monkey/ChaosDemoApplication.java @@ -25,7 +25,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.boot.restclient.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.client.RestTemplate; @@ -44,7 +44,7 @@ public static void main(String[] args) { @Bean public RestTemplate restTemplateWithTimeout(final TestOutgoingConfigurationProperties properties, final RestTemplateBuilder restTemplateBuilder) { - return restTemplateBuilder.setReadTimeout(Duration.of(properties.timeOut, ChronoUnit.MILLIS)).build(); + return restTemplateBuilder.readTimeout(Duration.of(properties.timeOut, ChronoUnit.MILLIS)).build(); } @Bean diff --git a/chaos-monkey-spring-boot/src/test/resources/application-test-chaos-monkey-profile.properties b/chaos-monkey-spring-boot/src/test/resources/application-test-chaos-monkey-profile.properties index 4f26664b..ea17844a 100644 --- a/chaos-monkey-spring-boot/src/test/resources/application-test-chaos-monkey-profile.properties +++ b/chaos-monkey-spring-boot/src/test/resources/application-test-chaos-monkey-profile.properties @@ -23,8 +23,8 @@ chaos.monkey.assaults.exception.type=java.lang.RuntimeException chaos.monkey.assaults.exception.arguments[0].className=java.lang.String chaos.monkey.assaults.exception.arguments[0].value='test string' # enable Chaos Monkey endpoint -management.endpoint.chaosmonkey.enabled=true +management.endpoint.chaosmonkey.access=unrestricted management.endpoints.web.exposure.include=chaosmonkey -management.endpoints.enabled-by-default=true +management.endpoints.access.default=unrestricted diff --git a/demo-apps/chaos-monkey-demo-app-ext-jar/pom.xml b/demo-apps/chaos-monkey-demo-app-ext-jar/pom.xml index 8366cd03..ab1587e2 100644 --- a/demo-apps/chaos-monkey-demo-app-ext-jar/pom.xml +++ b/demo-apps/chaos-monkey-demo-app-ext-jar/pom.xml @@ -33,7 +33,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc compile @@ -50,6 +50,11 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-webmvc-test + test + org.springframework.boot spring-boot-devtools diff --git a/demo-apps/chaos-monkey-demo-app-ext-jar/runChaos.sh b/demo-apps/chaos-monkey-demo-app-ext-jar/runChaos.sh index 3fbfc453..b6283392 100755 --- a/demo-apps/chaos-monkey-demo-app-ext-jar/runChaos.sh +++ b/demo-apps/chaos-monkey-demo-app-ext-jar/runChaos.sh @@ -1 +1 @@ -java -cp ./target/chaos-monkey-demo-app-ext-jar-2.3.11-SNAPSHOT.jar -Dloader.path=../../chaos-monkey-spring-boot/target/chaos-monkey-spring-boot-2.3.11-SNAPSHOT-jar-with-dependencies.jar org.springframework.boot.loader.PropertiesLauncher --spring.profiles.active=chaos-monkey +java -cp ./target/chaos-monkey-demo-app-ext-jar-2.3.11-SNAPSHOT.jar -Dloader.path=../../chaos-monkey-spring-boot/target/chaos-monkey-spring-boot-2.3.11-SNAPSHOT-jar-with-dependencies.jar org.springframework.boot.loader.launch.PropertiesLauncher --spring.profiles.active=chaos-monkey diff --git a/demo-apps/chaos-monkey-demo-app-ext-jar/src/main/resources/application.properties b/demo-apps/chaos-monkey-demo-app-ext-jar/src/main/resources/application.properties index 569c0360..ac8911e4 100644 --- a/demo-apps/chaos-monkey-demo-app-ext-jar/src/main/resources/application.properties +++ b/demo-apps/chaos-monkey-demo-app-ext-jar/src/main/resources/application.properties @@ -23,8 +23,8 @@ chaos.monkey.watcher.restController=true chaos.monkey.watcher.service=true chaos.monkey.watcher.repository=false chaos.monkey.assaults.level=1 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* management.server.port=8888 diff --git a/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java b/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java index 6b50643f..30678495 100644 --- a/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java +++ b/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import com.example.chaos.monkey.chaosdemo.ChaosDemoApplication; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,6 +32,7 @@ /** @author Benjamin Wilms */ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource("classpath:application-test.properties") +@AutoConfigureTestRestTemplate public class HelloControllerIntegrationTest { @LocalServerPort diff --git a/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java b/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java index 4ede8fe0..b14c4bf2 100644 --- a/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app-ext-jar/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.web.servlet.MockMvc; /** @author Benjamin Wilms */ diff --git a/demo-apps/chaos-monkey-demo-app-jdbc/pom.xml b/demo-apps/chaos-monkey-demo-app-jdbc/pom.xml index 354463f6..aac5f3a2 100644 --- a/demo-apps/chaos-monkey-demo-app-jdbc/pom.xml +++ b/demo-apps/chaos-monkey-demo-app-jdbc/pom.xml @@ -37,9 +37,13 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc compile + + org.springframework.boot + spring-boot-starter-restclient + org.springframework.boot spring-boot-starter-actuator diff --git a/demo-apps/chaos-monkey-demo-app-naked/pom.xml b/demo-apps/chaos-monkey-demo-app-naked/pom.xml index f2fb68f6..ae3c1ce6 100644 --- a/demo-apps/chaos-monkey-demo-app-naked/pom.xml +++ b/demo-apps/chaos-monkey-demo-app-naked/pom.xml @@ -33,7 +33,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc compile @@ -58,6 +58,11 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-webmvc-test + test + org.springframework.boot spring-boot-devtools diff --git a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java index 5e69d5b0..26fc2359 100644 --- a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.web.servlet.MockMvc; /** @author Benjamin Wilms */ diff --git a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java index 8375196e..76a946d8 100644 --- a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.web.servlet.MockMvc; /** @author Benjamin Wilms */ diff --git a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java index 6b50643f..30678495 100644 --- a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java +++ b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import com.example.chaos.monkey.chaosdemo.ChaosDemoApplication; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,6 +32,7 @@ /** @author Benjamin Wilms */ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource("classpath:application-test.properties") +@AutoConfigureTestRestTemplate public class HelloControllerIntegrationTest { @LocalServerPort diff --git a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java index 970b5b2e..d393c93c 100644 --- a/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app-naked/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java @@ -26,7 +26,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; diff --git a/demo-apps/chaos-monkey-demo-app-unleash-toggles/pom.xml b/demo-apps/chaos-monkey-demo-app-unleash-toggles/pom.xml index 04408823..b568a2d0 100644 --- a/demo-apps/chaos-monkey-demo-app-unleash-toggles/pom.xml +++ b/demo-apps/chaos-monkey-demo-app-unleash-toggles/pom.xml @@ -33,7 +33,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc compile @@ -64,6 +64,11 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-webmvc-test + test + org.springframework.security spring-security-test diff --git a/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/main/resources/application.properties b/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/main/resources/application.properties index c760b4d8..d2a21afd 100644 --- a/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/main/resources/application.properties +++ b/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/main/resources/application.properties @@ -25,8 +25,8 @@ chaos.monkey.watcher.restController=true chaos.monkey.watcher.service=true chaos.monkey.watcher.repository=true chaos.monkey.assaults.level=1 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* management.server.port=8888 diff --git a/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/test/java/com/example/chaos/monkey/toggledemo/controller/HelloControllerIntegrationTest.java b/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/test/java/com/example/chaos/monkey/toggledemo/controller/HelloControllerIntegrationTest.java index e99fe431..0c53e4c9 100644 --- a/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/test/java/com/example/chaos/monkey/toggledemo/controller/HelloControllerIntegrationTest.java +++ b/demo-apps/chaos-monkey-demo-app-unleash-toggles/src/test/java/com/example/chaos/monkey/toggledemo/controller/HelloControllerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import com.example.chaos.monkey.toggledemo.ChaosDemoApplication; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,6 +32,7 @@ /** @author Benjamin Wilms */ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource("classpath:application-test.properties") +@AutoConfigureTestRestTemplate public class HelloControllerIntegrationTest { @LocalServerPort diff --git a/demo-apps/chaos-monkey-demo-app/pom.xml b/demo-apps/chaos-monkey-demo-app/pom.xml index 4635766e..8b6dadd9 100644 --- a/demo-apps/chaos-monkey-demo-app/pom.xml +++ b/demo-apps/chaos-monkey-demo-app/pom.xml @@ -33,7 +33,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc compile @@ -66,6 +66,11 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-webmvc-test + test + org.mockito mockito-core diff --git a/demo-apps/chaos-monkey-demo-app/src/main/resources/application.properties b/demo-apps/chaos-monkey-demo-app/src/main/resources/application.properties index 8478ee7b..abb31bb7 100644 --- a/demo-apps/chaos-monkey-demo-app/src/main/resources/application.properties +++ b/demo-apps/chaos-monkey-demo-app/src/main/resources/application.properties @@ -26,8 +26,8 @@ chaos.monkey.watcher.service=true chaos.monkey.watcher.repository=true chaos.monkey.watcher.beans=helloBean chaos.monkey.assaults.level=1 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* management.server.port=8888 diff --git a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java index 4f1cac53..203a6c96 100644 --- a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import com.example.chaos.monkey.chaosdemo.component.HelloComponent; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.web.servlet.MockMvc; /** @author Benjamin Wilms */ diff --git a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java index 8375196e..76a946d8 100644 --- a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/GreetingRestControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.web.servlet.MockMvc; /** @author Benjamin Wilms */ diff --git a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java index 9d18968e..56443b88 100644 --- a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java +++ b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerIntegrationTest.java @@ -22,14 +22,16 @@ import de.codecentric.spring.boot.chaos.monkey.endpoints.dto.AssaultPropertiesUpdate; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.TestRestTemplate; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; import org.springframework.boot.test.web.server.LocalManagementPort; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; /** @author Benjamin Wilms */ @SpringBootTest(classes = ChaosDemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "chaos.monkey.watcher.controller=true") +@AutoConfigureTestRestTemplate public class HelloControllerIntegrationTest { @Autowired @@ -67,11 +69,14 @@ public void whenExceptionAssaultIsActivatedExpectExceptionIsThrown() { assault.setExceptionsActive(true); assault.setLatencyActive(false); + ResponseEntity response = testRestTemplate.getForEntity("http://localhost:" + managementPort + "/actuator/chaosmonkey", String.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + ResponseEntity assaultResponse = testRestTemplate .postForEntity("http://localhost:" + managementPort + "/actuator/chaosmonkey/assaults", assault, String.class); assertEquals(HttpStatus.OK, assaultResponse.getStatusCode()); - ResponseEntity response = testRestTemplate.getForEntity("/goodbye", String.class); + response = testRestTemplate.getForEntity("/goodbye", String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } } diff --git a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java index 4b87c67c..b56a98df 100644 --- a/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java +++ b/demo-apps/chaos-monkey-demo-app/src/test/java/com/example/chaos/monkey/chaosdemo/controller/HelloControllerTest.java @@ -26,7 +26,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; diff --git a/demo-apps/chaos-monkey-demo-app/src/test/resources/application-component-test.properties b/demo-apps/chaos-monkey-demo-app/src/test/resources/application-component-test.properties index 75fe2300..08b79e5c 100644 --- a/demo-apps/chaos-monkey-demo-app/src/test/resources/application-component-test.properties +++ b/demo-apps/chaos-monkey-demo-app/src/test/resources/application-component-test.properties @@ -24,8 +24,8 @@ chaos.monkey.watcher.restController=false chaos.monkey.watcher.service=false chaos.monkey.watcher.repository=false chaos.monkey.assaults.level=1 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* management.server.port=8888 diff --git a/demo-apps/chaos-monkey-demo-app/src/test/resources/application.properties b/demo-apps/chaos-monkey-demo-app/src/test/resources/application.properties index ee8e309d..641123c6 100644 --- a/demo-apps/chaos-monkey-demo-app/src/test/resources/application.properties +++ b/demo-apps/chaos-monkey-demo-app/src/test/resources/application.properties @@ -26,8 +26,8 @@ chaos.monkey.watcher.service=false chaos.monkey.watcher.repository=false chaos.monkey.watcher.beans=helloBean chaos.monkey.assaults.level=1 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* diff --git a/demo-apps/chaos-monkey-web-reactive-app/pom.xml b/demo-apps/chaos-monkey-web-reactive-app/pom.xml index 6a44493e..26058b94 100644 --- a/demo-apps/chaos-monkey-web-reactive-app/pom.xml +++ b/demo-apps/chaos-monkey-web-reactive-app/pom.xml @@ -35,6 +35,14 @@ org.springframework.boot spring-boot-starter-webflux + + org.springframework.boot + spring-boot-starter-restclient + + + org.springframework.boot + spring-boot-starter-webclient + de.codecentric chaos-monkey-spring-boot diff --git a/demo-apps/chaos-monkey-web-reactive-app/src/main/resources/application.properties b/demo-apps/chaos-monkey-web-reactive-app/src/main/resources/application.properties index 085f3d9c..2506b57d 100644 --- a/demo-apps/chaos-monkey-web-reactive-app/src/main/resources/application.properties +++ b/demo-apps/chaos-monkey-web-reactive-app/src/main/resources/application.properties @@ -24,8 +24,8 @@ chaos.monkey.watcher.restController=false chaos.monkey.watcher.service=false chaos.monkey.watcher.repository=false chaos.monkey.assaults.level=3 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* management.server.port=8888 diff --git a/demo-apps/chaos-monkey-web-reactive-app/src/test/resources/application-component-test.properties b/demo-apps/chaos-monkey-web-reactive-app/src/test/resources/application-component-test.properties index 75fe2300..08b79e5c 100644 --- a/demo-apps/chaos-monkey-web-reactive-app/src/test/resources/application-component-test.properties +++ b/demo-apps/chaos-monkey-web-reactive-app/src/test/resources/application-component-test.properties @@ -24,8 +24,8 @@ chaos.monkey.watcher.restController=false chaos.monkey.watcher.service=false chaos.monkey.watcher.repository=false chaos.monkey.assaults.level=1 -management.endpoint.chaosmonkey.enabled=true -management.endpoint.chaosmonkeyjmx.enabled=false +management.endpoint.chaosmonkey.access=unrestricted +management.endpoint.chaosmonkeyjmx.access=none management.endpoints.web.exposure.include=* management.server.port=8888 diff --git a/pom.xml b/pom.xml index 11675e4e..9fdef18f 100644 --- a/pom.xml +++ b/pom.xml @@ -36,15 +36,15 @@ - 3.5.8 - 2024.0.3 - 1.8.0 + 4.0.0 + 2025.1.0 + 3.0.0 10.2.4 - 0.8.13 + 0.8.14 9.0.2 3.2.0 0.6.3