You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/06/11 11:33:23 UTC

svn commit: r666593 [2/2] - in /incubator/shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/rewrite/ main/java/org/apache/shindig/gadgets/servlet/ test/java/org/apache/shindig/gadgets/servlet/

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java?rev=666593&r1=666592&r2=666593&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java Wed Jun 11 02:33:22 2008
@@ -18,432 +18,91 @@
  */
 package org.apache.shindig.gadgets.servlet;
 
-import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
+import static org.junit.Assert.assertEquals;
 
-import org.apache.shindig.common.SecurityToken;
-import org.apache.shindig.gadgets.FakeGadgetToken;
 import org.apache.shindig.gadgets.GadgetException;
 import org.apache.shindig.gadgets.http.HttpRequest;
 import org.apache.shindig.gadgets.http.HttpResponse;
-import org.apache.shindig.gadgets.spec.Auth;
-import org.apache.shindig.gadgets.spec.Preload;
 
-import org.json.JSONArray;
-import org.json.JSONObject;
+import org.junit.Test;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.net.URI;
 import java.util.Arrays;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.servlet.ServletOutputStream;
-
-public class ProxyHandlerTest extends HttpTestFixture {
+import javax.servlet.http.HttpServletResponse;
 
+public class ProxyHandlerTest {
   private final static String URL_ONE = "http://www.example.org/test.html";
   private final static String DATA_ONE = "hello world";
 
-  private static final SecurityToken DUMMY_TOKEN = new FakeGadgetToken();
-
-  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-  final PrintWriter writer = new PrintWriter(baos);
+  private final ServletTestFixture fixture = new ServletTestFixture();
+  private final ProxyHandler proxyHandler
+      = new ProxyHandler(fixture.httpFetcher, fixture.lockedDomainService, fixture.rewriter);
+  private final HttpServletResponseRecorder recorder
+      = new HttpServletResponseRecorder(fixture.response);
 
-  final ServletOutputStream responseStream = new ServletOutputStream() {
-    @SuppressWarnings("unused")
-    @Override
-    public void write(int b) throws IOException {
-      baos.write(b);
-    }
-  };
-
-  final static Enumeration<String> EMPTY_LIST = new Enumeration<String>() {
-    public boolean hasMoreElements() {
-      return false;
-    }
-    public String nextElement() {
-      return null;
-    }
-  };
-
-  private void expectGetAndReturnData(String url, byte[] data)
-      throws Exception {
-    HttpRequest req = new HttpRequest(
-        "GET", new URI(url), null, null, new HttpRequest.Options());
+  private void expectGetAndReturnData(String url, byte[] data) throws Exception {
+    HttpRequest req = new HttpRequest(new URI(url), new HttpRequest.Options());
     HttpResponse resp = new HttpResponse(200, data, null);
-    expect(contentFetcherFactory.get()).andReturn(fetcher);
-    expect(fetcher.fetch(req)).andReturn(resp);
+    expect(fixture.httpFetcher.fetch(req)).andReturn(resp);
   }
 
   private void expectGetAndReturnHeaders(String url,
       Map<String, List<String>> headers) throws Exception {
-    HttpRequest req = new HttpRequest(
-      "GET", new URI(url), null, null, new HttpRequest.Options());
+    HttpRequest req = new HttpRequest(new URI(url), new HttpRequest.Options());
     HttpResponse resp = new HttpResponse(200, null, headers);
-    expect(contentFetcherFactory.get()).andReturn(fetcher);
-    expect(fetcher.fetch(req)).andReturn(resp);
-  }
-
-  private void expectPostAndReturnData(String url, byte[] body, byte[] data)
-      throws Exception {
-    HttpRequest req = new HttpRequest(
-        "POST", new URI(url), null, body, new HttpRequest.Options());
-    HttpResponse resp = new HttpResponse(200, data, null);
-    expect(contentFetcherFactory.get()).andReturn(fetcher);
-    expect(fetcher.fetch(req)).andReturn(resp);
-  }
-
-  private void setupPostRequestMock(String url, String body) throws Exception {
-    setupGenericRequestMock("POST", url);
-    expect(request.getParameter("postData")).andReturn(body).atLeastOnce();
-  }
-
-  private void setupGetRequestMock(String url) throws Exception {
-    setupGenericRequestMock("GET", url);
-  }
-
-  private void setupGenericRequestMock(String method, String url)
-      throws Exception {
-    expect(request.getMethod()).andReturn("POST").atLeastOnce();
-    expect(request.getParameter("httpMethod")).andReturn(method).atLeastOnce();
-    expect(request.getParameter("url")).andReturn(url).atLeastOnce();
-    expect(response.getWriter()).andReturn(writer).atLeastOnce();
+    expect(fixture.httpFetcher.fetch(req)).andReturn(resp);
   }
 
   private void setupProxyRequestMock(String host, String url) throws Exception {
-    expect(request.getMethod()).andReturn("GET").atLeastOnce();
-    expect(request.getHeader("Host")).andReturn(host);
-    expect(request.getParameter("url")).andReturn(url).atLeastOnce();
-    expect(request.getHeaderNames()).andReturn(EMPTY_LIST);
-    expect(response.getOutputStream()).andReturn(responseStream).atLeastOnce();
+    expect(fixture.request.getHeader("Host")).andReturn(host);
+    expect(fixture.request.getParameter("url")).andReturn(url).atLeastOnce();
   }
 
-  private void setupFailedProxyRequestMock(String host, String url)
-      throws Exception {
-    expect(request.getHeader("Host")).andReturn(host);
+  private void setupFailedProxyRequestMock(String host, String url) throws Exception {
+    expect(fixture.request.getHeader("Host")).andReturn(host);
   }
 
-  private JSONObject readJSONResponse(String body) throws Exception {
-    String json
-        = body.substring("throw 1; < don't be evil' >".length(), body.length());
-    return new JSONObject(json);
-  }
-
-  public void testFetchJson() throws Exception {
-    setupGetRequestMock(URL_ONE);
-    expectGetAndReturnData(URL_ONE, DATA_ONE.getBytes());
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(URL_ONE);
-    assertEquals(200, info.getInt("rc"));
-    assertEquals(DATA_ONE, info.get("body"));
-  }
+  @Test
+  public void ifModifiedSinceAlwaysReturnsEarly() throws Exception {
+    expect(fixture.request.getHeader("If-Modified-Since"))
+        .andReturn("Yes, this is an invalid header.");
+    fixture.replay();
 
-  public void testFetchFeed() throws Exception {
-    String entryTitle = "Feed title";
-    String entryLink = "http://example.org/entry/0/1";
-    String entrySummary = "This is the summary";
-    String rss = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
-                 "<rss version=\"2.0\"><channel>" +
-                 "<title>dummy</title>" +
-                 "<link>http://example.org/</link>" +
-                 "<item>" +
-                 "<title>" + entryTitle + "</title>" +
-                 "<link>" + entryLink + "</link>" +
-                 "<description>" + entrySummary + "</description>" +
-                 "</item>" +
-                 "</channel></rss>";
-    setupGetRequestMock(URL_ONE);
-    expect(request.getParameter(ProxyHandler.CONTENT_TYPE_PARAM)).andReturn("FEED");
-    expectGetAndReturnData(URL_ONE, rss.getBytes());
-    replay();
-
-    proxyHandler.fetchJson(request, response);
-
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(URL_ONE);
-    JSONObject feed = new JSONObject(info.getString("body"));
-    JSONObject entry = feed.getJSONArray("Entry").getJSONObject(0);
-
-    assertEquals(entryTitle, entry.getString("Title"));
-    assertEquals(entryLink, entry.getString("Link"));
-    assertNull("getSummaries has the wrong default value (should be false).",
-        entry.optString("Summary", null));
-  }
+    proxyHandler.fetch(fixture.request, recorder);
+    fixture.verify();
 
-  public void testFetchFeedParameters() throws Exception {
-    String entryTitle = "Feed title";
-    String entryLink = "http://example.org/entry/0/1";
-    String entrySummary = "This is the summary";
-    String rss = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
-                 "<rss version=\"2.0\"><channel>" +
-                 "<title>dummy</title>" +
-                 "<link>http://example.org/</link>" +
-                 "<item>" +
-                 "<title>" + entryTitle + "</title>" +
-                 "<link>" + entryLink + "</link>" +
-                 "<description>" + entrySummary + "</description>" +
-                 "</item>" +
-                 "<item>" +
-                 "<title>" + entryTitle + "</title>" +
-                 "<link>" + entryLink + "</link>" +
-                 "<description>" + entrySummary + "</description>" +
-                 "</item>" +
-                 "<item>" +
-                 "<title>" + entryTitle + "</title>" +
-                 "<link>" + entryLink + "</link>" +
-                 "<description>" + entrySummary + "</description>" +
-                 "</item>" +
-                 "</channel></rss>";
-    setupGetRequestMock(URL_ONE);
-    expect(request.getParameter(ProxyHandler.CONTENT_TYPE_PARAM)).andReturn("FEED");
-    expect(request.getParameter(ProxyHandler.GET_SUMMARIES_PARAM)).andReturn("true");
-    expect(request.getParameter(ProxyHandler.NUM_ENTRIES_PARAM)).andReturn("2");
-    expectGetAndReturnData(URL_ONE, rss.getBytes());
-    replay();
-
-    proxyHandler.fetchJson(request, response);
-
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(URL_ONE);
-    JSONObject feed = new JSONObject(info.getString("body"));
-    JSONArray feeds = feed.getJSONArray("Entry");
-
-    assertEquals("numEntries not parsed correctly!", 2, feeds.length());
-
-    JSONObject entry = feeds.getJSONObject(1);
-    assertEquals(entryTitle, entry.getString("Title"));
-    assertEquals(entryLink, entry.getString("Link"));
-    assertEquals(entrySummary, entry.getString("Summary"));
+    assertEquals(HttpServletResponse.SC_NOT_MODIFIED, recorder.getHttpStatusCode());
   }
 
-  public void testLockedDomainEmbed() throws Exception {
+  @Test
+  public void lockedDomainEmbed() throws Exception {
     setupProxyRequestMock("www.example.com", URL_ONE);
-    expect(lockedDomainService.embedCanRender("www.example.com"))
-        .andReturn(true);
-    expectGetAndReturnData(URL_ONE, DATA_ONE.getBytes());
-    replay();
-    proxyHandler.fetch(request, response);
-    verify();
-    responseStream.close();
-    assertEquals(DATA_ONE, new String(baos.toByteArray()));
-  }
-
-  public void testLockedDomainFailedEmbed() throws Exception {
-    setupFailedProxyRequestMock("www.example.com", URL_ONE);
-    expect(lockedDomainService.embedCanRender("www.example.com"))
-        .andReturn(false);
-    replay();
-    try {
-      proxyHandler.fetch(request, response);
-      fail("should have thrown");
-    } catch (GadgetException e) {
-      assertTrue(
-              e.getMessage().contains("made to wrong domain www.example.com"));
-    }
-    verify();
-  }
-
-  public void testFetchDecodedUrl() throws Exception {
-    String origUrl = "http://www.example.com";
-    String cleanedUrl = "http://www.example.com/";
-    setupGetRequestMock(origUrl);
-    expectGetAndReturnData(cleanedUrl, DATA_ONE.getBytes());
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(origUrl);
-    assertEquals(200, info.getInt("rc"));
-    assertEquals(DATA_ONE, info.get("body"));
-  }
-
-  public void testEmptyDocument() throws Exception {
-    setupGetRequestMock(URL_ONE);
-    expectGetAndReturnData(URL_ONE, "".getBytes());
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(URL_ONE);
-    assertEquals(200, info.getInt("rc"));
-    assertEquals("", info.get("body"));
-  }
-
-  public void testPostRequest() throws Exception {
-    String body = "abc";
-    setupPostRequestMock(URL_ONE, body);
-    expectPostAndReturnData(URL_ONE, body.getBytes(), DATA_ONE.getBytes());
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(URL_ONE);
-    assertEquals(200, info.getInt("rc"));
-    assertEquals(DATA_ONE, info.get("body"));
-  }
-
-  public void testSignedGetRequest() throws Exception {
-    // Doesn't actually sign since it returns the standard fetcher.
-    // Signing tests are in SigningFetcherTest
-    setupGetRequestMock(URL_ONE);
-    expect(securityTokenDecoder.createToken("fake-token")).andReturn(DUMMY_TOKEN);
-    expect(request.getParameter(ProxyHandler.SECURITY_TOKEN_PARAM))
-        .andReturn("fake-token").atLeastOnce();
-    expect(request.getParameter(Preload.AUTHZ_ATTR))
-        .andReturn(Auth.SIGNED.toString()).atLeastOnce();
-    HttpResponse resp = new HttpResponse(200, DATA_ONE.getBytes(), null);
-    expect(contentFetcherFactory.getSigningFetcher(eq(DUMMY_TOKEN)))
-        .andReturn(fetcher);
-    expect(fetcher.fetch(isA(HttpRequest.class))).andReturn(resp);
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-  }
-
-  public void testSignedPostRequest() throws Exception {
-    // Doesn't actually sign since it returns the standard fetcher.
-    // Signing tests are in SigningFetcherTest
-    String postBody = "foo=bar%20baz";
-    setupPostRequestMock(URL_ONE, postBody);
-    expect(securityTokenDecoder.createToken("fake-token")).andReturn(DUMMY_TOKEN);
-    expect(request.getParameter(ProxyHandler.SECURITY_TOKEN_PARAM))
-        .andReturn("fake-token").atLeastOnce();
-    expect(request.getParameter(Preload.AUTHZ_ATTR))
-        .andReturn(Auth.SIGNED.toString()).atLeastOnce();
-    HttpResponse resp = new HttpResponse(200, DATA_ONE.getBytes(), null);
-    expect(contentFetcherFactory.getSigningFetcher(eq(DUMMY_TOKEN)))
-        .andReturn(fetcher);
-    expect(fetcher.fetch(isA(HttpRequest.class))).andReturn(resp);
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    assertFalse(json.getJSONObject(URL_ONE).has("st"));
-  }
-
-  public void testChangeSecurityToken() throws Exception {
-    // Doesn't actually sign since it returns the standard fetcher.
-    // Signing tests are in SigningFetcherTest
-    FakeGadgetToken authToken = new FakeGadgetToken("updated");
-    setupGetRequestMock(URL_ONE);
-    expect(securityTokenDecoder.createToken("fake-token")).andReturn(authToken);
-    expect(request.getParameter(ProxyHandler.SECURITY_TOKEN_PARAM))
-    .andReturn("fake-token").atLeastOnce();
-    expect(request.getParameter(Preload.AUTHZ_ATTR))
-    .andReturn(Auth.SIGNED.toString()).atLeastOnce();
-    HttpResponse resp = new HttpResponse(200, DATA_ONE.getBytes(), null);
-    expect(contentFetcherFactory.getSigningFetcher(eq(authToken)))
-    .andReturn(fetcher);
-    expect(fetcher.fetch(isA(HttpRequest.class))).andReturn(resp);
-    replay();
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-    JSONObject json = readJSONResponse(baos.toString());
-    assertEquals("updated", json.getJSONObject(URL_ONE).getString("st"));
-  }
-
-  public void testInvalidSigningTypeTreatedAsNone() throws Exception {
-    setupGenericRequestMock("GET", URL_ONE);
+    expect(fixture.lockedDomainService.embedCanRender("www.example.com")).andReturn(true);
     expectGetAndReturnData(URL_ONE, DATA_ONE.getBytes());
-    expect(request.getParameter(Preload.AUTHZ_ATTR))
-        .andReturn("garbage").atLeastOnce();
-    replay();
-
-    proxyHandler.fetchJson(request, response);
-    verify();
-    writer.close();
-
-    JSONObject json = readJSONResponse(baos.toString());
-    JSONObject info = json.getJSONObject(URL_ONE);
-    assertEquals(200, info.getInt("rc"));
-    assertEquals(DATA_ONE, info.get("body"));
-  }
-
-  public void testValidateUrlNoPath() throws Exception {
-    URI url = proxyHandler.validateUrl("http://www.example.com");
-    assertEquals("http", url.getScheme());
-    assertEquals("www.example.com", url.getHost());
-    assertEquals(-1, url.getPort());
-    assertEquals("/", url.getPath());
-    assertNull(url.getQuery());
-    assertNull(url.getFragment());
-  }
+    fixture.replay();
 
-  public void testValidateUrlWithPath() throws Exception {
-    URI url = proxyHandler.validateUrl("http://www.example.com/foo");
-    assertEquals("http", url.getScheme());
-    assertEquals("www.example.com", url.getHost());
-    assertEquals(-1, url.getPort());
-    assertEquals("/foo", url.getPath());
-    assertNull(url.getQuery());
-    assertNull(url.getFragment());
-  }
+    proxyHandler.fetch(fixture.request, recorder);
+    fixture.verify();
 
-  public void testValidateUrlWithPort() throws Exception {
-    URI url = proxyHandler.validateUrl("http://www.example.com:8080/foo");
-    assertEquals("http", url.getScheme());
-    assertEquals("www.example.com", url.getHost());
-    assertEquals(8080, url.getPort());
-    assertEquals("/foo", url.getPath());
-    assertNull(url.getQuery());
-    assertNull(url.getFragment());
+    assertEquals(DATA_ONE, recorder.getResponseAsString());
   }
 
-  public void testValidateUrlWithEncodedPath() throws Exception {
-    URI url
-        = proxyHandler.validateUrl("http://www.example.com:8080/foo%20bar");
-    assertEquals("http", url.getScheme());
-    assertEquals("www.example.com", url.getHost());
-    assertEquals(8080, url.getPort());
-    assertEquals("/foo%20bar", url.getRawPath());
-    assertEquals("/foo bar", url.getPath());
-    assertNull(url.getQuery());
-    assertNull(url.getFragment());
-  }
-
-  public void testValidateUrlWithEncodedQuery() throws Exception {
-    URI url = proxyHandler.validateUrl(
-        "http://www.example.com:8080/foo?q=with%20space");
-    assertEquals("http", url.getScheme());
-    assertEquals("www.example.com", url.getHost());
-    assertEquals(8080, url.getPort());
-    assertEquals("/foo", url.getPath());
-    assertEquals("q=with%20space", url.getRawQuery());
-    assertEquals("q=with space", url.getQuery());
-    assertNull(url.getFragment());
-  }
+  @Test(expected = GadgetException.class)
+  public void lockedDomainFailedEmbed() throws Exception {
+    setupFailedProxyRequestMock("www.example.com", URL_ONE);
+    expect(fixture.lockedDomainService.embedCanRender("www.example.com")).andReturn(false);
+    fixture.replay();
 
-  public void testValidateUrlWithNoPathAndEncodedQuery() throws Exception {
-    URI url
-        = proxyHandler.validateUrl("http://www.example.com?q=with%20space");
-    assertEquals("http", url.getScheme());
-    assertEquals("www.example.com", url.getHost());
-    assertEquals(-1, url.getPort());
-    assertEquals("/", url.getPath());
-    assertEquals("q=with%20space", url.getRawQuery());
-    assertEquals("q=with space", url.getQuery());
-    assertNull(url.getFragment());
+    proxyHandler.fetch(fixture.request, fixture.response);
   }
 
-  public void testHeadersPreserved() throws Exception {
+  @Test
+  public void headersPreserved() throws Exception {
     // Some headers may be blacklisted. These are ok.
     String url = "http://example.org/file.evil";
     String domain = "example.org";
@@ -453,15 +112,15 @@
     headers.put("Content-Type", Arrays.asList(contentType));
     headers.put("X-Magic-Garbage", Arrays.asList(magicGarbage));
 
-    expect(lockedDomainService.embedCanRender(domain))
-        .andReturn(true).atLeastOnce();
+    expect(fixture.lockedDomainService.embedCanRender(domain)).andReturn(true).atLeastOnce();
     setupProxyRequestMock(domain, url);
     expectGetAndReturnHeaders(url, headers);
-    response.addHeader("Content-Type", contentType);
-    response.addHeader("X-Magic-Garbage", magicGarbage);
 
-    replay();
-    proxyHandler.fetch(request, response);
-    verify();
+    fixture.replay();
+
+    proxyHandler.fetch(fixture.request, recorder);
+
+    assertEquals(contentType, recorder.getHeader("Content-Type"));
+    assertEquals(magicGarbage, recorder.getHeader("X-Magic-Garbage"));
   }
 }

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyServletTest.java?rev=666593&r1=666592&r2=666593&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyServletTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyServletTest.java Wed Jun 11 02:33:22 2008
@@ -30,8 +30,6 @@
 import org.junit.Test;
 
 import java.net.URI;
-import java.util.Collections;
-import java.util.Enumeration;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -49,10 +47,10 @@
       = "http://opensocial.org/proxy/foo=bar/" + REQUEST_URL;
   private static final String RESPONSE_BODY = "Hello, world!";
   private static final String ERROR_MESSAGE = "Broken!";
-  private static final Enumeration<String> EMPTY_ENUM
-      = Collections.enumeration(Collections.<String>emptyList());
 
   private final ServletTestFixture fixture = new ServletTestFixture();
+  private final ProxyHandler proxyHandler
+      = new ProxyHandler(fixture.httpFetcher, fixture.lockedDomainService, fixture.rewriter);
   private final ProxyServlet servlet = new ProxyServlet();
   private final HttpServletResponseRecorder recorder
       = new HttpServletResponseRecorder(fixture.response);
@@ -61,13 +59,9 @@
 
   @Before
   public void setUp() {
-    servlet.setProxyHandler(fixture.proxyHandler);
-    expect(fixture.request.getHeaderNames()).andReturn(EMPTY_ENUM).anyTimes();
-    expect(fixture.request.getParameter(ProxyHandler.METHOD_PARAM))
-        .andReturn("GET").anyTimes();
-    expect(fixture.request.getParameter(ProxyHandler.URL_PARAM))
+    servlet.setProxyHandler(proxyHandler);
+    expect(fixture.request.getParameter(ProxyBase.URL_PARAM))
         .andReturn(REQUEST_URL).anyTimes();
-    expect(fixture.request.getMethod()).andReturn("GET").anyTimes();
     expect(fixture.request.getHeader("Host")).andReturn(REQUEST_DOMAIN).anyTimes();
     expect(fixture.lockedDomainService.embedCanRender(REQUEST_DOMAIN))
         .andReturn(true).anyTimes();

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ServletTestFixture.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ServletTestFixture.java?rev=666593&r1=666592&r2=666593&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ServletTestFixture.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ServletTestFixture.java Wed Jun 11 02:33:22 2008
@@ -19,11 +19,17 @@
 package org.apache.shindig.gadgets.servlet;
 
 import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
 
+import org.apache.shindig.common.SecurityToken;
 import org.apache.shindig.common.SecurityTokenDecoder;
+import org.apache.shindig.gadgets.GadgetException;
 import org.apache.shindig.gadgets.LockedDomainService;
+import org.apache.shindig.gadgets.SigningFetcher;
 import org.apache.shindig.gadgets.http.ContentFetcherFactory;
 import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.oauth.OAuthFetcher;
+import org.apache.shindig.gadgets.oauth.OAuthRequestParams;
 import org.apache.shindig.gadgets.rewrite.ContentRewriter;
 import org.apache.shindig.gadgets.rewrite.NoOpContentRewriter;
 
@@ -45,20 +51,24 @@
   public final HttpServletResponse response = mock(HttpServletResponse.class);
   public final SecurityTokenDecoder securityTokenDecoder = mock(SecurityTokenDecoder.class);
   public final HttpFetcher httpFetcher = mock(HttpFetcher.class);
+  public final SigningFetcher signingFetcher = mock(SigningFetcher.class);
+  public final OAuthFetcher oauthFetcher = mock(OAuthFetcher.class);
+  public final ContentFetcherFactory contentFetcherFactory = mock(ContentFetcherFactory.class);
   public final LockedDomainService lockedDomainService = mock(LockedDomainService.class);
   public final ContentRewriter rewriter = new NoOpContentRewriter();
-  public final ProxyHandler proxyHandler;
 
   public ServletTestFixture() {
-    // TODO: This is horrible. It needs to be fixed.
-    ContentFetcherFactory contentFetcherFactory = mock(ContentFetcherFactory.class);
-    expect(contentFetcherFactory.get()).andReturn(httpFetcher).anyTimes();
-
-    proxyHandler = new ProxyHandler(
-        contentFetcherFactory,
-        securityTokenDecoder,
-        lockedDomainService,
-        rewriter);
+    try {
+      // TODO: This is horrible. It needs to be fixed.
+      expect(contentFetcherFactory.get()).andReturn(httpFetcher).anyTimes();
+      expect(contentFetcherFactory.getSigningFetcher(isA(SecurityToken.class)))
+          .andReturn(signingFetcher).anyTimes();
+      expect(contentFetcherFactory.getOAuthFetcher(
+          isA(SecurityToken.class), isA(OAuthRequestParams.class)))
+          .andReturn(oauthFetcher).anyTimes();
+    } catch (GadgetException e) {
+      // Blah
+    }
   }
 
   /**
@@ -101,4 +111,8 @@
   protected void verify() {
     EasyMock.verify(mocks.toArray());
   }
+
+  protected void reset() {
+    EasyMock.reset(mocks.toArray());
+  }
 }