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 java.util.Calendar;
19  import java.util.Date;
20  
21  import junit.framework.AssertionFailedError;
22  
23  import org.eclipse.swt.widgets.DateTime;
24  import org.seasar.uruma.annotation.EventListener;
25  import org.seasar.uruma.annotation.ImportExportValue;
26  import org.seasar.uruma.annotation.InitializeMethod;
27  
28  /**
29   * {@link DateTimeRenderer} のためのテストクラスです。<br />
30   * 
31   * @author y-komori
32   */
33  public class DateTimeRendererGUITest extends AbstractGUITest {
34      @ImportExportValue(id = "time")
35      public Date timeValue;
36  
37      @ImportExportValue(id = "date")
38      public Date dateValue;
39  
40      public DateTime date;
41  
42      public DateTime time;
43  
44      @InitializeMethod
45      public void initialize() {
46          Calendar calendar = Calendar.getInstance();
47          calendar.set(Calendar.YEAR, 1977);
48          calendar.set(Calendar.MONTH, 0);
49          calendar.set(Calendar.DATE, 12);
50          calendar.set(Calendar.HOUR_OF_DAY, 20);
51          calendar.set(Calendar.MINUTE, 30);
52          calendar.set(Calendar.SECOND, 15);
53  
54          dateValue = calendar.getTime();
55          timeValue = calendar.getTime();
56      }
57  
58      /*
59       * @see org.seasar.uruma.renderer.impl.AbstractGUITest#okButtonAction()
60       */
61      @Override
62      @EventListener(id = "okButton")
63      public void okButtonAction() {
64          Calendar calendar = Calendar.getInstance();
65  
66          try {
67              calendar.setTime(dateValue);
68              assertEquals("1", date.getYear(), calendar.get(Calendar.YEAR));
69              assertEquals("2", date.getMonth(), calendar.get(Calendar.MONTH));
70              assertEquals("3", date.getDay(), calendar.get(Calendar.DATE));
71  
72              calendar.setTime(timeValue);
73              assertEquals("4", time.getHours(), calendar
74                      .get(Calendar.HOUR_OF_DAY));
75              assertEquals("5", time.getMinutes(), calendar.get(Calendar.MINUTE));
76              assertEquals("6", time.getSeconds(), calendar.get(Calendar.SECOND));
77  
78              super.okButtonAction();
79          } catch (AssertionFailedError error) {
80              shell.close();
81              result = false;
82              throw error;
83          }
84      }
85  }