1. Test Step 등록
a. Login
b. GetUser
c. ModifyUser
d. DelUser
2. Groovy Script 등록
Login 요청의 응답에 토큰이 포함되어 있고, 이 토큰은 다음 모든 요청의 헤더에 포함되어야 한다.
따라서 Login 이후에 Groovy Script를 추가한다.
import groovy.json.JsonSlurper
import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.support.types.StringToStringsMap
// PARSE TOKEN FROM RESPONSE
def resp = testRunner.testCase.getTestStepByName("Login").getProperty("Response").getValue();
def json = new JsonSlurper().parseText(resp);
def token = json.data['X-AUTH-TOKEN'];
log.info token
// APPLY HEADER FOR REST REQUEST
def headers = new StringToStringsMap();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json");
headers.put("X-AUTH-TOKEN", token);
for( testCase in testRunner.testCase.testSuite.getTestCaseList() ) {
for( testStep in testCase.getTestStepList() ) {
if( testStep instanceof RestTestRequestStepInterface ) {
log.info("Setting HTTP headers ${headers} in test case ${testStep.getLabel()}")
testStep.getTestRequest().setRequestHeaders(headers)
}
}
}