VloConfigMarshaller { public final VloConfig unmarshal(Source source) throws JAXBException { final Unmarshaller unmarshaller = jc.createUnmarshaller(); SchemaFactory xsdFac = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setXIncludeAware(true); spf.setNamespaceAware(true); try { spf.setFeature("http: Schema schema = xsdFac.newSchema(getClass().getResource("/VloConfig.xsd")); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(getConfigValidationEventHandler()); final XMLReader xr = spf.newSAXParser().getXMLReader(); final InputSource inputSource = SAXSource.sourceToInputSource(source); final SAXSource saxSource = new SAXSource(xr, inputSource); return (VloConfig) unmarshaller.unmarshal(saxSource); } catch (ParserConfigurationException | SAXException ex) { throw new JAXBException(ex); } } VloConfigMarshaller(); final void marshal(VloConfig config, Result result); final VloConfig unmarshal(Source source);  }
@Test public void testUnmarshal() throws Exception { try (InputStream configFile = getClass().getResourceAsStream(VLO_CONFIG_FILE)) { VloConfig config = instance.unmarshal(new StreamSource(configFile, getClass().getResource(VLO_CONFIG_FILE).toString())); assertNotNull(config); assertEquals(testProps.getProperty("solrUrl"), config.getSolrUrl()); assertEquals(13, config.getFacetFieldNames().size()); assertEquals(4, config.getAvailabilityValues().size()); assertEquals("Public", config.getAvailabilityValues().get(0).getDisplayValue()); } }
@Test public void testDefaultConfigValidity() throws Exception { final VloConfigMarshaller failingOnValidationErrorInstance = new VloConfigMarshaller() { @Override protected ValidationEventHandler getConfigValidationEventHandler() { return (event) -> { fail("Validation error while unmarshalling default configuration:" + event.getMessage()); return false; }; } }; try (InputStream configFile = getClass().getResourceAsStream(VLO_CONFIG_FILE)) { VloConfig config = failingOnValidationErrorInstance.unmarshal(new StreamSource(configFile, getClass().getResource(VLO_CONFIG_FILE).toString())); } }