-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-342 - Allow disabling event externalization.
We now expose spring.modulith.events.externalization.enabled that can be set to false to disable the event externalization completely. Useful in test cases, for example.
- Loading branch information
Showing
11 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...gframework/modulith/events/amqp/RabbitEventExternalizerConfigurationIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2023 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 org.springframework.modulith.events.amqp; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.amqp.rabbit.core.RabbitMessageOperations; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.modulith.events.EventExternalizationConfiguration; | ||
import org.springframework.modulith.events.support.DelegatingEventExternalizer; | ||
|
||
/** | ||
* Integration tests for {@link RabbitEventExternalizerConfiguration}. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 1.1 | ||
*/ | ||
class RabbitEventExternalizerConfigurationIntegrationTests { | ||
|
||
@Test // GH-342 | ||
void registersExternalizerByDefault() { | ||
|
||
basicSetup() | ||
.run(ctxt -> { | ||
assertThat(ctxt).hasSingleBean(DelegatingEventExternalizer.class); | ||
}); | ||
} | ||
|
||
@Test // GH-342 | ||
void disablesExternalizationIfConfigured() { | ||
|
||
basicSetup() | ||
.withPropertyValues("spring.modulith.events.externalization.enabled=false") | ||
.run(ctxt -> { | ||
assertThat(ctxt).doesNotHaveBean(DelegatingEventExternalizer.class); | ||
}); | ||
} | ||
|
||
private ApplicationContextRunner basicSetup() { | ||
|
||
return new ApplicationContextRunner() | ||
.withConfiguration( | ||
AutoConfigurations.of(RabbitEventExternalizerConfiguration.class)) | ||
.withBean(EventExternalizationConfiguration.class, () -> EventExternalizationConfiguration.disabled()) | ||
.withBean(RabbitMessageOperations.class, () -> mock(RabbitMessageOperations.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...pringframework/modulith/events/jms/JmsEventExternalizerConfigurationIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 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 org.springframework.modulith.events.jms; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.jms.core.JmsOperations; | ||
import org.springframework.modulith.events.EventExternalizationConfiguration; | ||
import org.springframework.modulith.events.core.EventSerializer; | ||
import org.springframework.modulith.events.support.DelegatingEventExternalizer; | ||
|
||
/** | ||
* Integration tests for {@link JmsEventExternalizerConfiguration}. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 1.1 | ||
*/ | ||
class JmsEventExternalizerConfigurationIntegrationTests { | ||
|
||
@Test // GH-342 | ||
void registersExternalizerByDefault() { | ||
|
||
basicSetup() | ||
.run(ctxt -> { | ||
assertThat(ctxt).hasSingleBean(DelegatingEventExternalizer.class); | ||
}); | ||
} | ||
|
||
@Test // GH-342 | ||
void disablesExternalizationIfConfigured() { | ||
|
||
basicSetup() | ||
.withPropertyValues("spring.modulith.events.externalization.enabled=false") | ||
.run(ctxt -> { | ||
assertThat(ctxt).doesNotHaveBean(DelegatingEventExternalizer.class); | ||
}); | ||
} | ||
|
||
private ApplicationContextRunner basicSetup() { | ||
|
||
return new ApplicationContextRunner() | ||
.withConfiguration( | ||
AutoConfigurations.of(JmsEventExternalizerConfiguration.class)) | ||
.withBean(EventExternalizationConfiguration.class, () -> EventExternalizationConfiguration.disabled()) | ||
.withBean(EventSerializer.class, () -> mock(EventSerializer.class)) | ||
.withBean(JmsOperations.class, () -> mock(JmsOperations.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...gframework/modulith/events/kafka/KafkaEventExternalizerConfigurationIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2023 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 org.springframework.modulith.events.kafka; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.kafka.core.KafkaOperations; | ||
import org.springframework.modulith.events.EventExternalizationConfiguration; | ||
import org.springframework.modulith.events.support.DelegatingEventExternalizer; | ||
|
||
/** | ||
* Integration tests for {@link KafkaEventExternalizerConfiguration}. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 1.1 | ||
*/ | ||
class KafkaEventExternalizerConfigurationIntegrationTests { | ||
|
||
@Test // GH-342 | ||
void registersExternalizerByDefault() { | ||
|
||
basicSetup() | ||
.run(ctxt -> { | ||
assertThat(ctxt).hasSingleBean(DelegatingEventExternalizer.class); | ||
}); | ||
} | ||
|
||
@Test // GH-342 | ||
void disablesExternalizationIfConfigured() { | ||
|
||
basicSetup() | ||
.withPropertyValues("spring.modulith.events.externalization.enabled=false") | ||
.run(ctxt -> { | ||
assertThat(ctxt).doesNotHaveBean(DelegatingEventExternalizer.class); | ||
}); | ||
} | ||
|
||
private ApplicationContextRunner basicSetup() { | ||
|
||
return new ApplicationContextRunner() | ||
.withConfiguration( | ||
AutoConfigurations.of(KafkaEventExternalizerConfiguration.class)) | ||
.withBean(EventExternalizationConfiguration.class, () -> EventExternalizationConfiguration.disabled()) | ||
.withBean(KafkaOperations.class, () -> mock(KafkaOperations.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters