空手道:奇怪的匹配行为JSON

时间:2018-05-04 12:17:11

标签: karate

我偶然发现了一个对我来说根本没有意义的JSON匹配行为,因为如果我通过并行运行程序执行我的功能,则匹配失败(不应该)。但是,如果我独立运行该功能(在IntelliJ中,运行功能),匹配将按预期成功。我对此几乎失去了理智。 :)

这是我从REST调用中获得的实际响应:

[
{
"servicePointInfo": {
  "cplID": "CPL123",
  "klsID": 26035132,
  "type": "Gebaeudeteil",
  "state": "FREI",
  "stateText": "Freier Service Point",
  "plannedDisconnectDate": null,
  "recentInfo": {
    "firstName": null,
    "surname": null,
    "MSN0": null
  }
},
"buildingInfo": {
  "type": null,
  "typeText": null,
  "part": "FeH",
  "partText": "Fernsprechh�uschen",
  "partNumber": null,
  "partInfo": "vor Telekom",
  "partAlignment": null,
  "level": null,
  "levelText": null,
  "levelNumber": null,
  "floor": null,
  "floorText": null,
  "flatNumber": null,
  "flatInfo": null
}
},
{
"servicePointInfo": {
  "cplID": "CPL456",
  "klsID": 26035132,
  "type": "Wohnung",
  "state": "FREI",
  "stateText": "Freier Service Point",
  "plannedDisconnectDate": null,
  "recentInfo": {
    "firstName": "Karl",
    "surname": "Schaefer",
    "MSN0": null
  }
},
"buildingInfo": {
  "type": "M",
  "typeText": "Mehrfamilienhaus",
  "part": null,
  "partText": null,
  "partNumber": null,
  "partInfo": null,
  "partAlignment": null,
  "level": "EG",
  "levelText": "Erdgescho�",
  "levelNumber": null,
  "floor": "R",
  "floorText": "rechts",
  "flatNumber": "12",
  "flatInfo": null
}
},
{
"servicePointInfo": {
  "cplID": "CPL789",
  "klsID": 26035132,
  "type": "Gebaeudeteil",
  "state": "FREI",
  "stateText": "Freier Service Point",
  "plannedDisconnectDate": null,
  "recentInfo": {
    "firstName": null,
    "surname": null,
    "MSN0": null
  }
},
"buildingInfo": {
  "type": null,
  "typeText": null,
  "part": "VH",
  "partText": "Vorderhaus",
  "partNumber": null,
  "partInfo": "gelbe Haus mit dem h�sslichen Dach",
  "partAlignment": null,
  "level": null,
  "levelText": null,
  "levelNumber": null,
  "floor": null,
  "floorText": null,
  "flatNumber": null,
  "flatInfo": null
}
}
]

这是我用于匹配的JSON。它实际上是复制的实际响应,我使用了一些模糊匹配表达式,因为我认为特殊字符(ä,ß)可能是问题所在:

[
{
"servicePointInfo": {
  "cplID": "CPL123",
  "klsID": 26035132,
  "type": "Gebaeudeteil",
  "state": "FREI",
  "stateText": "Freier Service Point",
  "plannedDisconnectDate": null,
  "recentInfo": {
    "firstName": null,
    "surname": null,
    "MSN0": null
  }
},
"buildingInfo": {
  "type": null,
  "typeText": null,
  "part": "FeH",
  "partText": "#notnull",
  "partNumber": null,
  "partInfo": "vor Telekom",
  "partAlignment": null,
  "level": null,
  "levelText": null,
  "levelNumber": null,
  "floor": null,
  "floorText": null,
  "flatNumber": null,
  "flatInfo": null
}
},
{
"servicePointInfo": {
  "cplID": "CPL456",
  "klsID": 26035132,
  "type": "Wohnung",
  "state": "FREI",
  "stateText": "Freier Service Point",
  "plannedDisconnectDate": null,
  "recentInfo": {
    "firstName": "Karl",
    "surname": "Schaefer",
    "MSN0": null
  }
},
"buildingInfo": {
  "type": "M",
  "typeText": "Mehrfamilienhaus",
  "part": null,
  "partText": null,
  "partNumber": null,
  "partInfo": null,
  "partAlignment": null,
  "level": "EG",
  "levelText": "#notnull",
  "levelNumber": null,
  "floor": "R",
  "floorText": "rechts",
  "flatNumber": "12",
  "flatInfo": null
}
},
{
"servicePointInfo": {
  "cplID": "CPL789",
  "klsID": 26035132,
  "type": "Gebaeudeteil",
  "state": "FREI",
  "stateText": "Freier Service Point",
  "plannedDisconnectDate": null,
  "recentInfo": {
    "firstName": null,
    "surname": null,
    "MSN0": null
  }
},
"buildingInfo": {
  "type": null,
  "typeText": null,
  "part": "VH",
  "partText": "Vorderhaus",
  "partNumber": null,
  "partInfo": "#notnull",
  "partAlignment": null,
  "level": null,
  "levelText": null,
  "levelNumber": null,
  "floor": null,
  "floorText": null,
  "flatNumber": null,
  "flatInfo": null
}
}
]

