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.impl;
17  
18  import junit.framework.TestCase;
19  
20  import org.eclipse.swt.widgets.Control;
21  import org.seasar.uruma.component.UICompositeComponent;
22  import org.seasar.uruma.component.UIControlComponent;
23  import org.seasar.uruma.component.jface.ButtonComponent;
24  import org.seasar.uruma.component.jface.CommonAttriburtesImpl;
25  import org.seasar.uruma.component.jface.CompositeComponent;
26  import org.seasar.uruma.component.jface.ControlComponent;
27  import org.seasar.uruma.component.jface.GridDataInfo;
28  import org.seasar.uruma.component.jface.GridLayoutInfo;
29  
30  /**
31   * {@link AbstractControlRenderer} のためのテストクラスです。<br />
32   * 
33   * @author y-komori
34   */
35  public class AbstractControlRendererTest extends TestCase {
36      private ControlRenderer controlRenderer;
37  
38      /*
39       * @see junit.framework.TestCase#setUp()
40       */
41      @Override
42      protected void setUp() throws Exception {
43          this.controlRenderer = new ControlRenderer();
44      }
45  
46      /**
47       * {@link AbstractControlRenderer#inheritLayoutData(UIControlComponent)}
48       * メソッドのテストです。<br />
49       */
50      public void testInheritLayoutData() {
51          UICompositeComponent parentComponent = new CompositeComponent();
52          GridLayoutInfo gridLayoutInfo = new GridLayoutInfo();
53          parentComponent.setLayoutInfo(gridLayoutInfo);
54          GridDataInfo parentGridData = new GridDataInfo();
55          parentGridData.heightHint = "200";
56          parentGridData.widthHint = "400";
57          parentGridData.minimumHeight = "150";
58          gridLayoutInfo.setCommonLayoutDataInfo(parentGridData);
59  
60          UIControlComponent component = new ButtonComponent();
61          parentComponent.addChild(component);
62          GridDataInfo gridDataInfo = new GridDataInfo();
63          gridDataInfo.minimumHeight = "50";
64          gridDataInfo.minimumWidth = "100";
65          gridDataInfo.horizontalSpan = "3";
66          component.setLayoutDataInfo(gridDataInfo);
67  
68          controlRenderer.inheritLayoutData(component);
69  
70          assertEquals("1", "200", gridDataInfo.heightHint);
71          assertEquals("2", "400", gridDataInfo.widthHint);
72          assertEquals("3", "50", gridDataInfo.minimumHeight);
73          assertEquals("4", "100", gridDataInfo.minimumWidth);
74          assertEquals("5", "3", gridDataInfo.horizontalSpan);
75      }
76  
77      /**
78       * {@link AbstractControlRenderer#setCommonAttributes(org.seasar.uruma.component.UIComponent)}
79       * メソッドのテストです。<br />
80       */
81      public void testSetCommonAttributes() {
82          UICompositeComponent parentComponent = new CompositeComponent();
83          CommonAttriburtesImpl commonAttributes = new CommonAttriburtesImpl();
84          commonAttributes.setBackGround("WHITE");
85          commonAttributes.setFontHeight("20");
86          parentComponent.setCommonAttributes(commonAttributes);
87  
88          ButtonComponent component = new ButtonComponent();
89          parentComponent.addChild(component);
90          component.fontHeight = "15";
91  
92          controlRenderer.setCommonAttributes(component);
93  
94          assertEquals("1", "WHITE", component.background);
95          assertEquals("2", "15", component.fontHeight);
96      }
97  
98      /**
99       * @author y-komori
100      */
101     private static class ControlRenderer extends
102             AbstractControlRenderer<ControlComponent, Control> {
103 
104         @Override
105         protected void doRenderControl(final ControlComponent controlComponent,
106                 final Control control) {
107         }
108 
109         @Override
110         protected Class<Control> getWidgetType() {
111             return Control.class;
112         }
113     }
114 }