Package com.google.sitebricks

Examples of com.google.sitebricks.Respond$HtmlTagBuilder


  }

  @Test
  public final void renderHeader() throws ExpressionCompileException {

    Respond respond = RespondersForTesting.newRespond();

    MvelEvaluatorCompiler compiler = new MvelEvaluatorCompiler(Object.class);
    new HeaderWidget(new ProceedingWidgetChain(), Maps.<String, String>newHashMap(), compiler)
        .render(new Object(), respond);

    respond.writeToHead("<title>bs</title>");

    final String response = respond.toString();
    assert "<head><title>bs</title></head>".equals(response) :
        "instead printed: " + response;
  }
View Full Code Here


  }

  @Test
  public final void renderHeaderWithContent() throws ExpressionCompileException {

    Respond respond = RespondersForTesting.newRespond();

    final WidgetChain widgetChain = new ProceedingWidgetChain();
    final EvaluatorCompiler mock = new MvelEvaluatorCompiler(Object.class);
    widgetChain.addWidget(new TextWidget("<meta name=\"thing\"/>", mock));

    MvelEvaluatorCompiler compiler = new MvelEvaluatorCompiler(Object.class);

    new HeaderWidget(widgetChain, Maps.<String, String>newHashMap(), compiler)
        .render(new Object(), respond);

    respond.writeToHead("<title>bs</title>");

    final String response = respond.toString();
    assert "<head><meta name=\"thing\"/><title>bs</title></head>".equals(response) :
        "instead printed: " + response;
  }
View Full Code Here

  }

    @Test
    public final void chooseWidgetSelectTagRender() {

        Respond respond = RespondersForTesting.newRespond();
        final String s1 = "aString";
        final String s2 = "anotherString";
        final String s3 = "aThirdStr";
        final List<String> boundTo = Arrays.asList(s1, s2, s3);

        @SuppressWarnings("unchecked")
        final Provider<FlashCache> cacheProvider = createMock(Provider.class);
        final FlashCache cache = createMock(FlashCache.class);

        expect(cacheProvider.get())
              .andReturn(cache);

        cache.put("strings", boundTo);

        replay(cacheProvider, cache);


        final ChooseWidget widget = new ChooseWidget(new ProceedingWidgetChain(), "from=strings, bind=choice", new MvelEvaluator());
        widget.setCache(cacheProvider);

        widget.render(new HashMap<String, Object>() {{
                    put("strings", boundTo);
                }}, respond);


        //assert the validity of the text tag:
        String tag = respond.toString();

//        System.out.println(tag);
        assert tag.startsWith("<select name=\"choice\">");
        assert tag.contains(String.format("<option value=\"[C/strings/%d\">", s1.hashCode()));
        assert tag.contains(String.format("<option value=\"[C/strings/%d\">", s2.hashCode()));
View Full Code Here

  public final void dispatchRequestAndRespondOnGet() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();


    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(request.getParameterMap())
        .andReturn(new HashMap())
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();

    expect(page.isHeadless())
        .andReturn(false);

    expect(page.widget())
        .andReturn(widget);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("GET");

    expect(page.doMethod("get", pageOb, "/thing", request))
        .andReturn(null);


    widget.render(pageOb, respond);
    expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, new Provider<Respond>() {
      public Respond get() {
        return respond;
      }
    }, createNiceMock(ResourcesService.class), flashCacheProvider,
        createNiceMock(HeadlessRenderer.class)).dispatch(request, response);
View Full Code Here

  public final void dispatchRequestToCorrectEventHandlerOnGet() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();


    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();


    expect(page.isHeadless())
        .andReturn(false);

    expect(page.widget())
        .andReturn(widget);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("GET");

    final HashMap<String, String[]> parameterMap = new HashMap<String, String[]>();
    expect(request.getParameterMap())
        .andReturn(parameterMap)
        .anyTimes();

    expect(page.doMethod("get", pageOb, "/thing", request))
        .andReturn(null);

    widget.render(pageOb, respond);
    expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, new Provider<Respond>() {
      public Respond get() {
        return respond;
      }
    }, createNiceMock(ResourcesService.class), flashCacheProvider,
        createNiceMock(HeadlessRenderer.class)).dispatch(request, response);
