2424import org .springframework .core .io .ByteArrayResource ;
2525import org .springframework .core .io .Resource ;
2626
27- import static org .assertj .core .api .Assertions .assertThat ;
28- import static org .assertj .core .api .Assertions .fail ;
27+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
2928
3029/**
3130 * @author Gary Russell
@@ -42,120 +41,100 @@ public void testRefGood() {
4241
4342 @ Test
4443 public void testRefExtraAttribute () {
45- try {
46- // Load context from a String to avoid IDEs reporting the invalid configuration
47- String badContext =
48- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
49- "<beans xmlns=\" http://www.springframework.org/schema/beans\" " +
50- " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" " +
51- " xmlns:int=\" http://www.springframework.org/schema/integration\" " +
52- " xmlns:int-jdbc=\" http://www.springframework.org/schema/integration/jdbc\" " +
53- " xsi:schemaLocation=\" http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd" +
54- " http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd" +
55- " http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd\" >" +
56- "" +
57- " <int:poller id=\" outer\" fixed-rate=\" 5000\" />" +
58- "" +
59- " <int:channel id=\" someChannel\" />" +
60- "" +
61- " <int-jdbc:inbound-channel-adapter channel=\" someChannel\" jdbc-operations=\" ops\" " +
62- " query=\" select 1\" >" +
63- " <int:poller ref=\" outer\" fixed-rate=\" 1000\" />" + // <<<<< fixed-rate not allowed here
64- " </int-jdbc:inbound-channel-adapter>" +
65- "" +
66- " <bean id=\" ops\" class=\" org.mockito.Mockito\" factory-method=\" mock\" >" +
67- " <constructor-arg value=\" org.springframework.jdbc.core.JdbcOperations\" />" +
68- " </bean>" +
69- "</beans>" ;
70-
71- Resource resource = new ByteArrayResource (badContext .getBytes ());
72- new GenericXmlApplicationContext (resource ).close ();
73- fail ("Expected Failure to load ApplicationContext" );
74- }
75- catch (BeanDefinitionParsingException bdpe ) {
76- assertThat (bdpe .getMessage ()
77- .startsWith ("Configuration problem: A 'poller' element that provides a 'ref' must have no other " +
78- "attributes." ))
79- .isTrue ();
80- }
44+ // Load context from a String to avoid IDEs reporting the invalid configuration
45+ String badContext = """
46+ <?xml version="1.0" encoding="UTF-8"?>
47+ <beans xmlns="http://www.springframework.org/schema/beans"
48+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
49+ xmlns:int="http://www.springframework.org/schema/integration"
50+ xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
51+ xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
52+ http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
53+ http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
54+
55+ <int:poller id="outer" fixed-rate="5000"/>
56+
57+ <int:channel id="someChannel"/>
58+
59+ <int-jdbc:inbound-channel-adapter channel="someChannel" jdbc-operations="ops" query="select 1">
60+ <int:poller ref="outer" fixed-rate="1000"/>
61+ </int-jdbc:inbound-channel-adapter>
62+
63+ <bean id="ops" class="org.mockito.Mockito" factory-method="mock">
64+ <constructor-arg value="org.springframework.jdbc.core.JdbcOperations"/>
65+ </bean>
66+ </beans>
67+ """ ;
68+ Resource resource = new ByteArrayResource (badContext .getBytes ());
69+ assertThatExceptionOfType (BeanDefinitionParsingException .class )
70+ .isThrownBy (() -> new GenericXmlApplicationContext (resource ))
71+ .withMessageStartingWith ("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes." );
8172 }
8273
8374 @ Test
8475 public void testRefDefaultTrue () {
85- try {
86- // Load context from a String to avoid IDEs reporting the invalid configuration
87- String badContext =
88- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
89- "<beans xmlns=\" http://www.springframework.org/schema/beans\" " +
90- " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" " +
91- " xmlns:int=\" http://www.springframework.org/schema/integration\" " +
92- " xmlns:int-jdbc=\" http://www.springframework.org/schema/integration/jdbc\" " +
93- " xsi:schemaLocation=\" http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd" +
94- " http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd" +
95- " http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd\" >" +
96- "" +
97- " <int:poller id=\" outer\" fixed-rate=\" 5000\" />" +
98- "" +
99- " <int:channel id=\" someChannel\" />" +
100- "" +
101- " <int-jdbc:inbound-channel-adapter channel=\" someChannel\" jdbc-operations=\" ops\" " +
102- " query=\" select 1\" >" +
103- " <int:poller ref=\" outer\" default=\" true\" />" + // <<<<< default true not allowed here
104- " </int-jdbc:inbound-channel-adapter>" +
105- "" +
106- " <bean id=\" ops\" class=\" org.mockito.Mockito\" factory-method=\" mock\" >" +
107- " <constructor-arg value=\" org.springframework.jdbc.core.JdbcOperations\" />" +
108- " </bean>" +
109- "</beans>" ;
110-
111- Resource resource = new ByteArrayResource (badContext .getBytes ());
112- new GenericXmlApplicationContext (resource ).close ();
113- fail ("Expected Failure to load ApplicationContext" );
114- }
115- catch (BeanDefinitionParsingException bdpe ) {
116- assertThat (bdpe .getMessage ()
117- .startsWith ("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes." ))
118- .isTrue ();
119- }
76+ // Load context from a String to avoid IDEs reporting the invalid configuration
77+ String badContext = """
78+ <?xml version="1.0" encoding="UTF-8"?>
79+ <beans xmlns="http://www.springframework.org/schema/beans"
80+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
81+ xmlns:int="http://www.springframework.org/schema/integration"
82+ xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
83+ xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
84+ http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
85+ http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
86+
87+ <int:poller id="outer" fixed-rate="5000"/>
88+
89+ <int:channel id="someChannel"/>
90+
91+ <int-jdbc:inbound-channel-adapter channel="someChannel" jdbc-operations="ops" query="select 1">
92+ <int:poller ref="outer" default="true"/>
93+ </int-jdbc:inbound-channel-adapter>
94+
95+ <bean id="ops" class="org.mockito.Mockito" factory-method="mock">
96+ <constructor-arg value="org.springframework.jdbc.core.JdbcOperations"/>
97+ </bean>
98+ </beans>
99+ """ ;
100+
101+ Resource resource = new ByteArrayResource (badContext .getBytes ());
102+ assertThatExceptionOfType (BeanDefinitionParsingException .class )
103+ .isThrownBy (() -> new GenericXmlApplicationContext (resource ))
104+ .withMessageStartingWith ("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes." );
120105 }
121106
122107 @ Test
123108 public void testRefExtraAttributeAndDefaultFalse () {
124- try {
125- // Load context from a String to avoid IDEs reporting the invalid configuration
126- String badContext =
127- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
128- "<beans xmlns=\" http://www.springframework.org/schema/beans\" " +
129- " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" " +
130- " xmlns:int=\" http://www.springframework.org/schema/integration\" " +
131- " xmlns:int-jdbc=\" http://www.springframework.org/schema/integration/jdbc\" " +
132- " xsi:schemaLocation=\" http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd" +
133- " http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd" +
134- " http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd\" >" +
135- "" +
136- " <int:poller id=\" outer\" fixed-rate=\" 5000\" />" +
137- "" +
138- " <int:channel id=\" someChannel\" />" +
139- "" +
140- " <int-jdbc:inbound-channel-adapter channel=\" someChannel\" jdbc-operations=\" ops\" " +
141- " query=\" select 1\" >" +
142- " <int:poller ref=\" outer\" default=\" false\" fixed-rate=\" 1000\" />" + // <<<<< fixed-rate not allowed here
143- " </int-jdbc:inbound-channel-adapter>" +
144- "" +
145- " <bean id=\" ops\" class=\" org.mockito.Mockito\" factory-method=\" mock\" >" +
146- " <constructor-arg value=\" org.springframework.jdbc.core.JdbcOperations\" />" +
147- " </bean>" +
148- "</beans>" ;
149-
150- Resource resource = new ByteArrayResource (badContext .getBytes ());
151- new GenericXmlApplicationContext (resource ).close ();
152- fail ("Expected Failure to load ApplicationContext" );
153- }
154- catch (BeanDefinitionParsingException bdpe ) {
155- assertThat (bdpe .getMessage ()
156- .startsWith ("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes." ))
157- .isTrue ();
158- }
109+ // Load context from a String to avoid IDEs reporting the invalid configuration
110+ String badContext = """
111+ <?xml version="1.0" encoding="UTF-8"?>
112+ <beans xmlns="http://www.springframework.org/schema/beans"
113+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
114+ xmlns:int="http://www.springframework.org/schema/integration"
115+ xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
116+ xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
117+ http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
118+ http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
119+
120+ <int:poller id="outer" fixed-rate="5000"/>
121+
122+ <int:channel id="someChannel"/>
123+
124+ <int-jdbc:inbound-channel-adapter channel="someChannel" jdbc-operations="ops" query="select 1">
125+ <int:poller ref="outer" default="false" fixed-rate="1000"/>
126+ </int-jdbc:inbound-channel-adapter>
127+
128+ <bean id="ops" class="org.mockito.Mockito" factory-method="mock">
129+ <constructor-arg value="org.springframework.jdbc.core.JdbcOperations"/>
130+ </bean>
131+ </beans>
132+ """ ;
133+
134+ Resource resource = new ByteArrayResource (badContext .getBytes ());
135+ assertThatExceptionOfType (BeanDefinitionParsingException .class )
136+ .isThrownBy (() -> new GenericXmlApplicationContext (resource ))
137+ .withMessageStartingWith ("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes." );
159138 }
160139
161140}
0 commit comments