/** * Tests the {@link AbstractAddAdapterRule#startElement} method * * @throws Exception if an error occurs */ public void testStartElement() throws Exception { // create an expanded name ExpandedName eName = new ImmutableExpandedName("testNamespace", "testLocalName"); Attributes atts = new AttributesImpl(); XMLPipeline pipeline = dynamicProcess.getPipeline(); NamespacePrefixTracker tracker = pipeline.getPipelineContext().getNamespacePrefixTracker(); // register the prefix with the tracker tracker.startPrefixMapping("p", "testNamespace"); // invoke startElement on the rule Object returned = rule.startElement(dynamicProcess, eName, atts); // ensure the process was added to the pipeline assertSame( "Adapter Process was not added to the pipeline", adapterProcess, pipeline.getHeadProcess()); // ensure the object return was the addapter process assertSame( "startElement should return the adapter process that was " + "added to the pipeline", adapterProcess, returned); // ensure the adapters processes setElementDetails method was invoked adapterProcess.assertSetElementDetailsInvoked( "testNamespace", "testLocalName", "p:testLocalName"); // ensure the processAttributes method was invoked ok adapterProcess.assertProcessAttributesInvoked(atts); }
/** * Tests the {@link AbstractAddAdapterRule#endElement} method * * @throws Exception if an error occurs */ public void testEndElement() throws Exception { // retrieve the pipeline XMLPipeline pipeline = dynamicProcess.getPipeline(); // add a process to the head of the pipeline pipeline.addHeadProcess(adapterProcess); ExpandedName eName = new ImmutableExpandedName("testNamespace", "testLocalName"); // call end element on the rule rule.endElement(dynamicProcess, eName, adapterProcess); // ensure that the process was removed from the pipeline assertNotSame( "endElement did not remove the adapter process from " + "the pipeline", adapterProcess, pipeline.getHeadProcess()); }
/** * Tests that the {@link AbstractAddAdapterRule#endElement} method throws an exception if you * attempt to remove a process that is not at the head of the pipeline * * @throws Exception if an error occurs */ public void testEndElementWithWrongProcess() throws Exception { // retrieve the pipeline XMLPipeline pipeline = dynamicProcess.getPipeline(); // add the process to the head of the pipeline pipeline.addHeadProcess(adapterProcess); // create an expanded name ExpandedName eName = new ImmutableExpandedName("testNamespace", "testLocalName"); try { // call end element on the rule rule.endElement(dynamicProcess, eName, new MockAdapterProcess()); fail( "endElement did not throw an exception when attempting to " + "remove a process that was not at the head of the pipeline"); } catch (XMLPipelineException e) { } }