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.ClasspathUrlFinder;
9 import java.io.IOException;
10 import java.io.PrintWriter;
16 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
17 * @version $Revision: 1 $
19 public class TestSmoke
23 public void testFindResourceBase() throws Exception
25 URL url = ClasspathUrlFinder.findResourceBase("com/titan/domain/Address.class");
26 Assert.assertNotNull(url);
31 public void testFindResourceBases() throws Exception
33 URL[] urls = ClasspathUrlFinder.findResourceBases("com/titan/domain/Address.class");
34 Assert.assertNotNull(urls);
39 public void testFindClasspaths() throws Exception
41 Assert.assertNotNull(System.getProperty("java.class.path"));
42 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
44 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");
48 URL[] urls = ClasspathUrlFinder.findClassPaths("titan-cruise-1.0.jar");
49 Assert.assertNotNull(urls);
55 public void testFindClasspaths2() throws Exception
57 Assert.assertNotNull(System.getProperty("java.class.path"));
58 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
60 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");
64 URL[] urls = ClasspathUrlFinder.findClassPaths();
65 Assert.assertNotNull(urls);
66 AnnotationDB db = verify(urls);
68 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
69 Set<String> tests = annotationIndex.get("org.junit.Test");
70 Assert.assertTrue(tests.contains(TestSmoke.class.getName()));
75 public void testFieldParameter() throws Exception
77 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
78 AnnotationDB db = new AnnotationDB();
81 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
82 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
83 Assert.assertTrue(simpleClasses.contains(ClassWithFieldAnnotation.class.getName()));
84 Assert.assertTrue(simpleClasses.contains(InterfaceWithParameterAnnotations.class.getName()));
86 Set<String> simpleAnnotations = db.getClassIndex().get(ClassWithFieldAnnotation.class.getName());
87 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
88 simpleAnnotations = db.getClassIndex().get(InterfaceWithParameterAnnotations.class.getName());
89 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
96 public void testCrossRef() throws Exception
98 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
99 AnnotationDB db = new AnnotationDB();
100 db.scanArchives(url);
101 db.crossReferenceImplementedInterfaces();
103 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
104 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
105 Assert.assertTrue(simpleClasses.contains(CrossRef.class.getName()));
107 Set<String> simpleAnnotations = db.getClassIndex().get(CrossRef.class.getName());
108 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
113 public void testCrossRefMetaAnnotations() throws Exception
115 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
116 AnnotationDB db = new AnnotationDB();
117 db.scanArchives(url);
118 db.crossReferenceMetaAnnotations();
120 Assert.assertTrue(db.getAnnotationIndex().get(MetaAnnotation.class.getName()).contains(CrossRefMetaAnnotaiton.class.getName()));
125 public void testByClass() throws Exception
127 URL url = ClasspathUrlFinder.findClassBase(Address.class);
128 Assert.assertNotNull(url);
133 private AnnotationDB verify(URL... urls)
136 AnnotationDB db = new AnnotationDB();
137 db.scanArchives(urls);
139 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
141 Set<String> entities = annotationIndex.get("javax.persistence.Entity");
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.GeneratedValue");
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"));
171 Set<String> entities = annotationIndex.get("javax.persistence.Id");
172 Assert.assertNotNull(entities);
174 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
175 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
176 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
177 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
178 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
179 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
180 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
181 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
182 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
185 Map<String, Set<String>> classIndex = db.getClassIndex();
186 Set<String> annotations = classIndex.get("com.titan.domain.Address");
187 Assert.assertNotNull(annotations);
188 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
189 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
190 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
192 annotations = classIndex.get("com.titan.domain.Cabin");
193 Assert.assertNotNull(annotations);
194 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
195 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
196 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
198 annotations = classIndex.get("com.titan.domain.CreditCard");
199 Assert.assertNotNull(annotations);
200 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
201 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
202 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
204 annotations = classIndex.get("com.titan.domain.CreditCompany");
205 Assert.assertNotNull(annotations);
206 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
207 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
208 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
210 annotations = classIndex.get("com.titan.domain.Cruise");
211 Assert.assertNotNull(annotations);
212 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
213 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
214 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
216 annotations = classIndex.get("com.titan.domain.Customer");
217 Assert.assertNotNull(annotations);
218 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
219 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
220 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
222 annotations = classIndex.get("com.titan.domain.Phone");
223 Assert.assertNotNull(annotations);
224 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
225 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
226 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
228 annotations = classIndex.get("com.titan.domain.Reservation");
229 Assert.assertNotNull(annotations);
230 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
231 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
232 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
234 annotations = classIndex.get("com.titan.domain.Ship");
235 Assert.assertNotNull(annotations);
236 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
237 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
238 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));