Example usage for org.apache.commons.httpclient.methods GetMethod setQueryString

List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods GetMethod setQueryString.

Prototype

public void setQueryString(String queryString) 

Source Link

Usage

From source file:org.apache.wookie.tests.functional.ParticipantsControllerTest.java

@Test
public void getParticipant_usingIdKey() {
    try {//ww w.j ava 2 s.com
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&id_key=" + 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();
    } catch (Exception e) {
        e.printStackTrace();
        fail("get failed");
    }
}

From source file:org.apache.wookie.tests.functional.ParticipantsControllerTest.java

@Test
public void deleteParticipant() {
    try {/*  ww  w  .ja  v a 2s.co  m*/
        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();
    } catch (Exception e) {
        e.printStackTrace();
        fail("delete failed");
    }
    // Now lets GET it to make sure it was deleted
    try {
        HttpClient 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);
        int 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();
    } catch (Exception e) {
        e.printStackTrace();
        fail("get failed");
    }
}

From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java

@Test
public void setPreferenceUsingPostParameters() throws Exception {
    try {/*from w w  w  . j a v  a  2  s. co m*/
        String url = TEST_PROPERTIES_SERVICE_URL_VALID;
        //String url = TEST_PROPERTIES_SERVICE_URL_VALID;
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(url);
        post.addParameter("api_key", API_KEY_VALID);
        post.addParameter("widgetid", WIDGET_ID_VALID);
        post.addParameter("userid", "test");
        post.addParameter("is_public", "false");
        post.addParameter("shareddatakey", "propstest");
        post.addParameter("propertyname", "testpost");
        post.addParameter("propertyvalue", "pass");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(201, code);
        post.releaseConnection();
    } catch (Exception e) {
        fail("POST failed");
    }
    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=propstest&propertyname=testpost");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String resp = get.getResponseBodyAsString();
        assertEquals("pass", resp);
        get.releaseConnection();
    } catch (Exception e) {
        fail("POST  failed to set info correctly");
    }
}

From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java

@Test
public void setPreference() {
    // Set some shared data
    try {//w ww. ja  va2 s  .c  o  m
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&is_public=false&shareddatakey=propstest&propertyname=pass&propertyvalue=pass");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(201, code);
        post.releaseConnection();
    } catch (Exception e) {
        fail("set shared data failed");
    }

    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=propstest&propertyname=pass");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String resp = get.getResponseBodyAsString();
        assertEquals("pass", resp);
        get.releaseConnection();
    } catch (Exception e) {
        fail("get preference failed");
    }
}

From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java

@Test
public void setSharedData() {
    // Set some shared data
    try {/*from  ww w.  j  av a  2 s.c om*/
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&is_public=true&shareddatakey=propstest&propertyname=cat&propertyvalue=garfield");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(201, code);
        post.releaseConnection();
    } catch (Exception e) {
        fail("set shared data failed");
    }

    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=propstest&propertyname=cat");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String resp = get.getResponseBodyAsString();
        assertEquals("garfield", resp);
        get.releaseConnection();
    } catch (Exception e) {
        fail("get property failed");
    }
}

From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java

@Test
public void updateProperty() {
    try {//  w w w . ja  v  a2  s  .  c  o  m
        HttpClient client = new HttpClient();
        PutMethod put = new PutMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        put.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&is_public=true&shareddatakey=propstest&propertyname=cat&propertyvalue=felix");
        client.executeMethod(put);
        int code = put.getStatusCode();
        assertEquals(200, code);
        put.releaseConnection();
    } catch (Exception e) {
        fail("set shared data failed");
    }

    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=propstest&propertyname=cat");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String resp = get.getResponseBodyAsString();
        assertEquals("felix", resp);
        get.releaseConnection();
    } catch (Exception e) {
        fail("get property failed");
    }

}

From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java

@Test
public void getPropertyInvalidAPIKey() {
    try {//  w w  w  .  java2  s.  c  o m
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=propstest&propertyname=cat");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(401, code);
        get.releaseConnection();
    } catch (Exception e) {
        fail("get property failed");
    }
}

From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java

@Test
public void getPropertyInvalidName() {
    try {//from w  ww .j av  a 2s .  com
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=propstest&propertyname=madeupname");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(404, code);
        get.releaseConnection();
    } catch (Exception e) {
        fail("get property failed");
    }
}

From source file:org.apache.wookie.tests.functional.ProxyTest.java

/**
 * This tests accessing a site passing through POST parameters
 * @throws Exception/*  www.ja  va2  s . c o  m*/
 */
@Test
public void postWithPassingParameters() throws Exception {
    try {
        String url = PROXY_URL;
        //String url = TEST_PROPERTIES_SERVICE_URL_VALID;
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(url);
        post.addParameter("instanceid_key", instance_id_key);
        post.addParameter("url", TEST_PROPERTIES_SERVICE_URL_VALID);
        post.addParameter("api_key", API_KEY_VALID);
        post.addParameter("widgetid", WIDGET_ID_VALID);
        post.addParameter("userid", "test");
        post.addParameter("is_public", "false");
        post.addParameter("shareddatakey", "proxytest");
        post.addParameter("propertyname", "pass");
        post.addParameter("propertyvalue", "pass");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(200, code);
        post.releaseConnection();
    } catch (Exception e) {
        fail("POST via proxy failed");
    }
    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=proxytest&propertyname=pass");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String resp = get.getResponseBodyAsString();
        assertEquals("pass", resp);
        get.releaseConnection();
    } catch (Exception e) {
        fail("POST via proxy failed to set info correctly");
    }
}

From source file:org.apache.wookie.tests.functional.WidgetsControllerTest.java

@Test
public void getAllWidgets() {
    try {// www .  ja  v a 2s  . c  o m
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_WIDGETS_SERVICE_URL_VALID);
        get.setQueryString("all=true");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String response = get.getResponseBodyAsString();
        assertTrue(response.contains("<widget id=\"1\" identifier=\"http://notsupported\""));
        get.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("get failed");
    }
}