001    /*
002     * Copyright 2002-2007 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.dialog;
017    
018    import java.awt.image.BufferedImage;
019    
020    import javax.swing.JLabel;
021    import javax.swing.JPanel;
022    
023    import junit.framework.TestCase;
024    
025    import org.springframework.richclient.core.DefaultMessage;
026    
027    /**
028     * Testcase for TitlePane
029     * 
030     * @author Peter De Bruycker
031     */
032    public class TitlePaneTests extends TestCase {
033    
034            public void testBlah() {
035                    TitlePane titlePane = new TitlePane();
036                    titlePane.setImage(new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB));
037                    titlePane.setTitle("new title");
038                    titlePane.setMessage(new DefaultMessage("test message", null));
039                    assertEquals("new title", titlePane.getTitle());
040    
041                    // trigger control creation
042                    JPanel panel = (JPanel) titlePane.getControl();
043    
044                    assertEquals("must have 3 components: title, icon and message", 3, panel.getComponentCount());
045    
046                    JLabel titleLabel = (JLabel) panel.getComponent(0);
047                    assertEquals("new title", titleLabel.getText());
048    
049                    JLabel iconLabel = (JLabel) panel.getComponent(1);
050                    assertNotNull(iconLabel.getIcon());
051    
052                    JLabel messageLabel = (JLabel) panel.getComponent(2);
053                    assertEquals("<html>test message</html>", messageLabel.getText());
054                    
055                    // change title and message after control creation
056                    titlePane.setTitle("other title");
057                    titlePane.setMessage(new DefaultMessage("other message", null));
058    
059                    assertEquals("other title", titleLabel.getText());
060                    assertEquals("<html>other message</html>", messageLabel.getText());
061            }
062    
063    }