@Test public void includesUrl() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include url='"+ URL_TO_INCLUDE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("IA", "IB", "C"); }
@Test public void findsIncludeFromSinglePath() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "C"); }
@Test public void includesResource() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include resource='"+ INCLUDED_AS_RESOURCE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("AR_A", "AR_B", "C"); }
@Test public void findsIncludeFromManyPaths() throws JoranException { final String NONEXIST_INCLUDES = new String(new char[1000]).replace("\0", "<include file='nonexistent.txt'/>"); final String xml = "<x>" + "<findInclude>" + NONEXIST_INCLUDES + "<include file='"+ SECOND_FILE +"'/>" + NONEXIST_INCLUDES + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "C"); }
@Test public void findsIncludeFromFewPaths() throws JoranException { final String NONEXIST_INCLUDES = new String(new char[5]).replace("\0", "<include file='nonexistent.txt'/>"); final String xml = "<x>" + "<findInclude>" + NONEXIST_INCLUDES + "<include file='"+ SECOND_FILE +"'/>" + NONEXIST_INCLUDES + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "C"); }
@Test public void ignoresMalformedUrl() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include url='htp://nonexistent.html'/>" + "<include url='"+ URL_TO_INCLUDE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("IA", "IB", "C"); }
@Test public void ignoresNonexistentResource() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include resource='nonexistent.txt'/>" + "<include resource='"+ INCLUDED_AS_RESOURCE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("AR_A", "AR_B", "C"); }
@Test public void findsIncludeFromMiddleOfPathList() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "<include file='nonexistent.txt'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "C"); }
@Test public void findsIncludeFromBeginningOfPathList() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='"+ SECOND_FILE +"'/>" + "<include file='nonexistent.txt'/>" + "<include file='"+ INVALID +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "C"); }
@Test public void findsIncludeFromEndOfPathList() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='nonexistent.txt'/>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "C"); }
@Test public void findsIncludeWithRegularInclude() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='"+ SECOND_FILE +"'/>" + "<include file='nonexistent.txt'/>" + "</findInclude>" + "<stack name='A'/>" + "<stack name='B'/>" + "<include file='"+ SECOND_FILE +"'/>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "A", "B", "SECOND", "C"); }
@Test public void ignoresUnknownUrl() throws JoranException { // FIXME: This test fails when the ISP does not return 404 for // unknown URLs (required to cause an exception upon opening // the URL request). This was observed when running tests // while tethered to bluetooth mobile hotspot. The fix would // be to refactor AbstractIncludeAction to inject a URL opener. final String xml = "<x>" + "<findInclude>" + "<include url='http://nonexistent.html'/>" + "<include url='"+ URL_TO_INCLUDE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("IA", "IB", "C"); }
@Test public void configHandlesMultipleFindIncludeElements() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<findInclude>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<stack name='B'/>" + "<findInclude>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); verifyConfig("SECOND", "SECOND", "B", "SECOND", "C"); }
@Test public void errorsOutForInvalidXmlAtFoundPath() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='"+ INVALID +"'/>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); assertEquals(Status.ERROR, statusChecker.getHighestLevel(0)); assertTrue(statusChecker.containsException(SAXParseException.class)); verifyConfig("C"); }