use of javax.xml.stream.XMLEventReader in project spring-framework by spring-projects.
the class StaxSourceTests method eventReaderSourceToStreamResult.
@Test
public void eventReaderSourceToStreamResult() throws Exception {
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML));
StaxSource source = new StaxSource(eventReader);
assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader());
assertNull("StreamReader returned", source.getXMLStreamReader());
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
assertThat("Invalid result", writer.toString(), isSimilarTo(XML));
}
use of javax.xml.stream.XMLEventReader in project spring-framework by spring-projects.
the class StaxSourceTests method eventReaderSourceToDOMResult.
@Test
public void eventReaderSourceToDOMResult() throws Exception {
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML));
StaxSource source = new StaxSource(eventReader);
assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader());
assertNull("StreamReader returned", source.getXMLStreamReader());
Document expected = documentBuilder.parse(new InputSource(new StringReader(XML)));
Document result = documentBuilder.newDocument();
transformer.transform(source, new DOMResult(result));
assertThat("Invalid result", result, isSimilarTo(expected));
}
use of javax.xml.stream.XMLEventReader in project spring-framework by spring-projects.
the class AbstractUnmarshallerTests method unmarshalJaxp14StaxSourceXmlEventReader.
@Test
public void unmarshalJaxp14StaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
use of javax.xml.stream.XMLEventReader in project spring-framework by spring-projects.
the class AbstractUnmarshallerTests method unmarshalStaxSourceXmlEventReader.
@Test
public void unmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class CachingStAXPipelineComponentTest method testCacheHit.
@Test
public void testCacheHit() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final CachedEventReader<XMLEvent> eventReader = new CachedEventReader<XMLEvent>(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
final Element cacheElement = new Element(cacheKey, eventReader);
final Ehcache cache = createMock(Ehcache.class);
final StAXPipelineComponent targetComponent = createMock(StAXPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(cacheElement);
replay(cache, targetComponent, elementsProvider);
final CachingStAXPipelineComponent cachingComponent = new CachingStAXPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<XMLEventReader, XMLEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
Aggregations