You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2014/02/19 11:49:02 UTC

svn commit: r1569676 [1/3] - /wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/

Author: scottbw
Date: Wed Feb 19 10:49:01 2014
New Revision: 1569676

URL: http://svn.apache.org/r1569676
Log:
Updated tests to use Request test framework class, and use signed API method calls

Modified:
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/FolderLocalizationTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ParticipantsControllerTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/PoliciesControllerTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/PropertiesControllerTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ProxyTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/UpdatesControllerTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java
    wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/WidgetsControllerTest.java

Modified: wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java?rev=1569676&r1=1569675&r2=1569676&view=diff
==============================================================================
--- wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java (original)
+++ wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java Wed Feb 19 10:49:01 2014
@@ -26,10 +26,10 @@ import java.util.Map;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.DeleteMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.wookie.tests.helpers.Request;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
@@ -43,409 +43,369 @@ import org.mortbay.util.ajax.JSON;
  */
 public class ApiKeyControllerTest extends AbstractControllerTest {
 
-  private static final String APIKEY_SERVICE_LOCATION_VALID = TEST_SERVER_LOCATION  + "keys";
+	private static final String APIKEY_SERVICE_LOCATION_VALID = TEST_SERVER_LOCATION  + "keys";
 
-  /**
-   * Attempt to get the list of API keys without having authenticated first
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void getEntriesUnauthorized() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    client.executeMethod(get);
-    int code = get.getStatusCode();
-    assertEquals(401, code);
-  }
-
-  /**
-   * Get the set of API keys using default admin credentials
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void getKeys() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    int code = get.getStatusCode();
-    assertEquals(200, code);
-  }
-  
-  /**
-   * Get the set of API keys in JSON using default admin credentials
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @SuppressWarnings("unchecked")
-  @Test
-  public void getKeysJson() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    //
-    // Set the accepts header to JSON
-    //
-    get.addRequestHeader("Accept", "application/json");
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    int code = get.getStatusCode();
-    assertEquals(200, code);
-    
-    //
-    // Parse the response and check the values
-    //
-    Object[] keys = (Object[]) JSON.parse(get.getResponseBodyAsStream());
-    assertEquals("TEST", ((Map<String, String>)keys[0]).get("id"));
-    assertEquals("TEST", ((Map<String, String>)keys[0]).get("value"));
-    
-    //
-    // Try again using ?format param overriding the accepts header
-    //
-    get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID+"?format=json");
-    get.addRequestHeader("Accept", "text/xml");
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    
-    //
-    // Parse the response and check the values
-    //
-    keys = (Object[]) JSON.parse(get.getResponseBodyAsStream());
-    assertEquals("TEST", ((Map<String, String>)keys[0]).get("id"));
-    assertEquals("TEST", ((Map<String, String>)keys[0]).get("value"));
-  }
-
-  /**
-   * Add a new key
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void addKey() throws HttpException, IOException {
-    
-    //
-    // POST a new API key
-    //
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    post.setParameter("apikey", "TEST_KEY");
-    post.setParameter("email", "test@incubator.apache.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(201, code);
-    
-    //
-    // Test that the set of API keys includes the one we just POSTed
-    //
-    client = new HttpClient();
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    assertTrue(get.getResponseBodyAsString().contains("TEST_KEY"));
-    
-    //
-    // Remove the key
-    // 
-    client = new HttpClient();
-    DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID + "/"  + "TEST_KEY");
-    setAuthenticationCredentials(client);
-    client.executeMethod(del);
-  }
-
-  /**
-   * Remove a key
-   * 
-   * @throws IOException
-   * @throws JDOMException
-   */
-  @Test
-  public void removeKey() throws JDOMException, IOException {
-    String id = null;
-    HttpClient client = new HttpClient();
-
-    //
-    // Create a new API key
-    //
-    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    post.setParameter("apikey", "TEST_KEY_TO_REMOVE");
-    post.setParameter("email", "test@incubator.apache.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(201, code);
-    
-    
- 
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    assertTrue(get.getResponseBodyAsString().contains("TEST_KEY_TO_REMOVE"));
-
-    //
-    // Get the ID of the key we created
-    //
-    Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
-    for (Object key : doc.getRootElement().getChildren()) {
-      Element keyElement = (Element) key;
-      if (keyElement.getAttributeValue("value").equals("TEST_KEY_TO_REMOVE")) {
-        id = keyElement.getAttributeValue("id");
-      }
-    }
-
-    //
-    // Delete the API key
-    //
-    client = new HttpClient();
-    DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID + "/"  + id);
-    setAuthenticationCredentials(client);
-    client.executeMethod(del);
-    code = del.getStatusCode();
-    assertEquals(200, code);
-
-    //
-    // Check that the key was deleted
-    //
-    client = new HttpClient();
-    get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    get.setRequestHeader("Content-type", "application/json");
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    System.out.println(get.getResponseBodyAsString());
-    assertFalse(get.getResponseBodyAsString().contains("TEST_KEY_TO_REMOVE"));
-
-  }
-
-  /**
-   * Try to remove a non-existant API key
-   * 
-   * @throws HttpException
-   * @throws IOException
-   */
-  @Test
-  public void removeNonExistantEntry() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID
-        + "/99999999");
-    setAuthenticationCredentials(client);
-    client.executeMethod(del);
-    int code = del.getStatusCode();
-    assertEquals(404, code);
-  }
-
-  /**
-   * Create an API key with missing parameters
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void addEntryNoEmailOrValue() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(400, code);
-  }
-
-  /**
-   * Try to create a new API key that duplicates an existing one
-   * 
-   * @throws IOException
-   * @throws HttpException
-   * @throws JDOMException 
-   */
-  @Test
-  public void addDuplicateEntry() throws HttpException, IOException, JDOMException {
-    //
-    // Create an API key
-    //
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    post.setParameter("apikey", "DUPLICATION_TEST");
-    post.setParameter("email", "test@127.0.0.1");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(201, code);
-    
-    //
-    // Replay the POST
-    //
-    client.executeMethod(post);
-    code = post.getStatusCode();
-    assertEquals(409, code);
-    
-    String id = null;
-
-    //
-    // Clean up
-    //
-    client = new HttpClient();
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    assertTrue(get.getResponseBodyAsString().contains("DUPLICATION_TEST"));
-
-    //
-    // Get the ID of the key we created
-    //
-    Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
-    for (Object key : doc.getRootElement().getChildren()) {
-      Element keyElement = (Element) key;
-      if (keyElement.getAttributeValue("value").equals("DUPLICATION_TEST")) {
-        id = keyElement.getAttributeValue("id");
-      }
-    }
-
-    //
-    // Delete the API key
-    //
-    client = new HttpClient();
-    DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID + "/"  + id);
-    setAuthenticationCredentials(client);
-    client.executeMethod(del);
-    code = del.getStatusCode();
-    assertEquals(200, code);
-
-    //
-    // Check that the key was deleted
-    //
-    client = new HttpClient();
-    get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    get.setRequestHeader("Content-type", "application/json");
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    System.out.println(get.getResponseBodyAsString());
-    assertFalse(get.getResponseBodyAsString().contains("DUPLICATION_TEST"));
-  }
-
-  /**
-   * Complex test for migrating an API key. This test is disabled as there are
-   * issues implementing this functionality - for now, migration has been
-   * disabled in the REST API.
-   * 
-   * @throws IOException
-   * @throws HttpException
-   * @throws JDOMException
-   */
-  @Test
-  @Ignore
-  public void migrateAPIKey() throws HttpException, IOException, JDOMException {
-
-    String keyId = null;
-    
-    //
-    // Create a new key
-    //
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    post.setParameter("apikey", "MIGRATION_TEST_KEY_1");
-    post.setParameter("email", "test@incubator.apache.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(201, code);
-    
-    //
-    // Get the ID
-    //
-    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-    setAuthenticationCredentials(client);
-    client.executeMethod(get);
-    Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
-    for (Object key : doc.getRootElement().getChildren()) {
-      Element keyElement = (Element) key;
-      if (keyElement.getAttributeValue("value").equals("MIGRATION_TEST_KEY_1")) {
-        keyId = keyElement.getAttributeValue("id");
-      }
-    }
-
-    //
-    // Create a widget instance
-    //
-    String instance_id_key = null;
-    client = new HttpClient();
-    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
-    client.executeMethod(post);
-    code = post.getStatusCode();
-    String response = post.getResponseBodyAsString();
-    instance_id_key = post.getResponseBodyAsString().substring(
-        response.indexOf("<identifier>") + 12,
-        response.indexOf("</identifier>"));
-    assertEquals(201, code);
-    post.releaseConnection();
-
-    //
-    // Set participant
-    //
-    client = new HttpClient();
-    post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=migration_test&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
-    client.executeMethod(post);
-    code = post.getStatusCode();
-    assertEquals(201, code);
-    post.releaseConnection();
-
-    //
-    // Migrate key
-    //
-    client = new HttpClient();
-    PutMethod put = new PutMethod(APIKEY_SERVICE_LOCATION_VALID + "/" + keyId);
-    put.setQueryString("apikey=MIGRATION_TEST_KEY_2&email=test@127.0.0.1");
-    setAuthenticationCredentials(client);
-    client.executeMethod(put);
-    code = put.getStatusCode();
-    assertEquals(200, code);
-    put.releaseConnection();
-
-    //
-    // Get instance again using the new key - should be 200 not 201
-    //
-    client = new HttpClient();
-    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=MIGRATION_TEST_KEY_2&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
-    client.executeMethod(post);
-    code = post.getStatusCode();
-    assertEquals(200, code);
-    post.releaseConnection();
-
-    //
-    // Get participant
-    //
-    client = new HttpClient();
-    get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    get.setQueryString("api_key=MIGRATION_TEST_KEY_2&id_key=" + instance_id_key);
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    response = get.getResponseBodyAsString();
-    assertTrue(response
-        .contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
-    get.releaseConnection();
+	/**
+	 * Attempt to get the list of API keys without having authenticated first
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void getEntriesUnauthorized() throws HttpException, IOException {
+		Request request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(false, false);
+		assertEquals(403, request.getStatusCode());
+	}
+
+	/**
+	 * Get the set of API keys using default admin credentials
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void getKeys() throws HttpException, IOException {
+		Request request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		assertEquals(200, request.getStatusCode());
+	}
+
+	/**
+	 * Get the set of API keys in JSON using default admin credentials
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@SuppressWarnings("unchecked")
+	@Test
+	public void getKeysJson() throws HttpException, IOException {
+
+		Request request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request.setAccepts("application/json");
+		request.execute(true, false);
+		assertEquals(200, request.getStatusCode());
+
+		String response = request.getResponseBodyAsString();
+		//
+		// Parse the response and check the values
+		//
+		Object[] keys = (Object[]) JSON.parse(response);
+		assertEquals("TEST", ((Map<String, String>)keys[0]).get("key"));
+
+		//
+		// Try again using ?format param overriding the accepts header
+		//
+		Request request2 = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request2.setAccepts("text/xml");
+		request2.addParameter("format", "json");
+		request2.execute(true, false);
+		assertEquals(200, request2.getStatusCode());
+
+		//
+		// Parse the response and check the values
+		//
+		keys = (Object[]) JSON.parse(request2.getResponseBodyAsString());
+		assertEquals("TEST", ((Map<String, String>)keys[0]).get("key"));
+	}
+
+	/**
+	 * Add a new key
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void addKey() throws HttpException, IOException {
+
+		//
+		// POST a new API key
+		//
+		Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
+		request.addParameter("apikey", "TEST_KEY");
+		request.addParameter("email", "test@incubator.apache.org");
+		request.execute(true, false);
+		int code = request.getStatusCode();
+		assertEquals(201, code);
+
+		//
+		// Test that the set of API keys includes the one we just POSTed
+		//
+		request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+		assertTrue(request.getResponseBodyAsString().contains("TEST_KEY"));
+
+		//
+		// Remove the key
+		// 
+		request = new Request("DELETE", APIKEY_SERVICE_LOCATION_VALID+"/"+"TEST_KEY");
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+	}
+
+	/**
+	 * Remove a key
+	 * 
+	 * @throws IOException
+	 * @throws JDOMException
+	 */
+	@Test
+	public void removeKey() throws JDOMException, IOException {
+		String id = null;
+
+		//
+		// Create a new API key
+		//
+		Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
+		request.addParameter("apikey", "TEST_KEY_TO_REMOVE");
+		request.addParameter("email", "test@incubator.apache.org");
+		request.execute(true, false);
+		int code = request.getStatusCode();
+		assertEquals(201, code);
+
+		request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+		assertTrue(request.getResponseBodyAsString().contains("TEST_KEY_TO_REMOVE"));
+
+		//
+		// Get the ID of the key we created
+		//
+		Document doc = new SAXBuilder().build(request.getResponseBodyAsStream());
+		for (Object key : doc.getRootElement().getChildren()) {
+			Element keyElement = (Element) key;
+			if (keyElement.getText().equals("TEST_KEY_TO_REMOVE")) {
+				id = keyElement.getText();
+			}
+		}
+
+		//
+		// Delete the API key
+		//
+		request = new Request("DELETE", APIKEY_SERVICE_LOCATION_VALID+"/"+id);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+
+		//
+		// Check that the key was deleted
+		//
+		request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+		assertFalse(request.getResponseBodyAsString().contains("TEST_KEY_TO_REMOVE"));
+
+	}
+
+	/**
+	 * Try to remove a non-existant API key
+	 * 
+	 * @throws HttpException
+	 * @throws IOException
+	 */
+	@Test
+	public void removeNonExistantEntry() throws HttpException, IOException {
+		Request request = new Request("DELETE", APIKEY_SERVICE_LOCATION_VALID+"/99999999");
+		request.execute(true, false);
+		int code = request.getStatusCode();
+		assertEquals(404, code);
+	}
+
+	/**
+	 * Create an API key with missing parameters
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void addEntryNoEmailOrValue() throws HttpException, IOException {  
+		Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		int code = request.getStatusCode();
+		assertEquals(400, code);
+	}
+
+	/**
+	 * Try to create a new API key that duplicates an existing one
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 * @throws JDOMException 
+	 */
+	@Test
+	public void addDuplicateEntry() throws HttpException, IOException, JDOMException {
+
+		//
+		// Create an API key
+		//
+		Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
+		request.addParameter("apikey", "DUPLICATION_TEST");
+		request.addParameter("email", "test@127.0.0.1");
+		request.execute(true, false);
+		int code = request.getStatusCode();
+		assertEquals(201, code);
+
+		//
+		// Replay the POST
+		//
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(409, code);
+
+		String id = null;
+
+		//
+		// Clean up
+		//
+
+		request = new Request("GET",APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+		assertTrue(request.getResponseBodyAsString().contains("DUPLICATION_TEST"));
+
+		//
+		// Get the ID of the key we created
+		//
+		Document doc = new SAXBuilder().build(request.getResponseBodyAsStream());
+		for (Object key : doc.getRootElement().getChildren()) {
+			Element keyElement = (Element) key;
+			if (keyElement.getText().equals("DUPLICATION_TEST")) {
+				id = keyElement.getText();
+			}
+		}
+
+		//
+		// Delete the API key
+		//
+		request = new Request("DELETE",APIKEY_SERVICE_LOCATION_VALID+"/"+id);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);    
+
+		//
+		// Check that the key was deleted
+		//
+		request = new Request("GET",APIKEY_SERVICE_LOCATION_VALID);
+		request.execute(true, false);
+		code = request.getStatusCode();
+		assertEquals(200, code);
+		assertFalse(request.getResponseBodyAsString().contains("DUPLICATION_TEST"));
+	}
+
+	/**
+	 * Complex test for migrating an API key. This test is disabled as there are
+	 * issues implementing this functionality - for now, migration has been
+	 * disabled in the REST API.
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 * @throws JDOMException
+	 */
+	@Test
+	@Ignore
+	public void migrateAPIKey() throws HttpException, IOException, JDOMException {
+
+		String keyId = null;
+
+		//
+		// Create a new key
+		//
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
+		setAuthenticationCredentials(client);
+		post.setParameter("apikey", "MIGRATION_TEST_KEY_1");
+		post.setParameter("email", "test@incubator.apache.org");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(201, code);
+
+		//
+		// Get the ID
+		//
+		GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+		setAuthenticationCredentials(client);
+		client.executeMethod(get);
+		Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
+		for (Object key : doc.getRootElement().getChildren()) {
+			Element keyElement = (Element) key;
+			if (keyElement.getAttributeValue("value").equals("MIGRATION_TEST_KEY_1")) {
+				keyId = keyElement.getAttributeValue("id");
+			}
+		}
+
+		//
+		// Create a widget instance
+		//
+		String instance_id_key = null;
+		client = new HttpClient();
+		post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+		post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
+		client.executeMethod(post);
+		code = post.getStatusCode();
+		String response = post.getResponseBodyAsString();
+		instance_id_key = post.getResponseBodyAsString().substring(
+				response.indexOf("<identifier>") + 12,
+				response.indexOf("</identifier>"));
+		assertEquals(201, code);
+		post.releaseConnection();
+
+		//
+		// Set participant
+		//
+		client = new HttpClient();
+		post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=migration_test&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
+		client.executeMethod(post);
+		code = post.getStatusCode();
+		assertEquals(201, code);
+		post.releaseConnection();
+
+		//
+		// Migrate key
+		//
+		client = new HttpClient();
+		PutMethod put = new PutMethod(APIKEY_SERVICE_LOCATION_VALID + "/" + keyId);
+		put.setQueryString("apikey=MIGRATION_TEST_KEY_2&email=test@127.0.0.1");
+		setAuthenticationCredentials(client);
+		client.executeMethod(put);
+		code = put.getStatusCode();
+		assertEquals(200, code);
+		put.releaseConnection();
+
+		//
+		// Get instance again using the new key - should be 200 not 201
+		//
+		client = new HttpClient();
+		post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+		post.setQueryString("api_key=MIGRATION_TEST_KEY_2&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
+		client.executeMethod(post);
+		code = post.getStatusCode();
+		assertEquals(200, code);
+		post.releaseConnection();
+
+		//
+		// Get participant
+		//
+		client = new HttpClient();
+		get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		get.setQueryString("api_key=MIGRATION_TEST_KEY_2&id_key=" + instance_id_key);
+		client.executeMethod(get);
+		code = get.getStatusCode();
+		assertEquals(200, code);
+		response = get.getResponseBodyAsString();
+		assertTrue(response
+				.contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
+		get.releaseConnection();
 
-  }
+	}
 }

Modified: wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/FolderLocalizationTest.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/FolderLocalizationTest.java?rev=1569676&r1=1569675&r2=1569676&view=diff
==============================================================================
--- wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/FolderLocalizationTest.java (original)
+++ wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/FolderLocalizationTest.java Wed Feb 19 10:49:01 2014
@@ -23,14 +23,12 @@ import java.io.StringReader;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.DeleteMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.multipart.FilePart;
 import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
 import org.apache.commons.httpclient.methods.multipart.Part;
 import org.apache.commons.lang.StringUtils;
+import org.apache.wookie.tests.helpers.Request;
 import org.jdom.Document;
 import org.jdom.input.SAXBuilder;
 import org.junit.AfterClass;
@@ -42,301 +40,284 @@ import org.junit.Test;
  */
 public class FolderLocalizationTest extends AbstractControllerTest {
 
-  private static String WIDGET_START_URL_ROOT;
+	private static String WIDGET_START_URL_ROOT;
 
-  private static HttpClient client;
-  private static GetMethod get;
+	private static HttpClient client;
+	private static GetMethod get;
 
-  /**
-   * Setup a widget instance to test with, and create a shared HTTP client with
-   * cookies enabled.
-   * 
-   * @throws HttpException
-   * @throws IOException
-   */
-  @BeforeClass
-  public static void setup() throws HttpException, IOException {
-    client = new HttpClient();
-    
-    //
-    // Use admin credentials
-    //
-    setAuthenticationCredentials(client);
-    
-    //
-    // Setup POST method
-    //
-    PostMethod post = new PostMethod(TEST_WIDGETS_SERVICE_URL_VALID);
-    
-    //
-    // Get the locale test widget
-    //
-    File file = new File("src/test/resources/localetest.wgt");
-    assertTrue(file.exists());
-    
-    //
-    // Add test wgt file to POST
-    //
-    Part[] parts = { new FilePart(file.getName(), file) };
-    post.setRequestEntity(new MultipartRequestEntity(parts, post
-        .getParams()));
-    
-    //
-    // POST the file to /widgets and check we get 201 (Created)
-    //
-    client.executeMethod(post);   
-    int code = post.getStatusCode();
-    assertEquals(201,code);
-    post.releaseConnection(); 
-    
-    //
-    // Set up the client and enable cookies
-    //
-    client = new HttpClient();
-    client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
-    get = new GetMethod();
-
-    //
-    // Create a widget instance localized to Yorkshire English
-    //
-    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_LOCALIZED
-        + "&userid=foldertest1&shareddatakey=foldertest1&locale=en-gb-yorks");
-    client.executeMethod(post);
-
-    //
-    // Get the root URL
-    //
-    WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
-
-    //
-    // We have to load the start file in order to start the session
-    //
-    getResource(WIDGET_START_URL_ROOT);
-
-    //
-    // take off the resource bit
-    //
-    WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
-    
-    post.releaseConnection();
-  }
-  
-  @AfterClass
-  public static void tearDown() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    DeleteMethod delete = new DeleteMethod(TEST_WIDGETS_SERVICE_URL_VALID + "/" + WIDGET_ID_LOCALIZED);
-    client.executeMethod(delete);
-    delete.releaseConnection();
-  }  
-
-  /**
-   * Gets the start file url for an instance
-   * 
-   * @param response
-   * @return
-   */
-  private static String getStartFile(String response) {
-    SAXBuilder builder = new SAXBuilder();
-    Reader in = new StringReader(response);
-    Document doc;
-    try {
-      doc = builder.build(in);
-    } catch (Exception e) {
-      return null;
-    }
-    return doc.getRootElement().getChild("url").getText();
-  }
-
-  /**
-   * Gets a resource and returns the final URL after redirection
-   * 
-   * @param url
-   * @return
-   */
-  private static String getResource(String url) {
-    get = new GetMethod(url);
-    get.setFollowRedirects(true);
-    try {
-      client.executeMethod(get);
-      return TEST_SERVER_ORIGIN + get.getPath();
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-    return null;
-  }
-
-  /**
-   * Test that the root resource is overridden by the EN-GB-YORKS localized
-   * resource
-   */
-  @Test
-  public void getLocalizedResourceFromRootPath() {
-    String resource = "index.htm";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "locales/en-gb-yorks/" + resource,
-        getResource(url));
-  }
-
-  /**
-   * The root resource is correct, so should not be redirected
-   */
-  @Test
-  public void getRootResourceFromRootResource() {
-    String resource = "Images/test.png";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + resource, getResource(url));
-  }
-
-  /**
-   * The FR resource is replaced by the Root resource as there is no EN resource
-   */
-  @Test
-  public void getRootResourceFromIncorrectLocalizedPath() {
-    String resource = "locales/fr/Images/test.png";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "Images/test.png", getResource(url));
-  }
-
-  /**
-   * The EN resource is replaced by the Root resource as there is no EN resource
-   */
-  @Test
-  public void getRootResourceFromLocalizedPath() {
-    String resource = "locales/en/Images/test.png";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "Images/test.png", getResource(url));
-  }
-
-  /**
-   * The FR resource is replaced by the EN-GB-YORKS resource
-   */
-  @Test
-  public void getLocalizedResourceFromIncorrectLocalizedPath() {
-    String resource = "locales/fr/index.htm";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "locales/en-gb-yorks/index.htm",
-        getResource(url));
-  }
-
-  /**
-   * The EN-GB-YORKS resource is not available and is replaced by the EN
-   * resource
-   */
-  @Test
-  public void getLocalizedResourceGracefulDegradation() {
-    String resource = "locales/en-gb-yorks/test.txt";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "locales/en/test.txt",
-        getResource(url));
-  }
-
-  /**
-   * Request the instance with different locales, and check that the correct
-   * resources are returned in each case (i.e. that the locale of the instance
-   * has changed)
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void updateLocalizedResources() throws HttpException, IOException {
-    //
-    // Update the widget instance localized to French
-    //
-    PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_LOCALIZED
-        + "&userid=foldertest1&shareddatakey=foldertest1&locale=fr");
-    client.executeMethod(post);
-
-    WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
-    
-    //
-    // We have to load the start file in order to start the session
-    //
-    getResource(WIDGET_START_URL_ROOT);
-
-    //
-    // take off the resource bit
-    //
-    WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
-    
-    post.releaseConnection();
-
-    String resource = "index.htm";
-    String url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "locales/fr/index.htm",getResource(url));
-
-    //
-    // Update the widget instance localized to English
-    //
-
-    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_LOCALIZED
-        + "&userid=foldertest1&shareddatakey=foldertest1&locale=en");
-    client.executeMethod(post);
-
-    WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
-    
-    //
-    // We have to load the start file in order to start the session
-    //
-    getResource(WIDGET_START_URL_ROOT);
-    
-    //
-    // take off the resource bit
-    //
-    WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
-    
-    post.releaseConnection();
-
-    resource = "index.htm";
-    url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "locales/en/index.htm",
-        getResource(url));
-
-    //
-    // Update the widget instance unlocalized (expecting the default locale here
-    // to be "en")
-    //
-    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_LOCALIZED + "&userid=foldertest1&shareddatakey=foldertest1");
-    client.executeMethod(post);
-
-    WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
-    
-    //
-    // We have to load the start file in order to start the session
-    //
-    getResource(WIDGET_START_URL_ROOT);
-    
-    //
-    // take off the resource bit
-    //
-    WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
-   
-    post.releaseConnection();
-
-    resource = "index.htm";
-    url = WIDGET_START_URL_ROOT + resource;
-    assertEquals(WIDGET_START_URL_ROOT + "locales/en/index.htm",
-        getResource(url));
-  }
-  
-  /**
-   * Removes the resource path and query components of a given URL
-   * @param url
-   * @return the "root" url
-   */
-  private static String getRootUrl(String url){
-    String path = url.substring(url.indexOf("locales"));
-    url = StringUtils.remove(url, path);
-    return url;
-  }
+	/**
+	 * Setup a widget instance to test with, and create a shared HTTP client with
+	 * cookies enabled.
+	 * 
+	 * @throws HttpException
+	 * @throws IOException
+	 */
+	@BeforeClass
+	public static void setup() throws HttpException, IOException {    
+		//
+		// Setup POST method
+		//
+		Request post = new Request("POST", TEST_WIDGETS_SERVICE_URL_VALID);
+
+		//
+		// Get the locale test widget
+		//
+		File file = new File("src/test/resources/localetest.wgt");
+		assertTrue(file.exists());
+
+		//
+		// Add test wgt file to POST
+		//
+		Part[] parts = { new FilePart(file.getName(), file) };
+		post.setRequestEntity(new MultipartRequestEntity(parts, post.getClient().getParams()));
+
+		//
+		// POST the file to /widgets and check we get 201 (Created)
+		//
+		post.execute(true, false);  
+		int code = post.getStatusCode();
+		assertEquals(201,code);
+		client = post.getClient();
+
+		//
+		// Create a widget instance localized to Yorkshire English
+		//
+		post = new Request("POST", TEST_INSTANCES_SERVICE_URL_VALID, client);
+		post.addParameter("api_key", API_KEY_VALID);
+		post.addParameter("widgetid", WIDGET_ID_LOCALIZED);
+		post.addParameter("userid", "foldertest1");
+		post.addParameter("shareddatakey", "foldertest1");
+		post.addParameter("locale", "en-gb-yorks");
+
+		post.execute(true, false);
+
+		//
+		// Get the root URL
+		//
+		WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
+
+		//
+		// We have to load the start file in order to start the session
+		//
+		getResource(WIDGET_START_URL_ROOT);
+
+		//
+		// take off the resource bit
+		//
+		WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
+
+	}
+
+	@AfterClass
+	public static void tearDown() throws HttpException, IOException{
+		Request delete = new Request("DELETE", TEST_WIDGETS_SERVICE_URL_VALID + "/" + WIDGET_ID_LOCALIZED);
+		delete.execute(true, false);
+	}  
+
+	/**
+	 * Gets the start file url for an instance
+	 * 
+	 * @param response
+	 * @return
+	 */
+	private static String getStartFile(String response) {
+		SAXBuilder builder = new SAXBuilder();
+		Reader in = new StringReader(response);
+		Document doc;
+		try {
+			doc = builder.build(in);
+		} catch (Exception e) {
+			return null;
+		}
+		return doc.getRootElement().getChild("url").getText();
+	}
+
+	/**
+	 * Gets a resource and returns the final URL after redirection
+	 * 
+	 * @param url
+	 * @return
+	 */
+	private static String getResource(String url) {
+		get = new GetMethod(url);
+		get.setFollowRedirects(true);
+		try {
+			client.executeMethod(get);
+			return TEST_SERVER_ORIGIN + get.getPath();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * Test that the root resource is overridden by the EN-GB-YORKS localized
+	 * resource
+	 */
+	@Test
+	public void getLocalizedResourceFromRootPath() {
+		String resource = "index.htm";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "locales/en-gb-yorks/" + resource,
+				getResource(url));
+	}
+
+	/**
+	 * The root resource is correct, so should not be redirected
+	 */
+	@Test
+	public void getRootResourceFromRootResource() {
+		String resource = "Images/test.png";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + resource, getResource(url));
+	}
+
+	/**
+	 * The FR resource is replaced by the Root resource as there is no EN resource
+	 */
+	@Test
+	public void getRootResourceFromIncorrectLocalizedPath() {
+		String resource = "locales/fr/Images/test.png";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "Images/test.png", getResource(url));
+	}
+
+	/**
+	 * The EN resource is replaced by the Root resource as there is no EN resource
+	 */
+	@Test
+	public void getRootResourceFromLocalizedPath() {
+		String resource = "locales/en/Images/test.png";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "Images/test.png", getResource(url));
+	}
+
+	/**
+	 * The FR resource is replaced by the EN-GB-YORKS resource
+	 */
+	@Test
+	public void getLocalizedResourceFromIncorrectLocalizedPath() {
+		String resource = "locales/fr/index.htm";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "locales/en-gb-yorks/index.htm",
+				getResource(url));
+	}
+
+	/**
+	 * The EN-GB-YORKS resource is not available and is replaced by the EN
+	 * resource
+	 */
+	@Test
+	public void getLocalizedResourceGracefulDegradation() {
+		String resource = "locales/en-gb-yorks/test.txt";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "locales/en/test.txt",
+				getResource(url));
+	}
+
+	/**
+	 * Request the instance with different locales, and check that the correct
+	 * resources are returned in each case (i.e. that the locale of the instance
+	 * has changed)
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void updateLocalizedResources() throws HttpException, IOException {
+		//
+		// Update the widget instance localized to French
+		//
+		Request post = new Request("POST",TEST_INSTANCES_SERVICE_URL_VALID, client);
+		post.addParameter("api_key", API_KEY_VALID);
+		post.addParameter("widgetid", WIDGET_ID_LOCALIZED);
+		post.addParameter("userid", "foldertest1");
+		post.addParameter("shareddatakey", "foldertest1");
+		post.addParameter("locale", "fr");
+		post.execute(true, false);
+		WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
+		assertEquals(200, post.getStatusCode());
+		//
+		// We have to load the start file in order to start the session
+		//
+		getResource(WIDGET_START_URL_ROOT);
+
+		//
+		// take off the resource bit
+		//
+		WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
+
+		String resource = "index.htm";
+		String url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "locales/fr/index.htm",getResource(url));
+
+		//
+		// Update the widget instance localized to English
+		//
+		post = new Request("POST",TEST_INSTANCES_SERVICE_URL_VALID, client);
+		post.addParameter("api_key", API_KEY_VALID);
+		post.addParameter("widgetid", WIDGET_ID_LOCALIZED);
+		post.addParameter("userid", "foldertest1");
+		post.addParameter("shareddatakey", "foldertest1");
+		post.addParameter("locale", "en");
+		post.execute(true, false);
+
+		WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
+
+		//
+		// We have to load the start file in order to start the session
+		//
+		getResource(WIDGET_START_URL_ROOT);
+
+		//
+		// take off the resource bit
+		//
+		WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
+
+		resource = "index.htm";
+		url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "locales/en/index.htm",
+				getResource(url));
+
+		//
+		// Update the widget instance unlocalized (expecting the default locale here
+		// to be "en")
+		//
+		post = new Request("POST",TEST_INSTANCES_SERVICE_URL_VALID, client);
+		post.addParameter("api_key", API_KEY_VALID);
+		post.addParameter("widgetid", WIDGET_ID_LOCALIZED);
+		post.addParameter("userid", "foldertest1");
+		post.addParameter("shareddatakey", "foldertest1");
+		post.execute(true, false);
+		assertEquals(200, post.getStatusCode());
+
+		WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString());
+
+		//
+		// We have to load the start file in order to start the session
+		//
+		getResource(WIDGET_START_URL_ROOT);
+
+		//
+		// take off the resource bit
+		//
+		WIDGET_START_URL_ROOT = getRootUrl(WIDGET_START_URL_ROOT);
+
+		resource = "index.htm";
+		url = WIDGET_START_URL_ROOT + resource;
+		assertEquals(WIDGET_START_URL_ROOT + "locales/en/index.htm",
+				getResource(url));
+	}
+
+	/**
+	 * Removes the resource path and query components of a given URL
+	 * @param url
+	 * @return the "root" url
+	 */
+	private static String getRootUrl(String url){
+		String path = url.substring(url.indexOf("locales"));
+		url = StringUtils.remove(url, path);
+		return url;
+	}
 
 }

