Я пытался создать Groovy-скрипт, который анализирует ответы jdbc и REST, помещает результаты в модель и затем сравнивает их. Я следую за этим ответом: Динамически сравнивайте ответы Rest XML / JSON и JDBC, используя массив Groovy в SoapUI , но без особого успеха. Мой ответ JDBC ниже:
<Results>
<ResultSet fetchSize="128">
<Row rowNumber="1">
<ID>BCE448A4DFB94C6892D957DB8275D2AC</ID>
<NAME>SevDealRecord</NAME>
<AMOUNT/>
<CREATIONDATE>2012-06-20 11:31:48.0</CREATIONDATE>
<MODIFICATIONDATE>2012-06-20 15:20:02.0</MODIFICATIONDATE>
<CURRENCY>EUR</CURRENCY>
<REFERENCEDATE>2012-06-20 00:00:00.0</REFERENCEDATE>
<STATUSCODE>DPE_2</STATUSCODE>
<STATUSDESCRIPTION>2 - Preliminary evaluation in progress (Direct PE)</STATUSDESCRIPTION>
<ASSIGNEDTOUSERIQID>E506565555A6486FBA8FCC431F4E979E</ASSIGNEDTOUSERIQID>
<ASSIGNTOUSERDISPLAYNAME>NMISO</ASSIGNTOUSERDISPLAYNAME>
<WORKFLOWID>140AE208F9334FB9946BFEAF5C89CE18</WORKFLOWID>
<WORKFLOWNAME>1 - Direct Private Equity</WORKFLOWNAME>
</Row>
<Row rowNumber="2">
<ID>D4DBB1B906A04DE49AB1FF3EE4653180</ID>
<NAME>T28678</NAME>
<AMOUNT/>
<CREATIONDATE>2012-06-21 13:45:36.0</CREATIONDATE>
<MODIFICATIONDATE>2012-06-21 13:46:03.0</MODIFICATIONDATE>
<CURRENCY>EUR</CURRENCY>
<REFERENCEDATE>2012-06-21 00:00:00.0</REFERENCEDATE>
<STATUSCODE>DRAFT</STATUSCODE>
<STATUSDESCRIPTION>Draft{F}Brouillon</STATUSDESCRIPTION>
<ASSIGNEDTOUSERIQID>E506565555A6486FBA8FCC431F4E979E</ASSIGNEDTOUSERIQID>
<ASSIGNTOUSERDISPLAYNAME>NMISO</ASSIGNTOUSERDISPLAYNAME>
<WORKFLOWID/>
<WORKFLOWNAME/>
</Row>
А вот ответ ОТДЫХА:
[{
"id": "12CF6F8DA3B148D98D63A428EC7F8D7B",
"name": "アコム株式会社",
"amount1": null,
"creationDate": null,
"modificationDate": "2019-01-14T16:28:21.027+00:00",
"currency": "USD",
"referenceDate": "2019-01-04T00:00:00+00:00",
"status": {
"code": "DRAFT",
"description": "Draft"
},
"assignedToUser": {
"id": "E506565555A6486FBA8FCC431F4E979E",
"displayName": "NMISO"
},
"assignedToGroup": null,
"workflow": null
}, {
"id": "AA4F19E5C8B34222865EFED293D52146",
"name": "Lürssen",
"amount1": null,
"creationDate": null,
"modificationDate": "2019-01-14T16:28:20.963+00:00",
"currency": "USD",
"referenceDate": "2019-01-04T00:00:00+00:00",
"status": {
"code": "DRAFT",
"description": "Draft"
},
"assignedToUser": {
"id": "E506565555A6486FBA8FCC431F4E979E",
"displayName": "NMISO"
},
"assignedToGroup": null,
"workflow": null
},
Что я пробовал:
@groovy.transform.Canonical
class Model {
def id
def name
def amount1
def creationDate
def modificationDate
def currency
def referenceDate
def statusCode
def statusDescription
def assignedToUserIqid
def assignedToUserDisplayName
def assignedToGroup
def workflowId
def workflowName
// this will accept jdbc row
def buildJdbcData(row) {
row.with {
id = ID
name = NAME
amount1 = AMOUNT
creationDate = CREATIONDATE
modificationDate = MODIFICATIONDATE
currency = CURRENCY
referenceDate = REFERENCEDATE
statusCode = STATUSCODE
statusDescription = STATUSDESCRIPTION
assignedToUserDisplayName = ASSIGNTOUSERDISPLAYNAME
assignedToGroup = ASSIGNTOUSERDISPLAYNAME
workflowId = WORKFLOWID
workflowName = WORKFLOWNAME
}
}
def buildJsonData(slurp){
id = slurp.id
name = slurp.name
amount1 = slurp.amount1
creationDate = slurp.creationDate
modificationDate = slurp.modificationDate
currency = slurp.currency
referenceDate = slurp.referenceDate
statusCode = slurp.status.code
statusDescription = slurp.status.description
assignedToUserIqid = slurp.assignedToUser.id
assignedToUserDisplayName = slurp.assignedToUser.displayName
assignedToGroup = slurp.assignedToGroup
workflowId = slurp.workflow
}
}
def jdbcResponse = context.expand('${JDBC_DealList#ResponseAsXml}')
def results = new XmlSlurper().parseText(jdbcResponse)
def jdbcDataObjects = []
results.ResultSet.Row.each { row ->
jdbcDataObjects.add(new Model().buildJdbcData(row)) //Objects not added properly to the model
}
log.info jdbcDataObjects
def jsonResponse = testRunner.testCase.testSteps["Deals"].testRequest.response.contentAsString
def jsonObjects = new JsonSlurper().parseText(jsonResponse)
log.info jsonObjects
def jsonDataObjects = [] jsonDataObjects.add(new Model().buildJsonData(jsonObjects))
Теперь log.info jdbcDataObjects
дает мне элементы WORKFLOWNAME из ответа jdbc. И log.info jsonObjects
дает мне всю модель JSON, и я не уверен, как добавить все элементы в определенную выше модель? Некоторая помощь будет высоко ценится.