package dev.caskeleton.adapter.outbound.mongo.autoconfigure; import org.junit.jupiter.api.Test; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Configuration; /** Analysis-only probe: how MongoPlatformSettings treats two out-of-contract inputs. */ class AnalysisPlatformSettingsBindingProbe { @Test void changeStreamsTrueIsAcceptedAndDiscarded() { new ApplicationContextRunner() .withUserConfiguration(PlatformSettingsOnly.class) .withPropertyValues("ca-skeleton.persistence-mongo.platform.change-streams=true") .run( context -> { Throwable failure = context.getStartupFailure(); System.out.println("changeStreams.contextFailed=" + (failure != null)); if (failure == null) { MongoPlatformSettings settings = context.getBean(MongoPlatformSettings.class); System.out.println("changeStreams.boundValue=" + settings.changeStreams()); System.out.println("changeStreams.transactions=" + settings.transactions()); System.out.println( "changeStreams.requiredSecondaries=" + settings.requiredSecondaries()); } }); } @Test void transactionsTrueIsAcceptedAndKept() { new ApplicationContextRunner() .withUserConfiguration(PlatformSettingsOnly.class) .withPropertyValues("ca-skeleton.persistence-mongo.platform.transactions=true") .run( context -> { Throwable failure = context.getStartupFailure(); System.out.println("transactions.contextFailed=" + (failure != null)); if (failure == null) { System.out.println( "transactions.boundValue=" + context.getBean(MongoPlatformSettings.class).transactions()); } }); } @Test void negativeRequiredSecondariesIsRefused() { new ApplicationContextRunner() .withUserConfiguration(PlatformSettingsOnly.class) .withPropertyValues("ca-skeleton.persistence-mongo.platform.required-secondaries=-1") .run( context -> { Throwable failure = context.getStartupFailure(); System.out.println("negativeSecondaries.contextFailed=" + (failure != null)); if (failure != null) { System.out.println( "negativeSecondaries.failureType=" + rootCause(failure).getClass().getName()); } }); } private static Throwable rootCause(Throwable failure) { Throwable current = failure; while (current.getCause() != null) { current = current.getCause(); } return current; } @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(MongoPlatformSettings.class) static class PlatformSettingsOnly {} }