Assertion failure while using containsInAnyOrder












0















I am trying to extract Json response as a list of type string in the code below-



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


upon System.out.println(titleTypeAssertions);
below is the result- it is clearly evident that the list is being stored in variable 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]]


but when i try this assertion-



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


it throws the following error-



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


not sure what seems to be the issue here.



this is a bit of json response being shown to verify the path in(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"
},
{


any help would be greatly appreciated!
thank you!



further to it, i changed the path and tried -



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


these assertions seem to work-



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));


but not this -



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


it throws the following error-



    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)









share|improve this question

























  • I am wondering why are you getting two square brackets [[ around your list? Can you try to print size of list?

    – codeLover
    Nov 16 '18 at 10:50











  • Hi there,Thanks for the reply. you are right there seems to be an issue with the path. the count is returning as 1. but when i tried List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]"); the count is 270

    – Raj
    Nov 18 '18 at 13:20


















0















I am trying to extract Json response as a list of type string in the code below-



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


upon System.out.println(titleTypeAssertions);
below is the result- it is clearly evident that the list is being stored in variable 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]]


but when i try this assertion-



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


it throws the following error-



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


not sure what seems to be the issue here.



this is a bit of json response being shown to verify the path in(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"
},
{


any help would be greatly appreciated!
thank you!



further to it, i changed the path and tried -



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


these assertions seem to work-



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));


but not this -



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


it throws the following error-



    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)









share|improve this question

























  • I am wondering why are you getting two square brackets [[ around your list? Can you try to print size of list?

    – codeLover
    Nov 16 '18 at 10:50











  • Hi there,Thanks for the reply. you are right there seems to be an issue with the path. the count is returning as 1. but when i tried List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]"); the count is 270

    – Raj
    Nov 18 '18 at 13:20
















0












0








0








I am trying to extract Json response as a list of type string in the code below-



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


upon System.out.println(titleTypeAssertions);
below is the result- it is clearly evident that the list is being stored in variable 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]]


but when i try this assertion-



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


it throws the following error-



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


not sure what seems to be the issue here.



this is a bit of json response being shown to verify the path in(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"
},
{


any help would be greatly appreciated!
thank you!



further to it, i changed the path and tried -



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


these assertions seem to work-



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));


but not this -



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


it throws the following error-



    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)









share|improve this question
















I am trying to extract Json response as a list of type string in the code below-



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


upon System.out.println(titleTypeAssertions);
below is the result- it is clearly evident that the list is being stored in variable 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]]


but when i try this assertion-



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


it throws the following error-



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


not sure what seems to be the issue here.



this is a bit of json response being shown to verify the path in(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"
},
{


any help would be greatly appreciated!
thank you!



further to it, i changed the path and tried -



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


these assertions seem to work-



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));


but not this -



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


it throws the following error-



    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)






java api junit rest-assured rest-assured-jsonpath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 13:25







Raj

















asked Nov 15 '18 at 22:27









RajRaj

2117




2117













  • I am wondering why are you getting two square brackets [[ around your list? Can you try to print size of list?

    – codeLover
    Nov 16 '18 at 10:50











  • Hi there,Thanks for the reply. you are right there seems to be an issue with the path. the count is returning as 1. but when i tried List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]"); the count is 270

    – Raj
    Nov 18 '18 at 13:20





















  • I am wondering why are you getting two square brackets [[ around your list? Can you try to print size of list?

    – codeLover
    Nov 16 '18 at 10:50











  • Hi there,Thanks for the reply. you are right there seems to be an issue with the path. the count is returning as 1. but when i tried List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]"); the count is 270

    – Raj
    Nov 18 '18 at 13:20



















I am wondering why are you getting two square brackets [[ around your list? Can you try to print size of list?

– codeLover
Nov 16 '18 at 10:50





I am wondering why are you getting two square brackets [[ around your list? Can you try to print size of list?

– codeLover
Nov 16 '18 at 10:50













Hi there,Thanks for the reply. you are right there seems to be an issue with the path. the count is returning as 1. but when i tried List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]"); the count is 270

– Raj
Nov 18 '18 at 13:20







Hi there,Thanks for the reply. you are right there seems to be an issue with the path. the count is returning as 1. but when i tried List<String> titleTypeAssertions = response.getBody().path("content.items.type[0]"); the count is 270

– Raj
Nov 18 '18 at 13:20














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328761%2fassertion-failure-while-using-containsinanyorder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328761%2fassertion-failure-while-using-containsinanyorder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues