From 5cce308aec2a4fd9deaebc1153d864e7c5b76ac2 Mon Sep 17 00:00:00 2001 From: Rick Giles Date: Sat, 5 Jul 2003 17:16:05 +0000 Subject: [PATCH] tests for j2ee checks. --- .../j2ee/InputAbstractEntityBean.java | 20 ++ .../checkstyle/j2ee/InputEntityBean.java | 83 +++++++++ .../j2ee/InputEntityBeanCreate.java | 89 +++++++++ .../checkstyle/j2ee/InputEntityBeanFind.java | 85 +++++++++ .../checkstyle/j2ee/InputEntityBeanHome.java | 86 +++++++++ .../j2ee/InputEntityBeanMatchEjbCreate.java | 116 ++++++++++++ .../j2ee/InputEntityBeanPostCreate.java | 86 +++++++++ .../checkstyle/j2ee/InputHomeInterface.java | 26 +++ .../j2ee/InputLocalHomeInterface.java | 25 +++ .../InputLocalHomeInterfaceDuplicateFind.java | 19 ++ .../j2ee/InputLocalHomeInterfaceNoFind.java | 19 ++ .../checkstyle/j2ee/InputLocalInterface.java | 23 +++ .../checkstyle/j2ee/InputMessageBean.java | 98 ++++++++++ .../checkstyle/j2ee/InputMessageBean2.java | 47 +++++ .../j2ee/InputRemoteHomeInterface.java | 26 +++ ...InputRemoteHomeInterfaceDuplicateFind.java | 21 +++ .../j2ee/InputRemoteHomeInterfaceNoFind.java | 21 +++ .../checkstyle/j2ee/InputRemoteInterface.java | 23 +++ .../checkstyle/j2ee/InputSessionBean.java | 115 ++++++++++++ .../checks/j2ee/EntityBeanCheckTest.java | 171 ++++++++++++++++++ .../checks/j2ee/FinalStaticCheckTest.java | 18 ++ .../checks/j2ee/HomeInterfaceCheckTest.java | 26 +++ .../j2ee/LocalHomeInterfaceCheckTest.java | 54 ++++++ .../checks/j2ee/LocalInterfaceCheckTest.java | 19 ++ .../checks/j2ee/MessageBeanCheckTest.java | 28 +++ .../j2ee/RemoteHomeInterfaceCheckTest.java | 55 ++++++ .../checks/j2ee/RemoteInterfaceCheckTest.java | 18 ++ .../checks/j2ee/SessionBeanCheckTest.java | 26 +++ .../checks/j2ee/ThisParameterCheckTest.java | 40 ++++ .../checks/j2ee/ThisReturnCheckTest.java | 40 ++++ 30 files changed, 1523 insertions(+) create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputAbstractEntityBean.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBean.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanCreate.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanFind.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanHome.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanMatchEjbCreate.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanPostCreate.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputHomeInterface.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterface.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceDuplicateFind.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceNoFind.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalInterface.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean2.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterface.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceDuplicateFind.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceNoFind.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteInterface.java create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputSessionBean.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/EntityBeanCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/FinalStaticCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/HomeInterfaceCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalHomeInterfaceCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalInterfaceCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/MessageBeanCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteHomeInterfaceCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteInterfaceCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/SessionBeanCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisParameterCheckTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisReturnCheckTest.java diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputAbstractEntityBean.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputAbstractEntityBean.java new file mode 100644 index 000000000..086650333 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputAbstractEntityBean.java @@ -0,0 +1,20 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import javax.ejb.EntityBean; + +/** + * Test EntityBean + */ +public abstract class InputAbstractEntityBean + implements EntityBean +{ + + public InputAbstractEntityBean() + { + } + + public Object ejbFindByPrimaryKey(Object aObject) + { + return null; + } +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBean.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBean.java new file mode 100644 index 000000000..c6962ebe3 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBean.java @@ -0,0 +1,83 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; + +/** + * Test EntityBean + */ +public class InputEntityBean + implements EntityBean +{ + + public InputEntityBean() + { + } + + public Object thisMethod(Object aObject) + { + thisMethod(this); + return this; + } + + static int sInt; + /** + * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) + */ + public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#unsetEntityContext() + */ + public void unsetEntityContext() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbRemove() + */ + public void ejbRemove() throws RemoveException, EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbLoad() + */ + public void ejbLoad() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbStore() + */ + public void ejbStore() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanCreate.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanCreate.java new file mode 100644 index 000000000..44f0bc048 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanCreate.java @@ -0,0 +1,89 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; + +/** + * Test EntityBean + */ +public class InputEntityBeanCreate + implements EntityBean +{ + public InputEntityBeanCreate() + { + } + + private final static void ejbCreateSomething() + { + } + + public Object ejbFindByPrimaryKey(Object aObject) + { + return null; + } + + public void ejbPostCreateSomething(int i) + { + } + + /** + * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) + */ + public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#unsetEntityContext() + */ + public void unsetEntityContext() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbRemove() + */ + public void ejbRemove() throws RemoveException, EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbLoad() + */ + public void ejbLoad() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbStore() + */ + public void ejbStore() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanFind.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanFind.java new file mode 100644 index 000000000..6015ecab5 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanFind.java @@ -0,0 +1,85 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; + +/** + * Test EntityBean + */ +public class InputEntityBeanFind + implements EntityBean +{ + public InputEntityBeanFind() + { + } + + private final static void ejbFindSomething() + { + } + + public Object ejbFindByPrimaryKey(Object aObject) + { + return null; + } + + /** + * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) + */ + public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#unsetEntityContext() + */ + public void unsetEntityContext() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbRemove() + */ + public void ejbRemove() throws RemoveException, EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbLoad() + */ + public void ejbLoad() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbStore() + */ + public void ejbStore() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanHome.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanHome.java new file mode 100644 index 000000000..7ce039a46 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanHome.java @@ -0,0 +1,86 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; + +/** + * Test EntityBean + */ +public class InputEntityBeanHome + implements EntityBean +{ + public InputEntityBeanHome() + { + } + + private final static void ejbHomeSomething() + throws RemoteException + { + } + + public Object ejbFindByPrimaryKey(Object aObject) + { + return null; + } + + /** + * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) + */ + public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#unsetEntityContext() + */ + public void unsetEntityContext() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbRemove() + */ + public void ejbRemove() throws RemoveException, EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbLoad() + */ + public void ejbLoad() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbStore() + */ + public void ejbStore() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanMatchEjbCreate.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanMatchEjbCreate.java new file mode 100644 index 000000000..b8dd2b4de --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanMatchEjbCreate.java @@ -0,0 +1,116 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; + +/** + * Test EntityBean + */ +public class InputEntityBeanMatchEjbCreate + implements EntityBean +{ + + public InputEntityBeanMatchEjbCreate ejbCreate() + { + return null; + } + + public InputEntityBeanMatchEjbCreate ejbCreate(int i) + { + return null; + } + + public void ejbPostCreate(long i) + { + } + + public InputEntityBeanMatchEjbCreate ejbCreateThing(int i) + { + return null; + } + + public void ejbPostCreatething(int i) + { + } + + public InputEntityBeanMatchEjbCreate ejbCreateInteger(java.lang.Integer i) + { + return null; + } + + public void ejbPostCreateInteger(java.lang.Integer i) + { + } + + public InputEntityBeanMatchEjbCreate ejbCreateInteger(java.lang.Integer i, + long x) + { + return null; + } + + public void ejbPostCreateInteger(java.lang.Integer i, + double x) + { + } + /** + * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) + */ + public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#unsetEntityContext() + */ + public void unsetEntityContext() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbRemove() + */ + public void ejbRemove() throws RemoveException, EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbLoad() + */ + public void ejbLoad() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbStore() + */ + public void ejbStore() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + +} + diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanPostCreate.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanPostCreate.java new file mode 100644 index 000000000..4fff46eab --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputEntityBeanPostCreate.java @@ -0,0 +1,86 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.RemoveException; + +/** + * Test EntityBean + */ +public class InputEntityBeanPostCreate + implements EntityBean +{ + public InputEntityBeanPostCreate() + { + } + + private final static Object ejbPostCreateSomething() + { + return null; + } + + public Object ejbFindByPrimaryKey(Object aObject) + { + return null; + } + + /** + * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) + */ + public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#unsetEntityContext() + */ + public void unsetEntityContext() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbRemove() + */ + public void ejbRemove() throws RemoveException, EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbLoad() + */ + public void ejbLoad() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.EntityBean#ejbStore() + */ + public void ejbStore() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputHomeInterface.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputHomeInterface.java new file mode 100644 index 000000000..e7c79ab8e --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputHomeInterface.java @@ -0,0 +1,26 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; +import javax.ejb.FinderException; + +/** + * test for LocalHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputHomeInterface + extends EJBHome +{ + public Integer createInteger(int aParam) + throws CreateException, RemoteException; + + abstract void createSomething(int aParam); + + abstract void findSomething(int aParam); + + public Integer findInteger(int aParam) + throws FinderException, RemoteException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterface.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterface.java new file mode 100644 index 000000000..c5457d3a5 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterface.java @@ -0,0 +1,25 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import javax.ejb.CreateException; +import javax.ejb.FinderException; + +/** + * test for LocalHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputLocalHomeInterface + extends javax.ejb.EJBLocalHome +{ + public Integer createInteger(int aParam) + throws CreateException; + + abstract void createSomething(int aParam); + + abstract void findSomething(int aParam); + + public Integer findInteger(int aParam) + throws FinderException; + + public void method() throws java.rmi.RemoteException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceDuplicateFind.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceDuplicateFind.java new file mode 100644 index 000000000..8b879a2af --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceDuplicateFind.java @@ -0,0 +1,19 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import javax.ejb.EJBLocalHome; +import javax.ejb.FinderException; + +/** + * test for RemoteHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputLocalHomeInterfaceDuplicateFind + extends EJBLocalHome +{ + public Object findByPrimaryKey(Object aParam) + throws FinderException; + + public Object findByPrimaryKey() + throws FinderException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceNoFind.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceNoFind.java new file mode 100644 index 000000000..fc4b31f8b --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalHomeInterfaceNoFind.java @@ -0,0 +1,19 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import javax.ejb.EJBLocalHome; +import javax.ejb.FinderException; + +/** + * test for RemoteHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputLocalHomeInterfaceNoFind + extends EJBLocalHome +{ + public Object findByPrimaryKey(Object aParam, Object aParam2) + throws FinderException; + + public Object findByPrimaryKey() + throws FinderException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalInterface.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalInterface.java new file mode 100644 index 000000000..4aefbbfe8 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputLocalInterface.java @@ -0,0 +1,23 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBLocalObject; + +/** + * test for RemoteInterfaceCheck + * @author Rick Giles + * + */ +public interface InputLocalInterface + extends EJBLocalObject +{ + public void invalid1() + throws RemoteException; + + public void invalid2() + throws java.rmi.RemoteException; + + public void valid() + throws Exception; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean.java new file mode 100644 index 000000000..90c1b3789 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean.java @@ -0,0 +1,98 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import javax.ejb.EJBException; +import javax.ejb.MessageDrivenBean; +import javax.ejb.MessageDrivenContext; +import javax.jms.Message; +import javax.jms.MessageListener; + +/** + * Test MessageBeanCheck + */ +public class InputMessageBean + implements MessageDrivenBean, MessageListener +{ + + /** + * @see javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext) + */ + public void setMessageDrivenContext(MessageDrivenContext arg0) throws EJBException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.MessageDrivenBean#ejbRemove() + */ + public void ejbRemove() throws EJBException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.jms.MessageListener#onMessage(javax.jms.Message) + */ + public void onMessage(Message arg0) { + // TODO Auto-generated method stub + + } +} + +abstract class AbstractMessageBean + implements MessageDrivenBean, MessageListener +{ + public AbstractMessageBean() + { + } + + public void ejbCreate() + { + } +} + +final class FinalMessageBean + implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener +{ + public FinalMessageBean() + { + } + + public Object method() + { + this.equals(""); + "".equals(this); + return this; + } + + protected static final int ejbCreate(int i) + { + return 0; + } + /** + * @see javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext) + */ + public void setMessageDrivenContext(MessageDrivenContext arg0) throws EJBException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.MessageDrivenBean#ejbRemove() + */ + public void ejbRemove() throws EJBException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.jms.MessageListener#onMessage(javax.jms.Message) + */ + public void onMessage(Message arg0) { + // TODO Auto-generated method stub + + } + + public void ejbCreate() + { + } +} \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean2.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean2.java new file mode 100644 index 000000000..22c8fec0b --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputMessageBean2.java @@ -0,0 +1,47 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import javax.ejb.EJBException; +import javax.ejb.MessageDrivenBean; +import javax.ejb.MessageDrivenContext; +import javax.jms.Message; +import javax.jms.MessageListener; + +/** + * Test MessageBeanCheck + */ +public class InputMessageBean2 + implements MessageDrivenBean, MessageListener +{ + public InputMessageBean2() + { + } + + public void ejbCreate() + { + } + + /** + * @see javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext) + */ + public void setMessageDrivenContext(MessageDrivenContext arg0) throws EJBException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.MessageDrivenBean#ejbRemove() + */ + public void ejbRemove() throws EJBException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.jms.MessageListener#onMessage(javax.jms.Message) + */ + public void onMessage(Message arg0) { + // TODO Auto-generated method stub + + } +} + diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterface.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterface.java new file mode 100644 index 000000000..06b1ae529 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterface.java @@ -0,0 +1,26 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; +import javax.ejb.FinderException; + +/** + * test for RemoteHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputRemoteHomeInterface + extends EJBHome +{ + public Integer createInteger(int aParam) + throws CreateException, RemoteException; + + abstract void createSomething(int aParam); + + abstract void findSomething(int aParam); + + public Integer findInteger(int aParam) + throws FinderException, RemoteException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceDuplicateFind.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceDuplicateFind.java new file mode 100644 index 000000000..df68113ff --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceDuplicateFind.java @@ -0,0 +1,21 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBHome; +import javax.ejb.FinderException; + +/** + * test for RemoteHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputRemoteHomeInterfaceDuplicateFind + extends EJBHome +{ + public Object findByPrimaryKey(Object aParam) + throws FinderException, RemoteException; + + public Object findByPrimaryKey() + throws FinderException, RemoteException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceNoFind.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceNoFind.java new file mode 100644 index 000000000..6664598c5 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteHomeInterfaceNoFind.java @@ -0,0 +1,21 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBHome; +import javax.ejb.FinderException; + +/** + * test for RemoteHomeInterfaceCheck + * @author Rick Giles + * + */ +public interface InputRemoteHomeInterfaceNoFind + extends EJBHome +{ + public Object findByPrimaryKey(Object aParam, Object aParam2) + throws FinderException, RemoteException; + + public Object findByPrimaryKey() + throws FinderException, RemoteException; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteInterface.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteInterface.java new file mode 100644 index 000000000..b1daac646 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputRemoteInterface.java @@ -0,0 +1,23 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBObject; + +/** + * test for RemoteInterfaceCheck + * @author Rick Giles + * + */ +public interface InputRemoteInterface + extends EJBObject +{ + public void valid1() + throws RemoteException; + + public void valid2() + throws java.rmi.RemoteException; + + public void invalid() + throws Exception; +} diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputSessionBean.java b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputSessionBean.java new file mode 100644 index 000000000..21bce31f2 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/j2ee/InputSessionBean.java @@ -0,0 +1,115 @@ +package com.puppycrawl.tools.checkstyle.j2ee; + +import java.rmi.RemoteException; + +import javax.ejb.EJBException; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; + +/** + * SessionBean test + */ +public class InputSessionBean + implements SessionBean +{ + /** + * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) + */ + public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.SessionBean#ejbRemove() + */ + public void ejbRemove() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.SessionBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.SessionBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + public void finalize(int i) + { + return; + } +} + +abstract class AbstractSessionBean + implements SessionBean +{ +} + +final class FinalSessionBean + implements SessionBean +{ + public FinalSessionBean() + { + } + + public void ejbCreate(int aInt) + { + } + + public void ejbPostCreate(int aInt) + { + } + + public Object method() + { + this.equals(""); + "".equals(this); + return this; + } + + public void finalize() + { + } + /** + * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) + */ + public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.SessionBean#ejbRemove() + */ + public void ejbRemove() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.SessionBean#ejbActivate() + */ + public void ejbActivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } + + /** + * @see javax.ejb.SessionBean#ejbPassivate() + */ + public void ejbPassivate() throws EJBException, RemoteException { + // TODO Auto-generated method stub + + } +} + diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/EntityBeanCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/EntityBeanCheckTest.java new file mode 100644 index 000000000..2948694fb --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/EntityBeanCheckTest.java @@ -0,0 +1,171 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheck; +import com.puppycrawl.tools.checkstyle.checks.j2ee.PersistenceOption; + +public class EntityBeanCheckTest extends BaseCheckTestCase +{ + public void testDefaultBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + final String[] expected = { + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } + + public void testMixedBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + checkConfig.addAttribute("persistence", + PersistenceOption.MIXED.toString()); + final String[] expected = { + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } + + public void testBeanBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + checkConfig.addAttribute("persistence", + PersistenceOption.BEAN.toString()); + final String[] expected = { + "13:14: Entity bean 'InputEntityBean' must have method 'ejbFindByPrimaryKey'.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } + + public void testAbstractBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + final String[] expected = { + }; + verify(checkConfig, getPath("j2ee/InputAbstractEntityBean.java"), expected); + checkConfig.addAttribute("persistence", + PersistenceOption.CONTAINER.toString()); + verify(checkConfig, getPath("j2ee/InputAbstractEntityBean.java"), expected); + } + + public void testAbstractBeanBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + checkConfig.addAttribute("persistence", + PersistenceOption.BEAN.toString()); + final String[] expected = { + "8:23: Entity bean 'InputAbstractEntityBean' must not be abstract.", + }; + verify(checkConfig, getPath("j2ee/InputAbstractEntityBean.java"), expected); + } + + public void testContainerBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + checkConfig.addAttribute("persistence", + PersistenceOption.CONTAINER.toString()); + final String[] expected = { + "13:14: Entity bean 'InputEntityBean' must be abstract.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } + + public void testCreate() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + final String[] expected = { + "20:31: Method 'ejbCreateSomething' must be non-void.", + "20:31: Method 'ejbCreateSomething' must be public.", + "20:31: Method 'ejbCreateSomething' must have a matching 'ejbPostCreateSomething' method.", + "20:31: Method 'ejbCreateSomething' must not have modifier 'final'.", + "20:31: Method 'ejbCreateSomething' must not have modifier 'static'.", + }; + // default (MIXED) persistence + verify(checkConfig, getPath("j2ee/InputEntityBeanCreate.java"), expected); + // bean-managed persistence + checkConfig.addAttribute( + "persistence", + PersistenceOption.BEAN.toString()); + verify(checkConfig, getPath("j2ee/InputEntityBeanCreate.java"), expected); +// // container-managed persistence +// checkConfig.addAttribute( +// "persistence", +// PersistenceOption.CONTAINER.toString()); +// verify(checkConfig, getPath("InputEntityBeanCreate.java"), expected); + } + + public void testPostCreate() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + final String[] expected = { + "20:33: Method 'ejbPostCreateSomething' must be public.", + "20:33: Method 'ejbPostCreateSomething' must be void.", + "20:33: Method 'ejbPostCreateSomething' must not have modifier 'final'.", + "20:33: Method 'ejbPostCreateSomething' must not have modifier 'static'.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBeanPostCreate.java"), expected); + // bean-managed persistence + checkConfig.addAttribute( + "persistence", + PersistenceOption.BEAN.toString()); + verify(checkConfig, getPath("j2ee/InputEntityBeanPostCreate.java"), expected); +// // container-managed persistence +// checkConfig.addAttribute( +// "persistence", +// PersistenceOption.CONTAINER.toString()); +// verify(checkConfig, getPath("InputEntityBeanCreate.java"), expected); + } + + public void testHome() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + final String[] expected = { + "20:31: Method 'ejbHomeSomething' must be public.", + "20:31: Method 'ejbHomeSomething' must not have modifier 'static'.", + "20:31: Method 'ejbHomeSomething' must not throw 'java.rmi.RemoteException'.", + }; + // default (MIXED) persistence + verify(checkConfig, getPath("j2ee/InputEntityBeanHome.java"), expected); + // bean-managed persistence + checkConfig.addAttribute( + "persistence", + PersistenceOption.BEAN.toString()); + verify(checkConfig, getPath("j2ee/InputEntityBeanHome.java"), expected); +// // container-managed persistence +// checkConfig.addAttribute( +// "persistence", +// PersistenceOption.CONTAINER.toString()); +// verify(checkConfig, getPath("InputEntityBeanHome.java"), expected); + } + public void testFind() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(EntityBeanCheck.class); + checkConfig.addAttribute("persistence", + PersistenceOption.BEAN.toString()); + final String[] expected = { + "20:31: Method 'ejbFindSomething' must be non-void.", + "20:31: Method 'ejbFindSomething' must be public.", + "20:31: Method 'ejbFindSomething' must not have modifier 'final'.", + "20:31: Method 'ejbFindSomething' must not have modifier 'static'.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBeanFind.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/FinalStaticCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/FinalStaticCheckTest.java new file mode 100644 index 000000000..b2d2dedc5 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/FinalStaticCheckTest.java @@ -0,0 +1,18 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.FinalStaticCheck; + +public class FinalStaticCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(FinalStaticCheck.class); + final String[] expected = { + "27:16: Static field 'sInt' should be final.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/HomeInterfaceCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/HomeInterfaceCheckTest.java new file mode 100644 index 000000000..a8ec604bf --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/HomeInterfaceCheckTest.java @@ -0,0 +1,26 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.RemoteHomeInterfaceCheck; + +public class HomeInterfaceCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(RemoteHomeInterfaceCheck.class); + final String[] expected = { + "14:18: Home interface must have method findByPrimaryKey.", + "20:19: Method createSomething must be non-void.", + "20:19: Method createSomething must be public.", + "20:19: Method createSomething must throw java.rmi.RemoteException.", + "20:19: Method createSomething must throw javax.ejb.CreateException.", + "22:19: Method findSomething must be non-void.", + "22:19: Method findSomething must be public.", + "22:19: Method findSomething must throw java.rmi.RemoteException.", + "22:19: Method findSomething must throw javax.ejb.FinderException.", + }; + verify(checkConfig, getPath("j2ee/InputHomeInterface.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalHomeInterfaceCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalHomeInterfaceCheckTest.java new file mode 100644 index 000000000..e9e375415 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalHomeInterfaceCheckTest.java @@ -0,0 +1,54 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.LocalHomeInterfaceCheck; + +public class LocalHomeInterfaceCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(LocalHomeInterfaceCheck.class); + final String[] expected = { + "11:18: Home interface 'InputLocalHomeInterface' must have method 'findByPrimaryKey()'.", + "17:19: Method 'createSomething' must be non-void.", + "17:19: Method 'createSomething' must throw 'javax.ejb.CreateException'.", + "19:19: Method 'findSomething' must be non-void.", + "19:19: Method 'findSomething' must throw 'javax.ejb.FinderException'.", + "24:17: Method 'method' must not throw 'java.rmi.RemoteException'.", + }; + verify(checkConfig, getPath("j2ee/InputLocalHomeInterface.java"), expected); + } + + public void testDuplicateFind() throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(LocalHomeInterfaceCheck.class); + final String[] expected = + { + "17:19: Home interface can have only one 'findByPrimaryKey()' method.", + "17:19: Method 'findByPrimaryKey' must have 1 parameter(s).", + }; + verify( + checkConfig, + getPath("j2ee/InputLocalHomeInterfaceDuplicateFind.java"), + expected); + } + + public void testNoFind() throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(LocalHomeInterfaceCheck.class); + final String[] expected = + { + "14:19: Method 'findByPrimaryKey' must have 1 parameter(s).", + "17:19: Home interface can have only one 'findByPrimaryKey()' method.", + "17:19: Method 'findByPrimaryKey' must have 1 parameter(s).", + }; + verify( + checkConfig, + getPath("j2ee/InputLocalHomeInterfaceNoFind.java"), + expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalInterfaceCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalInterfaceCheckTest.java new file mode 100644 index 000000000..756492673 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/LocalInterfaceCheckTest.java @@ -0,0 +1,19 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.LocalInterfaceCheck; + +public class LocalInterfaceCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(LocalInterfaceCheck.class); + final String[] expected = { + "15:17: Method 'invalid1' must not throw 'java.rmi.RemoteException'.", + "18:17: Method 'invalid2' must not throw 'java.rmi.RemoteException'.", + }; + verify(checkConfig, getPath("j2ee/InputLocalInterface.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/MessageBeanCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/MessageBeanCheckTest.java new file mode 100644 index 000000000..2a8817382 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/MessageBeanCheckTest.java @@ -0,0 +1,28 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.MessageBeanCheck; + +public class MessageBeanCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(MessageBeanCheck.class); + final String[] expected = { + "12:14: Message bean 'InputMessageBean' must have a public constructor with no parameters.", + "12:14: Message bean 'InputMessageBean' must have method 'ejbCreate()'.", + "41:16: Message bean 'AbstractMessageBean' must be public.", + "41:16: Message bean 'AbstractMessageBean' must not have modifier 'abstract'.", + "53:13: Message bean 'FinalMessageBean' must be public.", + "53:13: Message bean 'FinalMessageBean' must not have modifier 'final'.", + "67:32: Method 'ejbCreate' must be public.", + "67:32: Method 'ejbCreate' must be void.", + "67:32: Method 'ejbCreate' must have 0 parameter(s).", + "67:32: Method 'ejbCreate' must not have modifier 'final'.", + "67:32: Method 'ejbCreate' must not have modifier 'static'.", + }; + verify(checkConfig, getPath("j2ee/InputMessageBean.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteHomeInterfaceCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteHomeInterfaceCheckTest.java new file mode 100644 index 000000000..e4e2221d0 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteHomeInterfaceCheckTest.java @@ -0,0 +1,55 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.RemoteHomeInterfaceCheck; + +public class RemoteHomeInterfaceCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(RemoteHomeInterfaceCheck.class); + final String[] expected = { + "14:18: Home interface 'InputRemoteHomeInterface' must have method 'findByPrimaryKey()'.", + "20:19: Method 'createSomething' must be non-void.", + "20:19: Method 'createSomething' must throw 'java.rmi.RemoteException'.", + "20:19: Method 'createSomething' must throw 'javax.ejb.CreateException'.", + "22:19: Method 'findSomething' must be non-void.", + "22:19: Method 'findSomething' must throw 'java.rmi.RemoteException'.", + "22:19: Method 'findSomething' must throw 'javax.ejb.FinderException'.", + }; + verify(checkConfig, getPath("j2ee/InputRemoteHomeInterface.java"), expected); + } + + public void testDuplicateFind() throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(RemoteHomeInterfaceCheck.class); + final String[] expected = + { + "19:19: Home interface can have only one 'findByPrimaryKey()' method.", + "19:19: Method 'findByPrimaryKey' must have 1 parameter(s).", + }; + verify( + checkConfig, + getPath("j2ee/InputRemoteHomeInterfaceDuplicateFind.java"), + expected); + } + + public void testNoFind() throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(RemoteHomeInterfaceCheck.class); + final String[] expected = + { + "16:19: Method 'findByPrimaryKey' must have 1 parameter(s).", + "19:19: Home interface can have only one 'findByPrimaryKey()' method.", + "19:19: Method 'findByPrimaryKey' must have 1 parameter(s).", + }; + verify( + checkConfig, + getPath("j2ee/InputRemoteHomeInterfaceNoFind.java"), + expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteInterfaceCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteInterfaceCheckTest.java new file mode 100644 index 000000000..a5d389b35 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/RemoteInterfaceCheckTest.java @@ -0,0 +1,18 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.RemoteInterfaceCheck; + +public class RemoteInterfaceCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(RemoteInterfaceCheck.class); + final String[] expected = { + "21:17: Method 'invalid' must throw 'java.rmi.RemoteException'.", + }; + verify(checkConfig, getPath("j2ee/InputRemoteInterface.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/SessionBeanCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/SessionBeanCheckTest.java new file mode 100644 index 000000000..bf2b1b01b --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/SessionBeanCheckTest.java @@ -0,0 +1,26 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.SessionBeanCheck; + +public class SessionBeanCheckTest extends BaseCheckTestCase +{ + public void testDefault() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(SessionBeanCheck.class); + final String[] expected = { + "12:14: Session bean 'InputSessionBean' must have a public constructor with no parameters.", + "12:14: Session bean 'InputSessionBean' must have method 'ejbCreate(...)'.", + "53:16: Session bean 'AbstractSessionBean' must be public.", + "53:16: Session bean 'AbstractSessionBean' must have a public constructor with no parameters.", + "53:16: Session bean 'AbstractSessionBean' must have method 'ejbCreate(...)'.", + "53:16: Session bean 'AbstractSessionBean' must not have modifier 'abstract'.", + "58:13: Session bean 'FinalSessionBean' must be public.", + "58:13: Session bean 'FinalSessionBean' must not define the 'finalize()' method.", + "58:13: Session bean 'FinalSessionBean' must not have modifier 'final'.", + }; + verify(checkConfig, getPath("j2ee/InputSessionBean.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisParameterCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisParameterCheckTest.java new file mode 100644 index 000000000..b82b3d816 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisParameterCheckTest.java @@ -0,0 +1,40 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.ThisParameterCheck; + +public class ThisParameterCheckTest extends BaseCheckTestCase +{ + public void testEntityBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(ThisParameterCheck.class); + final String[] expected = { + "23:20: Do not pass 'this' as a parameter.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } + + public void testMessageBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(ThisParameterCheck.class); + final String[] expected = { + "63:19: Do not pass 'this' as a parameter.", + }; + verify(checkConfig, getPath("j2ee/InputMessageBean.java"), expected); + } + + public void testSessionBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(ThisParameterCheck.class); + final String[] expected = { + "76:19: Do not pass 'this' as a parameter.", + }; + verify(checkConfig, getPath("j2ee/InputSessionBean.java"), expected); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisReturnCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisReturnCheckTest.java new file mode 100644 index 000000000..532e2f63c --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/j2ee/ThisReturnCheckTest.java @@ -0,0 +1,40 @@ +package com.puppycrawl.tools.checkstyle.checks.j2ee; +import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.j2ee.ThisReturnCheck; + +public class ThisReturnCheckTest extends BaseCheckTestCase +{ + public void testEntityBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(ThisReturnCheck.class); + final String[] expected = { + "24:16: Do not return 'this'.", + }; + verify(checkConfig, getPath("j2ee/InputEntityBean.java"), expected); + } + + public void testMessageBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(ThisReturnCheck.class); + final String[] expected = { + "64:16: Do not return 'this'.", + }; + verify(checkConfig, getPath("j2ee/InputMessageBean.java"), expected); + } + + public void testSessionBean() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(ThisReturnCheck.class); + final String[] expected = { + "77:16: Do not return 'this'.", + }; + verify(checkConfig, getPath("j2ee/InputSessionBean.java"), expected); + } +}