PageRenderTime 62ms CodeModel.GetById 17ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 1ms

/sitebricks/src/test/java/com/google/sitebricks/routing/PageBookImplTest.java

http://github.com/dhanji/sitebricks
Java | 814 lines | 612 code | 193 blank | 9 comment | 8 complexity | a86b4d23f9f64f7c29be0003ab21e632 MD5 | raw file
  1package com.google.sitebricks.routing;
  2
  3import static org.easymock.EasyMock.createMock;
  4import static org.easymock.EasyMock.expect;
  5import static org.easymock.EasyMock.replay;
  6
  7import java.io.IOException;
  8import java.util.Date;
  9import java.util.HashMap;
 10import java.util.List;
 11import java.util.Map;
 12import java.util.Set;
 13
 14import javax.servlet.http.HttpServletRequest;
 15
 16import org.testng.annotations.BeforeTest;
 17import org.testng.annotations.DataProvider;
 18import org.testng.annotations.Test;
 19
 20import com.google.common.collect.Iterators;
 21import com.google.inject.Guice;
 22import com.google.inject.Injector;
 23import com.google.inject.name.Named;
 24import com.google.sitebricks.At;
 25import com.google.sitebricks.Renderable;
 26import com.google.sitebricks.Respond;
 27import com.google.sitebricks.SitebricksModule;
 28import com.google.sitebricks.TestRequestCreator;
 29import com.google.sitebricks.headless.Reply;
 30import com.google.sitebricks.headless.Request;
 31import com.google.sitebricks.http.Get;
 32import com.google.sitebricks.http.Post;
 33import com.google.sitebricks.http.Select;
 34import com.google.sitebricks.rendering.EmbedAs;
 35
 36/**
 37 * @author Dhanji R. Prasanna (dhanji@gmail.com)
 38 */
 39public class PageBookImplTest {
 40  private static final String FIRST_PATH_ELEMENTS = "firstPathElements";
 41  private static final String URI_TEMPLATES_AND_MATCHES = "uriTemplatesAndMatches";
 42  private static final String NOT_URIS_AND_TEMPLATES = "noturisandTemplates";
 43  private static final String REDIRECTED_GET = "/redirected_get";
 44  private static final String REDIRECTED_POST = "/redirected_post";
 45
 46  private Injector injector;
 47
 48  @BeforeTest
 49  public final void pre() {
 50    injector = Guice.createInjector(new SitebricksModule());
 51  }
 52
 53  @Test
 54  public final void storeAndRetrievePageInstance() {
 55    final Respond respond = new MockRespond();
 56
 57    Renderable mock = new Renderable() {
 58      public void render(Object bound, Respond respond) {
 59
 60      }
 61
 62      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
 63        return null;
 64      }
 65    };
 66
 67    final PageBook pageBook = new DefaultPageBook(injector);
 68    pageBook.at("/wiki", MyPage.class);
 69
 70    PageBook.Page page = pageBook.get("/wiki");
 71    page.apply(mock);
 72    page.widget().render(new Object(), respond);
 73
 74    assert page.widget().equals(mock);
 75  }
 76
 77  @Test
 78  public final void fireGetMethodOnPage() throws IOException {
 79    Renderable mock = new Renderable() {
 80      public void render(Object bound, Respond respond) {
 81
 82      }
 83
 84      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
 85        return null;
 86      }
 87    };
 88
 89    final PageBook pageBook = new DefaultPageBook(injector);
 90    pageBook.at("/wiki", MyPage.class);
 91
 92    PageBook.Page page = pageBook.get("/wiki");
 93    page.apply(mock);
 94    final MyPage bound = new MyPage();
 95    page.doMethod("get", bound, "/wiki", fakeRequestWithParams(new HashMap<String, String[]>()));
 96
 97    assert page.widget().equals(mock);
 98    assert bound.getted : "@Get method was not fired, on doGet()";
 99  }
