use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.
the class OsgiConsoleClient method getBundleInfo.
/**
* Returns the wrapper for the bundle info json
*
* @param id the id of the bundle
* @param expectedStatus list of accepted statuses of the response
* @return the bundle info
* @throws ClientException if the response status does not match any of the expectedStatus
*/
public BundleInfo getBundleInfo(String id, int... expectedStatus) throws ClientException {
SlingHttpResponse resp = this.doGet(URL_BUNDLES + "/" + id + ".json");
HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_OK, expectedStatus));
return new BundleInfo(JsonUtils.getJsonNodeFromString(resp.getContent()));
}
use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.
the class OsgiConsoleClient method getConfiguration.
//
// OSGi configurations
//
/**
* Returns a map of all properties set for the config referenced by the PID, where the map keys
* are the property names.
*
* @param pid the pid of the configuration
* @param expectedStatus list of accepted statuses of the response
* @return the properties as a map
* @throws ClientException if the response status does not match any of the expectedStatus
*/
public Map<String, Object> getConfiguration(String pid, int... expectedStatus) throws ClientException {
// make the request
SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + pid, null);
// check the returned status
HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_OK, expectedStatus));
// get the JSON node
JsonNode rootNode = JsonUtils.getJsonNodeFromString(resp.getContent());
// go through the params
Map<String, Object> props = new HashMap<String, Object>();
if (rootNode.get("properties") == null)
return props;
JsonNode properties = rootNode.get("properties");
for (Iterator<String> it = properties.getFieldNames(); it.hasNext(); ) {
String propName = it.next();
JsonNode value = properties.get(propName).get("value");
if (value != null) {
props.put(propName, value.getValueAsText());
continue;
}
value = properties.get(propName).get("values");
if (value != null) {
Iterator<JsonNode> iter = value.getElements();
List<String> list = new ArrayList<String>();
while (iter.hasNext()) {
list.add(iter.next().getValueAsText());
}
props.put(propName, list.toArray(new String[list.size()]));
}
}
return props;
}
use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.
the class OsgiConsoleClient method getComponentInfo.
/**
* Returns the wrapper for the component info json
*
* @param id the id of the component
* @param expectedStatus list of accepted statuses of the response
* @return the component info
* @throws ClientException if the response status does not match any of the expectedStatus
*/
public ComponentInfo getComponentInfo(String id, int expectedStatus) throws ClientException {
SlingHttpResponse resp = this.doGet(URL_COMPONENTS + "/" + id + ".json");
HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_OK, expectedStatus));
return new ComponentInfo(JsonUtils.getJsonNodeFromString(resp.getContent()));
}
use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.
the class OsgiConsoleClient method getComponentsInfo.
/**
* Returns the wrapper for the components info json
*
* @param expectedStatus list of accepted statuses of the response
* @return the components info
* @throws ClientException if the response status does not match any of the expectedStatus
*/
public ComponentsInfo getComponentsInfo(int... expectedStatus) throws ClientException {
SlingHttpResponse resp = this.doGet(URL_COMPONENTS + ".json");
HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_OK, expectedStatus));
return new ComponentsInfo(JsonUtils.getJsonNodeFromString(resp.getContent()));
}
use of org.apache.sling.testing.clients.SlingHttpResponse in project sling by apache.
the class RemoteLogDumperRule method failed.
@Override
protected void failed(Throwable e, Description description) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
if (slingClient != null) {
try {
SlingHttpResponse response = slingClient.doGet(SERVLET_PATH, URLParameterBuilder.create().add(TEST_CLASS_HEADER, description.getClassName()).add(TEST_NAME_HEADER, description.getMethodName()).getList(), 200);
String msg = response.getSlingMessage();
if (msg != null) {
pw.println(msg);
}
pw.printf("=============== Logs from server [%s] for [%s]===================%n", slingClient.getUrl(), description.getMethodName());
pw.print(response.getContent());
pw.println("========================================================");
System.err.print(sw.toString());
} catch (Throwable t) {
System.err.printf("Error occurred while fetching test logs from server [%s] %n", slingClient.getUrl());
t.printStackTrace(System.err);
}
} else {
System.err.println("No SlingClient configured with the rule");
}
}
Aggregations