@Test public void testModelValidate() throws Exception { JAXBContext ctx = JAXBContext.newInstance("jsr352.batch.jsl"); Unmarshaller u = ctx.createUnmarshaller(); u.setSchema(ValidatorHelper.getXJCLSchema()); XJCLValidationEventHandler handler = new XJCLValidationEventHandler(); u.setEventHandler(handler); URL url = this.getClass().getResource("/job1.xml"); // Use this for anonymous type // Job job = (Job)u.unmarshal(url.openStream()); // Use this for named complex type Object elem = u.unmarshal(url.openStream()); assertFalse("XSD invalid, see sysout", handler.eventOccurred()); JSLJob job = (JSLJob) ((JAXBElement) elem).getValue(); assertEquals("job1", job.getId()); assertEquals(1, job.getExecutionElements().size()); Step step = (Step) job.getExecutionElements().get(0); assertEquals("step1", step.getId()); Batchlet b = step.getBatchlet(); assertEquals("step1Ref", b.getRef()); }
@Test public void testValidateInvalid() throws Exception { JAXBContext ctx = JAXBContext.newInstance("jsr352.batch.jsl"); Unmarshaller u = ctx.createUnmarshaller(); u.setSchema(ValidatorHelper.getXJCLSchema()); XJCLValidationEventHandler handler = new XJCLValidationEventHandler(); u.setEventHandler(handler); URL url = this.getClass().getResource("/invalid.job1.xml"); // Use this for anonymous type // Job job = (Job)u.unmarshal(url.openStream()); // Use this for named complex type Object elem = u.unmarshal(url.openStream()); assertTrue("XSD invalid, see sysout", handler.eventOccurred()); }