java.lang.AssertionError: JSON path expect different result
I have a Junit test which works with mockMvc, and it happens something weird.
My test case looks like that...
@Test
public void getSignatureData() throws Exception {
String dataXValues = "[0,5,10,15,20]";
String dataYValues1 = "[100.0,20.0,30.0,40.0,50.0]";
String dataYValues2 = "[1.0,2.0,3.0,4.0,5.0]";
this.mockMvc
.perform(get("/sources/fmf/actuators/w01.pmv/signatures/1486684800000"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.signature.id").value("1486684800000"))
.andExpect(jsonPath("$.signature.actuatorId").value("w01.pmv"))
.andExpect(jsonPath("$.signature.operation").value("OPEN"))
.andExpect(jsonPath("$.signature.timestamp").value("1486684800000"))
.andExpect(jsonPath("$.signature.ref").value(true))
.andExpect(jsonPath("$.signature.current").value(false))
.andExpect(jsonPath("$.signature.valid").value(true))
.andExpect(jsonPath("$.signature.source").value("A"))
.andExpect(jsonPath("$.data[0].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[0].sensorType").value("PRESSURE"))
.andExpect(jsonPath("$.data[0].xValues", is(dataXValues)))
.andExpect(jsonPath("$.data[0].yValues").value(dataYValues1))
.andExpect(jsonPath("$.data[1].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[1].sensorType").value("FLOW"))
.andExpect(jsonPath("$.data[1].xValues").value(dataXValues))
.andExpect(jsonPath("$.data[1].yValues").value(dataYValues2));
}
And I expect it works, but I got this message.
java.lang.AssertionError: JSON path "$.data[0].xValues"
Expected: is "[0,5,10,15,20]"
but: was <[0,5,10,15,20]>
Expected :is "[0,5,10,15,20]"
Actual :<[0,5,10,15,20]>
are there someone can help me?
In this case, I use those..
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import static org.hamcrest.Matchers.*;
junit jsonpath mockmvc
add a comment |
I have a Junit test which works with mockMvc, and it happens something weird.
My test case looks like that...
@Test
public void getSignatureData() throws Exception {
String dataXValues = "[0,5,10,15,20]";
String dataYValues1 = "[100.0,20.0,30.0,40.0,50.0]";
String dataYValues2 = "[1.0,2.0,3.0,4.0,5.0]";
this.mockMvc
.perform(get("/sources/fmf/actuators/w01.pmv/signatures/1486684800000"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.signature.id").value("1486684800000"))
.andExpect(jsonPath("$.signature.actuatorId").value("w01.pmv"))
.andExpect(jsonPath("$.signature.operation").value("OPEN"))
.andExpect(jsonPath("$.signature.timestamp").value("1486684800000"))
.andExpect(jsonPath("$.signature.ref").value(true))
.andExpect(jsonPath("$.signature.current").value(false))
.andExpect(jsonPath("$.signature.valid").value(true))
.andExpect(jsonPath("$.signature.source").value("A"))
.andExpect(jsonPath("$.data[0].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[0].sensorType").value("PRESSURE"))
.andExpect(jsonPath("$.data[0].xValues", is(dataXValues)))
.andExpect(jsonPath("$.data[0].yValues").value(dataYValues1))
.andExpect(jsonPath("$.data[1].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[1].sensorType").value("FLOW"))
.andExpect(jsonPath("$.data[1].xValues").value(dataXValues))
.andExpect(jsonPath("$.data[1].yValues").value(dataYValues2));
}
And I expect it works, but I got this message.
java.lang.AssertionError: JSON path "$.data[0].xValues"
Expected: is "[0,5,10,15,20]"
but: was <[0,5,10,15,20]>
Expected :is "[0,5,10,15,20]"
Actual :<[0,5,10,15,20]>
are there someone can help me?
In this case, I use those..
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import static org.hamcrest.Matchers.*;
junit jsonpath mockmvc
add a comment |
I have a Junit test which works with mockMvc, and it happens something weird.
My test case looks like that...
@Test
public void getSignatureData() throws Exception {
String dataXValues = "[0,5,10,15,20]";
String dataYValues1 = "[100.0,20.0,30.0,40.0,50.0]";
String dataYValues2 = "[1.0,2.0,3.0,4.0,5.0]";
this.mockMvc
.perform(get("/sources/fmf/actuators/w01.pmv/signatures/1486684800000"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.signature.id").value("1486684800000"))
.andExpect(jsonPath("$.signature.actuatorId").value("w01.pmv"))
.andExpect(jsonPath("$.signature.operation").value("OPEN"))
.andExpect(jsonPath("$.signature.timestamp").value("1486684800000"))
.andExpect(jsonPath("$.signature.ref").value(true))
.andExpect(jsonPath("$.signature.current").value(false))
.andExpect(jsonPath("$.signature.valid").value(true))
.andExpect(jsonPath("$.signature.source").value("A"))
.andExpect(jsonPath("$.data[0].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[0].sensorType").value("PRESSURE"))
.andExpect(jsonPath("$.data[0].xValues", is(dataXValues)))
.andExpect(jsonPath("$.data[0].yValues").value(dataYValues1))
.andExpect(jsonPath("$.data[1].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[1].sensorType").value("FLOW"))
.andExpect(jsonPath("$.data[1].xValues").value(dataXValues))
.andExpect(jsonPath("$.data[1].yValues").value(dataYValues2));
}
And I expect it works, but I got this message.
java.lang.AssertionError: JSON path "$.data[0].xValues"
Expected: is "[0,5,10,15,20]"
but: was <[0,5,10,15,20]>
Expected :is "[0,5,10,15,20]"
Actual :<[0,5,10,15,20]>
are there someone can help me?
In this case, I use those..
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import static org.hamcrest.Matchers.*;
junit jsonpath mockmvc
I have a Junit test which works with mockMvc, and it happens something weird.
My test case looks like that...
@Test
public void getSignatureData() throws Exception {
String dataXValues = "[0,5,10,15,20]";
String dataYValues1 = "[100.0,20.0,30.0,40.0,50.0]";
String dataYValues2 = "[1.0,2.0,3.0,4.0,5.0]";
this.mockMvc
.perform(get("/sources/fmf/actuators/w01.pmv/signatures/1486684800000"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.signature.id").value("1486684800000"))
.andExpect(jsonPath("$.signature.actuatorId").value("w01.pmv"))
.andExpect(jsonPath("$.signature.operation").value("OPEN"))
.andExpect(jsonPath("$.signature.timestamp").value("1486684800000"))
.andExpect(jsonPath("$.signature.ref").value(true))
.andExpect(jsonPath("$.signature.current").value(false))
.andExpect(jsonPath("$.signature.valid").value(true))
.andExpect(jsonPath("$.signature.source").value("A"))
.andExpect(jsonPath("$.data[0].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[0].sensorType").value("PRESSURE"))
.andExpect(jsonPath("$.data[0].xValues", is(dataXValues)))
.andExpect(jsonPath("$.data[0].yValues").value(dataYValues1))
.andExpect(jsonPath("$.data[1].sensorSource").value("SEMA"))
.andExpect(jsonPath("$.data[1].sensorType").value("FLOW"))
.andExpect(jsonPath("$.data[1].xValues").value(dataXValues))
.andExpect(jsonPath("$.data[1].yValues").value(dataYValues2));
}
And I expect it works, but I got this message.
java.lang.AssertionError: JSON path "$.data[0].xValues"
Expected: is "[0,5,10,15,20]"
but: was <[0,5,10,15,20]>
Expected :is "[0,5,10,15,20]"
Actual :<[0,5,10,15,20]>
are there someone can help me?
In this case, I use those..
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import static org.hamcrest.Matchers.*;
junit jsonpath mockmvc
junit jsonpath mockmvc
asked Aug 15 at 11:31
Lady Hams
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I run into same issue and solved it by converting expected and actual arrays in test to Lists using:
Arrays.asList()
That solved this issue for me.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51857869%2fjava-lang-assertionerror-json-path-expect-different-result%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I run into same issue and solved it by converting expected and actual arrays in test to Lists using:
Arrays.asList()
That solved this issue for me.
add a comment |
I run into same issue and solved it by converting expected and actual arrays in test to Lists using:
Arrays.asList()
That solved this issue for me.
add a comment |
I run into same issue and solved it by converting expected and actual arrays in test to Lists using:
Arrays.asList()
That solved this issue for me.
I run into same issue and solved it by converting expected and actual arrays in test to Lists using:
Arrays.asList()
That solved this issue for me.
answered Nov 20 at 16:03
Jan Dudek
1
1
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51857869%2fjava-lang-assertionerror-json-path-expect-different-result%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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