From 3eacf6dd5692646d72d5fb04eb7ea8e252589b37 Mon Sep 17 00:00:00 2001 From: Ulf Sauer Date: Tue, 6 Jul 2021 14:18:52 +0200 Subject: [PATCH 1/4] Test custom EncryptionEventListener bean registration --- ...EncryptionWithCustomEventListenerTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java diff --git a/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java b/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java new file mode 100644 index 0000000..2b19d6e --- /dev/null +++ b/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java @@ -0,0 +1,45 @@ +package com.bol.system.autoconfig; + +import com.bol.config.EncryptAutoConfiguration; +import com.bol.crypt.CryptVault; +import com.bol.secure.AbstractEncryptionEventListener; +import com.bol.secure.CachedEncryptionEventListener; +import com.bol.secure.ReflectionEncryptionEventListener; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@ActiveProfiles("autoconfig-short") +@RunWith(SpringRunner.class) +@EnableAutoConfiguration +@SpringBootTest(classes = {EncryptionWithCustomEventListenerTest.class, EncryptionWithCustomEventListenerTest.AbstractEventListenerConfig.class, EncryptAutoConfiguration.class}) +public class EncryptionWithCustomEventListenerTest { + + @Autowired(required = false) CryptVault cryptVault; + @Autowired(required = false) AbstractEncryptionEventListener eventListener; + + @Test + public void sanityTest() { + assertThat(cryptVault).isNotNull(); + assertThat(eventListener).isNotNull(); + assertThat(eventListener).isInstanceOf(ReflectionEncryptionEventListener.class); + } + + + @TestConfiguration + static class AbstractEventListenerConfig { + @Bean + ReflectionEncryptionEventListener encryptionEventListener(CryptVault cryptVault) { + return new ReflectionEncryptionEventListener(cryptVault); + } + } +} From 58f0897fa7062de900e81ea54ed0004f5e78001f Mon Sep 17 00:00:00 2001 From: Ulf Sauer Date: Tue, 6 Jul 2021 14:21:02 +0200 Subject: [PATCH 2/4] Test custom AbstractEncryptionEventListener bean registration --- ...onWithCustomAbstractEventListenerTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/bol/system/autoconfig/EncryptionWithCustomAbstractEventListenerTest.java diff --git a/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomAbstractEventListenerTest.java b/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomAbstractEventListenerTest.java new file mode 100644 index 0000000..48230e2 --- /dev/null +++ b/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomAbstractEventListenerTest.java @@ -0,0 +1,45 @@ +package com.bol.system.autoconfig; + +import com.bol.config.EncryptAutoConfiguration; +import com.bol.crypt.CryptVault; +import com.bol.secure.AbstractEncryptionEventListener; +import com.bol.secure.CachedEncryptionEventListener; +import com.bol.secure.ReflectionEncryptionEventListener; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@ActiveProfiles("autoconfig-short") +@RunWith(SpringRunner.class) +@EnableAutoConfiguration +@SpringBootTest(classes = {EncryptionWithCustomAbstractEventListenerTest.class, EncryptionWithCustomAbstractEventListenerTest.AbstractEventListenerConfig.class, EncryptAutoConfiguration.class}) +public class EncryptionWithCustomAbstractEventListenerTest { + + @Autowired(required = false) CryptVault cryptVault; + @Autowired(required = false) AbstractEncryptionEventListener eventListener; + + @Test + public void sanityTest() { + assertThat(cryptVault).isNotNull(); + assertThat(eventListener).isNotNull(); + assertThat(eventListener).isInstanceOf(ReflectionEncryptionEventListener.class); + } + + + @TestConfiguration + static class AbstractEventListenerConfig { + @Bean + AbstractEncryptionEventListener encryptionEventListener(CryptVault cryptVault) { + return new ReflectionEncryptionEventListener(cryptVault); + } + } +} From a226e0a002f54753ba0ff934b473b4df064a2d35 Mon Sep 17 00:00:00 2001 From: Ulf Sauer Date: Tue, 6 Jul 2021 14:23:58 +0200 Subject: [PATCH 3/4] Fix bean condition for AbstractEncryptionEventListener --- src/main/java/com/bol/config/EncryptAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bol/config/EncryptAutoConfiguration.java b/src/main/java/com/bol/config/EncryptAutoConfiguration.java index e227322..806f27c 100644 --- a/src/main/java/com/bol/config/EncryptAutoConfiguration.java +++ b/src/main/java/com/bol/config/EncryptAutoConfiguration.java @@ -27,7 +27,7 @@ CryptVault cryptVault(EncryptConfigurationProperties properties) { } @Bean - @ConditionalOnMissingBean({ReflectionEncryptionEventListener.class, CachedEncryptionEventListener.class}) + @ConditionalOnMissingBean({AbstractEncryptionEventListener.class}) @ConditionalOnBean(CryptVault.class) AbstractEncryptionEventListener encryptionEventListener(CryptVault cryptVault, EncryptConfigurationProperties properties) { AbstractEncryptionEventListener eventListener; From 2244dbd8ce104d8f3f06a6ef20a524fb398fbe95 Mon Sep 17 00:00:00 2001 From: Ulf Sauer Date: Wed, 7 Jul 2021 10:45:46 +0200 Subject: [PATCH 4/4] Revert "Test custom EncryptionEventListener bean registration" This reverts commit 3eacf6dd5692646d72d5fb04eb7ea8e252589b37. --- ...EncryptionWithCustomEventListenerTest.java | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java diff --git a/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java b/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java deleted file mode 100644 index 2b19d6e..0000000 --- a/src/test/java/com/bol/system/autoconfig/EncryptionWithCustomEventListenerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.bol.system.autoconfig; - -import com.bol.config.EncryptAutoConfiguration; -import com.bol.crypt.CryptVault; -import com.bol.secure.AbstractEncryptionEventListener; -import com.bol.secure.CachedEncryptionEventListener; -import com.bol.secure.ReflectionEncryptionEventListener; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@ActiveProfiles("autoconfig-short") -@RunWith(SpringRunner.class) -@EnableAutoConfiguration -@SpringBootTest(classes = {EncryptionWithCustomEventListenerTest.class, EncryptionWithCustomEventListenerTest.AbstractEventListenerConfig.class, EncryptAutoConfiguration.class}) -public class EncryptionWithCustomEventListenerTest { - - @Autowired(required = false) CryptVault cryptVault; - @Autowired(required = false) AbstractEncryptionEventListener eventListener; - - @Test - public void sanityTest() { - assertThat(cryptVault).isNotNull(); - assertThat(eventListener).isNotNull(); - assertThat(eventListener).isInstanceOf(ReflectionEncryptionEventListener.class); - } - - - @TestConfiguration - static class AbstractEventListenerConfig { - @Bean - ReflectionEncryptionEventListener encryptionEventListener(CryptVault cryptVault) { - return new ReflectionEncryptionEventListener(cryptVault); - } - } -}