1 package ejava.projects.edmv.ejb;
2
3 import java.io.InputStream;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import static junit.framework.TestCase.*;
8
9
10 import gov.ojp.it.jxdm._3_0.Person;
11 import gov.ojp.it.jxdm._3_0.ReferenceType;
12 import gov.ojp.it.jxdm._3_0.ResidenceType;
13 import gov.ojp.it.jxdm._3_0.VehicleRegistration;
14 import info.ejava.projects.edmv._1.Dmv;
15
16 import javax.annotation.PostConstruct;
17 import javax.annotation.Resource;
18 import javax.ejb.Stateless;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import ejava.projects.edmv.xml.EDmvParser;
24
25 @Stateless
26 public class ParserTestEJB implements ParserTestRemote {
27 private static final Logger log = LoggerFactory.getLogger(ParserTestEJB.class);
28
29 @Resource(name="vals/xmlFile")
30 private String xmlFile;
31
32 @PostConstruct
33 public void init() {
34 log.debug("*** ParserTestEJB ***");
35 log.debug("xmlFile=" + xmlFile);
36 }
37
38 public void ingest() throws Exception {
39 log.info("ingest");
40
41 InputStream is = null;
42
43 try {
44 log.trace("getting input file:" + xmlFile);
45 is = this.getClass().getResourceAsStream(xmlFile);
46 if (is == null) {
47 throw new Exception(xmlFile + " was not found");
48 }
49
50 log.trace("creating parser");
51 EDmvParser parser = new EDmvParser(Dmv.class, is);
52
53 log.trace("starting parse loop");
54 List<Person> people = new ArrayList<Person>();
55 Object object=null;
56 do {
57 object = parser.getObject(
58 "Person", "VehicleRegistration");
59 if (object instanceof Person) {
60 if (((Person)object).getId().contains("1000")) {
61 log.debug("here");
62 }
63 check((Person)object, people);
64 }
65 else if (object instanceof VehicleRegistration) {
66 check((VehicleRegistration)object, people);
67 }
68 else if (object != null) {
69 fail("object of unknown type:" + object);
70 }
71 } while (object != null);
72 }
73 finally {
74 if (is != null) is.close();
75 }
76 }
77
78 protected void check(Person p, List<Person> people) {
79 log.info("checking person:" + p.getId());
80
81 assertNotNull(p.getId());
82 assertNotNull(p.getSourceIDText());
83 assertNotNull(p.getPersonBirthDate());
84 assertNotNull(p.getPersonBirthDate().getValue());
85 assertNotNull(p.getPersonName());
86 assertNotNull(p.getPersonName().getPersonGivenName());
87 assertNotNull(p.getPersonName().getPersonGivenName().getValue());
88 assertNotNull(p.getPersonName().getPersonMiddleName());
89 assertNotNull(p.getPersonName().getPersonMiddleName().getValue());
90 assertNotNull(p.getPersonName().getPersonSurName());
91 assertNotNull(p.getPersonName().getPersonSurName().getValue());
92
93 assertNotNull(p.getPersonPhysicalDetails());
94
95 assertNotNull(p.getPersonPhysicalDetails().getPersonEyeColorCode().getValue());
96 assertNotNull(p.getPersonPhysicalDetails().getPersonHairColorText().getValue());
97 assertNotNull(p.getPersonPhysicalDetails().getPersonHeightMeasure().getValue());
98 assertNotNull(p.getPersonPhysicalDetails().getPersonWeightMeasure().getValue());
99
100 assertNotNull(p.getPersonPhysicalDetails().getPersonSexCode().getValue());
101 assertNotNull(p.getResidence());
102 for (ResidenceType res : p.getResidence()) {
103 assertNotNull(res.getResidenceStartDate());
104 assertNotNull(res.getResidenceStartDate().getValue());
105
106 assertNotNull(res.getLocationAddress());
107 assertNotNull(res.getLocationAddress().getLocationCityName());
108 assertNotNull(res.getLocationAddress().getLocationCityName().getValue());
109 assertNotNull(res.getLocationAddress().getLocationPostalCodeID());
110 assertNotNull(res.getLocationAddress().getLocationPostalCodeID().getID());
111 assertNotNull(res.getLocationAddress().getLocationPostalCodeID().getID().getValue());
112 assertNotNull(res.getLocationAddress().getLocationStateCodeUSPostalService());
113 assertNotNull(res.getLocationAddress().getLocationStateCodeUSPostalService().getValue());
114 assertNotNull(res.getLocationAddress().getLocationStreet());
115 assertNotNull(res.getLocationAddress().getLocationStreet().getStreetName());
116 assertNotNull(res.getLocationAddress().getLocationStreet().getStreetName().getValue());
117 assertNotNull(res.getLocationAddress().getLocationStreet().getStreetNumberText());
118 assertNotNull(res.getLocationAddress().getLocationStreet().getStreetNumberText().getValue());
119 }
120
121 people.add(p);
122 }
123
124 protected void check(VehicleRegistration r, List<Person> people) {
125 log.info("checking registration:" + r.getId());
126
127 assertNotNull(r.getId());
128 assertNotNull(r.getSourceIDText());
129 assertNotNull(r.getVehicle());
130 assertNotNull(r.getVehicle().getPropertyOwnerPerson());
131 for (ReferenceType ref : r.getVehicle().getPropertyOwnerPerson()) {
132 assertNotNull(ref.getRef());
133 assertTrue(ref.getRef() instanceof Person);
134 Person o = (Person)ref.getRef();
135 assertTrue(people.contains(o));
136 }
137 assertNotNull(r.getVehicle().getVehicleColorPrimaryCode());
138 assertNotNull(r.getVehicle().getVehicleColorPrimaryCode().getValue());
139 assertNotNull(r.getVehicle().getVehicleID());
140 assertNotNull(r.getVehicle().getVehicleID().getID());
141 assertNotNull(r.getVehicle().getVehicleMakeCode());
142 assertNotNull(r.getVehicle().getVehicleMakeCode().getValue());
143 assertNotNull(r.getVehicle().getVehicleModelCode());
144 assertNotNull(r.getVehicle().getVehicleModelCode().getValue());
145 assertNotNull(r.getVehicle().getVehicleModelYearDate());
146 assertNotNull(r.getVehicle().getVehicleModelYearDate().getValue());
147 assertNotNull(r.getVehicleLicensePlateID());
148 assertNotNull(r.getVehicleLicensePlateID().getID());
149 assertNotNull(r.getVehicleLicensePlateID().getID().getValue());
150 assertNotNull(r.getVehicleRegistrationDecal());
151 assertNotNull(r.getVehicleRegistrationDecal().getDecalMonthDate());
152
153 assertNotNull("decal month date is null",
154 r.getVehicleRegistrationDecal().getDecalMonthDate().getValue());
155
156
157
158 assertNotNull(r.getVehicleRegistrationDecal().getDecalYearDate());
159 assertNotNull(r.getVehicleRegistrationDecal().getDecalYearDate().getValue());
160 }
161 }