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;
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");
47 URL[] urls = ClasspathUrlFinder.findClassPaths("titan-cruise-1.0.jar");
48 Assert.assertNotNull(urls);
54 public void testFindClasspaths2() throws Exception
56 Assert.assertNotNull(System.getProperty("java.class.path"));
57 if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
59 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");
63 URL[] urls = ClasspathUrlFinder.findClassPaths();
64 Assert.assertNotNull(urls);
65 AnnotationDB db = verify(urls);
67 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
68 Set<String> tests = annotationIndex.get("org.junit.Test");
69 Assert.assertTrue(tests.contains(TestSmoke.class.getName()));
74 public void testFieldParameter() throws Exception
76 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
77 AnnotationDB db = new AnnotationDB();
80 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
81 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
82 Assert.assertTrue(simpleClasses.contains(ClassWithFieldAnnotation.class.getName()));
83 Assert.assertTrue(simpleClasses.contains(InterfaceWithParameterAnnotations.class.getName()));
85 Set<String> simpleAnnotations = db.getClassIndex().get(ClassWithFieldAnnotation.class.getName());
86 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
87 simpleAnnotations = db.getClassIndex().get(InterfaceWithParameterAnnotations.class.getName());
88 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
95 public void testCrossRef() throws Exception
97 URL url = ClasspathUrlFinder.findClassBase(TestSmoke.class);
98 AnnotationDB db = new AnnotationDB();
100 db.crossReferenceImplementedInterfaces();
102 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
103 Set<String> simpleClasses = annotationIndex.get(SimpleAnnotation.class.getName());
104 Assert.assertTrue(simpleClasses.contains(CrossRef.class.getName()));
106 Set<String> simpleAnnotations = db.getClassIndex().get(CrossRef.class.getName());
107 Assert.assertTrue(simpleAnnotations.contains(SimpleAnnotation.class.getName()));
112 public void testByClass() throws Exception
114 URL url = ClasspathUrlFinder.findClassBase(Address.class);
115 Assert.assertNotNull(url);
120 private AnnotationDB verify(URL... urls)
123 AnnotationDB db = new AnnotationDB();
124 db.scanArchives(urls);
126 Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
128 Set<String> entities = annotationIndex.get("javax.persistence.Entity");
129 Assert.assertNotNull(entities);
131 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
132 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
133 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
134 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
135 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
136 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
137 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
138 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
139 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
143 Set<String> entities = annotationIndex.get("javax.persistence.GeneratedValue");
144 Assert.assertNotNull(entities);
146 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
147 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
148 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
149 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
150 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
151 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
152 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
153 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
154 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
158 Set<String> entities = annotationIndex.get("javax.persistence.Id");
159 Assert.assertNotNull(entities);
161 Assert.assertTrue(entities.contains("com.titan.domain.Address"));
162 Assert.assertTrue(entities.contains("com.titan.domain.Cabin"));
163 Assert.assertTrue(entities.contains("com.titan.domain.CreditCard"));
164 Assert.assertTrue(entities.contains("com.titan.domain.CreditCompany"));
165 Assert.assertTrue(entities.contains("com.titan.domain.Cruise"));
166 Assert.assertTrue(entities.contains("com.titan.domain.Customer"));
167 Assert.assertTrue(entities.contains("com.titan.domain.Phone"));
168 Assert.assertTrue(entities.contains("com.titan.domain.Reservation"));
169 Assert.assertTrue(entities.contains("com.titan.domain.Ship"));
172 Map<String, Set<String>> classIndex = db.getClassIndex();
173 Set<String> annotations = classIndex.get("com.titan.domain.Address");
174 Assert.assertNotNull(annotations);
175 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
176 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
177 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
179 annotations = classIndex.get("com.titan.domain.Cabin");
180 Assert.assertNotNull(annotations);
181 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
182 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
183 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
185 annotations = classIndex.get("com.titan.domain.CreditCard");
186 Assert.assertNotNull(annotations);
187 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
188 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
189 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
191 annotations = classIndex.get("com.titan.domain.CreditCompany");
192 Assert.assertNotNull(annotations);
193 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
194 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
195 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
197 annotations = classIndex.get("com.titan.domain.Cruise");
198 Assert.assertNotNull(annotations);
199 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
200 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
201 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
203 annotations = classIndex.get("com.titan.domain.Customer");
204 Assert.assertNotNull(annotations);
205 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
206 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
207 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
209 annotations = classIndex.get("com.titan.domain.Phone");
210 Assert.assertNotNull(annotations);
211 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
212 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
213 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
215 annotations = classIndex.get("com.titan.domain.Reservation");
216 Assert.assertNotNull(annotations);
217 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
218 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
219 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));
221 annotations = classIndex.get("com.titan.domain.Ship");
222 Assert.assertNotNull(annotations);
223 Assert.assertTrue(annotations.contains("javax.persistence.Entity"));
224 Assert.assertTrue(annotations.contains("javax.persistence.Id"));
225 Assert.assertTrue(annotations.contains("javax.persistence.GeneratedValue"));