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

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


    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


    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

    @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"));
        log.info("Response  {}",result.getContent());
    }
View Full Code Here

        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());
        log.info("Response  {}",result.getContent());

        assertEquals("/mdc", jb.getString("req.requestURI"));
        assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL"));
        assertEquals("foo-forwarded-for", jb.getString("req.xForwardedFor"));
        assertEquals("foo-test-header", jb.getString("mdc-test-header"));
View Full Code Here

    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);

        return executor;
    }
View Full Code Here

        MultipartEntity entity = new MultipartEntity();
        entity.addPart("sling:resourceType", new StringBody("validation/test/resourceType1"));
        entity.addPart("field1", new StringBody("HelloWorld"));
        entity.addPart("field2", new StringBody("30.01.1988"));
        entity.addPart(SlingPostConstants.RP_OPERATION, new StringBody("validation"));
        RequestExecutor re = getRequestExecutor().execute(getRequestBuilder().buildPostRequest
                ("/validation/testing/fakeFolder1/resource").withEntity(entity)).assertStatus(200);
        JSONObject jsonResponse = new JSONObject(re.getContent());
        assertTrue(jsonResponse.getBoolean("valid"));
    }
View Full Code Here

    public void testInvalidRequestModel1() throws IOException, JSONException {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("sling:resourceType", new StringBody("validation/test/resourceType1"));
        entity.addPart("field1", new StringBody("Hello World"));
        entity.addPart(SlingPostConstants.RP_OPERATION, new StringBody("validation"));
        RequestExecutor re = getRequestExecutor().execute(getRequestBuilder().buildPostRequest
                ("/validation/testing/fakeFolder1/resource").withEntity(entity)).assertStatus(200);
        String content = re.getContent();
        JSONObject jsonResponse = new JSONObject(content);
        assertFalse(jsonResponse.getBoolean("valid"));
    }
View Full Code Here

   
    @Test
    public void testScriptableTest() throws Exception {
       
        // Execute all available scriptable tests and count failures
        final RequestExecutor executor = testClient.runTests(
                "org.apache.sling.junit.scriptable.ScriptableTestsProvider",
                null,
                "json"
                );
        executor.assertContentType("application/json");
        final JSONArray json = new JSONArray(new JSONTokener((executor.getContent())));
       
        int testsCount = 0;
        final List<String> failures = new ArrayList<String>();
        for(int i = 0 ; i < json.length(); i++) {
            final JSONObject obj = json.getJSONObject(i);
View Full Code Here

       final String testClassesSelector = method.getMethod().getDeclaringClass().getName();
       final String methodName = method.getMethod().getName();
      
       final RemoteTestHttpClient testHttpClient = new RemoteTestHttpClient(remoteUrl, remoteUsername, remotePassword, false);
       testHttpClient.setRequestCustomizer(this);
       final RequestExecutor executor = testHttpClient.runTests(
               testClassesSelector, methodName, "serialized"
       );
       log.debug("Ran test {} method {} at URL {}",
               new Object[] { testClassesSelector, methodName, remoteUrl });
      
       final HttpEntity entity = executor.getResponse().getEntity();
       if (entity != null) {
           try {
               final Object o = new ObjectInputStream(entity.getContent()).readObject();
               if( !(o instanceof ExecutionResult) ) {
                   throw new IllegalStateException("Expected an ExecutionResult, got a " + o.getClass().getName());
View Full Code Here

        if(testParameters instanceof RequestCustomizer) {
            testHttpClient.setRequestCustomizer((RequestCustomizer)testParameters);
        }
       
        // Run tests remotely and get response
        final RequestExecutor executor = testHttpClient.runTests(
                testParameters.getTestClassesSelector(),
                testParameters.getTestMethodSelector(),
                "json"
                );
        executor.assertContentType("application/json");
        final JSONArray json = new JSONArray(new JSONTokener((executor.getContent())));

        // Response contains an array of objects identified by
        // their INFO_TYPE, extract the tests
        // based on this vlaue
        for(int i = 0 ; i < json.length(); i++) {
View Full Code Here

TOP

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

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.