Package org.strecks.interceptor

Source Code of org.strecks.interceptor.TestHistoryRecorder

/*
* 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.interceptor;

import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.strecks.constants.InfrastructureKeys;
import org.strecks.context.impl.TestContextImpl;
import org.testng.annotations.Test;

/**
* @author Phil Zoio
*/
public class TestHistoryRecorder
{

  @Test
  public void testHistoryRecorderPost()
  {

    HttpServletRequest request = createMock(HttpServletRequest.class);

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

    replay(request);

    HistoryRecorder interceptor = new HistoryRecorder();
    interceptor.afterExecute(null, new TestContextImpl(request, null, null, null, null), null);

    verify(request);

  }

  @Test
  public void testHistoryRecorderGet()
  {

    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpSession session = createMock(HttpSession.class);

    expect(request.getMethod()).andReturn("GET");
    expect(request.getSession()).andReturn(session);
    expect(request.getServletPath()).andReturn("path");
    expect(request.getQueryString()).andReturn("queryString");
    List<String> arrayList = new ArrayList<String>();
    expect(session.getAttribute(InfrastructureKeys.GOOD_URL_HISTORY)).andReturn(arrayList);
    arrayList.add("path?queryString");
    session.setAttribute(InfrastructureKeys.GOOD_URL_HISTORY, arrayList);

    replay(request);
    replay(session);

    HistoryRecorder interceptor = new HistoryRecorder();
    interceptor.afterExecute(null, new TestContextImpl(request, null, null, null, null), null);

    verify(request);
    verify(session);
  }

}
TOP

Related Classes of org.strecks.interceptor.TestHistoryRecorder

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.