Modified: wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ParticipantsControllerTest.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ParticipantsControllerTest.java?rev=1569676&r1=1569675&r2=1569676&view=diff
==============================================================================
--- wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ParticipantsControllerTest.java (original)
+++ wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/ParticipantsControllerTest.java Wed Feb 19 10:49:01 2014
@@ -32,322 +32,322 @@ import org.junit.Test;
  */
 public class ParticipantsControllerTest extends AbstractControllerTest {
 
-  private static String instance_id_key;
+	private static String instance_id_key;
 
-  /**
-   * Create a widget instance to test
-   * 
-   * @throws Exception
-   */
-  @BeforeClass
-  public static void setUp() throws Exception {
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
-    client.executeMethod(post);
-    String response = post.getResponseBodyAsString();
-    instance_id_key = response.substring(response.indexOf("<identifier>") + 12,
-        response.indexOf("</identifier>"));
-    post.releaseConnection();
-  }
-  
-  @AfterClass
-  public static void tearDown() throws HttpException, IOException{
-	  HttpClient client = new HttpClient();
-	  DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-	  post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-			  + WIDGET_ID_VALID
-			  + "&userid=test&shareddatakey=participantstest&participant_id=80");
-	  client.executeMethod(post);
-	  int code = post.getStatusCode();
-	  assertEquals(200, code);
-	  post.releaseConnection();
-  }
-
-  /**
-   * Tests adding and then getting a participant
-   * 
-   * @throws HttpException
-   * @throws IOException
-   */
-  @Test
-  public void addParticipant() throws HttpException, IOException {
-
-    //
-    // Create a new participant
-    //
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key="
-        + API_KEY_VALID
-        + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(201, code);
-    post.releaseConnection();
-
-    //
-    // Now lets GET it to make sure it was added OK
-    //
-    client = new HttpClient();
-    GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    String response = get.getResponseBodyAsString();
-    assertTrue(response
-        .contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
-    get.releaseConnection();
-
-  }
-
-  /**
-   * Tests getting a participant using the widget instance ID key
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void getParticipant_usingIdKey() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    get.setQueryString("api_key=" + API_KEY_VALID + "&idkey="
-        + instance_id_key);
-    client.executeMethod(get);
-    int code = get.getStatusCode();
-    assertEquals(200, code);
-    String response = get.getResponseBodyAsString();
-    assertTrue(response
-        .contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
-    get.releaseConnection();
-  }
-
-  /**
-   * Tests trying to add a duplicate participant
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void addParticipant_AlreadyExists() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key="
-        + API_KEY_VALID
-        + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=1&participant_display_name=bob&participants_thumbnail_url=http://www.test.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(200, code);
-    post.releaseConnection();
-  }
-
-  /**
-   * Try to add a participant with an invalid API key
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void addParticipant_InvalidAPIkey() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(403, code);
-    post.releaseConnection();
-  }
-
-  /**
-   * Try to add a participant with no participant ID
-   * 
-   * @throws HttpException
-   * @throws IOException
-   */
-  @Test
-  public void addParticipant_InvalidParticipant() throws HttpException,
-      IOException {
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key="
-        + API_KEY_VALID
-        + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=&participant_display_name=bob&participants_thumbnail_url=http://www.test.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(400, code);
-    post.releaseConnection();
-  }
-
-  /**
-   * Try to add a participant using a non-existing widget
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void addParticipant_InvalidWidget() throws HttpException, IOException {
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key="
-        + API_KEY_VALID
-        + "&widgetid="
-        + WIDGET_ID_INVALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=1&participant_display_name=bob&participants_thumbnail_url=http://www.test.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(400, code);
-    post.releaseConnection();
-  }
-
-  /**
-   * Delete a participant and check it was deleted
-   * 
-   * @throws HttpException
-   * @throws IOException
-   */
-  @Test
-  public void deleteParticipant() throws HttpException, IOException {
-    //
-    // Delete the participant
-    //
-    HttpClient client = new HttpClient();
-    DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=1");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(200, code);
-    post.releaseConnection();
-
-    //
-    // Now lets GET it to make sure it was deleted
-    //
-
-    client = new HttpClient();
-    GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    String response = get.getResponseBodyAsString();
-    assertFalse(response
-        .contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
-    get.releaseConnection();
-
-  }
-
-  /**
-   * Try to delete a participant with an invalid API key
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void deleteParticipant_InvalidAPIKey() throws HttpException,
-      IOException {
-    HttpClient client = new HttpClient();
-    DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(403, code);
-    post.releaseConnection();
-  }
-
-  /**
-   * Try to delete a non-existing participant
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void deleteParticipant_InvalidParticipant() throws HttpException,
-      IOException {
-    HttpClient client = new HttpClient();
-    DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=99");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(404, code);
-    post.releaseConnection();
-  }
-
-  /**
-   * Try to delete a participant for a non-existing widget instance
-   * 
-   * @throws IOException
-   * @throws HttpException
-   */
-  @Test
-  public void deleteParticipant_InvalidInstance() throws HttpException,
-      IOException {
-    HttpClient client = new HttpClient();
-    DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key="
-        + API_KEY_VALID
-        + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstestinvalidkey&participant_id=1");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(400, code);
-    post.releaseConnection();
-  }
-  
-  /**
-   * Tests adding and then getting a participant who is also the Host
-   * 
-   * @throws HttpException
-   * @throws IOException
-   */
-  @Test
-  public void addHost() throws HttpException, IOException {
-
-    //
-    // Create a new participant
-    //
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    post.setQueryString("api_key="
-        + API_KEY_VALID
-        + "&widgetid="
-        + WIDGET_ID_VALID
-        + "&userid=test&shareddatakey=participantstest&participant_id=80&participant_display_name=bob&participant_role=host&participant_thumbnail_url=http://www.test.org");
-    client.executeMethod(post);
-    int code = post.getStatusCode();
-    assertEquals(201, code);
-    post.releaseConnection();
-
-    //
-    // Now lets GET it to make sure it was added OK
-    //
-    client = new HttpClient();
-    GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-    get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
-        + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
-    client.executeMethod(get);
-    code = get.getStatusCode();
-    assertEquals(200, code);
-    String response = get.getResponseBodyAsString();
-    assertTrue(response
-        .contains("<participant id=\"80\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" role=\"host\" />"));
-    get.releaseConnection();
+	/**
+	 * Create a widget instance to test
+	 * 
+	 * @throws Exception
+	 */
+	@BeforeClass
+	public static void setUp() throws Exception {
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+		post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+		client.executeMethod(post);
+		String response = post.getResponseBodyAsString();
+		instance_id_key = response.substring(response.indexOf("<identifier>") + 12,
+				response.indexOf("</identifier>"));
+		post.releaseConnection();
+	}
+
+	@AfterClass
+	public static void tearDown() throws HttpException, IOException{
+		HttpClient client = new HttpClient();
+		DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=80");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(200, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Tests adding and then getting a participant
+	 * 
+	 * @throws HttpException
+	 * @throws IOException
+	 */
+	@Test
+	public void addParticipant() throws HttpException, IOException {
+
+		//
+		// Create a new participant
+		//
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key="
+				+ API_KEY_VALID
+				+ "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(201, code);
+		post.releaseConnection();
+
+		//
+		// Now lets GET it to make sure it was added OK
+		//
+		client = new HttpClient();
+		GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+		client.executeMethod(get);
+		code = get.getStatusCode();
+		assertEquals(200, code);
+		String response = get.getResponseBodyAsString();
+		assertTrue(response
+				.contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
+		get.releaseConnection();
+
+	}
+
+	/**
+	 * Tests getting a participant using the widget instance ID key
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void getParticipant_usingIdKey() throws HttpException, IOException {
+		HttpClient client = new HttpClient();
+		GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		get.setQueryString("api_key=" + API_KEY_VALID + "&idkey="
+				+ instance_id_key);
+		client.executeMethod(get);
+		int code = get.getStatusCode();
+		assertEquals(200, code);
+		String response = get.getResponseBodyAsString();
+		assertTrue(response
+				.contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
+		get.releaseConnection();
+	}
+
+	/**
+	 * Tests trying to add a duplicate participant
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void addParticipant_AlreadyExists() throws HttpException, IOException {
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key="
+				+ API_KEY_VALID
+				+ "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=1&participant_display_name=bob&participants_thumbnail_url=http://www.test.org");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(200, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Try to add a participant with an invalid API key
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void addParticipant_InvalidAPIkey() throws HttpException, IOException {
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(403, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Try to add a participant with no participant ID
+	 * 
+	 * @throws HttpException
+	 * @throws IOException
+	 */
+	@Test
+	public void addParticipant_InvalidParticipant() throws HttpException,
+	IOException {
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key="
+				+ API_KEY_VALID
+				+ "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=&participant_display_name=bob&participants_thumbnail_url=http://www.test.org");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(400, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Try to add a participant using a non-existing widget
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void addParticipant_InvalidWidget() throws HttpException, IOException {
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key="
+				+ API_KEY_VALID
+				+ "&widgetid="
+				+ WIDGET_ID_INVALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=1&participant_display_name=bob&participants_thumbnail_url=http://www.test.org");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(400, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Delete a participant and check it was deleted
+	 * 
+	 * @throws HttpException
+	 * @throws IOException
+	 */
+	@Test
+	public void deleteParticipant() throws HttpException, IOException {
+		//
+		// Delete the participant
+		//
+		HttpClient client = new HttpClient();
+		DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=1");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(200, code);
+		post.releaseConnection();
+
+		//
+		// Now lets GET it to make sure it was deleted
+		//
+
+		client = new HttpClient();
+		GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+		client.executeMethod(get);
+		code = get.getStatusCode();
+		assertEquals(200, code);
+		String response = get.getResponseBodyAsString();
+		assertFalse(response
+				.contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
+		get.releaseConnection();
+
+	}
+
+	/**
+	 * Try to delete a participant with an invalid API key
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void deleteParticipant_InvalidAPIKey() throws HttpException,
+	IOException {
+		HttpClient client = new HttpClient();
+		DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(403, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Try to delete a non-existing participant
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void deleteParticipant_InvalidParticipant() throws HttpException,
+	IOException {
+		HttpClient client = new HttpClient();
+		DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=99");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(404, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Try to delete a participant for a non-existing widget instance
+	 * 
+	 * @throws IOException
+	 * @throws HttpException
+	 */
+	@Test
+	public void deleteParticipant_InvalidInstance() throws HttpException,
+	IOException {
+		HttpClient client = new HttpClient();
+		DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key="
+				+ API_KEY_VALID
+				+ "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstestinvalidkey&participant_id=1");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(404, code);
+		post.releaseConnection();
+	}
+
+	/**
+	 * Tests adding and then getting a participant who is also the Host
+	 * 
+	 * @throws HttpException
+	 * @throws IOException
+	 */
+	@Test
+	public void addHost() throws HttpException, IOException {
+
+		//
+		// Create a new participant
+		//
+		HttpClient client = new HttpClient();
+		PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		post.setQueryString("api_key="
+				+ API_KEY_VALID
+				+ "&widgetid="
+				+ WIDGET_ID_VALID
+				+ "&userid=test&shareddatakey=participantstest&participant_id=80&participant_display_name=bob&participant_role=host&participant_thumbnail_url=http://www.test.org");
+		client.executeMethod(post);
+		int code = post.getStatusCode();
+		assertEquals(201, code);
+		post.releaseConnection();
+
+		//
+		// Now lets GET it to make sure it was added OK
+		//
+		client = new HttpClient();
+		GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+		get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+				+ WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+		client.executeMethod(get);
+		code = get.getStatusCode();
+		assertEquals(200, code);
+		String response = get.getResponseBodyAsString();
+		assertTrue(response
+				.contains("<participant id=\"80\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" role=\"host\" />"));
+		get.releaseConnection();
 
-  }
+	}
 
 }

Modified: wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/PoliciesControllerTest.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/PoliciesControllerTest.java?rev=1569676&r1=1569675&r2=1569676&view=diff
==============================================================================
--- wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/PoliciesControllerTest.java (original)
+++ wookie/trunk/wookie-server/src/test/java/org/apache/wookie/tests/functional/PoliciesControllerTest.java Wed Feb 19 10:49:01 2014
@@ -23,12 +23,9 @@ import static org.junit.Assert.fail;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wookie.tests.helpers.Request;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
@@ -41,183 +38,161 @@ import org.junit.Test;
  * Test cases for policies API
  */
 public class PoliciesControllerTest extends AbstractControllerTest {
-  
-  private static String POLICY_TEST_SCOPE = "http://policies.test.scope";
-  private static String POLICY_TEST_INVALID_SCOPE = "http://no.such.scope";
-  private static String POLICY_TEST_ORIGIN = "http://policies.test.origin";
-  private static String POLICY_TEST_ORIGIN_2 = "http://policies.test2.origin";
-  
-  private static String POLICY_TEST_VALID = POLICY_TEST_SCOPE + " " + POLICY_TEST_ORIGIN + " " + "ALLOW";
-  private static String POLICY_TEST_VALID_2 = POLICY_TEST_SCOPE + " " + POLICY_TEST_ORIGIN_2 + " " + "ALLOW";
-  private static String POLICY_TEST_INVALID = POLICY_TEST_INVALID_SCOPE + " " + POLICY_TEST_ORIGIN + " " + "ALLOW";
-
-
-  @BeforeClass
-  public static void setup() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    PostMethod post = new PostMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    StringRequestEntity entity = new StringRequestEntity(POLICY_TEST_VALID, "text/plain", "UTF-8");
-    post.setRequestEntity(entity);
-    client.executeMethod(post);
-  }
-
-  @AfterClass
-  public static void tearDown() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    DeleteMethod delete = new DeleteMethod(TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_VALID_2));
-    client.executeMethod(delete);
-    assertEquals(200, delete.getStatusCode());
-  }
-  
-  @Test
-  public void getPolicies() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);    
-    GetMethod get = new GetMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    //this needs to be Accept rather than accepts which fails on tomcat
-    get.setRequestHeader("Accept", "text/xml");
-    client.executeMethod(get);
-    try {
-      Element policies = processPolicies(get.getResponseBodyAsStream());
-      assertEquals("policies", policies.getName());
-    } catch (JDOMException e) {
-      fail("Response did not contain any policies");
-    }
-  }
-  
-  @Test
-  public void getPoliciesUnauthorized() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    GetMethod get = new GetMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    get.setRequestHeader("Accept", "text/xml");
-    client.executeMethod(get);
-    assertEquals(401, get.getStatusCode());
-  }
-  
-  @Test
-  public void getPoliciesWithScope() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    //
-    // We should have a policy setup from above
-    //
-    GetMethod get = new GetMethod(TEST_POLICIES_SERVICE_URL_VALID + "/" + POLICY_TEST_SCOPE);
-    //this needs to be Accept rather than accepts which fails on tomcat
-    get.setRequestHeader("Accept", "text/xml");
-    client.executeMethod(get);
-    try {
-      Element policies = processPolicies(get.getResponseBodyAsStream());
-      assertEquals("policies", policies.getName());
-      assertEquals(1, policies.getChildren("policy").size());
-    } catch (JDOMException e) {
-      fail("Response did not contain any policies");
-    }
-  }
-  
-  @Test
-  public void getPoliciesWithNonexistingScope() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);    
-    GetMethod get = new GetMethod(TEST_POLICIES_SERVICE_URL_VALID + "/nosuchscope");
-    //this needs to be Accept rather than accepts which fails on tomcat   
-    get.setRequestHeader("Accept", "text/xml");
-    client.executeMethod(get);
-    try {
-      Element policies = processPolicies(get.getResponseBodyAsStream());
-      assertEquals("policies", policies.getName());
-      assertEquals(0, policies.getChildren("policy").size());
-    } catch (JDOMException e) {
-      fail("Response did not contain any policies");
-    }
-  }
-  
-  @Test
-  public void createPolicyUnauthorized() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    PostMethod post = new PostMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    StringRequestEntity entity = new StringRequestEntity("http://dodgyplace.org * ALLOW", "text/plain", "UTF-8");
-    post.setRequestEntity(entity);
-    client.executeMethod(post);
-    assertEquals(401,post.getStatusCode());
-  }
-  
-  @Test
-  public void createPolicyInvalidDirective() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    PostMethod post = new PostMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    StringRequestEntity entity = new StringRequestEntity("http://dodgyplace.org * MAYBE", "text/plain", "UTF-8");
-    post.setRequestEntity(entity);
-    client.executeMethod(post);
-    assertEquals(400,post.getStatusCode());    
-  }
-  
-  @Test
-  public void createPolicyInvalidScope() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    PostMethod post = new PostMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    StringRequestEntity entity = new StringRequestEntity("FAIL * DENY", "text/plain", "UTF-8");
-    post.setRequestEntity(entity);
-    client.executeMethod(post);
-    assertEquals(400,post.getStatusCode());
-  }
-  
-  @Test
-  public void createPolicyInvalidOrigin() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    PostMethod post = new PostMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    StringRequestEntity entity = new StringRequestEntity("http://dodgyplace.org FAIL DENY", "text/plain", "UTF-8");
-    post.setRequestEntity(entity);
-    client.executeMethod(post);
-    assertEquals(400,post.getStatusCode());
-  }
-  
-  @Test
-  public void createPolicy() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    PostMethod post = new PostMethod(TEST_POLICIES_SERVICE_URL_VALID);
-    StringRequestEntity entity = new StringRequestEntity(POLICY_TEST_VALID_2, "text/plain", "UTF-8");
-    post.setRequestEntity(entity);
-    client.executeMethod(post);
-    assertEquals(201,post.getStatusCode());
-  }
-  
-  @Test
-  public void deletePolicyUnauthorized() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    DeleteMethod delete = new DeleteMethod(TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_VALID));
-    client.executeMethod(delete);
-    assertEquals(401, delete.getStatusCode());   
-  }
-  
-  @Test
-  public void deletePolicyNonexistant() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    DeleteMethod delete = new DeleteMethod(TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_INVALID));
-    client.executeMethod(delete);
-    assertEquals(404, delete.getStatusCode());
-  }
-  
-  @Test
-  public void deletePolicy() throws HttpException, IOException{
-    HttpClient client = new HttpClient();
-    setAuthenticationCredentials(client);
-    DeleteMethod delete = new DeleteMethod(TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_VALID));
-    client.executeMethod(delete);
-    assertEquals(200, delete.getStatusCode());
-  }
-  
-  public static Element processPolicies(InputStream in) throws JDOMException, IOException{
-    SAXBuilder builder = new SAXBuilder();
-    Document doc = builder.build(in);
-    Element policies = doc.getRootElement();
-    return policies;
-  }
+
+	private static String POLICY_TEST_SCOPE = "http://policies.test.scope";
+	private static String POLICY_TEST_INVALID_SCOPE = "http://no.such.scope";
+	private static String POLICY_TEST_ORIGIN = "http://policies.test.origin";
+	private static String POLICY_TEST_ORIGIN_2 = "http://policies.test2.origin";
+
+	private static String POLICY_TEST_VALID = POLICY_TEST_SCOPE + " " + POLICY_TEST_ORIGIN + " " + "ALLOW";
+	private static String POLICY_TEST_VALID_2 = POLICY_TEST_SCOPE + " " + POLICY_TEST_ORIGIN_2 + " " + "ALLOW";
+	private static String POLICY_TEST_INVALID = POLICY_TEST_INVALID_SCOPE + " " + POLICY_TEST_ORIGIN + " " + "ALLOW";
+
+
+	@BeforeClass
+	public static void setup() throws HttpException, IOException{
+		Request post = new Request("POST", TEST_POLICIES_SERVICE_URL_VALID);
+		StringRequestEntity entity = new StringRequestEntity(POLICY_TEST_VALID, "text/plain", "UTF-8");
+		post.setRequestEntity(entity);
+		post.execute(true, false);
+		assertEquals(201, post.getStatusCode());
+	}
+
+	@AfterClass
+	public static void tearDown() throws HttpException, IOException{
+		Request delete = new Request("DELETE", TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_VALID_2));
+		delete.execute(true, false);
+		assertEquals(200, delete.getStatusCode());
+	}
+
+	@Test
+	public void getPolicies() throws HttpException, IOException{    
+		Request get = new Request("GET", TEST_POLICIES_SERVICE_URL_VALID);
+		get.setAccepts("text/xml");
+		get.execute(true, false);
+		try {
+			Element policies = processPolicies(get.getResponseBodyAsStream());
+			assertEquals("policies", policies.getName());
+		} catch (JDOMException e) {
+			fail("Response did not contain any policies");
+		}
+	}
+
+	@Test
+	public void getPoliciesUnauthorized() throws HttpException, IOException{
+		Request get = new Request("GET", TEST_POLICIES_SERVICE_URL_VALID);
+		get.setAccepts("text/xml");
+		get.execute(false, false);
+		assertEquals(403, get.getStatusCode());
+	}
+
+	@Test
+	public void getPoliciesWithScope() throws HttpException, IOException{
+		//
+		// We should have a policy setup from above
+		//
+		Request get = new Request("GET", TEST_POLICIES_SERVICE_URL_VALID + "/" + POLICY_TEST_SCOPE);
+		get.setAccepts("text/xml");
+		get.execute(true, false);
+		try {
+			Element policies = processPolicies(get.getResponseBodyAsStream());
+			assertEquals("policies", policies.getName());
+			assertEquals(1, policies.getChildren("policy").size());
+		} catch (JDOMException e) {
+			fail("Response did not contain any policies");
+		}
+	}
+
+	@Test
+	public void getPoliciesWithNonexistingScope() throws HttpException, IOException{  
+		Request get = new Request("GET", TEST_POLICIES_SERVICE_URL_VALID + "/nosuchscope");
+		get.setAccepts("text/xml");
+		get.execute(true, false);
+
+		try {
+			Element policies = processPolicies(get.getResponseBodyAsStream());
+			assertEquals("policies", policies.getName());
+			assertEquals(0, policies.getChildren("policy").size());
+		} catch (JDOMException e) {
+			fail("Response did not contain any policies");
+		}
+	}
+
+	@Test
+	public void createPolicyUnauthorized() throws HttpException, IOException{
+		Request post = new Request("POST", TEST_POLICIES_SERVICE_URL_VALID);
+		post.setAccepts("text/xml");
+		StringRequestEntity entity = new StringRequestEntity("http://dodgyplace.org * ALLOW", "text/plain", "UTF-8");
+		post.setRequestEntity(entity);
+		post.execute(false, false);
+		assertEquals(403,post.getStatusCode());
+	}
+
+	@Test
+	public void createPolicyInvalidDirective() throws HttpException, IOException{
+		Request post = new Request("POST", TEST_POLICIES_SERVICE_URL_VALID);
+		post.setAccepts("text/xml");
+		StringRequestEntity entity = new StringRequestEntity("http://dodgyplace.org * MAYBE", "text/plain", "UTF-8");
+		post.setRequestEntity(entity);
+		post.execute(true, false);
+		assertEquals(400,post.getStatusCode());    
+	}
+
+	@Test
+	public void createPolicyInvalidScope() throws HttpException, IOException{
+		Request post = new Request("POST", TEST_POLICIES_SERVICE_URL_VALID);
+		post.setAccepts("text/xml");
+		StringRequestEntity entity = new StringRequestEntity("FAIL * DENY", "text/plain", "UTF-8");
+		post.setRequestEntity(entity);
+		post.execute(true, false);
+		assertEquals(400,post.getStatusCode());
+	}
+
+	@Test
+	public void createPolicyInvalidOrigin() throws HttpException, IOException{
+		Request post = new Request("POST", TEST_POLICIES_SERVICE_URL_VALID);
+		post.setAccepts("text/xml");
+		StringRequestEntity entity = new StringRequestEntity("http://dodgyplace.org FAIL DENY", "text/plain", "UTF-8");
+		post.setRequestEntity(entity);
+		post.execute(true, false);
+		assertEquals(400,post.getStatusCode());
+	}
+
+	@Test
+	public void createPolicy() throws HttpException, IOException{
+		Request post = new Request("POST", TEST_POLICIES_SERVICE_URL_VALID);
+		StringRequestEntity entity = new StringRequestEntity(POLICY_TEST_VALID_2, "text/plain", "UTF-8");
+		post.setRequestEntity(entity);
+		post.execute(true, false);
+		assertEquals(201,post.getStatusCode());
+	}
+
+	@Test
+	public void deletePolicyUnauthorized() throws HttpException, IOException{
+		Request delete = new Request("DELETE", TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_VALID));
+		delete.execute(false, false);
+		assertEquals(403, delete.getStatusCode());   
+	}
+
+	@Test
+	public void deletePolicyNonexistant() throws HttpException, IOException{
+		Request delete = new Request("DELETE", TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_INVALID));
+		delete.execute(true, false);
+		assertEquals(404, delete.getStatusCode());
+	}
+
+	@Test
+	public void deletePolicy() throws HttpException, IOException{
+		Request delete = new Request("DELETE", TEST_POLICIES_SERVICE_URL_VALID + "/" + encodeString(POLICY_TEST_VALID));
+		delete.execute(true, false);
+		assertEquals(200, delete.getStatusCode());
+	}
+
+	public static Element processPolicies(InputStream in) throws JDOMException, IOException{
+		SAXBuilder builder = new SAXBuilder();
+		Document doc = builder.build(in);
+		Element policies = doc.getRootElement();
+		return policies;
+	}
 
 }