1
2
3
4
5
6
7
8
9
10 package org.mule.test.config;
11
12
13 import org.mule.api.AnnotatedObject;
14 import org.mule.api.construct.FlowConstruct;
15 import org.mule.api.endpoint.EndpointBuilder;
16 import org.mule.api.endpoint.ImmutableEndpoint;
17 import org.mule.api.endpoint.OutboundEndpoint;
18 import org.mule.api.transformer.Transformer;
19 import org.mule.component.DefaultJavaComponent;
20 import org.mule.component.simple.EchoComponent;
21 import org.mule.construct.Flow;
22 import org.mule.tck.FunctionalTestCase;
23
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertTrue;
28
29
30 import org.junit.Test;
31
32 import javax.xml.namespace.QName;
33
34
35
36
37 public class ConfigurationAnnotationsTestCase extends FunctionalTestCase
38 {
39 @Override
40 protected String getConfigResources()
41 {
42 return "org/mule/config/spring/annotations.xml";
43 }
44
45 @Test
46 public void testAnnotations()
47 {
48 Transformer stb = muleContext.getRegistry().lookupTransformer("StringtoByteArray");
49 assertNotNull(stb);
50 assertEquals("stb-transformer", getDocName(stb));
51 assertEquals("Convert a String to a Byte Array", getDocDescription(stb));
52 EndpointBuilder in = muleContext.getRegistry().lookupEndpointBuilder("in");
53 assertNotNull(in);
54 assertEquals("inbound vm endpoint", getDocName(in));
55 assertEquals("Accepts inbound messages", getDocDescription(in));
56 FlowConstruct flow = muleContext.getRegistry().lookupFlowConstruct("Bridge");
57 assertNotNull(flow);
58 assertEquals("Bridge flow", getDocName(flow));
59 assertEquals("Main flow", getDocDescription(flow));
60 DefaultJavaComponent echo = muleContext.getRegistry().lookupByType(DefaultJavaComponent.class).values().iterator().next();
61 assertEquals("echo", getDocName(echo));
62 ImmutableEndpoint ep = (ImmutableEndpoint) ((Flow)flow).getMessageSource();
63 assertNotNull(ep);
64 assertEquals("inbound flow endpoint", getDocName(ep));
65 assertNull("Accepts inbound messages", getDocDescription(ep));
66 OutboundEndpoint out = muleContext.getRegistry().lookupByType(OutboundEndpoint.class).values().iterator().next();
67 assertNotNull(out);
68 assertEquals("outbound vm endpoint", getDocName(out));
69 assertEquals("Accepts outbound messages", getDocDescription(out));
70 }
71
72 protected String getDocName(Object obj)
73 {
74 assertTrue(obj instanceof AnnotatedObject);
75 return (String) ((AnnotatedObject)obj).getAnnotation(new QName("http://www.mulesoft.org/schema/mule/doc", "name"));
76 }
77
78 protected String getDocDescription(Object obj)
79 {
80 assertTrue(obj instanceof AnnotatedObject);
81 return (String) ((AnnotatedObject)obj).getAnnotation(new QName("http://www.mulesoft.org/schema/mule/doc", "description"));
82 }
83 }