KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > SerializabilityTest


1 package org.jbpm;
2
3 import java.io.File JavaDoc;
4 import java.io.Serializable JavaDoc;
5 import java.lang.reflect.Modifier JavaDoc;
6 import java.util.Arrays JavaDoc;
7 import java.util.HashSet JavaDoc;
8 import java.util.Set JavaDoc;
9
10 import junit.framework.TestCase;
11
12 import org.jbpm.file.def.FileDefinitionFileSystemConfigTest;
13 import org.jbpm.instantiation.ClassLoaderUtil;
14
15 public class SerializabilityTest extends TestCase {
16
17   String JavaDoc testRootDir = FileDefinitionFileSystemConfigTest.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
18   
19   static Set JavaDoc excusedClasses = new HashSet JavaDoc(Arrays.asList(new String JavaDoc[] {
20     "org.jbpm.ant.DeployParTask",
21     "org.jbpm.ant.JbpmSchemaTask",
22     "org.jbpm.ant.Launcher",
23     "org.jbpm.ant.StartHsqldbTask",
24     "org.jbpm.ant.StartJBossTask",
25     "org.jbpm.context.exe.JbpmType",
26     "org.jbpm.db.hibernate.ConverterEnumType",
27     "org.jbpm.db.hibernate.Converters",
28     "org.jbpm.db.hibernate.JbpmNamingStrategy",
29     "org.jbpm.db.jmx.JbpmService",
30     "org.jbpm.db.ContextSession",
31     "org.jbpm.db.FileSession",
32     "org.jbpm.db.GraphSession",
33     "org.jbpm.db.JbpmSession",
34     "org.jbpm.db.LoggingSession",
35     "org.jbpm.db.SchedulerSession",
36     "org.jbpm.db.TaskMgmtSession",
37     "org.jbpm.graph.exe.ExecutionContext",
38     "org.jbpm.instantiation.BeanInstantiator",
39     "org.jbpm.instantiation.ClassLoaderUtil",
40     "org.jbpm.instantiation.ConfigurationPropertyInstantiator",
41     "org.jbpm.instantiation.ConstructorInstantiator",
42     "org.jbpm.instantiation.DefaultInstantiator",
43     "org.jbpm.instantiation.FieldInstantiator",
44     "org.jbpm.instantiation.ProcessClassLoader",
45     "org.jbpm.instantiation.XmlInstantiator",
46     "org.jbpm.JbpmConfiguration",
47     "org.jbpm.jmx.JbpmService",
48     "org.jbpm.jpdl.convert.Converter",
49     "org.jbpm.jpdl.convert.Converter$1",
50     "org.jbpm.graph.action.ActionTypes",
51     "org.jbpm.graph.node.Fork$ForkedToken",
52     "org.jbpm.graph.node.InterleaveStart$DefaultInterleaver",
53     "org.jbpm.graph.node.NodeTypes",
54     "org.jbpm.graph.node.ProcessFactory",
55     "org.jbpm.jpdl.par.FileArchiveParser",
56     "org.jbpm.jpdl.par.JpdlArchiveParser",
57     "org.jbpm.jpdl.par.ProcessArchive",
58     "org.jbpm.jpdl.par.ProcessArchiveDeployer",
59     "org.jbpm.jpdl.par.ProcessArchiveDeployerTask",
60     "org.jbpm.jpdl.xml.JpdlXmlReader",
61     "org.jbpm.jpdl.xml.JpdlXmlWriter",
62     "org.jbpm.jpdl.xml.SchemaValidationHelper$Handler",
63     "org.jbpm.jpdl.xml.SchemaValidationHelper$Resolver",
64     "org.jbpm.jpdl.xml.SchemaValidationHelper",
65     "org.jbpm.scheduler.exe.SchedulerInstance$CancelledTimer",
66     "org.jbpm.scheduler.impl.Scheduler",
67     "org.jbpm.scheduler.impl.Scheduler$HistoryListener",
68     "org.jbpm.scheduler.impl.SchedulerMain$1",
69     "org.jbpm.scheduler.impl.SchedulerMain$LogListener",
70     "org.jbpm.scheduler.impl.SchedulerMain",
71     "org.jbpm.scheduler.impl.SchedulerThread",
72     "org.jbpm.security.authenticator.JBossAuthenticator",
73     "org.jbpm.security.authenticator.JbpmDefaultAuthenticator",
74     "org.jbpm.security.authenticator.SubjectAuthenticator",
75     "org.jbpm.security.Authorization",
76     "org.jbpm.security.authorizer.AccessControllerAuthorizer",
77     "org.jbpm.security.authorizer.JbpmIdentityAuthorizer",
78     "org.jbpm.security.authorizer.RolesAuthorizer",
79     "org.jbpm.security.filter.JbpmAuthenticationFilter"
80   }));
81   
82   public void testForNonSerializableClasses() {
83     File JavaDoc jbpmRoot = new File JavaDoc(testRootDir+"../classes.jbpm/");
84     scanForClasses(jbpmRoot, "");
85   }
86   
87   private void scanForClasses(File JavaDoc rootClassDir, String JavaDoc packageDir) {
88     File JavaDoc packageDirFile = new File JavaDoc(rootClassDir.getPath()+"/"+packageDir);
89     File JavaDoc[] files = packageDirFile.listFiles();
90     for (int i=0; i<files.length; i++) {
91       if (files[i].isDirectory()) {
92         String JavaDoc newPackageDir = ( "".equals(packageDir) ? files[i].getName() : packageDir+"/"+files[i].getName() );
93         // log.debug("descending into directory "+newPackageDir);
94
scanForClasses(rootClassDir, newPackageDir);
95         
96       } else if ( (files[i].isFile())
97                   && (files[i].getName().endsWith(".class"))
98                 ) {
99         // log.debug("found class file "+files[i].getName());
100
String JavaDoc classFilePath = packageDir+"/"+files[i].getName();
101         String JavaDoc className = classFilePath.replace('/', '.');
102         className = className.substring(0, className.length()-6);
103         assertSerializabilityOfClass(className);
104       }
105     }
106   }
107
108   private void assertSerializabilityOfClass(String JavaDoc className) {
109     Class JavaDoc clazz = ClassLoaderUtil.loadClass(className);
110     
111     if ( ! ( (Serializable JavaDoc.class.isAssignableFrom(clazz))
112              || (Modifier.isAbstract(clazz.getModifiers()))
113              || (excusedClasses.contains(clazz.getName()))
114            )
115        ) {
116       fail(className+" is NOT Serializable");
117     }
118   }
119
120   // private static final Log log = LogFactory.getLog(SerializabilityTest.class);
121
}
122
Popular Tags