|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
29 | 29 |
|
30 | 30 | import org.springframework.aop.framework.ProxyFactory;
|
31 | 31 | import org.springframework.context.support.StaticApplicationContext;
|
32 |
| -import org.springframework.messaging.Message; |
33 |
| -import org.springframework.messaging.handler.annotation.Payload; |
34 | 32 | import org.springframework.integration.annotation.Publisher;
|
35 | 33 | import org.springframework.integration.channel.QueueChannel;
|
| 34 | +import org.springframework.messaging.Message; |
| 35 | +import org.springframework.messaging.handler.annotation.Payload; |
36 | 36 |
|
37 | 37 | /**
|
38 | 38 | * @author Mark Fisher
|
| 39 | + * @author Jeff Maxwell |
| 40 | + * |
39 | 41 | * @since 2.0
|
40 | 42 | */
|
41 | 43 | public class PublisherAnnotationAdvisorTests {
|
42 | 44 |
|
43 | 45 | private final StaticApplicationContext context = new StaticApplicationContext();
|
44 | 46 |
|
45 |
| - |
46 | 47 | @Before
|
47 | 48 | public void setup() {
|
48 | 49 | context.registerSingleton("testChannel", QueueChannel.class);
|
49 | 50 | context.registerSingleton("testMetaChannel", QueueChannel.class);
|
50 | 51 | }
|
51 | 52 |
|
52 |
| - |
53 | 53 | @Test
|
54 | 54 | public void annotationAtMethodLevelOnVoidReturnWithParamAnnotation() {
|
55 | 55 | PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
|
@@ -120,65 +120,190 @@ public void metaAnnotationAtClassLevel() {
|
120 | 120 | assertEquals("foo", message.getPayload());
|
121 | 121 | }
|
122 | 122 |
|
| 123 | + @Test |
| 124 | + public void annotationViaValueAtMethodLevelOnVoidReturnWithParamAnnotation() { |
| 125 | + PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(); |
| 126 | + advisor.setBeanFactory(context); |
| 127 | + QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class); |
| 128 | + ProxyFactory pf = new ProxyFactory(new AnnotationViaValueAtMethodLevelTestBeanImpl()); |
| 129 | + pf.addAdvisor(advisor); |
| 130 | + TestVoidBean proxy = (TestVoidBean) pf.getProxy(); |
| 131 | + proxy.testVoidMethod("foo"); |
| 132 | + Message<?> message = testChannel.receive(0); |
| 133 | + assertNotNull(message); |
| 134 | + assertEquals("foo", message.getPayload()); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void annotationViaValueAtMethodLevel() { |
| 139 | + PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(); |
| 140 | + advisor.setBeanFactory(context); |
| 141 | + QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class); |
| 142 | + ProxyFactory pf = new ProxyFactory(new AnnotationViaValueAtMethodLevelTestBeanImpl()); |
| 143 | + pf.addAdvisor(advisor); |
| 144 | + TestBean proxy = (TestBean) pf.getProxy(); |
| 145 | + proxy.test(); |
| 146 | + Message<?> message = testChannel.receive(0); |
| 147 | + assertNotNull(message); |
| 148 | + assertEquals("foo", message.getPayload()); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void annotationViaValueAtClassLevel() { |
| 153 | + PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(); |
| 154 | + advisor.setBeanFactory(context); |
| 155 | + QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class); |
| 156 | + ProxyFactory pf = new ProxyFactory(new AnnotationViaValueAtClassLevelTestBeanImpl()); |
| 157 | + pf.addAdvisor(advisor); |
| 158 | + TestBean proxy = (TestBean) pf.getProxy(); |
| 159 | + proxy.test(); |
| 160 | + Message<?> message = testChannel.receive(0); |
| 161 | + assertNotNull(message); |
| 162 | + assertEquals("foo", message.getPayload()); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void metaAnnotationViaValueAtMethodLevel() { |
| 167 | + PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(); |
| 168 | + advisor.setBeanFactory(context); |
| 169 | + QueueChannel testMetaChannel = context.getBean("testMetaChannel", QueueChannel.class); |
| 170 | + ProxyFactory pf = new ProxyFactory(new MetaAnnotationViaValueAtMethodLevelTestBeanImpl()); |
| 171 | + pf.addAdvisor(advisor); |
| 172 | + TestBean proxy = (TestBean) pf.getProxy(); |
| 173 | + proxy.test(); |
| 174 | + Message<?> message = testMetaChannel.receive(0); |
| 175 | + assertNotNull(message); |
| 176 | + assertEquals("foo", message.getPayload()); |
| 177 | + } |
| 178 | + |
| 179 | + @Test |
| 180 | + public void metaAnnotationViaValueAtClassLevel() { |
| 181 | + PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(); |
| 182 | + advisor.setBeanFactory(context); |
| 183 | + QueueChannel testMetaChannel = context.getBean("testMetaChannel", QueueChannel.class); |
| 184 | + ProxyFactory pf = new ProxyFactory(new MetaAnnotationViaValueAtClassLevelTestBeanImpl()); |
| 185 | + pf.addAdvisor(advisor); |
| 186 | + TestBean proxy = (TestBean) pf.getProxy(); |
| 187 | + proxy.test(); |
| 188 | + Message<?> message = testMetaChannel.receive(0); |
| 189 | + assertNotNull(message); |
| 190 | + assertEquals("foo", message.getPayload()); |
| 191 | + } |
123 | 192 |
|
124 | 193 | interface TestBean {
|
125 | 194 |
|
126 | 195 | String test();
|
127 | 196 |
|
128 | 197 | }
|
129 | 198 |
|
130 |
| - |
131 | 199 | interface TestVoidBean {
|
132 | 200 |
|
133 | 201 | void testVoidMethod(String s);
|
134 | 202 |
|
135 | 203 | }
|
136 | 204 |
|
137 |
| - |
138 | 205 | static class AnnotationAtMethodLevelTestBeanImpl implements TestBean, TestVoidBean {
|
139 | 206 |
|
| 207 | + @Override |
140 | 208 | @Publisher(channel = "testChannel")
|
141 | 209 | public String test() {
|
142 | 210 | return "foo";
|
143 | 211 | }
|
144 | 212 |
|
| 213 | + @Override |
145 | 214 | @Publisher(channel = "testChannel")
|
146 |
| - public void testVoidMethod(@Payload String s) { } |
147 |
| - } |
| 215 | + public void testVoidMethod(@Payload String s) { |
| 216 | + } |
148 | 217 |
|
| 218 | + } |
149 | 219 |
|
150 | 220 | @Publisher(channel = "testChannel")
|
151 | 221 | static class AnnotationAtClassLevelTestBeanImpl implements TestBean {
|
152 | 222 |
|
| 223 | + @Override |
153 | 224 | public String test() {
|
154 | 225 | return "foo";
|
155 | 226 | }
|
156 | 227 |
|
157 | 228 | }
|
158 | 229 |
|
159 |
| - |
160 |
| - @Target({ElementType.METHOD, ElementType.TYPE}) |
| 230 | + @Target({ ElementType.METHOD, ElementType.TYPE }) |
161 | 231 | @Retention(RetentionPolicy.RUNTIME)
|
162 | 232 | @Publisher(channel = "testMetaChannel")
|
163 | 233 | public @interface TestMetaPublisher {
|
164 |
| - } |
165 | 234 |
|
| 235 | + } |
166 | 236 |
|
167 | 237 | static class MetaAnnotationAtMethodLevelTestBeanImpl implements TestBean {
|
168 | 238 |
|
| 239 | + @Override |
169 | 240 | @TestMetaPublisher
|
170 | 241 | public String test() {
|
171 | 242 | return "foo";
|
172 | 243 | }
|
173 |
| - } |
174 | 244 |
|
| 245 | + } |
175 | 246 |
|
176 | 247 | @TestMetaPublisher
|
177 | 248 | static class MetaAnnotationAtClassLevelTestBeanImpl implements TestBean {
|
178 | 249 |
|
| 250 | + @Override |
| 251 | + public String test() { |
| 252 | + return "foo"; |
| 253 | + } |
| 254 | + |
| 255 | + } |
| 256 | + |
| 257 | + static class AnnotationViaValueAtMethodLevelTestBeanImpl implements TestBean, TestVoidBean { |
| 258 | + |
| 259 | + @Override |
| 260 | + @Publisher("testChannel") |
179 | 261 | public String test() {
|
180 | 262 | return "foo";
|
181 | 263 | }
|
| 264 | + |
| 265 | + @Override |
| 266 | + @Publisher("testChannel") |
| 267 | + public void testVoidMethod(@Payload String s) { |
| 268 | + } |
| 269 | + |
| 270 | + } |
| 271 | + |
| 272 | + @Publisher("testChannel") |
| 273 | + static class AnnotationViaValueAtClassLevelTestBeanImpl implements TestBean { |
| 274 | + |
| 275 | + @Override |
| 276 | + public String test() { |
| 277 | + return "foo"; |
| 278 | + } |
| 279 | + |
| 280 | + } |
| 281 | + |
| 282 | + @Target({ ElementType.METHOD, ElementType.TYPE }) |
| 283 | + @Retention(RetentionPolicy.RUNTIME) |
| 284 | + @Publisher("testMetaChannel") |
| 285 | + public @interface TestMetaPublisherViaValue { |
| 286 | + |
| 287 | + } |
| 288 | + |
| 289 | + static class MetaAnnotationViaValueAtMethodLevelTestBeanImpl implements TestBean { |
| 290 | + |
| 291 | + @Override |
| 292 | + @TestMetaPublisherViaValue |
| 293 | + public String test() { |
| 294 | + return "foo"; |
| 295 | + } |
| 296 | + |
| 297 | + } |
| 298 | + |
| 299 | + @TestMetaPublisherViaValue |
| 300 | + static class MetaAnnotationViaValueAtClassLevelTestBeanImpl implements TestBean { |
| 301 | + |
| 302 | + @Override |
| 303 | + public String test() { |
| 304 | + return "foo"; |
| 305 | + } |
| 306 | + |
182 | 307 | }
|
183 | 308 |
|
184 | 309 | }
|
0 commit comments