100
101  @Test
102  public final void fireGetMethodOnPageAndRedirectToURL() throws IOException {
103    Renderable mock = new Renderable() {
104      public void render(Object bound, Respond respond) {
105
106      }
107
108      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
109        return null;
110      }
111    };
112
113    final PageBook pageBook = new DefaultPageBook(injector);
114    pageBook.at("/wiki", MyRedirectingPage.class);
115
116    PageBook.Page page = pageBook.get("/wiki");
117    page.apply(mock);
118    final MyRedirectingPage bound = new MyRedirectingPage();
119    Object redirect = page.doMethod("get", bound, "/wiki", fakeRequestWithParams(new HashMap<String, String[]>()));
120
121    assert REDIRECTED_GET.equals(redirect);
122    assert page.widget().equals(mock);
123  }
124
125  @Test
126  public final void firePostMethodOnPageAndRedirectToURL() throws IOException {
127    Renderable mock = new
128        Renderable() {
129          public void render(Object bound, Respond respond) {
130
131          }
132
133          public <T extends Renderable> Set<T> collect(Class<T> clazz) {
134            return null;
135          }
136        };
137
138    final PageBook pageBook = new DefaultPageBook(injector);
139    pageBook.at("/wiki", MyRedirectingPage.class);
140
141    PageBook.Page page = pageBook.get("/wiki");
142    page.apply(mock);
143    final MyRedirectingPage bound = new MyRedirectingPage();
144    Object redirect = page.doMethod("post", bound, "/wiki", fakeRequestWithParams(new HashMap<String, String[]>()));
145
146    assert REDIRECTED_POST.equals(redirect);
147    assert page.widget().equals(mock);
148  }
149  
150  @Test
151  public final void fireGetMethodOnPageAndReply403() throws IOException {
152    Renderable mock = new Renderable() {
153      public void render(Object bound, Respond respond) {
154
155      }
156
157      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
158        return null;
159      }
160    };
161
162    final PageBook pageBook = new DefaultPageBook(injector);
163    pageBook.at("/forbidden", MyForbiddenPage.class);
164
165    PageBook.Page page = pageBook.get("/forbidden");
166    page.apply(mock);
167    final MyForbiddenPage bound = new MyForbiddenPage();
168    Object redirect = page.doMethod("get", bound, "/forbidden", fakeRequestWithParams(new HashMap<String, String[]>()));
169
170    assert Reply.saying().forbidden().equals(redirect);
171    assert page.widget().equals(mock);
172  }
173
174  @Test
175  public final void firePostMethodOnPageAndReply403() throws IOException {
176    Renderable mock = new Renderable() {
177        public void render(Object bound, Respond respond) {
178
179        }
180
181        public <T extends Renderable> Set<T> collect(Class<T> clazz) {
182          return null;
183        }
184      };
185
186      final PageBook pageBook = new DefaultPageBook(injector);
187      pageBook.at("/forbidden", MyForbiddenPage.class);
188
189      PageBook.Page page = pageBook.get("/forbidden");
190      page.apply(mock);
191      final MyForbiddenPage bound = new MyForbiddenPage();
192      Object redirect = page.doMethod("post", bound, "/forbidden", fakeRequestWithParams(new HashMap<String, String[]>()));
193
194      assert Reply.saying().forbidden().equals(redirect);
195      assert page.widget().equals(mock);
196  }
197
198  @Test
199  public final void fireGetMethodOnPageToCorrectHandler() throws IOException {
200    Renderable mock = new Renderable() {
201      public void render(Object bound, Respond respond) {
202
203      }
204
205      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
206        return null;
207      }
208    };
209
210    Map<String, String[]> params = new HashMap<String, String[]>() {
211      {
212        put("event", new String[]{"1", "2"});
213      }
214    };
215
216    final PageBook pageBook = new DefaultPageBook(injector);
217    pageBook.at("/wiki", MyEventSupportingPage.class);
218
219    PageBook.Page page = pageBook.get("/wiki");
220    page.apply(mock);
221    final MyEventSupportingPage bound = new MyEventSupportingPage();
222    page.doMethod("get", bound, "/wiki", fakeRequestWithParams(params));
223
224    assert page.widget().equals(mock);
225    assert bound.getted1 : "@Get @On method was not fired, on doGet() for [event=1]";
226    assert bound.getted2 : "@Get @On method was not fired, on doGet() for [event=2]";
227  }
228
229  @Test
230  public final void firePostMethodOnPageToCorrectHandler() throws IOException {
231    Renderable mock = new Renderable() {
232      public void render(Object bound, Respond respond) {
233
234      }
235
236      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
237        return null;
238      }
239    };
240
241    Map<String, String[]> params = new HashMap<String, String[]>() {
242      {
243        put("event", new String[]{"1", "2"});
244      }
245    };
246
247    final PageBook pageBook = new DefaultPageBook(injector);
248    pageBook.at("/wiki", MyEventSupportingPage.class);
249
250    PageBook.Page page = pageBook.get("/wiki");
251    page.apply(mock);
252    final MyEventSupportingPage bound = new MyEventSupportingPage();
253    page.doMethod("post", bound, "/wiki", fakeRequestWithParams(params));
254
255    assert page.widget().equals(mock);
256    assert bound.posted1 : "@Post @On method was not fired, on doPost() for [event=1]";
257    assert bound.posted2 : "@Post @On method was not fired, on doPost() for [event=2]";
258  }
259
260  @Test
261  public final void fireGetMethodOnPageToCorrectHandlerOnlyOnce() throws IOException {
262    Renderable mock = new Renderable() {
263      public void render(Object bound, Respond respond) {
264
265      }
266
267      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
268        return null;
269      }
270    };
271
272    Map<String, String[]> params = new HashMap<String, String[]>() {
273      {
274        put("event", new String[]{"2"});
275      }
276    };
277
278    final PageBook pageBook = new DefaultPageBook(injector);
279    pageBook.at("/wiki", MyEventSupportingPage.class);
280
281    PageBook.Page page = pageBook.get("/wiki");
282    page.apply(mock);
283    final MyEventSupportingPage bound = new MyEventSupportingPage();
284    page.doMethod("get", bound, "/wiki", fakeRequestWithParams(params));
285
286    assert page.widget().equals(mock);
287    assert !bound.getted1 : "@Get @On method was fired, on doGet() for [event=1]";
288    assert bound.getted2 : "@Get @On method was not fired, on doGet() for [event=2]";
289  }
290
291  @Test
292  public final void firePostMethodOnPageToCorrectHandlerOnlyOnce() throws IOException {
293    Renderable mock = new Renderable() {
294      public void render(Object bound, Respond respond) {
295
296      }
297
298      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
299        return null;
300      }
301    };
302
303    Map<String, String[]> params = new HashMap<String, String[]>() {
304      {
305        put("event", new String[]{"2"});
306      }
307    };
308
309    final PageBook pageBook = new DefaultPageBook(injector);
310    pageBook.at("/wiki", MyEventSupportingPage.class);
311
312    PageBook.Page page = pageBook.get("/wiki");
313    page.apply(mock);
314    final MyEventSupportingPage bound = new MyEventSupportingPage();
315    page.doMethod("post", bound, "/wiki", fakeRequestWithParams(params));
316
317    assert page.widget().equals(mock);
318    assert !bound.posted1 : "@Post @On method was fired, on doGet() for [event=1]";
319    assert bound.posted2 : "@Post @On method was not fired, on doGet() for [event=2]";
320  }
321
322  @Test
323  public final void fireGetMethodOnPageToDefaultHandler() throws IOException {
324    Renderable mock = new Renderable() {
325      public void render(Object bound, Respond respond) {
326
327      }
328
329      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
330        return null;
331      }
332    };
333
334    Map<String, String[]> params = new HashMap<String, String[]>() {
335      {
336        put("event", new String[]{"3"});
337      }
338    };
339
340    final PageBook pageBook = new DefaultPageBook(injector);
341    pageBook.at("/wiki", MyEventSupportingPage.class);
342
343    PageBook.Page page = pageBook.get("/wiki");
344    page.apply(mock);
345    final MyEventSupportingPage bound = new MyEventSupportingPage();
346    page.doMethod("get", bound, "/wiki", fakeRequestWithParams(params));
347
348    assert page.widget().equals(mock);
349    assert !bound.getted1 : "@Get @On method was fired, on doGet() for [event=1]";
350    assert !bound.getted2 : "@Get @On method was fired, on doGet() for [event=2]";
351    assert bound.defaultGet : "@Get @On default method was not fired, on doGet() for [event=...]";
352
353  }
354
355
356  @Test
357  public final void firePostMethodOnPageToDefaultHandler() throws IOException {
358    Renderable mock = new Renderable() {
359      public void render(Object bound, Respond respond) {
360
361      }
362
363      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
364        return null;
365      }
366    };
367
368    Map<String, String[]> params = new HashMap<String, String[]>() {
369      {
370        put("event", new String[]{"3"});
371      }
372    };
373
374    final PageBook pageBook = new DefaultPageBook(injector);
375    pageBook.at("/wiki", MyEventSupportingPage.class);
376
377    PageBook.Page page = pageBook.get("/wiki");
378    page.apply(mock);
379    final MyEventSupportingPage bound = new MyEventSupportingPage();
380    page.doMethod("post", bound, "/wiki", fakeRequestWithParams(params));
381
382    assert page.widget().equals(mock);
383    assert !bound.getted2 : "@Get @On method was fired, on doPost() for [event=2]";
384    assert !bound.getted1 : "@Get @On method was fired, on doPost() for [event=1]";
385    assert !bound.posted1 : "@Post @On method was fired, on doPost() for [event=1]";
386    assert !bound.posted2 : "@Post @On method was fired, on doPost() for [event=2]";
387    assert bound.defaultPost : "@Post @On default method was not fired, on doPost() for [event=...]";
388
389  }
390
391  @Test
392  public final void fireGetMethodWithArgsOnPage() throws IOException {
393    Renderable mock = new Renderable() {
394      public void render(Object bound, Respond respond) {
395
396      }
397
398      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
399        return null;
400      }
401    };
402
403    final PageBook pageBook = new DefaultPageBook(injector);
404    pageBook.at("/wiki/:title", MyPageWithTemplate.class);
405
406    PageBook.Page page = pageBook.get("/wiki/IMAX");
407    page.apply(mock);
408    final MyPageWithTemplate bound = new MyPageWithTemplate();
409    page.doMethod("get", bound, "/wiki/IMAX", fakeRequestWithParams(new HashMap<String, String[]>()));
410
411    assert page.widget().equals(mock);
412    assert "IMAX".equals(bound.title) : "@Get method was not fired, on doGet() with the right arg, instead: " + bound.title;
413  }
414
415  
416  @Test
417  public final void fireGetMethodWithPrimitiveArgsOnPage() throws IOException {
418    Renderable mock = new Renderable() {
419      public void render(Object bound, Respond respond) {
420
421      }
422
423      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
424        return null;
425      }
426    };
427
428//    SimpleDateFormat sdf = new SimpleDateFormat(StringToDateTimeCalendarConverter.USA_SHORT);
429    
430    final PageBook pageBook = new DefaultPageBook(injector);
431//    pageBook.at("/wiki/:title/cat/:int/:bool/:float/:date", MyPageWithPrimitivesTemplate.class);
432    pageBook.at("/wiki/:title/cat/:int/:bool/:float", MyPageWithPrimitivesTemplate.class);
433
434    String targetURL = "/wiki/IMAX/cat/1/true/2.5";
435    PageBook.Page page = pageBook.get(targetURL);
436    page.apply(mock);
437    final MyPageWithPrimitivesTemplate bound = new MyPageWithPrimitivesTemplate();
438    page.doMethod("get", bound, targetURL, fakeRequestWithParams(new HashMap<String, String[]>()));
439
440    assert page.widget().equals(mock);
441    assert "IMAX".equals(bound.title) && bound.id == 1 && bound.bool == true && bound.flt == 2.5
442//    	&& sdf.format(date).equals(sdf.format(bound.date)): 
443    	 : "@Get method did not bind in args correctly, title: " + bound.title + 
444//    	" id: " + bound.id + " bool: " + bound.bool + " float: " + bound.flt + " date: " +  sdf.format(bound.date);
445    	" id: " + bound.id + " bool: " + bound.bool + " float: " + bound.flt;
446    ;
447  }
448  
449
450  @Test
451  public final void firePostMethodWithArgsOnPage() throws IOException {
452    Renderable mock = new
453        Renderable() {
454          public void render(Object bound, Respond respond) {
455
456          }
457
458          public <T extends Renderable> Set<T> collect(Class<T> clazz) {
459            return null;
460          }
461        };
462
463    final PageBook pageBook = new DefaultPageBook(injector);
464    pageBook.at("/wiki/:title/cat/:id", MyPageWithTemplate.class);
465
466    PageBook.Page page = pageBook.get("/wiki/IMAX_P/cat/12");
467    page.apply(mock);
468    final MyPageWithTemplate bound = new MyPageWithTemplate();
469    page.doMethod("post", bound, "/wiki/IMAX_P/cat/12", fakeRequestWithParams(new HashMap<String, String[]>()));
470
471    assert page.widget().equals(mock);
472    assert "IMAX_P".equals(bound.post) && "12".equals(bound.id)
473        : "@Post method was not fired, on doPost() with the right arg, instead: " + bound.post;
474  }
475
476  @Test(expectedExceptions = InvalidEventHandlerException.class)
477  public final void errorOnPostMethodWithUnnamedArgs() throws IOException {
478    Renderable mock = new Renderable() {
479      public void render(Object bound, Respond respond) {
480
481      }
482
483      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
484        return null;
485      }
486    };
487
488    final PageBook pageBook = new DefaultPageBook(injector);
489    pageBook.at("/wiki/:title/cat/:id", MyBrokenPageWithTemplate.class);
490
491    PageBook.Page page = pageBook.get("/wiki/IMAX_P/cat/12");
492    final MyBrokenPageWithTemplate bound = new MyBrokenPageWithTemplate();
493    page.doMethod("post", bound, "/wiki/IMAX_P/cat/12", fakeRequestWithParams(new HashMap<String, String[]>()));
494
495    assert page.widget().equals(mock);
496  }
497
498  @Test
499  public final void firePostMethodOnPage() throws IOException {
500    Renderable mock = new Renderable() {
501      public void render(Object bound, Respond respond) {
502
503      }
504
505      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
506        return null;
507      }
508    };
509
510    final PageBook pageBook = new DefaultPageBook(injector);
511    pageBook.at("/wiki", MyPage.class);
512
513    PageBook.Page page = pageBook.get("/wiki");
514    final MyPage bound = new MyPage();
515    page.apply(mock);
516    page.doMethod("post", bound, "/wiki", fakeRequestWithParams(new HashMap<String, String[]>()));
517
518    assert page.widget().equals(mock);
519    assert bound.posted : "@Post method was not fired, on doPost()";
520  }
521
522  @DataProvider(name = URI_TEMPLATES_AND_MATCHES)
523  public Object[][] getUriTemplatesAndMatches() {
524    return new Object[][]{
525        {"/wiki/:title", "/wiki/HelloPage"},
526        {"/wiki/:title", "/wiki/HelloPage%20"},
527        {"/wiki/:title/dude", "/wiki/HelloPage/dude"},
528        {"/:title/thing", "/wiki/thing"},
529        {"/:title", "/aposkdapoksd"},
530    };
531  }
532
533  @Test(dataProvider = URI_TEMPLATES_AND_MATCHES)
534  public final void matchPageByUriTemplate(final String template, final String toMatch) {
535    final Respond respond = new MockRespond();
536
537    Renderable mock = new Renderable() {
538      public void render(Object bound, Respond respond) {
539
540      }
541
542      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
543        return null;
544      }
545    };
546
547    final PageBook pageBook = new DefaultPageBook(injector);
548    pageBook.at(template, MyPage.class);
549
550    PageBook.Page page = pageBook.get(toMatch);
551    final MyPage myPage = new MyPage();
552
553    page.apply(mock);
554    page.widget().render(myPage, respond);
555
556    assert mock.equals(page.widget());
557  }
558
559  @DataProvider(name = NOT_URIS_AND_TEMPLATES)
560  public Object[][] getNotUriTemplatesAndMatches() {
561    return new Object[][]{
562        {"/wiki/:title", "/tiki/HelloPage"},
563        {"/wiki/:title", "/wiki/HelloPage%20/didle"},
564        {"/wiki/:title/dude", "/wiki/HelloPage"},
565        {"/:title/thing", "/wiki/thing/thingaling"},
566        {"/:title", "/aposkdapoksd/12"},
567    };
568  }
569
570  @Test(dataProvider = NOT_URIS_AND_TEMPLATES)
571  public final void notMatchPageByUriTemplate(final String template, final String toMatch) {
572    final PageBook pageBook = new DefaultPageBook(injector);
573    pageBook.at(template, MyPage.class);
574
575    //cant find
576    assert null == pageBook.get(toMatch);
577
578  }
579
580  public static Request fakeRequestWithParams(Map<String, String[]> map) {
581    HttpServletRequest request = createMock(HttpServletRequest.class);
582
583    expect(request.getParameterMap()).andReturn(map);
584    expect(request.getHeaderNames()).andReturn(Iterators.asEnumeration(Iterators.<Object>emptyIterator()));
585    replay(request);
586
587    return TestRequestCreator.from(request, null);
588  }
589
590  @At("/wiki")
591  @Select("event")
592  public static class MyEventSupportingPage {
593    private boolean getted1;
594    private boolean getted2;
595    private boolean posted1;
596    private boolean posted2;
597    private boolean defaultGet;
598    private boolean defaultPost;
599
600    @Get("1")
601    public void get1() {
602      getted1 = true;
603    }
604
605    @Get("2")
606    public void get2() {
607      getted2 = true;
608    }
609
610    @Get
611    public void defaultGet() {
612      defaultGet = true;
613    }
614
615    @Post("1")
616    public void post1() {
617      posted1 = true;
618    }
619
620    @Post("2")
621    public void post2() {
622      posted2 = true;
623    }
624
625    @Post
626    public void defaultPost() {
627      defaultPost = true;
628    }
629
630  }
631
632  @At("/wiki")
633  @EmbedAs("Hi")
634  public static class MyPage {
635    private boolean getted;
636    private boolean posted;
637
638    @Get
639    public void get() {
640      getted = true;
641    }
642
643    @Post
644    public void post() {
645      posted = true;
646    }
647
648  }
649
650  @At("/wiki/:title/cat/:id")
651  @EmbedAs("Hi")
652  public static class MyPageWithTemplate {
653    private String title;
654    private boolean posted;
655    private String post;
656    private String id;
657
658    @Get
659    public void get(@Named("title") String title) {
660      this.title = title;
661    }
662
663    @Post
664    public void post(@Named("title") String title, @Named("id") String id) {
665      this.post = title;
666      this.id = id;
667    }
668  }
669  
670
671  @At("/wiki/:title/cat/:int/:bool/:float/:date")
672  @EmbedAs("Hi")
673  public static class MyPageWithPrimitivesTemplate {
674    private String title;
675    private int id;
676    private boolean bool;
677    private Float flt;
678    private Date date;
679
680    @Get
681    public void get(@Named("title") String title, @Named("int") Integer id, @Named("bool") Boolean bool, 
682//    		@Named("float") float flt, @Named("date") Date date) {
683            @Named("float") float flt) {
684      this.title = title;
685      this.id = id;
686      this.bool = bool;
687      this.flt = flt;
688    }
689
690  }
691  
692  
693
694  @At("/wiki/:title/cat/:id")
695  @EmbedAs("Hi")
696  public static class MyBrokenPageWithTemplate {
697
698    @Post
699    public void post(@Named("title") String title, int x, @Named("id") String id) {
700    }
701
702  }
703
704  @DataProvider(name = FIRST_PATH_ELEMENTS)
705  public Object[][] get() {
706    return new Object[][]{
707        {"/wiki/:title", "wiki"},
708        {"/wiki/:title/:thing", "wiki"},
709        {"/wiki/other/thing/dude", "wiki"},
710        {"/wiki", "wiki"},
711        {"/wiki/", "wiki"},
712        {"/", ""},
713    };
714  }
715
716  @Test(dataProvider = FIRST_PATH_ELEMENTS)
717  public final void firstPathElement(final String uri, final String answer) {
718    final String fPath = new DefaultPageBook(injector)
719        .firstPathElement(uri);
720
721    assert answer.equals(fPath) : "wrong path: " + fPath;
722  }
723
724  private static class MockRespond implements Respond {
725
726    public void write(String text) {
727    }
728
729    public HtmlTagBuilder withHtml() {
730      throw new AssertionError();
731    }
732
733    public void write(char c) {
734    }
735
736    public void chew() {
737
738    }
739
740    public void writeToHead(String text) {
741
742    }
743
744    public void require(String requireString) {
745
746    }
747
748    public void redirect(String to) {
749
750    }
751
752    public String getContentType() {
753      return null;
754    }
755
756    public String getRedirect() {
757      return null;
758    }
759
760    public Renderable include(String argument) {
761      return null;
762    }
763
764    public String getHead() {
765      return null;
766    }
767
768    @Override
769    public void clear() {
770    }
771
772    @Override public Object pageObject() {
773      return null;
774    }
775
776    @Override
777    public List<String> getErrors() {
778        return null;
779    }
780  
781    @Override
782    public void setErrors(List<String> errors) {
783    }
784  
785  }
786
787  @At("/wiki")
788  private class MyRedirectingPage {
789
790    @Get
791    public String get() {
792      return REDIRECTED_GET;
793    }
794
795    @Post
796    public String post() {
797      return REDIRECTED_POST;
798    }
799  }
800  
801  @At("/forbidden")
802  private class MyForbiddenPage {
803
804    @Get
805    public Object get() {
806    	return Reply.saying().forbidden();
807    }
808
809    @Post
810    public Object post() {
811      return Reply.saying().forbidden();
812    }
813  }
814}