use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.
the class RestOperationTests method post_usingFormParameters.
/**
* A POST which sends form parameters.
*
* In the particular case on the server side a new person will be added to the list
* of known persons.
* It returns info about the newly added person.
*/
@Test
public void post_usingFormParameters() {
RestClient client = new RestClient(BASE_URI + "peoplepage/post");
// create a RestForm and add parameters' info
RestForm formParameters = new RestForm().addParameter("firstName", "Chuck").addParameter("lastName", "Norris").addParameter("age", "70");
// send the form data
RestResponse response = client.postForm(formParameters);
// check the status code is "201 CREATED"
response.verifyStatusCode(201);
// check the returned result to make sure the server accepted the data we sent
assertTrue(response.getBodyAsString().startsWith("Saved Person with name Chuck Norris at 70 years"));
}
use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.
the class RestHelper method post.
public RestResponse post(String atsAgentIp, String baseRestUri, String relativeRestUri, Object[] values) {
// check if ActiveDbAppender is attached
if (!ActiveDbAppender.isAttached) {
throw new IllegalStateException("Unable to execute monitoring operation.ATS DB Appender is not presented in log4j2.xml");
}
RestResponse response = null;
initializeRestClient(atsAgentIp, baseRestUri, relativeRestUri);
String jsonBody = null;
if (relativeRestUri.endsWith(INITIALIZE_DB_CONNECTION_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructInitializeDbConnectionJson(values);
} else if (relativeRestUri.endsWith(JOIN_TESTCASE_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructJoinTestcaseJson(values);
} else if (relativeRestUri.endsWith(INITIALIZE_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructInitializeMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_SYSTEM_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleSystemMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_PROCESS_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleProcessMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_CHILD_PROCESS_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleProcessMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_JVM_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleJvmProcessMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_CUSTOM_JVM_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleCustomJvmProcessMonitoringJson(values);
} else if (relativeRestUri.endsWith(SCHEDULE_USER_ACTIVITY_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructScheduleUserActivityJson(values);
} else if (relativeRestUri.endsWith(START_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructStartMonitoringJson(values);
} else if (relativeRestUri.endsWith(STOP_MONITORING_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructStopMonitoringJson(values);
} else if (relativeRestUri.endsWith(LEAVE_TESTCASE_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructLeaveTestcaseJson(values);
} else if (relativeRestUri.endsWith(DEINITIALIZE_DB_CONNECTION_RELATIVE_URI)) {
jsonBody = JsonMonitoringUtils.constructDeinitializeDbConnectionJson(values);
} else {
throw new IllegalArgumentException("relativeRestUri does not lead to existing REST method. Please consult the documentation.");
}
response = this.restClient.postObject(jsonBody);
return response;
}
use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.
the class SystemMonitor method performMonitoringOperation.
/**
* Executes specific monitoring service REST call
* If an error is returned/occurred, the error message is returned,
* else null is returned, which means no errors occurred
*/
private String performMonitoringOperation(String monitoredHost, String baseUri, String relativeUri, String errorMessage, Object[] values) {
RestHelper helper = null;
RestResponse response = null;
try {
helper = this.restHelpers.get(monitoredHost);
response = helper.post(monitoredHost, baseUri, relativeUri, values);
if (response.getStatusCode() >= 400) {
log.error(errorMessage + " on '" + monitoredHost + "'");
return response.getBodyAsJson().getString("error");
}
} catch (Exception e) {
log.error("Could not perform monitoring operation!", e);
} finally {
helper.disconnect();
}
return null;
}
Aggregations