KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > j2ee > EntityBeanCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.j2ee;
2 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
3 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
4 import com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheck;
5 import com.puppycrawl.tools.checkstyle.checks.j2ee.PersistenceOption;
6
7 public class EntityBeanCheckTest extends BaseCheckTestCase
8 {
9     public void testDefaultBean()
10             throws Exception JavaDoc
11     {
12         final DefaultConfiguration checkConfig =
13             createCheckConfig(EntityBeanCheck.class);
14         final String JavaDoc[] expected = {
15         };
16         verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected);
17     }
18         
19     public void testMissingConstructor()
20         throws Exception JavaDoc
21     {
22         final DefaultConfiguration checkConfig =
23             createCheckConfig(EntityBeanCheck.class);
24         final String JavaDoc[] expected = {
25             "13:14: Entity bean 'InputEntityBeanMissingConstructor' must have a public constructor with no parameters.",
26         };
27         verify(
28             checkConfig,
29             getPath("j2ee/InputEntityBeanMissingConstructor.java"),
30             expected);
31     }
32     public void testMixedBean()
33             throws Exception JavaDoc
34     {
35         final DefaultConfiguration checkConfig =
36             createCheckConfig(EntityBeanCheck.class);
37         checkConfig.addAttribute("persistence",
38             PersistenceOption.MIXED.toString());
39         final String JavaDoc[] expected = {
40         };
41         verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected);
42     }
43     
44     public void testBeanBean()
45             throws Exception JavaDoc
46     {
47         final DefaultConfiguration checkConfig =
48             createCheckConfig(EntityBeanCheck.class);
49         checkConfig.addAttribute("persistence",
50             PersistenceOption.BEAN.toString());
51         final String JavaDoc[] expected = {
52             "13:14: Entity bean 'InputEntityBean' must have method 'ejbFindByPrimaryKey'.",
53         };
54         verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected);
55     }
56     
57     public void testAbstractBean()
58             throws Exception JavaDoc
59     {
60         final DefaultConfiguration checkConfig =
61             createCheckConfig(EntityBeanCheck.class);
62         final String JavaDoc[] expected = {
63         };
64         verify(checkConfig, getPath("j2ee/InputAbstractEntityBean.java"), expected);
65         checkConfig.addAttribute("persistence",
66              PersistenceOption.CONTAINER.toString());
67         verify(checkConfig, getPath("j2ee/InputAbstractEntityBean.java"), expected);
68     }
69     
70     public void testAbstractBeanBean()
71             throws Exception JavaDoc
72     {
73         final DefaultConfiguration checkConfig =
74             createCheckConfig(EntityBeanCheck.class);
75         checkConfig.addAttribute("persistence",
76              PersistenceOption.BEAN.toString());
77         final String JavaDoc[] expected = {
78             "8:23: Entity bean 'InputAbstractEntityBean' must not be abstract.",
79         };
80         verify(checkConfig, getPath("j2ee/InputAbstractEntityBean.java"), expected);
81     }
82     
83     public void testContainerBean()
84             throws Exception JavaDoc
85     {
86         final DefaultConfiguration checkConfig =
87             createCheckConfig(EntityBeanCheck.class);
88         checkConfig.addAttribute("persistence",
89             PersistenceOption.CONTAINER.toString());
90         final String JavaDoc[] expected = {
91             "13:14: Entity bean 'InputEntityBean' must be abstract.",
92         };
93         verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected);
94     }
95     
96     public void testCreate()
97             throws Exception JavaDoc
98     {
99         final DefaultConfiguration checkConfig =
100             createCheckConfig(EntityBeanCheck.class);
101         final String JavaDoc[] expected = {
102             "20:31: Method 'ejbCreateSomething' must be non-void.",
103             "20:31: Method 'ejbCreateSomething' must be public.",
104             "20:31: Method 'ejbCreateSomething' must have a matching 'ejbPostCreateSomething' method.",
105             "20:31: Method 'ejbCreateSomething' must not have modifier 'final'.",
106             "20:31: Method 'ejbCreateSomething' must not have modifier 'static'.",
107         };
108         // default (MIXED) persistence
109
verify(checkConfig, getPath("j2ee/InputEntityBeanCreate.java"), expected);
110         // bean-managed persistence
111
checkConfig.addAttribute(
112             "persistence",
113             PersistenceOption.BEAN.toString());
114         verify(checkConfig, getPath("j2ee/InputEntityBeanCreate.java"), expected);
115 // // container-managed persistence
116
// checkConfig.addAttribute(
117
// "persistence",
118
// PersistenceOption.CONTAINER.toString());
119
// verify(checkConfig, getPath("InputEntityBeanCreate.java"), expected);
120
}
121     
122     public void testPostCreate()
123             throws Exception JavaDoc
124     {
125         final DefaultConfiguration checkConfig =
126             createCheckConfig(EntityBeanCheck.class);
127         final String JavaDoc[] expected = {
128             "20:33: Method 'ejbPostCreateSomething' must be public.",
129             "20:33: Method 'ejbPostCreateSomething' must be void.",
130             "20:33: Method 'ejbPostCreateSomething' must not have modifier 'final'.",
131             "20:33: Method 'ejbPostCreateSomething' must not have modifier 'static'.",
132         };
133         verify(checkConfig, getPath("j2ee/InputEntityBeanPostCreate.java"), expected);
134         // bean-managed persistence
135
checkConfig.addAttribute(
136             "persistence",
137             PersistenceOption.BEAN.toString());
138         verify(checkConfig, getPath("j2ee/InputEntityBeanPostCreate.java"), expected);
139 // // container-managed persistence
140
// checkConfig.addAttribute(
141
// "persistence",
142
// PersistenceOption.CONTAINER.toString());
143
// verify(checkConfig, getPath("InputEntityBeanCreate.java"), expected);
144
}
145
146     public void testHome()
147              throws Exception JavaDoc
148      {
149          final DefaultConfiguration checkConfig =
150              createCheckConfig(EntityBeanCheck.class);
151          final String JavaDoc[] expected = {
152              "20:31: Method 'ejbHomeSomething' must be public.",
153              "20:31: Method 'ejbHomeSomething' must not have modifier 'static'.",
154              "20:31: Method 'ejbHomeSomething' must not throw 'java.rmi.RemoteException'.",
155          };
156          // default (MIXED) persistence
157
verify(checkConfig, getPath("j2ee/InputEntityBeanHome.java"), expected);
158          // bean-managed persistence
159
checkConfig.addAttribute(
160              "persistence",
161              PersistenceOption.BEAN.toString());
162          verify(checkConfig, getPath("j2ee/InputEntityBeanHome.java"), expected);
163 // // container-managed persistence
164
// checkConfig.addAttribute(
165
// "persistence",
166
// PersistenceOption.CONTAINER.toString());
167
// verify(checkConfig, getPath("InputEntityBeanHome.java"), expected);
168
}
169     public void testFind()
170             throws Exception JavaDoc
171     {
172         final DefaultConfiguration checkConfig =
173             createCheckConfig(EntityBeanCheck.class);
174         checkConfig.addAttribute("persistence",
175             PersistenceOption.BEAN.toString());
176         final String JavaDoc[] expected = {
177             "20:31: Method 'ejbFindSomething' must be non-void.",
178             "20:31: Method 'ejbFindSomething' must be public.",
179             "20:31: Method 'ejbFindSomething' must not have modifier 'final'.",
180             "20:31: Method 'ejbFindSomething' must not have modifier 'static'.",
181         };
182         verify(checkConfig, getPath("j2ee/InputEntityBeanFind.java"), expected);
183     }
184 }
185
Popular Tags