MappedDocumentStrategy implements SchemeStrategy { @Override public InputStream getInputStream(final String sessionId, final URI uri, final RequestMethod method, final long timeout, final Collection<KeyValuePair> parameters) throws BadFetchError { if (uri == null) { throw new BadFetchError("Unable to retrieve a document for null!"); } final DocumentMap repository = DocumentMap.getInstance(); final String scheme = uri.getScheme(); final String path = uri.getPath(); final URI fragmentLessUri; try { fragmentLessUri = new URI(scheme, null, path, null); } catch (URISyntaxException e) { throw new BadFetchError(e.getMessage(), e); } final String document = repository.getDocument(fragmentLessUri); if (document == null) { return null; } String encoding = getEncoding(document); if (encoding == null) { encoding = System.getProperty("jvoicexml.xml.encoding", "UTF-8"); } try { return new ByteArrayInputStream(document.getBytes(encoding)); } catch (java.io.IOException ioe) { throw new BadFetchError(ioe); } } MappedDocumentStrategy(); @Override String getScheme(); @Override InputStream getInputStream(final String sessionId, final URI uri,
            final RequestMethod method, final long timeout,
            final Collection<KeyValuePair> parameters); @Override void sessionClosed(final String sessionId); static final String SCHEME_NAME; }
@Test public void testGetInputStream() throws Exception, BadFetchError { final MappedDocumentStrategy strategy = new MappedDocumentStrategy(); JVoiceXMLEvent error = null; try { strategy.getInputStream(null, null, null, 0, null); } catch (BadFetchError e) { error = e; } Assert.assertNotNull("BadFetchError expected", error); URI uri1 = map.getUri("/doc"); final InputStream stream1 = strategy.getInputStream(null, uri1, null, 0, null); Assert.assertNotNull(stream1); final InputSource inputSource = new InputSource(stream1); final VoiceXmlDocument doc1 = new VoiceXmlDocument(inputSource); final Vxml vxml1 = doc1.getVxml(); Assert.assertTrue(vxml1.hasChildNodes()); URI uri2 = map.getUri("/test"); final InputStream stream2 = strategy.getInputStream(null, uri2, null, 0, null); Assert.assertNotNull(stream2); final String test = readString(stream2); Assert.assertEquals("test", test); }