Package smartrics.rest.client

Examples of smartrics.rest.client.RestClient


    }

    @Test
    public void buildsRestClientWithStandardUri() throws Exception {
        Config c = Config.getConfig();
        RestClient restClient = f.buildRestClient(c);
        assertThat(restClient, is(instanceOf(RestClient.class)));
        Method m = getCreateUriMethod(restClient);
        m.setAccessible(true);
        Object r = m.invoke(restClient, "http://localhost:9900?something", false);
        assertThat(r, is(instanceOf(URI.class)));
View Full Code Here


    @Test
    public void buildsRestClientWithoutSquareBracketsInUri() throws Exception {
        // URI validation will throw an exception as per httpclient 3.1
        Config c = Config.getConfig();
        RestClient restClient = f.buildRestClient(c);
        assertThat(restClient, is(instanceOf(RestClient.class)));
        Method m = getCreateUriMethod(restClient);
        m.setAccessible(true);
        try {
            m.invoke(restClient, "http://localhost:9900?something[data]=1", true);
View Full Code Here

    @Test
    public void buildsRestClientWithEscapedSquareBracketsInUri() throws Exception {
        // URI will be escaped as per httpclient 3.1
        Config c = Config.getConfig();
        RestClient restClient = f.buildRestClient(c);
        assertThat(restClient, is(instanceOf(RestClient.class)));
        Method m = getCreateUriMethod(restClient);
        m.setAccessible(true);
        Object r = m.invoke(restClient, "http://localhost:9900?something[data]=1", false);
        assertThat(r, is(instanceOf(URI.class)));
View Full Code Here

    @Test
    public void buildsRestClientWithSquareBracketsInUri() throws Exception {
        Config c = Config.getConfig();
        c.add("http.client.use.new.http.uri.factory", "true");
        RestClient restClient = f.buildRestClient(c);
        assertThat(restClient, is(instanceOf(RestClient.class)));
        Method m = getCreateUriMethod(restClient);
        m.setAccessible(true);
        Object r = m.invoke(restClient, "http://localhost:9900?something[data]=1", false);
        assertThat(r, is(instanceOf(HttpURL.class)));
View Full Code Here

    }

    @Test
    public void buildsRestClientWithDefaultURIFactory() throws Exception {
        Config c = Config.getConfig();
        RestClient restClient = f.buildRestClient(c);
        assertThat(restClient, is(instanceOf(RestClient.class)));
        Method m = getGetMethodClassnameFromMethodNameMethod(restClient);
        m.setAccessible(true);
        Object r = m.invoke(restClient, "Some");
        assertThat(r.toString(), is(equalTo("org.apache.commons.httpclient.methods.SomeMethod")));
View Full Code Here

    @Test
    public void buildsRestClientWithNewURIFactory() throws Exception {
        Config c = Config.getConfig();
        c.add("http.client.use.new.http.uri.factory", "true");
        RestClient restClient = f.buildRestClient(c);
        assertThat(restClient, is(instanceOf(RestClient.class)));
        Method m = getGetMethodClassnameFromMethodNameMethod(restClient);
        m.setAccessible(true);
        Object r = m.invoke(restClient, "Some");
        assertThat(r.toString(), is(equalTo("smartrics.rest.fitnesse.fixture.support.http.SomeMethod")));
View Full Code Here

    public static void main(String[] args) {
        postForm(args);
    }

    public static void postForm(String[] args) {
        RestClient c = new RestClientImpl(new HttpClient());
        RestRequest req = new RestRequest();
        req.setBody("name=n&data=d1");
        req.setResource("/resources/");
        req.setMethod(Method.Post);
        req.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        RestResponse res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");
    }
View Full Code Here

        RestResponse res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");
    }

    public static void postXml(String[] args) {
        RestClient c = new RestClientImpl(new HttpClient());
        RestRequest req = new RestRequest();

        req.setBody("<resource><name>n</name><data>d1</data></resource>");
        req.setResource("/resources/");
        req.setMethod(Method.Post);
        RestResponse res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");

        String loc = res.getHeader("Location").get(0).getValue();
        req.setResource(loc + ".json");
        req.setMethod(Method.Get);
        res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");

        req.setMethod(Method.Put);
        req.setBody("<resource><name>another name</name><data>another data</data></resource>");
        res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");

        req.setResource("/resources/");
        req.setMethod(Method.Get);
        res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");

        req.setMethod(Method.Delete);
        req.setResource(loc);
        res = c.execute("http://localhost:8765", req);
        System.out.println("=======>\n" + res + "\n<=======");
    }
View Full Code Here

TOP

Related Classes of smartrics.rest.client.RestClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.