@Test public void validateCastorObjectAgainstSchema() throws Exception { org.exolab.castor.xml.Unmarshaller unmarshaller = CastorUtils.getUnmarshaller(getSampleClass()); unmarshaller.setValidation(true); @SuppressWarnings("unchecked") T obj = (T) unmarshaller.unmarshal(new InputSource(getSampleXmlInputStream())); assertNotNull(obj); }
/** Loads the test spec (castor classes) from an xml file. */ public PubSubScenario(Logger logger, File xmlFile, boolean validateXml) throws FileNotFoundException, IOException, MarshalException, ValidationException { this.logger = logger; if (xmlFile.exists() && !xmlFile.isDirectory() && xmlFile.canRead()) { Unmarshaller unm = new Unmarshaller(PubSubInfrastructureSpec.class); unm.setValidation(validateXml); spec = (PubSubInfrastructureSpec) unm.unmarshal(new FileReader(xmlFile)); } else { throw new FileNotFoundException(xmlFile.getAbsolutePath()); } }