Author: rgardler
Date: Thu Nov 23 16:29:36 2006
New Revision: 478724

URL: http://svn.apache.org/viewvc?view=rev&rev=478724
Log:
Add tests for missing optional and required resources

Modified:
    forrest/trunk/whiteboard/forrest2/core/src/test/locationmap.xml
    
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java

Modified: forrest/trunk/whiteboard/forrest2/core/src/test/locationmap.xml
URL: 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/test/locationmap.xml?view=diff&rev=478724&r1=478723&r2=478724
==============================================================================
--- forrest/trunk/whiteboard/forrest2/core/src/test/locationmap.xml (original)
+++ forrest/trunk/whiteboard/forrest2/core/src/test/locationmap.xml Thu Nov 23 
16:29:36 2006
@@ -27,4 +27,14 @@
   <location pattern="(.*)/variable/(.*)\..*">
     <source href="classpath:/xdocs/samples/xhtml2/$(2).html"/>
   </location>
+  
+  <location pattern="(.*)/optional/(.*)\..*">
+    <source href="classpath:/xdocs/samples/xhtml2/DOES_NOT_EXIST.html"/>
+    <source href="classpath:/xdocs/samples/xhtml2/$(2).html"/>    
+  </location>
+  
+  <location pattern="(.*)/required/(.*)\..*">
+    <source href="classpath:/xdocs/samples/xhtml2/DOES_NOT_EXIST.html" 
required="true"/>
+    <source href="classpath:/xdocs/samples/xhtml2/$(2).html"/>    
+  </location>
 </locationmap>

Modified: 
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java
URL: 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java?view=diff&rev=478724&r1=478723&r2=478724
==============================================================================
--- 
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java
 (original)
+++ 
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java
 Thu Nov 23 16:29:36 2006
@@ -60,6 +60,12 @@
        public static final String HELLO_WORLD_REQUEST_URI = BASE_REQUEST_URI
                        + "helloWorld.html";
 
+       public static final String OPTIONAL_RESOURCES_REQUEST_URI = 
BASE_REQUEST_URI
+                       + "optional/sample_simple.forrestSource";
+
+       public static final String REQUIRED_RESOURCES_REQUEST_URI = 
BASE_REQUEST_URI
+                       + "required/sample_simple.forrestSource";
+
        private IController controller;
 
        @Override
@@ -95,11 +101,10 @@
                        ProcessingException, URISyntaxException {
                final AbstractSourceDocument srcDoc = this.controller
                                .getSourceDocuments(new URI(XHTML_REQUEST_URI));
-               final List<InternalDocument> internalDocs = this.controller
-                               .getInternalDocuments(new 
URI(XHTML_REQUEST_URI));
+               final InternalDocument internalDoc = this.controller
+                               .getInternalDocument(new 
URI(XHTML_REQUEST_URI));
                final AbstractSourceDocument firstSrcDoc = srcDoc;
-               final InternalDocument firstIntDoc = internalDocs.get(0);
-               assertFalse(firstSrcDoc.equals(firstIntDoc));
+               assertFalse(firstSrcDoc.equals(internalDoc));
        }
 
        public void testProcessRequest() throws IOException, 
ProcessingException,
@@ -119,7 +124,7 @@
                                .getSourceDocuments(new 
URI(HELLO_WORLD_REQUEST_URI));
                assertTrue(
                                "Should not have an aggregated document for 
Hello World request",
-                               ! (source instanceof AggregatedSourceDocument));
+                               !(source instanceof AggregatedSourceDocument));
                assertEquals("Document type read by Hello world is incorrect",
                                "org.apache.forrest.helloWorld", 
source.getType());
        }
@@ -146,9 +151,31 @@
                        URISyntaxException, IOException {
                final AbstractOutputDocument output = this.controller
                                .getOutputDocument(new 
URI(VARIABLE_SUBSTITUTION_REQUEST_URI));
-                               assertNotNull(output);
-                               assertTrue("Content is not as expected", 
output.getContentAsString()
-                                               
.contains("http://www.w3.org/2002/06/xhtml2";));
+               assertNotNull(output);
+               assertTrue("Content is not as expected", 
output.getContentAsString()
+                               .contains("http://www.w3.org/2002/06/xhtml2";));
+       }
+
+       public void testOptionalResources() throws ProcessingException,
+                       URISyntaxException, IOException {
+               final AbstractOutputDocument output = this.controller
+                               .getOutputDocument(new 
URI(OPTIONAL_RESOURCES_REQUEST_URI));
+               assertNotNull(
+                               "We should have a result document from optional 
requests",
+                               output);
+               assertTrue("Content is not as expected", 
output.getContentAsString()
+                               .contains("http://www.w3.org/2002/06/xhtml2";));
+       }
+
+       public void testRequiredResources() throws ProcessingException,
+                       URISyntaxException, IOException {
+               try {
+                       final AbstractOutputDocument output = this.controller
+                                       .getOutputDocument(new 
URI(REQUIRED_RESOURCES_REQUEST_URI));
+               } catch (ProcessingException e) {
+                       return;
+               }
+               fail("We should throw a processing exception when a required 
document is missing");
        }
 
 }