/** Test the generateSaxFragment method. */ public void testGenerateSaxFragment() throws Exception { List beans = new ArrayList(2); beans.add(new TestBean("1", "One")); beans.add(new TestBean("2", "Two")); Map flowContextObject = new HashMap(); flowContextObject.put("beans", beans); Request request = new MockRequest(); Map objectModel = new HashMap(); FlowHelper.setContextObject(objectModel, flowContextObject); objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request); Map contextObjectModel = new HashMap(); contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel); Context context = new DefaultContext(contextObjectModel); Source sampleSource = new ResourceSource( "resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml"); Document sample = parser.parse(sampleSource.getInputStream()); Element datatypeElement = (Element) sample.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "datatype").item(0); Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); FlowJXPathSelectionList list = new FlowJXPathSelectionList( context, "beans", "key", "value", datatype, null, false, null, false); DOMBuilder dest = new DOMBuilder(); list.generateSaxFragment(dest, Locale.ENGLISH); Source expectedSource = new ResourceSource( "resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml"); Document expected = parser.parse(expectedSource.getInputStream()); assertEqual("Test if generated list matches expected", expected, dest.getDocument()); }
/** * Test the generateSaxFragment method with a nullable selection list * * @throws MalformedURLException * @throws ParserConfigurationException */ public void testGenerateSaxFragmentNullable() throws Exception { DOMBuilder dest = new DOMBuilder(); EnumSelectionList list = new EnumSelectionList(Sex.class.getName(), new EnumType(), true); list.generateSaxFragment(dest, Locale.ENGLISH); ResourceSource expectedSource = new ResourceSource( "resource://org/apache/cocoon/woody/datatype/EnumSelectionListTestCase.dest.xml"); Document expected = parser.parse(expectedSource.getInputStream()); assertEqual("Test if output is what is expected", expected, dest.getDocument()); }
/** * Test the generateSaxFragment method. * * @throws MalformedURLException * @throws ParserConfigurationException */ public void testGenerateSaxFragment() throws Exception { DOMBuilder dest = new DOMBuilder(); ResourceSource source = new ResourceSource( "resource://org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.source.xml"); Document sourceDoc = parser.parse(source.getInputStream()); Element datatypeElement = (Element) sourceDoc.getElementsByTagNameNS(Constants.WD_NS, "convertor").item(0); Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); DynamicSelectionList list = new DynamicSelectionList(datatype, null, this.getManager()); list.generateSaxFragment(dest, Locale.ENGLISH, source); ResourceSource expectedSource = new ResourceSource( "resource://org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.dest.xml"); Document expected = parser.parse(expectedSource.getInputStream()); assertEqual("Test if output is what is expected", expected, dest.getDocument()); }