Enhanced messaging support for stubrunner (#1389)
Co-authored-by: Tim Ysewyn <tysewyn@pivotal.io>
This commit is contained in:
committed by
Olga Maciaszek-Sharma
parent
50b36c49c7
commit
174c3565dd
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Object> contractVerifierMessaging(
|
||||
MessageVerifier<Object> exchange) {
|
||||
return new ContractVerifierMessaging<>(exchange);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user