1 package org.scannotation.test;
3 import com.titan.domain.Address;
4 import org.junit.Assert;
6 import org.scannotation.AnnotationDB;
7 import org.scannotation.classpath.ClasspathUrlFinder;
9 import java.io.IOException;
15 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
16 * @version $Revision: 1 $
18 public class TestSmoke
22 public void testFindResourceBase() throws Exception
24 URL url = ClasspathUrlFinder.findResourceBase("com/titan/domain/Address.class");
25 Assert.assertNotNull(url);
30 public void testFindResourceBases() throws Exception
32 URL[] urls = ClasspathUrlFinder.findResourceBases("com/titan/domain/Address.class");
33 Assert.assertNotNull(urls);
38 public void testFindClasspaths() throws Exception
40 Assert.assertNotNull(System.getProperty("java.class.path"));
41 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
43 System.err.println("WARNING!!!!!!!! CANNOT TEST testFindClasspaths(): This is a Maven2 and Surefire problem in that it doesn't set java.class.path correctly. I run this test within the IDE");
46 URL[] urls = ClasspathUrlFinder.findClassPaths("titan-cruise-1.0.jar");
47 Assert.assertNotNull(urls);
53 public void testFindClasspaths2() throws Exception
55 Assert.assertNotNull(System.getProperty("java.class.path"));
56 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
58 System.err.println("WARNING!!!!!!! CANNOT TEST testFindClasspaths2(): This is a Maven2 and Surefire problem in that it doesn't set java.class.path correctly. I run this test within the IDE");
61 URL[] urls = ClasspathUrlFinder.findClassPaths();
62 Assert.assertNotNull(urls);
63 AnnotationDB db = verify(urls);
65 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
66 Set<String> tests = annotationIndex.get("org.junit.Test");
67 Assert.assertTrue(tests.contains(TestSmoke.class.getName()));
72 public void testFieldParameter() throws Exception
74 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
75 AnnotationDB db = new AnnotationDB();
78 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
79 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
80 Assert.assertTrue(simpleClasses.contains(ClassWithFieldAnnotation.class.getName()));
81 Assert.assertTrue(simpleClasses.contains(InterfaceWithParameterAnnotations.class.getName()));
83 Set<String> simpleAnnotations = db.getClassIndex().get(ClassWithFieldAnnotation.class.getName());
84 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
85 simpleAnnotations = db.getClassIndex().get(InterfaceWithParameterAnnotations.class.getName());
86 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
93 public void testCrossRef() throws Exception
95 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
96 AnnotationDB db = new AnnotationDB();
98 db.crossReferenceImplementedInterfaces();
100 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
101 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
102 Assert.assertTrue(simpleClasses.contains(CrossRef.class.getName()));
104 Set<String> simpleAnnotations = db.getClassIndex().get(CrossRef.class.getName());
105 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
110 public void testByClass() throws Exception
112 URL url = ClasspathUrlFinder.findClassBase(Address.class);
113 Assert.assertNotNull(url);
118 private AnnotationDB verify(URL... urls)
121 AnnotationDB db = new AnnotationDB();
122 db.scanArchives(urls);
124 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
126 Set<String> entities = annotationIndex.get("javax.persistence.Entity");
127 Assert.assertNotNull(entities);
129 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
130 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
131 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
132 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
133 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
134 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
135 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
136 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
137 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
141 Set<String> entities = annotationIndex.get("javax.persistence.GeneratedValue");
142 Assert.assertNotNull(entities);
144 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
145 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
146 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
147 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
148 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
149 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
150 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
151 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
152 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
156 Set<String> entities = annotationIndex.get("javax.persistence.Id");
157 Assert.assertNotNull(entities);
159 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
160 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
161 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
162 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
163 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
164 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
165 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
166 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
167 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
170 Map<String, Set<String>> classIndex = db.getClassIndex();
171 Set<String> annotations = classIndex.get("com.titan.domain.Address");
172 Assert.assertNotNull(annotations);
173 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
174 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
175 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
177 annotations = classIndex.get("com.titan.domain.Cabin");
178 Assert.assertNotNull(annotations);
179 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
180 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
181 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
183 annotations = classIndex.get("com.titan.domain.CreditCard");
184 Assert.assertNotNull(annotations);
185 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
186 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
187 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
189 annotations = classIndex.get("com.titan.domain.CreditCompany");
190 Assert.assertNotNull(annotations);
191 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
192 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
193 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
195 annotations = classIndex.get("com.titan.domain.Cruise");
196 Assert.assertNotNull(annotations);
197 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
198 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
199 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
201 annotations = classIndex.get("com.titan.domain.Customer");
202 Assert.assertNotNull(annotations);
203 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
204 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
205 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
207 annotations = classIndex.get("com.titan.domain.Phone");
208 Assert.assertNotNull(annotations);
209 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
210 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
211 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
213 annotations = classIndex.get("com.titan.domain.Reservation");
214 Assert.assertNotNull(annotations);
215 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
216 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
217 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
219 annotations = classIndex.get("com.titan.domain.Ship");
220 Assert.assertNotNull(annotations);
221 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
222 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
223 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));