XqjTransmogrifier implements Transmogrifier<Source, T> { @Override public T zap(Source source, Object... params) { ResultHolder<T> accessor = ResultHolderFactory.create(outputFormat); Result result = accessor.createResult(); doZap(source, result, params); return accessor.getResult(); } @SuppressWarnings("unchecked")  XqjTransmogrifier();  XqjTransmogrifier(Class<T> outputFormat);  XqjTransmogrifier(Class<T> outputFormat, Map<String, Object> globalParams); @Override T zap(Source source, Object... params); Map<String, String> getStaticParams(); void setStaticParams(Map<String, String> staticParams);  }
@Test public void zapSimple() throws IOException, SAXException { String zapResult = transformer.zap(source("xquery/string.xml"), "xquery/string-q1.xq"); assertTrue(XMLUnit.compareXML(result("xquery/string-q1.xml"), zapResult).similar()); }
@Test public void zapStringParameter() throws IOException, SAXException { Map<String, Object> dynamicParams = new HashMap<String, Object>(); dynamicParams.put("language", "English"); Object[] params = new Object[] { "xquery/string-q2.xq", dynamicParams }; String zapResult1 = transformer.zap(source("xquery/string.xml"), params); assertTrue(XMLUnit.compareXML(result("xquery/string-q2.xml"), zapResult1).similar()); dynamicParams.put("language", "German"); String zapResult2 = transformer.zap(source("xquery/string.xml"), params); assertFalse(XMLUnit.compareXML(zapResult1, zapResult2).similar()); }
@Test(expected = RuntimeException.class) public void zapMissingParameter() throws IOException, SAXException { transformer.zap(source("xquery/string.xml"), "xquery/string-q2.xq"); }
@Test public void zapLocalFunction() throws IOException, SAXException { Map<String, Object> dynamicEvalParams = new HashMap<String, Object>(); dynamicEvalParams.put("language", "Bulgarian"); dynamicEvalParams.put("author_name", "John"); Object[] params = new Object[] { "xquery/string-q3.xq", dynamicEvalParams }; String zapResult = transformer.zap(source("xquery/string.xml"), params); assertTrue(XMLUnit.compareXML(result("xquery/string-q3.xml"), zapResult).similar()); }
@Test public void zapMainFunction() throws IOException, SAXException { String zapResult = transformer.zap(source("xquery/string.xml"), "xquery/string-q4.xq"); assertTrue(XMLUnit.compareXML(result("xquery/string.xml"), zapResult).similar()); }
@Test public void zapClasspathResolver() throws IOException, SAXException { String zapResult = transformer.zap(source("xquery/string.xml"), "xquery/string-q5.xq"); assertTrue(XMLUnit.compareXML(result("xquery/string.xml"), zapResult).similar()); }
@Test public void zapParametrisedConstructor() throws IOException, SAXException, XQException { Map<String, Object> configParams = new HashMap<String, Object>(); configParams.put(FeatureKeys.PRE_EVALUATE_DOC_FUNCTION, Boolean.TRUE); XqjTransmogrifier<String> localTransformer = new XqjTransmogrifier<String>(String.class, configParams); String zapResult = localTransformer.zap(source("xquery/string.xml"), new Object[] { "xquery/string-q5.xq" }); assertTrue(XMLUnit.compareXML(result("xquery/string.xml"), zapResult).similar()); }
@Test public void zapParametrisedConstructorNoParams() throws IOException, SAXException, XQException { XqjTransmogrifier<String> localTransformer = new XqjTransmogrifier<String>(String.class, null); String zapResult = localTransformer.zap(source("xquery/string.xml"), new Object[] { "xquery/string-q5.xq" }); assertTrue(XMLUnit.compareXML(result("xquery/string.xml"), zapResult).similar()); }
@Test public void zapWithNamespaces() throws IOException, SAXException { String zapResult = transformer.zap(source("xquery/ns.xml"), "xquery/ns-q1.xq"); assertTrue(XMLUnit.compareXML(result("xquery/ns-q1.xml"), zapResult).similar()); }
@Test public void zapRCase() throws IOException, SAXException { String zapResult = transformer.zap(new StreamSource(new StringReader("<empty/>")), "xquery/r-q1.xq"); assertTrue(XMLUnit.compareXML(result("xquery/r-q1.xml"), zapResult).similar()); }