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 11 { 12 final DefaultConfiguration checkConfig = 13 createCheckConfig(EntityBeanCheck.class); 14 final String [] expected = { 15 }; 16 verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); 17 } 18 19 public void testMissingConstructor() 20 throws Exception 21 { 22 final DefaultConfiguration checkConfig = 23 createCheckConfig(EntityBeanCheck.class); 24 final String [] 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 34 { 35 final DefaultConfiguration checkConfig = 36 createCheckConfig(EntityBeanCheck.class); 37 checkConfig.addAttribute("persistence", 38 PersistenceOption.MIXED.toString()); 39 final String [] expected = { 40 }; 41 verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); 42 } 43 44 public void testBeanBean() 45 throws Exception 46 { 47 final DefaultConfiguration checkConfig = 48 createCheckConfig(EntityBeanCheck.class); 49 checkConfig.addAttribute("persistence", 50 PersistenceOption.BEAN.toString()); 51 final String [] 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 59 { 60 final DefaultConfiguration checkConfig = 61 createCheckConfig(EntityBeanCheck.class); 62 final String [] 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 72 { 73 final DefaultConfiguration checkConfig = 74 createCheckConfig(EntityBeanCheck.class); 75 checkConfig.addAttribute("persistence", 76 PersistenceOption.BEAN.toString()); 77 final String [] 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 85 { 86 final DefaultConfiguration checkConfig = 87 createCheckConfig(EntityBeanCheck.class); 88 checkConfig.addAttribute("persistence", 89 PersistenceOption.CONTAINER.toString()); 90 final String [] 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 98 { 99 final DefaultConfiguration checkConfig = 100 createCheckConfig(EntityBeanCheck.class); 101 final String [] 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 verify(checkConfig, getPath("j2ee/InputEntityBeanCreate.java"), expected); 110 checkConfig.addAttribute( 112 "persistence", 113 PersistenceOption.BEAN.toString()); 114 verify(checkConfig, getPath("j2ee/InputEntityBeanCreate.java"), expected); 115 } 121 122 public void testPostCreate() 123 throws Exception 124 { 125 final DefaultConfiguration checkConfig = 126 createCheckConfig(EntityBeanCheck.class); 127 final String [] 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 checkConfig.addAttribute( 136 "persistence", 137 PersistenceOption.BEAN.toString()); 138 verify(checkConfig, getPath("j2ee/InputEntityBeanPostCreate.java"), expected); 139 } 145 146 public void testHome() 147 throws Exception 148 { 149 final DefaultConfiguration checkConfig = 150 createCheckConfig(EntityBeanCheck.class); 151 final String [] 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 verify(checkConfig, getPath("j2ee/InputEntityBeanHome.java"), expected); 158 checkConfig.addAttribute( 160 "persistence", 161 PersistenceOption.BEAN.toString()); 162 verify(checkConfig, getPath("j2ee/InputEntityBeanHome.java"), expected); 163 } 169 public void testFind() 170 throws Exception 171 { 172 final DefaultConfiguration checkConfig = 173 createCheckConfig(EntityBeanCheck.class); 174 checkConfig.addAttribute("persistence", 175 PersistenceOption.BEAN.toString()); 176 final String [] 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 |