这是匹配结果:

com.intuit.karate.exception.KarateException: path: $, actual: '[{"servicePointInfo":{"cplID":"CPL123","klsID":26035132,"type":"Gebaeudeteil","state":"FREI","stateText":"Freier Service Point","plannedDisconnectDate":null,"recentInfo":{"firstName":null,"surname":null,"MSN0":null}},"buildingInfo":{"type":null,"typeText":null,"part":"FeH","partText":"Fernsprechh�uschen","partNumber":null,"partInfo":"vor Telekom","partAlignment":null,"level":null,"levelText":null,"levelNumber":null,"floor":null,"floorText":null,"flatNumber":null,"flatInfo":null}},{"servicePointInfo":{"cplID":"CPL456","klsID":26035132,"type":"Wohnung","state":"FREI","stateText":"Freier Service Point","plannedDisconnectDate":null,"recentInfo":{"firstName":"Karl","surname":"Schaefer","MSN0":null}},"buildingInfo":{"type":"M","typeText":"Mehrfamilienhaus","part":null,"partText":null,"partNumber":null,"partInfo":null,"partAlignment":null,"level":"EG","levelText":"Erdgescho�","levelNumber":null,"floor":"R","floorText":"rechts","flatNumber":"12","flatInfo":null}},{"servicePointInfo":{"cplID":"CPL789","klsID":26035132,"type":"Gebaeudeteil","state":"FREI","stateText":"Freier Service Point","plannedDisconnectDate":null,"recentInfo":{"firstName":null,"surname":null,"MSN0":null}},"buildingInfo":{"type":null,"typeText":null,"part":"VH","partText":"Vorderhaus","partNumber":null,"partInfo":"gelbe Haus mit dem h�sslichen Dach","partAlignment":null,"level":null,"levelText":null,"levelNumber":null,"floor":null,"floorText":null,"flatNumber":null,"flatInfo":null}}]', expected: '[{"servicePointInfo":{"cplID":"CPL123","klsID":26035132,"type":"Gebaeudeteil","state":"FREI","stateText":"Freier Service Point","plannedDisconnectDate":null,"recentInfo":{"firstName":null,"surname":null,"MSN0":null}},"buildingInfo":{"type":null,"typeText":null,"part":"FeH","partText":"#notnull","partNumber":null,"partInfo":"vor Telekom","partAlignment":null,"level":null,"levelText":null,"levelNumber":null,"floor":null,"floorText":null,"flatNumber":null,"flatInfo":null}},{"servicePointInfo":{"cplID":"CPL456","klsID":26035132,"type":"Wohnung","state":"FREI","stateText":"Freier Service Point","plannedDisconnectDate":null,"recentInfo":{"firstName":"Karl","surname":"Schaefer","MSN0":null}},"buildingInfo":{"type":"M","typeText":"Mehrfamilienhaus","part":null,"partText":null,"partNumber":null,"partInfo":null,"partAlignment":null,"level":"EG","levelText":"#notnull","levelNumber":null,"floor":"R","floorText":"rechts","flatNumber":"12","flatInfo":null}},{"servicePointInfo":{"cplID":"CPL789","klsID":26035132,"type":"Gebaeudeteil","state":"FREI","stateText":"Freier Service Point","plannedDisconnectDate":null,"recentInfo":{"firstName":null,"surname":null,"MSN0":null}},"buildingInfo":{"type":null,"typeText":null,"part":"VH","partText":"Vorderhaus","partNumber":null,"partInfo":"#notnull","partAlignment":null,"level":null,"levelText":null,"levelNumber":null,"floor":null,"floorText":null,"flatNumber":null,"flatInfo":null}}]', reason: not equal

有人经历过这样的行为吗? 欢呼声

- 由于@Peter -

的回答而编辑

这是我目前的build.gradle:

version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
   mavenCentral()
}

sourceSets {
    test {
        resources {
            srcDir file('src/test/java')
            exclude '**/*.java'
        }
    }
 }


dependencies {
    testCompile('com.intuit.karate:karate-apache:0.8.0.RC3')
    testCompile('com.intuit.karate:karate-junit4:0.8.0.RC3')
    testCompile('net.masterthought:cucumber-reporting:3.8.0')
    testCompile('org.apache.commons:commons-text:1.3')
    testCompile('com.googlecode.json-simple:json-simple:1.1.1')
}

test.dependsOn clean

1 个答案:

答案 0 :(得分:1)

不用担心,将maven surefire插件强制转换为UTF-8应解决此问题,请在此处记录:https://github.com/intuit/karate#fileencoding

return Promise.resolve({});