com.smartbear.readyapi.client.result.TestStepResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ready-api-testserver-client Show documentation
Show all versions of ready-api-testserver-client Show documentation
Java client library for creating and executing test recipes against Ready!API TestServer
package com.smartbear.readyapi.client.result;
import com.google.common.collect.Lists;
import com.smartbear.readyapi.client.execution.Execution;
import com.smartbear.readyapi.client.model.HarContent;
import com.smartbear.readyapi.client.model.HarEntry;
import com.smartbear.readyapi.client.model.HarHeader;
import com.smartbear.readyapi.client.model.HarLogRoot;
import com.smartbear.readyapi.client.model.HarResponse;
import com.smartbear.readyapi.client.model.TestStepResultReport;
import java.util.Collections;
import java.util.List;
/**
* Result wrapper for individual TestSteps
*/
public class TestStepResult {
private final TestStepResultReport testStepResultReport;
private final Execution execution;
private boolean hasCheckedForHarEntry;
private HarEntry harEntry;
private static final List noHeadersList = Collections.unmodifiableList(Lists.newArrayList());
public TestStepResult(TestStepResultReport testStepResultReport, Execution execution) {
this.testStepResultReport = testStepResultReport;
this.execution = execution;
}
public TestStepResultReport assertionStatus(TestStepResultReport.AssertionStatusEnum assertionStatus) {
return testStepResultReport.assertionStatus(assertionStatus);
}
public String getTransactionId() {
return testStepResultReport.getTransactionId();
}
public String getTestStepName() {
return testStepResultReport.getTestStepName();
}
public Long getTimeTaken() {
return testStepResultReport.getTimeTaken();
}
public TestStepResultReport.AssertionStatusEnum getAssertionStatus() {
return testStepResultReport.getAssertionStatus();
}
public List getMessages() {
return testStepResultReport.getMessages();
}
public boolean hasTransactionData() {
return getHarEntry() != null;
}
public HarResponse getHarResponse() {
HarEntry harEntry = getHarEntry();
return harEntry == null ? null : harEntry.getResponse();
}
public HarEntry getHarEntry() {
if (harEntry == null && !hasCheckedForHarEntry) {
HarLogRoot logRoot = execution.getTestServerApi().getTransactionLog(execution.getId(),
testStepResultReport.getTransactionId(), execution.getAuth());
if (hasHarEntry(logRoot)) {
harEntry = logRoot.getLog().getEntries().get(0);
}
hasCheckedForHarEntry = true;
}
return harEntry;
}
private boolean hasHarEntry(HarLogRoot logRoot) {
return logRoot != null && logRoot.getLog() != null && logRoot.getLog().getEntries() != null &&
logRoot.getLog().getEntries().size() > 0;
}
public String getResponseContent() {
HarResponse harResponse = getHarResponse();
if (harResponse != null) {
HarContent content = harResponse.getContent();
if (content != null) {
return content.getText();
}
}
return null;
}
public List getResponseHeaders() {
HarResponse harResponse = getHarResponse();
return harResponse == null ? noHeadersList : harResponse.getHeaders();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy