1   /*
2    * Copyright 2002-2007 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.springframework.binding.form.support;
17  
18  import java.awt.Color;
19  import java.util.Locale;
20  
21  import javax.swing.Icon;
22  
23  import org.easymock.EasyMock;
24  import org.springframework.binding.form.FieldFace;
25  import org.springframework.context.support.MessageSourceAccessor;
26  import org.springframework.context.support.StaticMessageSource;
27  import org.springframework.richclient.image.IconSource;
28  import org.springframework.richclient.test.SpringRichTestCase;
29  import org.springframework.richclient.test.TestIcon;
30  
31  /**
32   * Testcase for MessageSourceFieldFaceSource
33   * 
34   * @author Peter De Bruycker
35   */
36  public class MessageSourceFieldFaceSourceTests extends SpringRichTestCase {
37  
38  	public void testLoadFieldFace() {
39  		Icon testIcon = new TestIcon(Color.RED);
40  
41  		MessageSourceFieldFaceSource fieldFaceSource = new MessageSourceFieldFaceSource();
42  
43  		StaticMessageSource messageSource = new StaticMessageSource();
44  		messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption");
45  		messageSource.addMessage("context.field.description", Locale.getDefault(), "the description");
46  		messageSource.addMessage("context.field.label", Locale.getDefault(), "the label");
47  		messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName");
48  		fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
49  
50  		IconSource mockIconSource = (IconSource) EasyMock.createMock(IconSource.class);
51  		EasyMock.expect(mockIconSource.getIcon("iconName")).andReturn(testIcon);
52  		EasyMock.replay(mockIconSource);
53  
54  		fieldFaceSource.setIconSource(mockIconSource);
55  
56  		FieldFace face = fieldFaceSource.loadFieldFace("field", "context");
57  
58  		assertEquals("the caption", face.getCaption());
59  		assertEquals("the label", face.getDisplayName());
60  		assertEquals("the description", face.getDescription());
61  
62  		assertEquals(testIcon, face.getIcon());
63  
64  		EasyMock.verify(mockIconSource);
65  	}
66  
67  }