Package org.strecks.navigate.spring

Source Code of org.strecks.navigate.spring.TestSpringRenderingViewAdapter

/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.strecks.navigate.spring;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.classextension.EasyMock.createStrictMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.View;
import org.strecks.context.ActionContext;
import org.strecks.exceptions.ApplicationRuntimeException;
import org.testng.annotations.Test;

public class TestSpringRenderingViewAdapter
{

  @Test
  public void test() throws Exception
  {

    View view = createStrictMock(View.class);
    Map model = createStrictMock(Map.class);
    ActionContext context = createStrictMock(ActionContext.class);
    HttpServletRequest request = createStrictMock(HttpServletRequest.class);
    HttpServletResponse response = createStrictMock(HttpServletResponse.class);

    SpringRenderingViewAdapter va = new SpringRenderingViewAdapter(view, model);

    expect(context.getRequest()).andReturn(request);
    expect(context.getResponse()).andReturn(response);
    view.render(model, request, response);

    replay(context);
    replay(view);
    replay(model);

    va.render(context);

    verify(context);
    verify(view);
    verify(model);

  }

  @Test
  public void testException() throws Exception
  {

    View view = createStrictMock(View.class);
    Map model = createStrictMock(Map.class);
    ActionContext context = createStrictMock(ActionContext.class);
    HttpServletRequest request = createStrictMock(HttpServletRequest.class);
    HttpServletResponse response = createStrictMock(HttpServletResponse.class);

    SpringRenderingViewAdapter va = new SpringRenderingViewAdapter(view, model);

    expect(context.getRequest()).andReturn(request);
    expect(context.getResponse()).andReturn(response);
    view.render(model, request, response);
    expectLastCall().andThrow(new IllegalStateException());

    replay(context);
    replay(view);
    replay(model);

    try
    {
      va.render(context);
    }
    catch (ApplicationRuntimeException e)
    {
      assert e.getMessage().startsWith("Exception thrown during rendering of view");
      assert e.getCause() instanceof IllegalStateException;
    }

    verify(context);
    verify(view);
    verify(model);

  }

}
TOP

Related Classes of org.strecks.navigate.spring.TestSpringRenderingViewAdapter

TOP
Copyright © 2018 www.massapi.com. 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.