From 174c3565dd414432efd0b0d1f3e155c7abe6b5a8 Mon Sep 17 00:00:00 2001 From: Tim Ysewyn Date: Wed, 29 Apr 2020 15:54:29 +0200 Subject: [PATCH] Enhanced messaging support for stubrunner (#1389) Co-authored-by: Tim Ysewyn --- .../server/EnableStubRunnerServer.java | 4 +- ....java => StubRunnerAutoConfiguration.java} | 25 +++--- .../StubRunnerAutoConfigurationTests.java | 68 ++++++++++++++++ ...actVerifierAmqpAutoConfigurationTests.java | 61 ++++++++++++++ .../AutoConfigureMessageVerifierTests.java | 58 ++++++++++++++ ...ntractVerifierCamelConfigurationTests.java | 66 ++++++++++++++++ ...VerifierIntegrationConfigurationTests.java | 44 +++++++++++ ...ContractVerifierJmsConfigurationTests.java | 64 +++++++++++++++ ...ntractVerifierKafkaConfigurationTests.java | 79 +++++++++++++++++++ ...ontractVerifierAutoConfigurationTests.java | 42 ++++++++++ ...tVerifierStreamAutoConfigurationTests.java | 65 +++++++++++++++ 11 files changed, 559 insertions(+), 17 deletions(-) rename spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/{StubRunnerBackupAutoConfiguration.java => StubRunnerAutoConfiguration.java} (57%) create mode 100644 spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/amqp/ContractVerifierAmqpAutoConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/boot/AutoConfigureMessageVerifierTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/jms/ContractVerifierJmsConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/kafka/ContractVerifierKafkaConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierAutoConfigurationTests.java create mode 100644 spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfigurationTests.java diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/EnableStubRunnerServer.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/EnableStubRunnerServer.java index 6103a18edb..555c33944f 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/EnableStubRunnerServer.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/EnableStubRunnerServer.java @@ -29,13 +29,13 @@ import org.springframework.context.annotation.Import; /** * Annotation to enable a Stub runner server. * @author Dave Syer + * @author Tim Ysewyn */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@Import({ HttpStubsController.class, TriggerController.class, - StubRunnerConfiguration.class }) +@Import({ HttpStubsController.class, StubRunnerConfiguration.class }) public @interface EnableStubRunnerServer { } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfiguration.java similarity index 57% rename from spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java rename to spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfiguration.java index 03499162cc..596c469efa 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerBackupAutoConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfiguration.java @@ -16,29 +16,24 @@ package org.springframework.cloud.contract.stubrunner.server; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; -import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging; -import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; /** * @author Marcin Grzejszczak + * @author Tim Ysewyn */ @Configuration(proxyBeanMethods = false) -class StubRunnerBackupAutoConfiguration { +class StubRunnerAutoConfiguration { - @Bean - @ConditionalOnMissingBean - public MessageVerifier contractVerifierMessageExchange() { - return new NoOpStubMessages(); - } + @ConditionalOnProperty(name = "stubrunner.messaging.enabled", havingValue = "true", + matchIfMissing = true) + @AutoConfigureMessageVerifier + @Import({ TriggerController.class }) + static class StubRunnerMessagingAutoConfiguration { - @Bean - public ContractVerifierMessaging contractVerifierMessaging( - MessageVerifier exchange) { - return new ContractVerifierMessaging<>(exchange); } } diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfigurationTests.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfigurationTests.java new file mode 100644 index 0000000000..234310ae4a --- /dev/null +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/server/StubRunnerAutoConfigurationTests.java @@ -0,0 +1,68 @@ +/* + * Copyright 2020-2020 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.cloud.contract.stubrunner.server; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration; +import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class StubRunnerAutoConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(StubRunnerConfiguration.class, + StubRunnerAutoConfiguration.class)); + + @Test + public void shouldCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(ContractVerifierMessaging.class)) + .hasSize(1); + assertThat(context.getBeansOfType(TriggerController.class)).hasSize(1); + }); + } + + @Test + public void shouldNotCreateBeansWhenDisabled() { + this.contextRunner.withPropertyValues("stubrunner.messaging.enabled=false") + .run((context) -> { + assertThat(context.getBeansOfType(ContractVerifierMessaging.class)) + .hasSize(0); + assertThat(context.getBeansOfType(TriggerController.class)) + .hasSize(0); + }); + } + + @Test + public void shouldCreateBeansWhenExplicitlyEnabled() { + this.contextRunner.withPropertyValues("stubrunner.messaging.enabled=true") + .run((context) -> { + assertThat(context.getBeansOfType(ContractVerifierMessaging.class)) + .hasSize(1); + assertThat(context.getBeansOfType(TriggerController.class)) + .hasSize(1); + }); + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/amqp/ContractVerifierAmqpAutoConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/amqp/ContractVerifierAmqpAutoConfigurationTests.java new file mode 100644 index 0000000000..46daeb629f --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/amqp/ContractVerifierAmqpAutoConfigurationTests.java @@ -0,0 +1,61 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.amqp; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class ContractVerifierAmqpAutoConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class, + ContractVerifierAmqpAutoConfiguration.class, + RabbitMockConnectionFactoryAutoConfiguration.class)); + + @Test + public void shouldNotCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(SpringAmqpStubMessages.class)).hasSize(0); + assertThat(context.getBeansOfType(ContractVerifierHelper.class)).hasSize(0); + }); + } + + @Test + public void shouldNotCreateBeansWhenDisabled() { + this.contextRunner.withPropertyValues("stubrunner.amqp.enabled=false") + .run((context) -> { + assertThat(context.getBeansOfType(SpringAmqpStubMessages.class)) + .hasSize(0); + assertThat(context.getBeansOfType(ContractVerifierHelper.class)) + .hasSize(0); + }); + } + + @Test + public void shouldCreateBeansWhenExplicitlyEnabled() { + // TODO + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/boot/AutoConfigureMessageVerifierTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/boot/AutoConfigureMessageVerifierTests.java new file mode 100644 index 0000000000..a37f78b061 --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/boot/AutoConfigureMessageVerifierTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.boot; + +import org.junit.Test; + +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.contract.verifier.messaging.MessageVerifierSender; +import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.kafka.core.KafkaTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class AutoConfigureMessageVerifierTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withUserConfiguration(Configuration.class); + + @Test + public void shouldConfigureForNoOpWhenMissingImplementation() { + this.contextRunner + .withClassLoader(new FilteredClassLoader(org.apache.camel.Message.class, + org.springframework.messaging.Message.class, JmsTemplate.class, + KafkaTemplate.class, RabbitTemplate.class, EnableBinding.class)) + .run((context) -> { + assertThat(context.getBeansOfType(MessageVerifierSender.class)) + .hasSize(1); + assertThat(context.getBeansOfType(NoOpStubMessages.class)).hasSize(1); + }); + } + + @AutoConfigureMessageVerifier + private static class Configuration { + + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfigurationTests.java new file mode 100644 index 0000000000..18eb9a24ee --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/camel/ContractVerifierCamelConfigurationTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.camel; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class ContractVerifierCamelConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(ContractVerifierCamelConfiguration.class)); + + @Test + public void shouldCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(CamelStubMessages.class)).hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierCamelHelper.class)) + .hasSize(1); + }); + } + + @Test + public void shouldNotCreateBeansWhenDisabled() { + this.contextRunner.withPropertyValues("stubrunner.camel.enabled=false") + .run((context) -> { + assertThat(context.getBeansOfType(CamelStubMessages.class)) + .hasSize(0); + assertThat(context.getBeansOfType(ContractVerifierCamelHelper.class)) + .hasSize(0); + }); + } + + @Test + public void shouldCreateBeansWhenExplicitlyEnabled() { + this.contextRunner.withPropertyValues("stubrunner.camel.enabled=true") + .run((context) -> { + assertThat(context.getBeansOfType(CamelStubMessages.class)) + .hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierCamelHelper.class)) + .hasSize(1); + }); + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfigurationTests.java new file mode 100644 index 0000000000..ba1dff955b --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/integration/ContractVerifierIntegrationConfigurationTests.java @@ -0,0 +1,44 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.integration; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class ContractVerifierIntegrationConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations + .of(ContractVerifierIntegrationConfiguration.class)); + + @Test + public void shouldCreateBeansWhenOnClasspath() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(SpringIntegrationStubMessages.class)) + .hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierHelper.class)).hasSize(1); + }); + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/jms/ContractVerifierJmsConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/jms/ContractVerifierJmsConfigurationTests.java new file mode 100644 index 0000000000..5046186a00 --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/jms/ContractVerifierJmsConfigurationTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.jms; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class ContractVerifierJmsConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(ContractVerifierJmsConfiguration.class)); + + @Test + public void shouldCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(JmsStubMessages.class)).hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierJmsHelper.class)) + .hasSize(1); + }); + } + + @Test + public void shouldNotCreateBeansWhenDisabled() { + this.contextRunner.withPropertyValues("stubrunner.jms.enabled=false") + .run((context) -> { + assertThat(context.getBeansOfType(JmsStubMessages.class)).hasSize(0); + assertThat(context.getBeansOfType(ContractVerifierJmsHelper.class)) + .hasSize(0); + }); + } + + @Test + public void shouldCreateBeansWhenExplicitlyEnabled() { + this.contextRunner.withPropertyValues("stubrunner.jms.enabled=true") + .run((context) -> { + assertThat(context.getBeansOfType(JmsStubMessages.class)).hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierJmsHelper.class)) + .hasSize(1); + }); + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/kafka/ContractVerifierKafkaConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/kafka/ContractVerifierKafkaConfigurationTests.java new file mode 100644 index 0000000000..058081856a --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/kafka/ContractVerifierKafkaConfigurationTests.java @@ -0,0 +1,79 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.kafka; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.kafka.test.EmbeddedKafkaBroker; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class ContractVerifierKafkaConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class, + ContractVerifierKafkaConfiguration.class)) + .withUserConfiguration(CustomConfiguration.class); + + @Test + public void shouldCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(KafkaStubMessages.class)).hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierKafkaHelper.class)) + .hasSize(1); + }); + } + + @Test + public void shouldNotCreateBeansWhenDisabled() { + this.contextRunner.withPropertyValues("stubrunner.kafka.enabled=false") + .run((context) -> { + assertThat(context.getBeansOfType(KafkaStubMessages.class)) + .hasSize(0); + assertThat(context.getBeansOfType(ContractVerifierKafkaHelper.class)) + .hasSize(0); + }); + } + + @Test + public void shouldCreateBeansWhenExplicitlyEnabled() { + this.contextRunner.withPropertyValues("stubrunner.kafka.enabled=true") + .run((context) -> { + assertThat(context.getBeansOfType(KafkaStubMessages.class)) + .hasSize(1); + assertThat(context.getBeansOfType(ContractVerifierKafkaHelper.class)) + .hasSize(1); + }); + } + + static class CustomConfiguration { + + @Bean + public EmbeddedKafkaBroker embeddedKafkaBroker() { + return new EmbeddedKafkaBroker(1); + } + + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierAutoConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierAutoConfigurationTests.java new file mode 100644 index 0000000000..58bb8f26bc --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/noop/NoOpContractVerifierAutoConfigurationTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.noop; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class NoOpContractVerifierAutoConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(NoOpContractVerifierAutoConfiguration.class)); + + @Test + public void shouldCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(NoOpStubMessages.class)).hasSize(1); + }); + } + +} diff --git a/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfigurationTests.java b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfigurationTests.java new file mode 100644 index 0000000000..9ed1fa0b2e --- /dev/null +++ b/spring-cloud-contract-verifier/src/test/java/org/springframework/cloud/contract/verifier/messaging/stream/ContractVerifierStreamAutoConfigurationTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2020-2020 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.cloud.contract.verifier.messaging.stream; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tim Ysewyn + */ +public class ContractVerifierStreamAutoConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(ContractVerifierStreamAutoConfiguration.class)); + + @Test + public void shouldCreateBeansByDefault() { + this.contextRunner.run((context) -> { + assertThat(context.getBeansOfType(ContractVerifierHelper.class)).hasSize(1); + assertThat(context.getBeansOfType(StreamStubMessages.class)).hasSize(1); + }); + } + + @Test + public void shouldNotCreateBeansWhenDisabled() { + this.contextRunner.withPropertyValues("stubrunner.stream.enabled=false") + .run((context) -> { + assertThat(context.getBeansOfType(ContractVerifierHelper.class)) + .hasSize(0); + assertThat(context.getBeansOfType(StreamStubMessages.class)) + .hasSize(0); + }); + } + + @Test + public void shouldCreateBeansWhenExplicitlyEnabled() { + this.contextRunner.withPropertyValues("stubrunner.stream.enabled=true") + .run((context) -> { + assertThat(context.getBeansOfType(ContractVerifierHelper.class)) + .hasSize(1); + assertThat(context.getBeansOfType(StreamStubMessages.class)) + .hasSize(1); + }); + } + +}