Skip to content

Commit 9a024ea

Browse files
committed
test: SqsContainerOptionsFactoryBeanTest
1 parent ba3165b commit 9a024ea

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111

1212
class SqsContainerOptionsFactoryBean implements FactoryBean<SqsContainerOptions> {
1313

14-
private final SqsContainerOptionsBuilder builder = SqsContainerOptions.builder();
14+
private final SqsContainerOptionsBuilder builder;
15+
16+
public SqsContainerOptionsFactoryBean() {
17+
this(SqsContainerOptions.builder());
18+
}
19+
20+
public SqsContainerOptionsFactoryBean(SqsContainerOptionsBuilder builder) {
21+
this.builder = builder;
22+
}
1523

1624
@Override
1725
public boolean isSingleton() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.springframework.integration.aws.config.xml;
2+
3+
import io.awspring.cloud.sqs.listener.QueueNotFoundStrategy;
4+
import io.awspring.cloud.sqs.listener.SqsContainerOptions;
5+
import io.awspring.cloud.sqs.listener.SqsContainerOptionsBuilder;
6+
import io.awspring.cloud.sqs.listener.acknowledgement.handler.AcknowledgementMode;
7+
import org.junit.jupiter.api.AfterEach;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import org.junit.jupiter.params.ParameterizedTest;
11+
import org.junit.jupiter.params.provider.CsvSource;
12+
import org.mockito.Answers;
13+
import org.mockito.InjectMocks;
14+
import org.mockito.Mock;
15+
import org.mockito.junit.jupiter.MockitoExtension;
16+
import org.springframework.beans.factory.FactoryBean;
17+
18+
import java.time.Duration;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.mockito.BDDMockito.*;
22+
23+
@ExtendWith(MockitoExtension.class)
24+
class SqsContainerOptionsFactoryBeanTest {
25+
26+
@Mock(answer = Answers.RETURNS_SELF)
27+
private SqsContainerOptionsBuilder builder;
28+
29+
@InjectMocks
30+
private SqsContainerOptionsFactoryBean factory;
31+
32+
@AfterEach
33+
void verify() {
34+
verifyNoMoreInteractions(builder);
35+
}
36+
37+
@Test
38+
void testFactory() {
39+
assertThat(factory)
40+
.returns(false, FactoryBean::isSingleton)
41+
.returns(SqsContainerOptions.class, FactoryBean::getObjectType)
42+
;
43+
}
44+
45+
@Test
46+
void testFactoryObject(@Mock SqsContainerOptions options) {
47+
given(builder.build())
48+
.willReturn(options);
49+
assertThat(factory.getObject())
50+
.isSameAs(options);
51+
}
52+
53+
@Test
54+
void testVisibilityTimeout() {
55+
factory.setVisibilityTimeout(5);
56+
then(builder).should()
57+
.messageVisibility(Duration.ofSeconds(5));
58+
}
59+
60+
@Test
61+
void testWaitTimeout() {
62+
factory.setWaitTimeOut(7);
63+
then(builder).should()
64+
.pollTimeout(Duration.ofSeconds(7));
65+
}
66+
67+
@Test
68+
void testMaxNumberOfMessages() {
69+
factory.setMaxNumberOfMessages(9);
70+
then(builder).should()
71+
.maxConcurrentMessages(9);
72+
then(builder).should()
73+
.maxMessagesPerPoll(9);
74+
}
75+
76+
@CsvSource({
77+
"NO_REDRIVE, ON_SUCCESS",
78+
"NEVER, MANUAL",
79+
"ON_SUCCESS, ON_SUCCESS",
80+
"ALWAYS, ALWAYS"
81+
})
82+
@ParameterizedTest
83+
void testMessageDeletionPolicy(String policy, AcknowledgementMode mode) {
84+
factory.setMessageDeletionPolicy(policy);
85+
then(builder).should()
86+
.acknowledgementMode(mode);
87+
}
88+
89+
@CsvSource({
90+
"true, FAIL",
91+
"false, CREATE"
92+
})
93+
@ParameterizedTest
94+
void testFailOnMissingQueueProperty(boolean fail, QueueNotFoundStrategy strategy) {
95+
factory.setFailOnMissingQueue(fail);
96+
then(builder).should()
97+
.queueNotFoundStrategy(strategy);
98+
}
99+
}

0 commit comments

Comments
 (0)