1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.richclient.application;
17
18 import java.util.Locale;
19
20 import junit.framework.TestCase;
21
22 import org.easymock.EasyMock;
23 import org.springframework.context.support.StaticApplicationContext;
24 import org.springframework.context.support.StaticMessageSource;
25 import org.springframework.richclient.progress.NullProgressMonitor;
26 import org.springframework.richclient.progress.ProgressMonitor;
27
28
29
30
31
32
33
34
35
36 public class ProgressMonitoringBeanFactoryPostProcessorTests extends TestCase {
37
38
39
40
41
42
43 public void testConstructor() {
44
45 try {
46 new ProgressMonitoringBeanFactoryPostProcessor(null, null);
47 fail("Should have thrown an IllegalArgumentException");
48 }
49 catch (IllegalArgumentException e) {
50
51 }
52
53 new ProgressMonitoringBeanFactoryPostProcessor(new NullProgressMonitor(), null);
54
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 public void testLoadingBeansWithMessageSource() {
77 String loadingAppCtxMessage = "Loading Application Context Message Test";
78 int expectedSingletonBeanCount = 2;
79 String beanName1 = "beanName1";
80 String beanName2 = "beanName2";
81 String beanName3 = "beanName3";
82 String loadingBeanMessage = "LoadBeanTestMessage {0}";
83 String expectedLoadBean1Message = "LoadBeanTestMessage beanName1";
84 String expectedLoadBean2Message = "LoadBeanTestMessage beanName2";
85
86 StaticApplicationContext appCtx = new StaticApplicationContext();
87 appCtx.registerSingleton(beanName1, Object.class);
88 appCtx.registerSingleton(beanName2, Object.class);
89 appCtx.registerPrototype(beanName3, Object.class);
90
91 StaticMessageSource messageSource = new StaticMessageSource();
92
93 messageSource.addMessage(ProgressMonitoringBeanFactoryPostProcessor.LOADING_APP_CONTEXT_KEY, Locale
94 .getDefault(), loadingAppCtxMessage);
95
96 messageSource.addMessage(ProgressMonitoringBeanFactoryPostProcessor.LOADING_BEAN_KEY, Locale.getDefault(),
97 loadingBeanMessage);
98
99 ProgressMonitor mockProgressMonitor = (ProgressMonitor) EasyMock.createStrictMock(ProgressMonitor.class);
100 mockProgressMonitor.taskStarted(loadingAppCtxMessage, expectedSingletonBeanCount);
101 mockProgressMonitor.subTaskStarted(expectedLoadBean1Message);
102 mockProgressMonitor.worked(1);
103 mockProgressMonitor.subTaskStarted(expectedLoadBean2Message);
104 mockProgressMonitor.worked(1);
105 EasyMock.replay(mockProgressMonitor);
106
107 ProgressMonitoringBeanFactoryPostProcessor processor = new ProgressMonitoringBeanFactoryPostProcessor(
108 mockProgressMonitor, messageSource);
109
110 appCtx.addBeanFactoryPostProcessor(processor);
111
112 appCtx.refresh();
113
114 EasyMock.verify(mockProgressMonitor);
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 public void testLoadingBeansWithoutMessageSource() {
135 int expectedSingletonBeanCount = 2;
136 String beanName1 = "beanName1";
137 String beanName2 = "beanName2";
138 String beanName3 = "beanName3";
139
140 StaticApplicationContext appCtx = new StaticApplicationContext();
141 appCtx.registerSingleton(beanName1, Object.class);
142 appCtx.registerSingleton(beanName2, Object.class);
143 appCtx.registerPrototype(beanName3, Object.class);
144
145 ProgressMonitor mockProgressMonitor = (ProgressMonitor) EasyMock.createStrictMock(ProgressMonitor.class);
146 mockProgressMonitor.taskStarted("Loading Application Context ...", expectedSingletonBeanCount);
147 mockProgressMonitor.subTaskStarted("Loading " + beanName1 + " ...");
148 mockProgressMonitor.worked(1);
149 mockProgressMonitor.subTaskStarted("Loading " + beanName2 + " ...");
150 mockProgressMonitor.worked(1);
151 EasyMock.replay(mockProgressMonitor);
152
153 ProgressMonitoringBeanFactoryPostProcessor processor = new ProgressMonitoringBeanFactoryPostProcessor(
154 mockProgressMonitor, null);
155 appCtx.addBeanFactoryPostProcessor(processor);
156
157 appCtx.refresh();
158
159 EasyMock.verify(mockProgressMonitor);
160 }
161
162 }