Ошибка подтверждения при использовании СодержитInAnyOrder - PullRequest
0 голосов
/ 16 ноября 2018

Я пытаюсь извлечь ответ Json как список строк типа в коде ниже-

List<String> titleTypeAssertions = response.getBody().path("content.items.type");

после System.out.println(titleTypeAssertions); ниже результат - ясно видно, что список хранится в переменной titleTypeAssertions

[[image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, gallery, image, image, image, image, image, image, image, image, image, image, image, image, image, image, page, page, page, page, page, page, image, article, image, image, image, article, image, image, image, image, image, augmPhysStore, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, image, article, image, page, article, video, image, image, article, article, page, video, image, image, article, page, article, image, image, image, page, page, image, page, image, image, page, page, page, article, article, page, article, page, page, image, image, page, augmentedCategory, augmentedCategory, augmentedCategory, article, video, page, article, article, gallery, gallery, gallery, gallery, gallery, article, article, article, article, article, article, article, video, page, video, page, article, image, image, image, page, image, image, image, image, page, video, image, video, image, image, image, image, video, video, video, video, video, page, page, page, page, page, page, page, page, page, page, image, image, image, image, image, image, image, image, image, page, image, video, image, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, page, video, video, page, page, page, image, image, video, article, article, page, image, article, article, page, gallery, article, article, article, article, article, article, article, article, article, article, article, article, article, article, article, image, image, image, image, image, image, image, image, image, video, video, image, image, image, image, image, image, image, article, image, article, video, video, image, image, image, image, article, image, article, page, image, image, image, image, video, video, video, video, video, video, video, video, video, video, video, video]]

но когда я попробую это утверждение-

Assert.assertTrue(titleTypeAssertions.contains("image"));

выдает следующую ошибку-

java.lang.AssertionError at com.salmon.test.step_definitions.api.coremedia.ComponentApiSteps.theApiShouldReturnsValidJsonResponseWithStatusAndContainTitleInAscendingOrder(ComponentApiSteps.java:127)

не уверен, в чем здесь проблема.

это немного ответа json, показываемого для проверки пути в (response.getBody().path("content.items.type"); -

{
"contentKey": "sorting",
"version": "1.2",
"lang": "ru_RU",
"country": "ru",
"content": [
{
"type": "queryList",
"pageNumber": 1,
"items": [
{
"type": "image",
"thumbnailUrl": "http://coremedia.imagesphere.dev.product.ext.net-a-porter.com/testfolder2/6/w84.jpg",
"externalDamItemId": "imagesphere-ton:///dam/picture/testfolder2-6.jpg",
"title": "6.jpg",
"externalDamItemName": "6.jpg",
"mimeType": "image/jpg",
"imageUrl": "http://coremedia.imagesphere.dev.product.ext.net-a-porter.com/testfolder2/6/w500.jpg",
"focusPoint": {
"x": "0.5",
"y": "0.5"
},
"focusArea": {
"x1": "0.0",
"y1": "0.0",
"x2": "1.0",
"y2": "1.0"
},
"callToActionEnabled": true,
"locale": "ru-RU"
},
{
"type": "image",
"externalDamItemId": "throntestbw3:///dam/picture/c356c820-f70b-4099-877d-d645a545cd71",
"mimeType": "image/jpeg",
"imageUrl": "/ycm/resource/blob/121826/21D4C5DE5ECAB9B6C1A98FE8DD710347/hc-jpg-data.jpg",
"focusPoint": {
"x": "0.5",
"y": "0.5"
},
"focusArea": {
"x1": "0.0",
"y1": "0.0",
"x2": "1.0",
"y2": "1.0"
},
"callToActionEnabled": true,
"locale": "ru-RU"
},
{

любая помощь будет принята с благодарностью! благодарю вас!

дальше я изменил путь и попробовал -

List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]");

эти утверждения, похоже, работают-

assertThat(titleTypeAssertions.contains("image"),is(true));
    assertThat(titleTypeAssertions.contains("gallery"),is(true));
    assertThat(titleTypeAssertions.contains("article"),is(true));
assertThat(titleTypeAssertions.contains("augmentedCategory"),is(true);
    assertThat(titleTypeAssertions.contains("video"),is(true)); 
     assertThat(titleTypeAssertions.contains("augmPhysStore"),is(true));

но не это -

assertThat(titleTypeAssertions,containsInAnyOrder("image","gallery","article","video","augmPhysStore","augmentedCategory"));

выдает следующую ошибку-

    java.lang.AssertionError:
Expected: iterable over ["image", "gallery", "article", "video", "augmPhysStore", "augmentedCategory"] in any order
     but: Not matched: "image"
  at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...