Package org.openqa.selenium.server

Source Code of org.openqa.selenium.server.ProxyHanderUnitTest

package org.openqa.selenium.server;

import junit.framework.TestCase;
import static org.easymock.classextension.EasyMock.*;

import org.mortbay.http.HttpRequest;
import org.mortbay.http.HttpResponse;

import java.lang.reflect.Method;

public class ProxyHanderUnitTest extends TestCase {

  public void testSendNotFoundSends404ResponseCode() throws Exception {
    ProxyHandler proxyHandler = new ProxyHandler(true, "", "");
    HttpResponse httpResponseMock = createMock(HttpResponse.class);
    httpResponseMock.sendError(HttpResponse.__404_Not_Found, "Not found");
    expectLastCall().once();
    replay(httpResponseMock);
    proxyHandler.sendNotFound(httpResponseMock);
    verify(httpResponseMock);
  }

  public void testHandleCallsSendNotFoundWhenAskingForNonExistentResource()
      throws Exception {
    ProxyHandler proxyHandlerMock = createMock(ProxyHandler.class,
        new Method[] { ProxyHandler.class.getDeclaredMethod(
            "sendNotFound", HttpResponse.class) });
   
    String pathInContext = "/invalid";
    String pathParams = "";
    HttpRequest httpRequest = new HttpRequest();
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setAttribute("NotFound", "True");
   
    proxyHandlerMock.sendNotFound(httpResponse);
    expectLastCall().once();
    replay(proxyHandlerMock);
   
    proxyHandlerMock.handle(pathInContext, pathParams, httpRequest,
        httpResponse);
    assertNull(httpResponse.getAttribute("NotFound"));
    verify(proxyHandlerMock);
  }
}
TOP

Related Classes of org.openqa.selenium.server.ProxyHanderUnitTest

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.