1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import java.util.Collection;
19 import java.util.Collections;
20
21 import org.kuali.rice.krad.messages.Message;
22 import org.kuali.rice.krad.messages.MessageProvider;
23 import org.kuali.rice.krad.messages.MessageService;
24 import org.kuali.rice.krad.messages.MessageServiceImpl;
25 import org.kuali.rice.krad.messages.providers.ResourceMessageProvider;
26
27
28
29
30
31
32 public class MockMessageService implements MessageService {
33
34 private MessageService delegate;
35
36 private MessageService getDelegate() {
37 if (delegate != null) {
38 return delegate;
39 }
40
41 ResourceMessageProvider provider = new ResourceMessageProvider();
42
43 MessageServiceImpl messageServiceDelegate = new MessageServiceImpl();
44 messageServiceDelegate.setMessageProviders(Collections.<MessageProvider> singletonList(provider));
45 delegate = messageServiceDelegate;
46 return delegate;
47 }
48
49
50
51
52
53 @Override
54 public Message getMessage(String namespace, String component, String key) {
55 Message rv = getDelegate().getMessage(namespace, component, key);
56 if (rv != null) {
57 return rv;
58 }
59
60 rv = new Message();
61 rv.setNamespaceCode(namespace);
62 rv.setComponentCode(component);
63 rv.setKey(key);
64 rv.setText(getMessageText(namespace, component, key));
65 return rv;
66 }
67
68
69
70
71
72 @Override
73 public Message getMessage(String namespace, String component, String key, String locale) {
74 Message rv = getDelegate().getMessage(namespace, component, key, locale);
75 if (rv != null) {
76 return rv;
77 }
78
79 rv = new Message();
80 rv.setNamespaceCode(namespace);
81 rv.setComponentCode(component);
82 rv.setKey(key);
83 rv.setLocale(locale);
84 rv.setText(namespace + ":" + component + ":" + key + ":" + locale);
85 return rv;
86 }
87
88
89
90
91
92 @Override
93 public String getMessageText(String namespace, String component, String key) {
94 String rv = getDelegate().getMessageText(namespace, component, key);
95 if (rv != null) {
96 return rv;
97 }
98
99 return namespace + ":" + component + ":" + key;
100 }
101
102
103
104
105
106 @Override
107 public String getMessageText(String namespace, String component, String key, String locale) {
108 String rv = getDelegate().getMessageText(namespace, component, key, locale);
109 if (rv != null) {
110 return rv;
111 }
112
113 return namespace + ":" + component + ":" + key + ":" + locale;
114 }
115
116
117
118
119 @Override
120 public String getMessageText(String key) {
121 String rv = getDelegate().getMessageText(key);
122 if (rv != null) {
123 return rv;
124 }
125
126 return key;
127 }
128
129
130
131
132
133 @Override
134 public String getMessageText(String key, String locale) {
135 String rv = getDelegate().getMessageText(key, locale);
136 if (rv != null) {
137 return rv;
138 }
139
140 return key + ":" + locale;
141 }
142
143
144
145
146
147 @Override
148 public Collection<Message> getAllMessagesForComponent(String namespace, String component) {
149 Collection<Message> rv = getDelegate().getAllMessagesForComponent(namespace, component);
150 if (rv != null) {
151 return rv;
152 }
153
154 Message rm = new Message();
155 rm.setNamespaceCode(namespace);
156 rm.setComponentCode(component);
157 rm.setText(namespace + ":" + component);
158 return Collections.singletonList(rm);
159 }
160
161
162
163
164
165 @Override
166 public Collection<Message> getAllMessagesForComponent(String namespace, String component, String locale) {
167 Collection<Message> rv = getDelegate().getAllMessagesForComponent(namespace, component, locale);
168 if (rv != null) {
169 return rv;
170 }
171
172 Message rm = new Message();
173 rm.setNamespaceCode(namespace);
174 rm.setComponentCode(component);
175 rm.setLocale(locale);
176 rm.setText(namespace + ":" + component + ":" + locale);
177 return Collections.singletonList(rm);
178 }
179
180 }