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.desc.impl;
17  
18  import java.util.List;
19  
20  import junit.framework.TestCase;
21  
22  import org.seasar.framework.beans.BeanDesc;
23  import org.seasar.framework.beans.PropertyDesc;
24  import org.seasar.framework.beans.factory.BeanDescFactory;
25  import org.seasar.uruma.annotation.ExportSelection;
26  import org.seasar.uruma.annotation.ExportValue;
27  import org.seasar.uruma.annotation.ImportExportValue;
28  import org.seasar.uruma.annotation.ImportSelection;
29  import org.seasar.uruma.annotation.ImportValue;
30  import org.seasar.uruma.desc.FormDesc;
31  
32  /**
33   * {@link FormDescImpl} のためのテストクラスです。<br />
34   * 
35   * @author y-komori
36   */
37  public class FormDescImplTest extends TestCase {
38      private BeanDesc beanDesc;
39  
40      private FormDesc desc;
41  
42      @Override
43      protected void setUp() throws Exception {
44          beanDesc = BeanDescFactory.getBeanDesc(Target01.class);
45          desc = new FormDescImpl(Target01.class);
46      }
47  
48      public void testGetImportValueProperties() throws Exception {
49          List<PropertyDesc> importProps = desc.getImportValueProperties();
50  
51          assertEquals("1", 3, importProps.size());
52          assertEquals("2", beanDesc.getPropertyDesc("field1"), importProps
53                  .get(0));
54          assertEquals("3", beanDesc.getPropertyDesc("field3"), importProps
55                  .get(1));
56          assertEquals("4", beanDesc.getPropertyDesc("field6"), importProps
57                  .get(2));
58  
59          try {
60              importProps.add(beanDesc.getPropertyDesc("field1"));
61              fail("5");
62          } catch (UnsupportedOperationException ex) {
63              assertTrue(true);
64          }
65      }
66  
67      public void testGetExportValueProperties() throws Exception {
68          List<PropertyDesc> exportProps = desc.getExportValueProperties();
69  
70          assertEquals("1", 3, exportProps.size());
71          assertEquals("2", beanDesc.getPropertyDesc("field2"), exportProps
72                  .get(0));
73          assertEquals("3", beanDesc.getPropertyDesc("field3"), exportProps
74                  .get(1));
75          assertEquals("4", beanDesc.getPropertyDesc("field7"), exportProps
76                  .get(2));
77  
78          try {
79              exportProps.add(beanDesc.getPropertyDesc("field1"));
80              fail("5");
81          } catch (UnsupportedOperationException ex) {
82              assertTrue(true);
83          }
84      }
85  
86      public void testGetImportSelectionProperties() throws Exception {
87          List<PropertyDesc> importSelectionProps = desc
88                  .getImportSelectionProperties();
89  
90          assertEquals("1", 2, importSelectionProps.size());
91          assertEquals("2", beanDesc.getPropertyDesc("field4"),
92                  importSelectionProps.get(0));
93          assertEquals("3", beanDesc.getPropertyDesc("field8"),
94                  importSelectionProps.get(1));
95          try {
96              importSelectionProps.add(beanDesc.getPropertyDesc("field1"));
97              fail("4");
98          } catch (UnsupportedOperationException ex) {
99              assertTrue(true);
100         }
101     }
102 
103     public void testGetExportSelectionProperties() throws Exception {
104         List<PropertyDesc> exportSelectionProps = desc
105                 .getExportSelectionProperties();
106 
107         assertEquals("1", 2, exportSelectionProps.size());
108         assertEquals("2", beanDesc.getPropertyDesc("field5"),
109                 exportSelectionProps.get(0));
110         assertEquals("3", beanDesc.getPropertyDesc("field9"),
111                 exportSelectionProps.get(1));
112 
113         try {
114             exportSelectionProps.add(beanDesc.getPropertyDesc("field1"));
115             fail("4");
116         } catch (UnsupportedOperationException ex) {
117             assertTrue(true);
118         }
119     }
120 
121     class SuperTarget {
122         @ImportValue
123         public String field6;
124 
125         @ExportValue
126         public String field7;
127 
128         @ImportSelection
129         public String field8;
130 
131         @ExportSelection
132         public String field9;
133     }
134 
135     class Target01 extends SuperTarget {
136         @ImportValue
137         public String field1;
138 
139         @ExportValue
140         public String field2;
141 
142         @ImportExportValue
143         public String field3;
144 
145         @ImportSelection
146         public String field4;
147 
148         @ExportSelection
149         public String field5;
150     }
151 }