Skip to content

Commit 4dc75a8

Browse files
committed
test: SqsOutboundChannelAdapterParserTest
1 parent 9aac595 commit 4dc75a8

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

int-aws-support/src/main/java/org/springframework/integration/aws/config/xml/SqsOutboundChannelAdapterParser.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.springframework.integration.aws.config.xml;
22

3+
import org.springframework.beans.factory.config.TypedStringValue;
34
import org.springframework.beans.factory.support.AbstractBeanDefinition;
45
import org.springframework.beans.factory.xml.ParserContext;
56
import org.springframework.integration.aws.outbound.SqsMessageHandler;
@@ -19,17 +20,18 @@ protected AbstractBeanDefinition parseConsumer(Element element, ParserContext pa
1920
.setExpressionValueIfAttributeDefined("message-group-id")
2021
.setExpressionValueIfAttributeDefined("message-deduplication-id")
2122
.setExpressionValueIfAttributeDefined("send-timeout")
22-
.setPropertyReference("outputChannelName", "success-channel")
23+
.setPropertyReferenceIfAttributeDefined("message-converter")
24+
.setPropertyReferenceIfAttributeDefined("outputChannelName", "success-channel")
2325
;
2426

2527
if (element.hasAttribute("sync")) {
2628
var sync = element.getAttribute("sync");
2729
if ("true".equalsIgnoreCase(sync)) {
28-
builder.getBeanDefinitionBuilder().addPropertyValue("async", "false");
30+
builder.getBeanDefinitionBuilder().addPropertyValue("async", new TypedStringValue("false"));
2931
} else if ("false".equalsIgnoreCase(sync)) {
30-
builder.getBeanDefinitionBuilder().addPropertyValue("async", "true");
32+
builder.getBeanDefinitionBuilder().addPropertyValue("async", new TypedStringValue("true"));
3133
} else {
32-
builder.error("expected boolean for sync attribute");
34+
builder.error("expected boolean for 'sync' attribute");
3335
}
3436
}
3537

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.springframework.integration.aws.config.xml;
2+
3+
import org.assertj.core.api.Condition;
4+
import org.assertj.core.api.InstanceOfAssertFactories;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.PropertyValue;
7+
import org.springframework.beans.factory.config.BeanDefinition;
8+
import org.springframework.beans.factory.config.RuntimeBeanReference;
9+
import org.springframework.beans.factory.config.TypedStringValue;
10+
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
11+
import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry;
12+
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
13+
import org.springframework.integration.aws.outbound.SqsMessageHandler;
14+
15+
import java.util.stream.Collectors;
16+
import java.util.stream.Stream;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
class SqsOutboundChannelAdapterParserTest {
21+
22+
private final BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
23+
24+
private final XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(registry);
25+
26+
@Test
27+
void testReader() {
28+
int beansLoaded = xmlBeanDefinitionReader.loadBeanDefinitions("classpath:/sqs-outbound-channel-adapter.xml");
29+
var beans = Stream.of(registry.getBeanDefinitionNames()).collect(Collectors.toMap(k -> k, registry::getBeanDefinition));
30+
31+
assertThat(beans)
32+
.hasSize(beansLoaded)
33+
.containsKey("adapter");
34+
35+
var def = beans.values().stream()
36+
.filter(bd -> bd.getBeanClassName().equals(SqsMessageHandler.class.getName()))
37+
.findAny().orElseThrow();
38+
39+
assertThat(def)
40+
.matches(bd -> bd.getConstructorArgumentValues().getArgumentValue(0, null).getValue().equals(new RuntimeBeanReference("sqsClient")))
41+
.extracting(BeanDefinition::getPropertyValues)
42+
.matches(properties -> properties.get("async").equals(new TypedStringValue("false")), "async")
43+
.matches(properties -> properties.get("messageConverter").equals(new RuntimeBeanReference("msgConv")), "message converter")
44+
;
45+
}
46+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
https://www.springframework.org/schema/beans/spring-beans.xsd
7+
http://www.springframework.org/schema/integration/aws
8+
https://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd">
9+
10+
<int-aws:sqs-outbound-channel-adapter
11+
id="adapter"
12+
sqs="sqsClient"
13+
sync="true"
14+
message-converter="msgConv"
15+
error-message-strategy="emb"/>
16+
</beans>

0 commit comments

Comments
 (0)