View Full Code Here

  public final void dispatchRequestAndRespondOnPost() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();

    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(request.getParameterMap())
        .andReturn(new HashMap())
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();


    expect(page.isHeadless())
        .andReturn(false);

    expect(page.widget())
        .andReturn(widget);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("POST");

    //noinspection unchecked
    expect(page.doMethod(matches("post"), eq(pageOb), eq("/thing"), isA(HttpServletRequest.class)))
        .andReturn(null);
//        expectLastCall().once();


    widget.render(pageOb, respond);
    expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, new Provider<Respond>() {
      public Respond get() {
        return respond;
      }
    }, createNiceMock(ResourcesService.class), flashCacheProvider,
        createNiceMock(HeadlessRenderer.class)).dispatch(request, response);
View Full Code Here

  public final void dispatchRequestAndRedirectOnPost() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();

    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(request.getParameterMap())
        .andReturn(new HashMap())
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();

    expect(page.isHeadless())
        .andReturn(false);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("POST");

    respond.redirect(REDIRECTED_POST);

    //noinspection unchecked
    expect(page.doMethod(matches("post"), eq(pageOb), eq("/thing"), isA(HttpServletRequest.class)))
        .andReturn(REDIRECTED_POST);


//        widget.render(pageOb, respond);
//        expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, new Provider<Respond>() {
      public Respond get() {
        return respond;
      }
    }, createNiceMock(ResourcesService.class), flashCacheProvider,
        createNiceMock(HeadlessRenderer.class)).dispatch(request, response);
View Full Code Here

  public final void dispatchRequestAndRedirectOnGet() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();


    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(request.getParameterMap())
        .andReturn(new HashMap())
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();

    expect(page.isHeadless())
        .andReturn(false);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("GET");

    respond.redirect(REDIRECTED_GET);

    //noinspection unchecked
    expect(page.doMethod(matches("get"), eq(pageOb), eq("/thing"), isA(HttpServletRequest.class)))
        .andReturn(REDIRECTED_GET);


//        widget.render(pageOb, respond);
//        expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, new Provider<Respond>() {
      public Respond get() {
        return respond;
      }
    }, createNiceMock(ResourcesService.class), flashCacheProvider,
        createNiceMock(HeadlessRenderer.class)).dispatch(request, response);
View Full Code Here

    expect(pageBook.get(A_STATIC_RESOURCE_URI))
        .andReturn(null);

    replay(request, pageBook, respond, binder);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, respond, createNiceMock(ResourcesService.class),
        flashCacheProvider,
        createNiceMock(HeadlessRenderer.class)).dispatch(request, response);


    assert out == null : "Did not respond correctly";
View Full Code Here

  public final void dispatchStaticResource() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    RequestBinder binder = createMock(RequestBinder.class);
    ResourcesService resourcesService = createMock(ResourcesService.class);
    Respond mockRespond = createMock(Respond.class);

    @SuppressWarnings("unchecked")
    Provider<Respond> respond = createMock(Provider.class);


    expect(request.getRequestURI())
        .andReturn(A_STATIC_RESOURCE_URI)
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(resourcesService.serve(A_STATIC_RESOURCE_URI))
        .andReturn(mockRespond);

    replay(request, pageBook, respond, binder, resourcesService);

    Respond out = new WidgetRoutingDispatcher(pageBook, binder, respond, resourcesService,
        flashCacheProvider, createNiceMock(HeadlessRenderer.class)).dispatch(request, response);


    assert out != null : "Did not respond correctly";
    assert mockRespond.equals(out);
View Full Code Here

TOP

Related Classes of com.google.sitebricks.Respond$HtmlTagBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.