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
24 public void testFindResourceBase() throws Exception
26 URL url = ClasspathUrlFinder.findResourceBase("com/titan/domain/Address.class");
27 Assert.assertNotNull(url);
34 public void testFindResourceBases() throws Exception
36 URL[] urls = ClasspathUrlFinder.findResourceBases("com/titan/domain/Address.class");
37 Assert.assertNotNull(urls);
43 public void testFindClasspaths() throws Exception
45 Assert.assertNotNull(System.getProperty("java.class.path"));
46 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
48 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");
52 URL[] urls = ClasspathUrlFinder.findClassPaths("titan-cruise-1.0.jar");
53 Assert.assertNotNull(urls);
59 public void testFindClasspaths2() throws Exception
61 Assert.assertNotNull(System.getProperty("java.class.path"));
62 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
64 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");
68 URL[] urls = ClasspathUrlFinder.findClassPaths();
69 Assert.assertNotNull(urls);
70 AnnotationDB db = verify(urls);
72 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
73 Set<String> tests = annotationIndex.get("org.junit.Test");
74 Assert.assertTrue(tests.contains(TestSmoke.class.getName()));
79 public void testFieldParameter() throws Exception
81 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
82 AnnotationDB db = new AnnotationDB();
85 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
86 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
87 Assert.assertTrue(simpleClasses.contains(ClassWithFieldAnnotation.class.getName()));
88 Assert.assertTrue(simpleClasses.contains(InterfaceWithParameterAnnotations.class.getName()));
90 Set<String> simpleAnnotations = db.getClassIndex().get(ClassWithFieldAnnotation.class.getName());
91 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
92 simpleAnnotations = db.getClassIndex().get(InterfaceWithParameterAnnotations.class.getName());
93 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
100 public void testCrossRef() throws Exception
102 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
103 AnnotationDB db = new AnnotationDB();
104 db.scanArchives(url);
105 db.crossReferenceImplementedInterfaces();
107 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
108 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
109 Assert.assertTrue(simpleClasses.contains(CrossRef.class.getName()));
111 Set<String> simpleAnnotations = db.getClassIndex().get(CrossRef.class.getName());
112 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
117 public void testCrossRefMetaAnnotations() throws Exception
119 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
120 AnnotationDB db = new AnnotationDB();
121 db.scanArchives(url);
122 db.crossReferenceMetaAnnotations();
124 Assert.assertTrue(db.getAnnotationIndex().get(MetaAnnotation.class.getName()).contains(CrossRefMetaAnnotaiton.class.getName()));
130 public void testByClass() throws Exception
132 URL url = ClasspathUrlFinder.findClassBase(Address.class);
133 Assert.assertNotNull(url);
139 private AnnotationDB verify(URL... urls)
142 AnnotationDB db = new AnnotationDB();
143 db.scanArchives(urls);
145 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
147 Set<String> entities = annotationIndex.get("javax.persistence.Entity");
148 Assert.assertNotNull(entities);
150 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
151 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
152 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
153 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
154 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
155 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
156 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
157 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
158 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
162 Set<String> entities = annotationIndex.get("javax.persistence.GeneratedValue");
163 Assert.assertNotNull(entities);
165 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
166 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
167 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
168 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
169 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
170 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
171 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
172 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
173 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
177 Set<String> entities = annotationIndex.get("javax.persistence.Id");
178 Assert.assertNotNull(entities);
180 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
181 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
182 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
183 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
184 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
185 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
186 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
187 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
188 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
191 Map<String, Set<String>> classIndex = db.getClassIndex();
192 Set<String> annotations = classIndex.get("com.titan.domain.Address");
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.Cabin");
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.CreditCard");
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.CreditCompany");
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.Cruise");
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.Customer");
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.Phone");
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.Reservation");
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"));
240 annotations = classIndex.get("com.titan.domain.Ship");
241 Assert.assertNotNull(annotations);
242 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
243 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
244 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));