1 package org.apache.turbine.annotation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25
26 import java.util.List;
27
28 import org.apache.commons.configuration.Configuration;
29 import org.apache.fulcrum.factory.FactoryService;
30 import org.apache.turbine.modules.Screen;
31 import org.apache.turbine.modules.ScreenLoader;
32 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
33 import org.apache.turbine.util.TurbineConfig;
34 import org.apache.turbine.util.TurbineException;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
37 import org.junit.Ignore;
38 import org.junit.Test;
39
40
41
42
43
44
45 public class AnnotationProcessorTest
46 {
47 private static TurbineConfig tc;
48
49 @TurbineConfiguration
50 private Configuration completeConfiguration = null;
51
52 @TurbineConfiguration("serverdata.default")
53 private Configuration serverdataDefaultConfiguration = null;
54
55 @TurbineConfiguration("module.cache")
56 private boolean moduleCache = true;
57
58 @TurbineConfiguration("action.cache.size")
59 private int actionCacheSize = 0;
60
61 @TurbineConfiguration("template.homepage")
62 private String templateHomepage;
63
64 @TurbineConfiguration("module.packages")
65 private List<String> modulePackages;
66
67 @TurbineConfiguration("does.not.exist")
68 private long notModified = 1;
69
70 @TurbineLoader(Screen.class)
71 private ScreenLoader screenLoader;
72
73 @TurbineService
74 private AssemblerBrokerService asb;
75
76 @TurbineService
77 private FactoryService factory;
78
79 @BeforeClass
80 public static void init() throws Exception
81 {
82 tc = new TurbineConfig(".", "/conf/test/CompleteTurbineResources.properties");
83 tc.initialize();
84 }
85
86 @AfterClass
87 public static void destroy()
88 throws Exception
89 {
90 tc.dispose();
91 }
92
93 @Test
94 public void testProcess() throws TurbineException
95 {
96 AnnotationProcessor.process(this);
97
98 assertNotNull(completeConfiguration);
99 assertFalse(completeConfiguration.getBoolean("module.cache", true));
100
101 assertNotNull(serverdataDefaultConfiguration);
102 assertEquals(80, serverdataDefaultConfiguration.getInt("serverPort"));
103
104 assertFalse(moduleCache);
105 assertEquals(20, actionCacheSize);
106 assertEquals("Index.vm", templateHomepage);
107 assertNotNull(modulePackages);
108 assertEquals(3, modulePackages.size());
109 assertEquals("org.apache.turbine.services.template.modules", modulePackages.get(1));
110 assertEquals(1, notModified);
111
112 assertNotNull(screenLoader);
113 assertNotNull(asb);
114 assertNotNull(factory);
115 }
116
117 @Ignore("For performance tests only") @Test
118 public void testProcessingPerformance() throws TurbineException
119 {
120 long startTime = System.currentTimeMillis();
121
122 for (int i = 0; i < 100000; i++)
123 {
124 AnnotationProcessor.process(this);
125 }
126
127 System.out.println(System.currentTimeMillis() - startTime);
128 }
129 }