Package org.apache.sling.testing.tools.http

Examples of org.apache.sling.testing.tools.http.RequestBuilder


    public static final String JSON_KEY_DATA = "data";
    public static final String JSON_KEY_STATE = "state";
    public static final String CONSOLE_BUNDLES_PATH = "/system/console/bundles";
   
    public WebconsoleClient(String slingServerUrl, String username, String password) {
        this.builder = new RequestBuilder(slingServerUrl);
        this.executor = new RequestExecutor(new DefaultHttpClient());
        this.username = username;
        this.password = password;
    }
View Full Code Here


            serverPassword = configuredPassword;
        } else {
            serverPassword = ADMIN;
        }

        builder = new RequestBuilder(slingTestState.getServerBaseUrl());
        webconsoleClient = new WebconsoleClient(slingTestState.getServerBaseUrl(), serverUsername, serverPassword);
        builder = new RequestBuilder(slingTestState.getServerBaseUrl());
        bundlesInstaller = new BundlesInstaller(webconsoleClient);

        if(!slingTestState.isServerInfoLogged()) {
            log.info("Server base URL={}", slingTestState.getServerBaseUrl());
            slingTestState.setServerInfoLogged(true);
View Full Code Here

   
    public SlingClient(String slingServerUrl, String username, String password) {
        this.slingServerUrl = slingServerUrl;
        this.username = username;
        this.password = password;
        builder = new RequestBuilder(slingServerUrl);
        executor = new RequestExecutor(new DefaultHttpClient());
    }
View Full Code Here

                public String getDescription() {
                    return "Check if MDCTestServlet is up";
                }

                public boolean isTrue() throws Exception {
                    RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
                    executor.execute(rb.buildGetRequest("/mdc")).assertStatus(200);
                    rb = new RequestBuilder(ServerConfiguration.getServerUrl());

                    //Create test config via servlet
                    executor.execute(rb.buildGetRequest("/mdc", "createTestConfig", "true"));
                    TimeUnit.SECONDS.sleep(1);
                    return true;
                }
            },5,100);
        }
View Full Code Here

        }
    }

    @Test
    public void testDefault() throws Exception{
        RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
        // Add Sling POST options
        RequestExecutor result = executor.execute(
                rb.buildGetRequest("/mdc","foo","bar"));

        JSONObject jb = new JSONObject(result.getContent());
        assertEquals("/mdc", jb.getString("req.requestURI"));
        assertEquals("foo=bar", jb.getString("req.queryString"));
        assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL"));
View Full Code Here

        log.info("Response  {}",result.getContent());
    }

    @Test
    public void testWihCustomData() throws Exception{
        RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());

        //Create test config via servlet
        executor.execute(rb.buildGetRequest("/mdc", "createTestConfig", "true"));
        TimeUnit.SECONDS.sleep(1);

        //Pass custom cookie
        BasicClientCookie cookie = new BasicClientCookie("mdc-test-cookie", "foo-test-cookie");
        cookie.setPath("/");
        cookie.setDomain("localhost");
        httpClient.getCookieStore().addCookie(cookie);

        //Execute request
        RequestExecutor result = executor.execute(
                rb.buildGetRequest("/mdc", "mdc-test-param", "foo-test-param", "ignored-param", "ignored-value")
                        .withHeader("X-Forwarded-For", "foo-forwarded-for")
                        .withHeader("mdc-test-header", "foo-test-header")
        );

        JSONObject jb = new JSONObject(result.getContent());
View Full Code Here

    private DefaultHttpClient httpClient = new DefaultHttpClient();
    private RequestExecutor executor = new RequestExecutor(httpClient);

    @Test
    public void testResourceResolver() throws Exception {
        RequestBuilder rb = new RequestBuilder("http://localhost:9000");

        final MultipartEntity entity = new MultipartEntity();
        // Add Sling POST options
        entity.addPart("lang", new StringBody("esp"));
        entity.addPart("code", new InputStreamBody(getClass().getResourceAsStream("/test.js"), "test.js"));
        executor.execute(
                rb.buildPostRequest("/system/console/scriptconsole.json")
                 .withEntity(entity)
                 .withCredentials("admin","admin")
            ).assertStatus(200);
    }
View Full Code Here

        return runTests(testClassesSelector, testMethodSelector, extension, null);
    }
   
    public RequestExecutor runTests(String testClassesSelector, String testMethodSelector, String extension, Map<String, String> requestOptions)
    throws ClientProtocolException, IOException {
        final RequestBuilder builder = new RequestBuilder(junitServletUrl);

        // Optionally let the client to consume the response entity
        final RequestExecutor executor = new RequestExecutor(new DefaultHttpClient()) {
            @Override
            protected void consumeEntity() throws ParseException, IOException {
                if(consumeContent) {
                    super.consumeEntity();
                }
            }
        };
       
        // Build path for POST request to execute the tests
       
        // Test classes selector
        subpath = new StringBuilder();
        if(!junitServletUrl.endsWith(SLASH)) {
            subpath.append(SLASH);
        }
        subpath.append(testClassesSelector);
       
        // Test method selector
        if(testMethodSelector != null && testMethodSelector.length() > 0) {
            subpath.append("/");
            subpath.append(testMethodSelector);
        }
       
        // Extension
        if(!extension.startsWith(DOT)) {
            subpath.append(DOT);
        }
        subpath.append(extension);

        // Request options if any
        final List<NameValuePair> opt = new ArrayList<NameValuePair>();
        if(requestOptions != null) {
            for(Map.Entry<String, String> e : requestOptions.entrySet()) {
                opt.add(new BasicNameValuePair(e.getKey(), e.getValue()));
            }
        }
       
        log.info("Executing test remotely, path={} JUnit servlet URL={}",
                subpath, junitServletUrl);
        final Request r = builder
        .buildPostRequest(subpath.toString())
        .withCredentials(username, password)
        .withCustomizer(requestCustomizer)
        .withEntity(new UrlEncodedFormEntity(opt));
        executor.execute(r).assertStatus(200);
View Full Code Here

        execute2("def a = 2+2; assert a == 4;");
    }

    private void execute(ContentBody code) throws Exception
    {
        RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());

        final MultipartEntity entity = new MultipartEntity();
        // Add Sling POST options
        entity.addPart("lang", new StringBody("groovy"));
        entity.addPart("code", code);
        executor.execute(
            rb.buildPostRequest("/system/console/sc").withEntity(entity).withCredentials(
                    "admin", "admin")).assertStatus(200);
    }
View Full Code Here

                    "admin", "admin")).assertStatus(200);
    }

    private void execute2(String code) throws Exception
    {
        RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("lang","groovy"));
        params.add(new BasicNameValuePair("code",code));

        final HttpEntity entity = new UrlEncodedFormEntity(params);
        // Add Sling POST options
        executor.execute(
                rb.buildPostRequest("/system/console/sc")
                        .withEntity(entity)
                        .withCredentials("admin", "admin"))
                .assertStatus(200);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.testing.tools.http.RequestBuilder

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.