Search in sources :

Example 6 with SlingHttpResponse

use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.

the class MimeTypeServletHttpIT method assertMimeType.

private void assertMimeType(String path, String expected) throws Exception {
    SlingClient client = slingInstanceRule.getAdminClient();
    SlingHttpResponse response = client.doGet(path + ".mimetype.txt", 200);
    response.checkContentContains(expected);
}
Also used : SlingHttpResponse(org.apache.sling.testing.clients.SlingHttpResponse) SlingClient(org.apache.sling.testing.clients.SlingClient)

Example 7 with SlingHttpResponse

use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.

the class OsgiConsoleClient method deleteConfiguration.

/**
     * Delete the config referenced by the PID
     *
     * @param pid pid
     * @param expectedStatus expected response status
     * @return the sling response
     * @throws ClientException if the response status does not match any of the expectedStatus
     */
public SlingHttpResponse deleteConfiguration(String pid, int... expectedStatus) throws ClientException {
    FormEntityBuilder builder = FormEntityBuilder.create();
    builder.addParameter("apply", "1");
    builder.addParameter("delete", "1");
    // make the request
    SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + pid, builder.build());
    // check the returned status
    HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(200, expectedStatus));
    return resp;
}
Also used : SlingHttpResponse(org.apache.sling.testing.clients.SlingHttpResponse) FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Example 8 with SlingHttpResponse

use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.

the class OsgiConsoleClient method editConfiguration.

/**
     * Sets properties of a config referenced by its PID. the properties to be edited are passed as
     * a map of property name,value pairs.
     *
     * @param PID Persistent identity string
     * @param factoryPID Factory persistent identity string or {@code null}
     * @param configProperties map of properties
     * @param expectedStatus expected response status
     * @return the location of the config
     * @throws ClientException if the response status does not match any of the expectedStatus
     */
public String editConfiguration(String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) throws ClientException {
    FormEntityBuilder builder = FormEntityBuilder.create();
    builder.addParameter("apply", "true");
    builder.addParameter("action", "ajaxConfigManager");
    // send factory PID if set
    if (factoryPID != null) {
        builder.addParameter("factoryPid", factoryPID);
    }
    // add properties to edit
    StringBuilder propertyList = new StringBuilder("");
    for (String propName : configProperties.keySet()) {
        Object o = configProperties.get(propName);
        if (o instanceof String) {
            builder.addParameter(propName, (String) o);
        } else if (o instanceof String[]) {
            for (String s : (String[]) o) {
                builder.addParameter(propName, s);
            }
        }
        propertyList.append(propName).append(",");
    }
    // cut off the last comma
    builder.addParameter("propertylist", propertyList.substring(0, propertyList.length() - 1));
    // make the request
    SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + PID, builder.build());
    // check the returned status
    HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_MOVED_TEMPORARILY, expectedStatus));
    Header[] locationHeader = resp.getHeaders("Location");
    if (locationHeader != null && locationHeader.length == 1) {
        return locationHeader[0].getValue().substring(URL_CONFIGURATION.length() + 1);
    } else {
        return null;
    }
}
Also used : SlingHttpResponse(org.apache.sling.testing.clients.SlingHttpResponse) Header(org.apache.http.Header) FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Aggregations

SlingHttpResponse (org.apache.sling.testing.clients.SlingHttpResponse)8 FormEntityBuilder (org.apache.sling.testing.clients.util.FormEntityBuilder)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Header (org.apache.http.Header)1 SlingClient (org.apache.sling.testing.clients.SlingClient)1 JsonNode (org.codehaus.jackson.JsonNode)1