Package net.jsunit.interceptor

Source Code of net.jsunit.interceptor.RequestSourceInterceptorTest

package net.jsunit.interceptor;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
import junit.framework.TestCase;
import net.jsunit.DummyHttpRequest;
import net.jsunit.action.RequestSourceAware;

import java.util.HashMap;

public class RequestSourceInterceptorTest extends TestCase {

    public void testSimple() throws Exception {
        DummyHttpRequest request = new DummyHttpRequest(new HashMap());
        request.setIpAddress("123.456.78.9");
        request.setHost("www.example.com");
        ServletActionContext.setRequest(request);
        RequestSourceInterceptor interceptor = new RequestSourceInterceptor();
        RequestSourceAction action = new RequestSourceAction();
        MockActionInvocation invocation = new MockActionInvocation(action);
        interceptor.intercept(invocation);
        assertTrue(invocation.wasInvokeCalled);

        assertEquals("123.456.78.9", action.ipAddress);
        assertEquals("www.example.com", action.host);
    }

    static class RequestSourceAction implements RequestSourceAware, Action {
        private String ipAddress;
        private String host;

        public void setRequestIPAddress(String ipAddress) {
            this.ipAddress = ipAddress;
        }

        public void setRequestHost(String host) {
            this.host = host;
        }

        public String getRequestIpAddress() {
            return null;
        }

        public void setReferrer(String referrer) {
        }

        public String execute() throws Exception {
            return null;
        }
    }
}
TOP

Related Classes of net.jsunit.interceptor.RequestSourceInterceptorTest

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.