Ian - Thanks for committing this.
In the future it would be great to add the patch providers name to the
commit log, like:

"SHINDIG-473.
Patch by Adam Winer. Adds more end to end tests etc etc"

- Cassie


On Fri, Jul 25, 2008 at 2:24 AM, <[EMAIL PROTECTED]> wrote:

> Author: ieb
> Date: Fri Jul 25 02:24:22 2008
> New Revision: 679724
>
> URL: http://svn.apache.org/viewvc?rev=679724&view=rev
> Log:
> SHINDIG-473
>
> Applied patch after moving EndToEndTests to EndToEndTest
>
> Added:
>
>  
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
>
>  
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
>
>  incubator/shindig/trunk/java/server/src/test/resources/endtoend/errorTest.xml
>
>  
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPeopleTest.xml
> Removed:
>
>  
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTests.java
>
>  
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/FetchPersonTest.java
> Modified:
>
>  
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPersonTest.xml
>
>  
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/testframework.js
>
> Added:
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java?rev=679724&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
> (added)
> +++
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
> Fri Jul 25 02:24:22 2008
> @@ -0,0 +1,156 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you 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.apache.shindig.server.endtoend;
> +
> +import com.google.common.base.Join;
> +import com.google.common.collect.Maps;
> +
> +import org.apache.shindig.common.servlet.GuiceServletContextListener;
> +import org.apache.shindig.gadgets.servlet.ConcatProxyServlet;
> +import org.apache.shindig.gadgets.servlet.GadgetRenderingServlet;
> +import org.apache.shindig.gadgets.servlet.HttpGuiceModule;
> +import org.apache.shindig.social.opensocial.service.DataServiceServlet;
> +import org.mortbay.jetty.Server;
> +import org.mortbay.jetty.handler.ResourceHandler;
> +import org.mortbay.jetty.servlet.Context;
> +import org.mortbay.jetty.servlet.ServletHolder;
> +import org.mortbay.resource.Resource;
> +
> +import java.io.IOException;
> +import java.net.URL;
> +import java.util.Map;
> +
> +import javax.servlet.Servlet;
> +import javax.servlet.ServletConfig;
> +import javax.servlet.ServletException;
> +import javax.servlet.ServletRequest;
> +import javax.servlet.ServletResponse;
> +import javax.servlet.http.HttpServletResponse;
> +
> +/**
> + * Suite for running the end-to-end tests. The suite is responsible for
> starting up and shutting
> + * down the server.
> + */
> +public class EndToEndServer {
> +  private static final int JETTY_PORT = 9003;
> +  private static final String GADGET_BASE = "/gadgets/ifr";
> +  private static final String JSON_BASE = "/social/rest/*";
> +  private static final String CONCAT_BASE = "/gadgets/concat";
> +  public static final String SERVER_URL = "http://localhost:"; +
> JETTY_PORT;
> +  public static final String GADGET_BASEURL = SERVER_URL + GADGET_BASE;
> +
> +  private final Server server;
> +
> +  /** Fake error code for data service servlet request */
> +  private int errorCode;
> +
> +  /** Fake error message for data service servlet request */
> +  private String errorMessage;
> +
> +  public EndToEndServer() throws Exception {
> +    server = createServer(JETTY_PORT);
> +  }
> +
> +  public void start() throws Exception {
> +    server.start();
> +  }
> +
> +  public void stop() throws Exception {
> +    server.stop();
> +  }
> +
> +  public void clearDataServiceError() {
> +    errorCode = 0;
> +  }
> +
> +  public void setDataServiceError(int errorCode, String errorMessage) {
> +    this.errorCode = errorCode;
> +    this.errorMessage = errorMessage;
> +  }
> +
> +  /**
> +   * Starts the server for end-to-end tests.
> +   */
> +  private Server createServer(int port) throws Exception {
> +    Server newServer = new Server(port);
> +
> +    // Attach the test resources in /endtoend as static content for the
> test
> +    ResourceHandler resources = new ResourceHandler();
> +    URL resource = EndToEndTest.class.getResource("/endtoend");
> +    resources.setBaseResource(Resource.newResource(resource));
> +    newServer.addHandler(resources);
> +
> +    Context context = new Context(newServer, "/", Context.SESSIONS);
> +    context.addEventListener(new GuiceServletContextListener());
> +
> +    Map<String, String> initParams = Maps.newHashMap();
> +    String modules = Join
> +        .join(":", EndToEndModule.class.getName(),
> HttpGuiceModule.class.getName());
> +
> +    initParams.put(GuiceServletContextListener.MODULES_ATTRIBUTE,
> modules);
> +    context.setInitParams(initParams);
> +
> +    // Attach the gadget rendering servlet
> +    ServletHolder gadgetServletHolder = new ServletHolder(new
> GadgetRenderingServlet());
> +    context.addServlet(gadgetServletHolder, GADGET_BASE);
> +
> +    // Attach DataServiceServlet, wrapped in a proxy to fake errors
> +    ServletHolder jsonServletHolder = new ServletHolder(new
> ForceErrorServlet(
> +        new DataServiceServlet()));
> +    context.addServlet(jsonServletHolder, JSON_BASE);
> +
> +    // Attach the ConcatProxyServlet - needed for
> +    ServletHolder concatHolder = new ServletHolder(new
> ConcatProxyServlet());
> +    context.addServlet(concatHolder, CONCAT_BASE);
> +
> +    return newServer;
> +  }
> +
> +  private class ForceErrorServlet implements Servlet {
> +    private final Servlet proxiedServlet;
> +
> +    public ForceErrorServlet(Servlet proxiedServlet) {
> +      this.proxiedServlet = proxiedServlet;
> +    }
> +
> +    public void init(ServletConfig servletConfig) throws ServletException
> {
> +      proxiedServlet.init(servletConfig);
> +    }
> +
> +    public ServletConfig getServletConfig() {
> +      return proxiedServlet.getServletConfig();
> +    }
> +
> +    public void service(ServletRequest servletRequest, ServletResponse
> servletResponse)
> +        throws ServletException, IOException {
> +      if (errorCode > 0) {
> +        ((HttpServletResponse) servletResponse).sendError(errorCode,
> errorMessage);
> +      } else {
> +        proxiedServlet.service(servletRequest, servletResponse);
> +      }
> +    }
> +
> +    public String getServletInfo() {
> +      return proxiedServlet.getServletInfo();
> +    }
> +
> +    public void destroy() {
> +      proxiedServlet.destroy();
> +    }
> +  }
> +}
>
> Added:
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java?rev=679724&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
> (added)
> +++
> incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
> Fri Jul 25 02:24:22 2008
> @@ -0,0 +1,161 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you 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.apache.shindig.server.endtoend;
> +
> +import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
> +import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
> +import com.gargoylesoftware.htmlunit.WebClient;
> +import com.gargoylesoftware.htmlunit.html.HtmlPage;
> +
> +import org.apache.shindig.common.BasicSecurityToken;
> +import org.apache.shindig.common.BasicSecurityTokenDecoder;
> +import org.apache.shindig.common.SecurityToken;
> +import org.apache.shindig.common.crypto.BlobCrypterException;
> +import org.junit.After;
> +import org.junit.AfterClass;
> +import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertFalse;
> +import static org.junit.Assert.assertNull;
> +import org.junit.Before;
> +import org.junit.BeforeClass;
> +import org.junit.Test;
> +
> +import java.io.IOException;
> +import java.net.URLEncoder;
> +
> +import javax.servlet.http.HttpServletResponse;
> +
> +/**
> + * Base class for end-to-end tests.
> + */
> +public class EndToEndTest {
> +  static private EndToEndServer server = null;
> +
> +  private WebClient webClient;
> +  private CollectingAlertHandler alertHandler;
> +  private SecurityToken token;
> +
> +  @Test
> +  public void fetchPerson() throws Exception {
> +    executeAllPageTests("fetchPersonTest");
> +  }
> +
> +  @Test
> +  public void fetchPeople() throws Exception {
> +    executeAllPageTests("fetchPeopleTest");
> +  }
> +
> +  @Test
> +  public void notFoundError() throws Exception {
> +    server.setDataServiceError(HttpServletResponse.SC_NOT_FOUND, "Not
> Found");
> +    executePageTest("errorTest", "notFoundError");
> +  }
> +
> +  @Test
> +  public void badRequest() throws Exception {
> +    server.setDataServiceError(HttpServletResponse.SC_BAD_REQUEST, "Bad
> Request");
> +    executePageTest("errorTest", "badRequestError");
> +  }
> +
> +  @Test
> +  public void internalError() throws Exception {
> +
>  server.setDataServiceError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
> "Internal Server Error");
> +    executePageTest("errorTest", "internalError");
> +  }
> +
> +  @BeforeClass
> +  public static void setUpOnce() throws Exception {
> +    server = new EndToEndServer();
> +    server.start();
> +  }
> +
> +  @AfterClass
> +  public static void tearDownOnce() throws Exception {
> +    server.stop();
> +  }
> +
> +  @Before
> +  public void setUp() throws Exception {
> +    webClient = new WebClient();
> +    // NicelyResynchronizingAjaxController changes XHR calls from
> asynchronous
> +    // to synchronous, saving the test from needing to wait or sleep for
> XHR
> +    // completion.
> +    webClient.setAjaxController(new
> NicelyResynchronizingAjaxController());
> +    alertHandler = new CollectingAlertHandler();
> +    webClient.setAlertHandler(alertHandler);
> +    token = createToken("canonical", "john.doe");
> +  }
> +
> +  @After
> +  public void tearDown() {
> +    server.clearDataServiceError();
> +  }
> +
> +  /**
> +   * Verify that the Javascript completed running.  This ensures that
> +   * logic errors or exceptions don't get treated as success.
> +   */
> +  @After
> +  public void verifyTestsFinished() {
> +    // Verify the format of the alerts - test method names followed by
> "finished"
> +    String testMethod = null;
> +    for (String alert : alertHandler.getCollectedAlerts()) {
> +      if (testMethod == null) {
> +        assertFalse("Test method omitted", "FINISHED".equals(alert));
> +        testMethod = alert;
> +      } else {
> +        assertEquals("test method " + testMethod + " did not finish",
> "FINISHED", alert);
> +        testMethod = null;
> +      }
> +    }
> +
> +    assertNull("test method " + testMethod + " did not finish",
> testMethod);
> +  }
> +
> +  /**
> +   * Executes a page test by loading the HTML page.
> +   * @param testName name of the test, which must match a gadget XML file
> +   *     name in test/resources/endtoend (minus .xml).
> +   * @param testMethod name of the javascript method to execute
> +   * @return the parsed HTML page
> +   */
> +  private HtmlPage executePageTest(String testName, String testMethod)
> +      throws IOException {
> +    String gadgetUrl = EndToEndServer.SERVER_URL + "/" + testName +
> ".xml";
> +    String url = EndToEndServer.GADGET_BASEURL + "?url=" +
> URLEncoder.encode(gadgetUrl, "UTF-8");
> +    BasicSecurityTokenDecoder decoder = new BasicSecurityTokenDecoder();
> +    url += "&st=" + URLEncoder.encode(decoder.encodeToken(token),
> "UTF-8");
> +    url += "&testMethod=" + URLEncoder.encode(testMethod, "UTF-8");
> +    return (HtmlPage) webClient.getPage(url);
> +  }
> +
> +  /**
> +   * Executes all page test in a single XML file.
> +   * @param testName name of the test, which must match a gadget XML file
> +   *     name in test/resources/endtoend (minus .xml).
> +   * @throws IOException
> +   */
> +  private void executeAllPageTests(String testName) throws IOException {
> +    executePageTest(testName, "all");
> +  }
> +
> +  private BasicSecurityToken createToken(String owner, String viewer)
> +      throws BlobCrypterException {
> +    return new BasicSecurityToken(owner, viewer, "test", "domain",
> "appUrl", "1");
> +  }
> +}
>
> Added:
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/errorTest.xml
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/errorTest.xml?rev=679724&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/errorTest.xml
> (added)
> +++
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/errorTest.xml
> Fri Jul 25 02:24:22 2008
> @@ -0,0 +1,71 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<!--
> +  Licensed to the Apache Software Foundation (ASF) under one
> +  or more contributor license agreements.  See the NOTICE file
> +  distributed with this work for additional information
> +  regarding copyright ownership.  The ASF licenses this file
> +  to you 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.
> +-->
> +<Module>
> +  <ModulePrefs title="EndToEndTest">
> +    <Require feature="opensocial-0.8" />
> +    <Require feature="views" />
> +  </ModulePrefs>
> +  <Content type="html">
> +    <![CDATA[
> +      <script type="text/javascript" src="testframework.js"></script>
> +      <script type="text/javascript">
> +
> +        var tests = {
> +          /** Test 404 */
> +          notFoundError: function() {
> +            errorTestCase(404, opensocial.ResponseItem.Error.BAD_REQUEST);
> +          },
> +
> +          /** Test 400 */
> +          badRequestError: function() {
> +            errorTestCase(400, opensocial.ResponseItem.Error.BAD_REQUEST);
> +          },
> +
> +          /** Test 500 */
> +          internalError: function() {
> +            errorTestCase(500,
> opensocial.ResponseItem.Error.INTERNAL_ERROR);
> +          }
> +        };
> +
> +
> +        /** Test a single error code case */
> +        function errorTestCase(httpCode, errorCode) {
> +          var req = opensocial.newDataRequest();
> +
> +          // Request the "canonical" viewer
> +          req.add(req.newFetchPersonRequest("canonical"), "canonical");
> +
> +          function receivedData(response) {
> +            assertTrue("Expecting error", response.hadError());
> +            var dataItem = response.get("canonical");
> +            assertFalse("Expecting data item", dataItem == undefined);
> +            assertTrue("Expecting item error", dataItem.hadError());
> +            assertEquals("Mismatched error code", errorCode,
> dataItem.getErrorCode());
> +
> +            finished();
> +          }
> +
> +          // Send the request
> +          req.send(receivedData);
> +        }
> +      </script>
> +    ]]>
> +  </Content>
> +</Module>
>
> Added:
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPeopleTest.xml
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPeopleTest.xml?rev=679724&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPeopleTest.xml
> (added)
> +++
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPeopleTest.xml
> Fri Jul 25 02:24:22 2008
> @@ -0,0 +1,78 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<!--
> +  Licensed to the Apache Software Foundation (ASF) under one
> +  or more contributor license agreements.  See the NOTICE file
> +  distributed with this work for additional information
> +  regarding copyright ownership.  The ASF licenses this file
> +  to you 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.
> +-->
> +<Module>
> +  <ModulePrefs title="EndToEndTest">
> +    <Require feature="opensocial-0.8" />
> +    <Require feature="views" />
> +  </ModulePrefs>
> +  <Content type="html">
> +    <![CDATA[
> +      <script type="text/javascript" src="testframework.js"></script>
> +      <script type="text/javascript">
> +
> +        var tests = {
> +          /** Test fetching the owner's friends, which should be
> 'canonical' */
> +          fetchOwnerFriends: function() {
> +            var req = opensocial.newDataRequest();
> +
> +            var idSpec = opensocial.newIdSpec({userId :
> opensocial.IdSpec.PersonId.OWNER,
> +                groupId : 'FRIENDS'})
> +            req.add(req.newFetchPeopleRequest(idSpec), 'ownerFriends');
> +            function receivedData(response) {
> +              var ownerFriends = getAndCheckError(response,
> 'ownerFriends');
> +              assertEquals('Wrong friend count', 4, ownerFriends.size());
> +
> +              var johnDoe = ownerFriends.getById('john.doe');
> +              assertEquals('Wrong name for john doe', 'John Doe',
> johnDoe.getDisplayName());
> +              finished();
> +            }
> +
> +            // Send the request
> +            req.send(receivedData);
> +          },
> +
> +          /** Test fetching 'maija.m' friends, of which there are none */
> +          fetchEmptyFriendsById: function() {
> +            var req = opensocial.newDataRequest();
> +
> +            var idSpec = opensocial.newIdSpec({userId : 'maija.m', groupId
> : 'FRIENDS'})
> +            req.add(req.newFetchPeopleRequest(idSpec), 'idFriends');
> +            function receivedData(response) {
> +              var ownerFriends = getAndCheckError(response, 'idFriends');
> +              assertEquals('Wrong friend count', 0, ownerFriends.size());
> +              finished();
> +            }
> +
> +            // Send the request
> +            req.send(receivedData);
> +          }
> +        };
> +
> +
> +        function getAndCheckError(response, key) {
> +          assertFalse('Data error', response.hadError());
> +          var dataItem = response.get(key);
> +          assertFalse('Data item error for ' + key, dataItem.hadError());
> +          return dataItem.getData();
> +        }
> +      </script>
> +    ]]>
> +  </Content>
> +</Module>
>
> Modified:
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPersonTest.xml
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPersonTest.xml?rev=679724&r1=679723&r2=679724&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPersonTest.xml
> (original)
> +++
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/fetchPersonTest.xml
> Fri Jul 25 02:24:22 2008
> @@ -26,61 +26,86 @@
>     <![CDATA[
>       <script type="text/javascript" src="testframework.js"></script>
>       <script type="text/javascript">
> +        var tests = {
> +          /** Test fetching a specific ID */
> +          fetchId: function() {
> +            var req = opensocial.newDataRequest();
> +
> +            // Request the "canonical" viewer
> +            req.add(req.newFetchPersonRequest("canonical"), "canonical");
> +
> +            function receivedData(response) {
> +              var user = getAndCheckError(response, "canonical");
> +              assertEquals("Names don't match",
> +                "Sir Shin H. Digg Social Butterfly",
> user.getDisplayName());
> +              finished();
> +            }
> +
> +            // Send the request
> +            req.send(receivedData);
> +          },
> +
> +          /** Test fetching the owner, which should be "canonical" */
> +          fetchOwner: function() {
> +            var req = opensocial.newDataRequest();
> +
> +            // Request the "canonical" viewer
> +
>  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER),
> "owner");
> +
> +            function receivedData(response) {
> +              var user = getAndCheckError(response, "owner");
> +              assertEquals("Names don't match",
> +                "Sir Shin H. Digg Social Butterfly",
> user.getDisplayName());
> +              finished();
> +            }
> +
> +            // Send the request
> +            req.send(receivedData);
> +          },
> +
> +          /** Test fetching the viewer, which should be "john.doe" */
> +          fetchViewer: function() {
> +            var req = opensocial.newDataRequest();
> +
> +            // Request the "canonical" viewer
> +
>  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER),
> "viewer");
> +
> +            function receivedData(response) {
> +              var user = getAndCheckError(response, "viewer");
> +              assertEquals("Names don't match",
> +                "John Doe", user.getDisplayName());
> +
> +              finished();
> +            }
> +
> +            // Send the request
> +            req.send(receivedData);
> +          },
> +
> +          /** Test fetching the owner and viewer as a batch */
> +          fetchOwnerAndViewer: function() {
> +            var req = opensocial.newDataRequest();
> +
> +            // Request the "canonical" viewer
> +
>  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER),
> "owner");
> +
>  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER),
> "viewer");
> +
> +            function receivedData(response) {
> +              var user = getAndCheckError(response, "owner");
> +              assertEquals("Names don't match",
> +                "Sir Shin H. Digg Social Butterfly",
> user.getDisplayName());
> +
> +              user = getAndCheckError(response, "viewer");
> +              assertEquals("Names don't match",
> +                "John Doe", user.getDisplayName());
> +              finished();
> +            }
>
> -        /** Test fetching a specific ID */
> -        function fetchId() {
> -          var req = opensocial.newDataRequest();
> -
> -          // Request the "canonical" viewer
> -          req.add(req.newFetchPersonRequest("canonical"), "canonical");
> -
> -          function receivedData(response) {
> -            var user = getAndCheckError(response, "canonical");
> -            assertEquals("Names don't match",
> -              "Sir Shin H. Digg Social Butterfly", user.getDisplayName());
> -            testFinished();
> +            // Send the request
> +            req.send(receivedData);
>           }
> -
> -          // Send the request
> -          req.send(receivedData);
> -        }
> -
> -        /** Test fetching the owner, which should be "canonical" */
> -        function fetchOwner() {
> -          var req = opensocial.newDataRequest();
> -
> -          // Request the "canonical" viewer
> -
>  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER),
> "owner");
> -
> -          function receivedData(response) {
> -            var user = getAndCheckError(response, "owner");
> -            assertEquals("Names don't match",
> -              "Sir Shin H. Digg Social Butterfly", user.getDisplayName());
> -            testFinished();
> -          }
> -
> -          // Send the request
> -          req.send(receivedData);
> -        }
> -
> -        /** Test fetching the viewer, which should be "john.doe" */
> -        function fetchViewer() {
> -          var req = opensocial.newDataRequest();
> -
> -          // Request the "canonical" viewer
> -
>  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER),
> "viewer");
> -
> -          function receivedData(response) {
> -            var user = getAndCheckError(response, "viewer");
> -            assertEquals("Names don't match",
> -              "John Doe", user.getDisplayName());
> -
> -            testFinished();
> -          }
> -
> -          // Send the request
> -          req.send(receivedData);
> -        }
> +        };
> +
>
>         function getAndCheckError(response, key) {
>           assertFalse("Data error", response.hadError());
>
> Modified:
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/testframework.js
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/testframework.js?rev=679724&r1=679723&r2=679724&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/testframework.js
> (original)
> +++
> incubator/shindig/trunk/java/server/src/test/resources/endtoend/testframework.js
> Fri Jul 25 02:24:22 2008
> @@ -17,6 +17,8 @@
>  * under the License.
>  */
>
> +var tests;
> +
>  function assertTrue(msg, value) {
>   if (!value) {
>     throw "assertTrue() failed: " + msg;
> @@ -37,11 +39,11 @@
>  }
>
>  /**
> - * Signals the server code that the test successfully finished.  This
> - * method must be called to verify that the test completed successfully,
> + * Signals the server code that a test successfully finished.  This
> + * method must be called to verify that a test completed successfully,
>  * instead of simply failing to load.
>  */
> -function testFinished() {
> +function finished() {
>   alert("FINISHED");
>  }
>
> @@ -53,13 +55,28 @@
>     throw "No testMethod parameter found.";
>   }
>
> -  var testMethodFunction = window[testMethod];
> -  if (!testMethodFunction) {
> -    throw "Test method " + testMethod + " not found.";
> +  // "all": run all the tests
> +  if ("all" == testMethod) {
> +    allTests();
> +  } else {
> +    // Show an alert for the test method name, identifying what test
> started.
> +    alert(testMethod);
> +
> +    var testMethodFunction = tests[testMethod];
> +    if (!testMethodFunction) {
> +      throw "Test method " + testMethod + " not found.";
> +    }
> +
> +    // Execute the test method
> +    testMethodFunction();
>   }
> +}
>
> -  // Execute the test method
> -  testMethodFunction();
> +function allTests() {
> +  for (var testMethod in tests) {
> +    alert(testMethod);
> +    tests[testMethod]();
> +  }
>  }
>
>  gadgets.util.registerOnLoadHandler(executeTest);
>
>
>

Reply via email to