1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.renderer;
17  
18  import junit.framework.TestCase;
19  
20  import org.eclipse.swt.SWT;
21  import org.eclipse.swt.graphics.RGB;
22  import org.eclipse.swt.widgets.Display;
23  import org.seasar.eclipse.common.util.ImageManager;
24  import org.seasar.uruma.annotation.RenderingPolicy.SetTiming;
25  import org.seasar.uruma.exception.RenderException;
26  
27  /**
28   * {@link RendererSupportUtil} のためのテストクラスです。<br />
29   * 
30   * @author y-komori
31   */
32  public class RenderSupportUtilTest extends TestCase {
33      private Display display;
34  
35      @Override
36      protected void setUp() throws Exception {
37          display = Display.getCurrent();
38          if (display == null) {
39              display = new Display();
40              ImageManager.init(display);
41          }
42      }
43  
44      @Override
45      protected void tearDown() throws Exception {
46          ImageManager.dispose();
47          if (display != null) {
48              display.dispose();
49          }
50      }
51  
52      public void testSetAttributes1() {
53          SrcObject src = new SrcObject();
54          src.setBasePath("org/seasar/uruma/renderer");
55          DestObject dest = new DestObject();
56  
57          RendererSupportUtil.setAttributes(src, dest, SetTiming.RENDER);
58  
59          assertEquals("1", "StringField1", dest.stringField);
60          assertEquals("2", "Text\tField1\nText\tField1\n", dest.textField);
61          assertEquals("3", 123, dest.intField);
62          assertTrue("4", dest.booleanField);
63          assertEquals("5", new RGB(255, 255, 255), dest.colorField.getRGB());
64          assertEquals("6", SWT.YES, dest.swtConstField);
65          assertEquals("7", ImageManager.getImage("/images/container.gif"),
66                  dest.imageField);
67          assertEquals("8", SWT.CTRL | SWT.ALT | 'A', dest.acceleratorField);
68          assertEquals("9", 'A', dest.charField);
69          assertEquals("10", 3, dest.intArrayField.length);
70          assertEquals("11", 1, dest.intArrayField[0]);
71          assertEquals("12", 2, dest.intArrayField[1]);
72          assertEquals("13", 3, dest.intArrayField[2]);
73  
74          assertEquals("14", "StringField2", dest.getStringProperty());
75          assertEquals("15", "Text\tField2\nText\tField2\n", dest
76                  .getTextProperty());
77          assertEquals("16", 456, dest.getIntProperty());
78          assertFalse("17", dest.getBooleanProperty());
79          assertEquals("18", new RGB(0, 0, 0), dest.getColorProperty().getRGB());
80          assertEquals("19", SWT.NO, dest.getSwtConstProperty());
81          assertEquals(
82                  "20",
83                  ImageManager
84                          .getImage("org/seasar/uruma/renderer/../../../../images/container.gif"),
85                  dest.getImageProperty());
86          assertEquals("21", SWT.F2, dest.getAcceleratorProperty());
87          assertEquals("22", 'x', dest.getCharProperty());
88          assertEquals("23", 1, dest.getIntArrayProperty().length);
89          assertEquals("24", 3, dest.getIntArrayProperty()[0]);
90  
91          assertNull("25", dest.nonTargetField);
92      }
93  
94      public void testSetAttributes2() {
95          SrcObject2 src = new SrcObject2();
96          DestObject dest = new DestObject();
97  
98          try {
99              RendererSupportUtil.setAttributes(src, dest, SetTiming.RENDER);
100             // TODO エラーログ出力を確認するようにする
101             assertTrue(true);
102         } catch (RenderException ex) {
103             fail(ex.getMessage());
104         }
105     }
106 
107     public void testSetAttributes3() {
108         SrcObject3 src = new SrcObject3();
109         DestObject dest = new DestObject();
110 
111         try {
112             RendererSupportUtil.setAttributes(src, dest, SetTiming.RENDER);
113             // TODO エラーログ出力を確認するようにする
114             assertTrue(true);
115         } catch (RenderException ex) {
116             fail(ex.getMessage());
117         }
118     }
119 
120     public void testSetAttributes4() {
121         SrcObject4 src = new SrcObject4();
122         DestObject dest = new DestObject();
123 
124         try {
125             RendererSupportUtil.setAttributes(src, dest, SetTiming.RENDER);
126             // TODO エラーログ出力を確認するようにする
127             assertTrue(true);
128         } catch (RenderException ex) {
129             fail(ex.getMessage());
130         }
131     }
132 }