1

我将 sopaUI 5.0.0 与库一起使用:

  • BTF 1.2
  • 杰克逊注释-2.0.1
  • 杰克逊核心2.8.1
  • 杰克逊-coreutils-1.8
  • json-schema-core-1.2.5
  • json-schema-validator-2.2.6

我尝试执行此代码:

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.fge.jsonschema.core.report.ProcessingReport
import com.github.fge.jsonschema.main.JsonSchema
import com.github.fge.jsonschema.main.JsonSchemaFactory



def response = testRunner.testCase.getTestStepByName("getClientByID").getPropertyValue("response")
ObjectMapper mapper = new ObjectMapper()
JsonNode invoiceJSON = mapper.readTree(response)

JsonNode invoiceSchemaJSON = mapper.readTree(new File("C:\\test\\resources\\schems\\client-card-rs.json"))
log.info( invoiceSchemaJSON)

JsonSchemaFactory factory = JsonSchemaFactory.byDefault()

JsonSchema invoiceSchema = factory.getJsonSchema(invoiceSchemaJSON)
if (invoiceSchema.validInstance(invoiceJSON)) log.info("Response  Validated!")
else {
testRunner.fail(invoiceSchema.validate(invoiceJSON).toString())
}

但是脚本崩溃并出现错误:

 JsonSchemaFactory factory = JsonSchemaFactory.byDefault()

首先,发出错误:

"write_bigdecimal_as_plain"

之后

java.lang.NoClassDefFoundError: Could not initialize class com.github.fge.jsonschema.SchemaVersion

SoapUI 错误日志:

2016-09-11 15:39:49,202 ERROR [errorlog] java.lang.NoClassDefFoundError: Could not initialize class com.github.fge.jsonschema.SchemaVersion
java.lang.NoClassDefFoundError: Could not initialize class com.github.fge.jsonschema.SchemaVersion
    at com.github.fge.jsonschema.core.load.configuration.LoadingConfigurationBuilder.<init>(LoadingConfigurationBuilder.java:117)
    at com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration.byDefault(LoadingConfiguration.java:151)
    at com.github.fge.jsonschema.main.JsonSchemaFactoryBuilder.<init>(JsonSchemaFactoryBuilder.java:67)
    at com.github.fge.jsonschema.main.JsonSchemaFactory.newBuilder(JsonSchemaFactory.java:123)
    at com.github.fge.jsonschema.main.JsonSchemaFactory.byDefault(JsonSchemaFactory.java:113)
    at com.github.fge.jsonschema.main.JsonSchemaFactory$byDefault.call(Unknown Source)
    at Script6.run(Script6.groovy:20)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:100)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:154)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:277)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

请帮忙。

4

1 回答 1

0

唯一对我有用的解决方案是使用来自com.github.java-json-tools的json-schema-validator-2.2.8-lib.jar ( https://mvnrepository.com/artifact/com.github.java- json-tools/json-schema-validator/2.2.8)而不是 com.github.fge (它支持该项目直到其 2.2.6 版本)。使用提供的库包而不是手动收集所有相关依赖项很重要。不知何故,它不想正常工作。

我在构建于 OpenJDK 8 映像之上的 Docker 容器上使用 SoapUI 5.2.1。

于 2017-10-16T12:28:37.490 回答