当我使用embeddedkafka和SpringContract测试执行SpringContract测试时,会出现此错误。当我使用来自“ldap\u group\u topic”的消息时,问题似乎出现了。错误是:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ldap_group_topic' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:812) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1282) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1115) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:47) [spring-cloud-contract-verifier-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:61) [spring-cloud-contract-verifier-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:29) [spring-cloud-contract-verifier-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:59) [spring-cloud-contract-verifier-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:30) [spring-cloud-contract-verifier-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging.receive(ContractVerifierMessaging.java:44) [spring-cloud-contract-verifier-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.arkcase.ldap.authority.org.arkcase.ldap.authority.SyncTest.validate_ldapGroupTopicFields(SyncTest.java:30) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686) [junit-platform-commons-1.6.2.jar:1.6.2]
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) [junit-jupiter-engine-5.6.2.jar:5.6.2]
atorg.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) ~[junit-jupiter-engine-5.6.2]
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:212) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:208) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71) ~[junit-jupiter-engine-5.6.2.jar:5.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_191]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_191]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) ~[junit-platform-engine-1.6.2.jar:1.6.2]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248) ~[junit-platform-launcher-1.6.2.jar:1.6.2]
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211) ~[junit-platform-launcher-1.6.2.jar:1.6.2]
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226) ~[junit-platform-launcher-1.6.2.jar:1.6.2]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199) ~[junit-platform-launcher-1.6.2.jar:1.6.2]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132) ~[junit-platform-launcher-1.6.2.jar:1.6.2]
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74) ~[junit5-rt.jar:na]
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) ~[junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) ~[junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) ~[junit-rt.jar:na]
java.lang.IllegalStateException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ldap_group_topic' available
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:55)
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:61)
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:29)
at org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:59)
at org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:30)
at org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging.receive(ContractVerifierMessaging.java:44)
at org.arkcase.ldap.authority.org.arkcase.ldap.authority.SyncTest.validate_ldapGroupTopicFields(SyncTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:212)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:208)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ldap_group_topic' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:812)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1282)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1115)
at org.springframework.cloud.contract.verifier.messaging.stream.StreamPollableChannelMessageReceiver.receive(StreamPollableChannelMessageReceiver.java:47)
... 69 more
不管怎样,这是我的代码:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@AutoConfigureMessageVerifier
@EmbeddedKafka(partitions = 1, topics = {"ldap_group_topic"})
@ActiveProfiles("test")
public abstract class BaseContractsTestClass
{
public static final String LDAP_GROUP_TOPIC_NAME = "ldap_group_topic";
@Autowired
private KafkaTemplate<String, Object> kafkaAvroTemplate;
@Autowired
private LdapSyncTopicProperties topicProperties;
@Autowired
LdapSyncLogProducer ldapSyncLogProducer;
@Before
public void setup()
{
ldapSyncLogProducer = new LdapSyncLogProducer(kafkaAvroTemplate, topicProperties);
}
public void addSyncedGroup()
{
PodamFactory factory = new PodamFactoryImpl();
factory.getStrategy().setDefaultNumberOfCollectionElements(2);
CharSequenceManufacturer charSequenceManufacturer = new CharSequenceManufacturer();
factory.getStrategy().addOrReplaceTypeManufacturer(CharSequence.class, charSequenceManufacturer);
Group groupEvent = factory.manufacturePojo(Group.class);
this.ldapSyncLogProducer.sendGroupMessage(groupEvent);
}
private class CharSequenceManufacturer implements TypeManufacturer<CharSequence>
{
@Override
public CharSequence getType(DataProviderStrategy strategy, AttributeMetadata attributeMetadata,
Map<String, Type> genericTypesArgumentsMap)
{
StringBuilder buff = new StringBuilder();
while (buff.length() < 10)
{
buff.append(PodamUtils.getNiceCharacter());
}
return buff.toString();
}
}
}
合同文件:
package contracts.org.arkcase.audit.api
import org.springframework.cloud.contract.spec.Contract
Contract.make {
description "ldap_group_topic fields test"
// Label by means of which the output message can be triggered
label 'group-synced'
// input to the contract
input {
// the contract will be triggered by a method
triggeredBy('addSyncedGroup()')
}
// output message of the contract
outputMessage {
// destination to which the output message will be sent
sentTo 'ldap_group_topic'
// the body of the output message
body(
"ldapSyncId": $(anyNonEmptyString()),
"id": $(anyNonEmptyString()),
"distinguishedName": $(anyNonEmptyString()),
"description": $(anyNonEmptyString()),
"displayName": $(anyNonEmptyString()),
"directoryName": $(anyNonEmptyString()),
"ancestorsString": $(anyNonEmptyString()),
"audit": [
"id": $(anyNonEmptyString()),
"traceId": $(anyNonEmptyString()),
"userId": $(anyNonEmptyString()),
"ipAddress": $(anyNonEmptyString()),
"serviceName": $(anyNonEmptyString()),
"serviceInstance": $(anyNonEmptyString()),
"eventDate": $(anyPositiveInt()),
"eventType": $(anyNonEmptyString()),
"objectId": $(anyNonEmptyString()),
"objectType": $(anyNonEmptyString()),
"parentObjectId": $(anyNonEmptyString()),
"parentObjectType": $(anyNonEmptyString())
]
)
}
}
应用测试.yaml:
spring:
zipkin:
enabled: false
cloud:
discovery.enabled: false
config:
discovery.enabled: false
enabled: false
fail-fast: false
bus:
refresh:
enabled: false
env:
enabled: false
kafka:
bootstrap-servers: ${spring.embedded.kafka.brokers}
consumer:
properties:
"key.serializer": "org.springframework.kafka.support.serializer.JsonSerializer"
"key.deserializer": "org.springframework.kafka.support.serializer.JsonDeserializer"
group-id: groupId
arkcase.kafka:
bootstrapAddress: ${spring.embedded.kafka.brokers}
schemaRegistryAddress: mock://localhost
jwt:
jwt-blacklisted-topic: jwt_blacklisted_topic
jwt-blacklisted-topic-replicas: 1
jwt-blacklisted-topic-partitions: 1
jwt-blacklisted-topic-group-id: jwt_blacklist_${spring.application.name}
retention-ms: "86400000"
eureka:
client:
register-with-eureka: false
fetch-registry: false
enabled: false
配置:
@Configuration
public class KafkaTestConfiguration
{
@Bean
KafkaStubMessagesInitializer kafkaStubMessagesInitializer()
{
return new ContractVerifierMessageInitializer();
}
}
承包商验证消息初始化器
public class ContractVerifierMessageInitializer implements KafkaStubMessagesInitializer
{
@ClassRule
public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true, "ldap_group_topic");
@Override
public Map<String, Consumer> initialize(EmbeddedKafkaBroker broker, KafkaProperties kafkaProperties)
{
Map<String, Consumer> map = new HashMap<>();
for (String topic : broker.getTopics())
{
map.put(topic, prepareListenerr(broker, topic, kafkaProperties));
}
return map;
}
Consumer prepareListenerr(EmbeddedKafkaBroker broker, String destination, KafkaProperties kafkaProperties)
{
Map<String, Object> consumerProperties = KafkaTestUtils.consumerProps(randomUUID().toString(), "false", broker);
consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
consumerProperties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, kafkaProperties.getConsumer().getKeyDeserializer());
consumerProperties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, kafkaProperties.getConsumer().getValueDeserializer());
consumerProperties.put("schema.registry.url", kafkaProperties.getProperties().get("schema.registry.url"));
consumerProperties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, embeddedKafka.getEmbeddedKafka().getBrokersAsString());
DefaultKafkaConsumerFactory<String, String> consumerFactory = new DefaultKafkaConsumerFactory<>(
consumerProperties);
Consumer<String, String> consumer = consumerFactory.createConsumer();
broker.consumeFromAnEmbeddedTopic(consumer, destination);
return consumer;
}
}
在目标文件夹中生成的协定测试:
public class SyncTest extends BaseContractsTestClass {
@Inject ContractVerifierMessaging contractVerifierMessaging;
@Inject ContractVerifierObjectMapper contractVerifierObjectMapper;
@Test
public void validate_ldapGroupTopicFields() throws Exception {
// when:
addSyncedGroup();
// then:
ContractVerifierMessage response = contractVerifierMessaging.receive("ldap_group_topic");
assertThat(response).isNotNull();
// and:
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload()));
assertThatJson(parsedJson).field("['ldapSyncId']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['id']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['distinguishedName']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['description']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['displayName']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['directoryName']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['ancestorsString']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['id']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['traceId']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['userId']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['ipAddress']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['serviceName']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['serviceInstance']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['eventDate']").matches("([1-9]\\d*)");
assertThatJson(parsedJson).field("['audit']").field("['eventType']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['objectId']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['objectType']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['parentObjectId']").matches("[\\S\\s]+");
assertThatJson(parsedJson).field("['audit']").field("['parentObjectType']").matches("[\\S\\s]+");
}
}
暂无答案!
目前还没有任何答案,快来回答吧!