You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@oltu.apache.org by Simone Tripodi <si...@apache.org> on 2014/12/05 19:39:34 UTC

JSON comparison in test case best practice

Hi all mates,

there are a couple of tests in the oauth-2.0/common codebase failing on
CLI, but succeed in Eclipse, see below for details...

I honestly think that comparing serialised JSON strings is not thebest way
to assert two JSON documents are representing exactly the same data, we
need to handle that situation...

Does anybody know a best practice to compare json object, such as XMLDiff
of something else?
I am asking google, in the meanwhile... :)
Best,
-Simo

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

OAuthResponseTest.testErrorResponse:47 expected:<{"[error_uri":"
http://example-uri","error":"error","param":"value","realm":"album","state":"ok","error_description":"error_description]"}>
but
was:<{"[param":"value","error_description":"error_description","realm":"album","state":"ok","error":"error","error_uri":"
http://example-uri]"}>

  WWWAuthHeaderParametersApplierTest.testApplyOAuthParameters:60
expected:<...ope="s1 s2
s3",error[_uri="http://www.example.com/error",error="invalid_token]">
but was:<...ope="s1 s2 s3",error[="invalid_token",error_uri="
http://www.example.com/error]">
http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi

Re: JSON comparison in test case best practice

Posted by Antonio Sanso <as...@adobe.com>.
hi Simo, see comment in the issue

regards

antonio
On Dec 5, 2014, at 10:47 PM, Simone Tripodi <si...@apache.org> wrote:

> patch attached! :P
> 
> http://people.apache.org/~simonetripodi/
> http://twitter.com/simonetripodi
> 
> On Fri, Dec 5, 2014 at 11:56 AM, Simone Tripodi <si...@apache.org>
> wrote:
> 
>> last message, promised: I followed up on OLTU-164
>> 
>> best,
>> -Simo
>> 
>> http://people.apache.org/~simonetripodi/
>> http://twitter.com/simonetripodi
>> 
>> On Fri, Dec 5, 2014 at 11:51 AM, Simone Tripodi <si...@apache.org>
>> wrote:
>> 
>>> just for the record: yes, I noticed it, WWWAuthHeaderParametersApplierTest
>>> does not handle JSON at all :P
>>> please apologise! :D
>>> -Simo
>>> 
>>> http://people.apache.org/~simonetripodi/
>>> http://twitter.com/simonetripodi
>>> 
>>> On Fri, Dec 5, 2014 at 11:44 AM, Simone Tripodi <simonetripodi@apache.org
>>>> wrote:
>>> 
>>>> Looks like there's a nice tool called JSONAssert that does the legwork -
>>>> and I am not surprised someone already thought on doing that :)
>>>> I am fixing broken tests to make them working but will let the
>>>> discussion open in order to find a general agreement... please join!
>>>> All the best,
>>>> -Simo
>>>> 
>>>> [1] http://jsonassert.skyscreamer.org/
>>>> 
>>>> http://people.apache.org/~simonetripodi/
>>>> http://twitter.com/simonetripodi
>>>> 
>>>> On Fri, Dec 5, 2014 at 11:39 AM, Simone Tripodi <
>>>> simonetripodi@apache.org> wrote:
>>>> 
>>>>> Hi all mates,
>>>>> 
>>>>> there are a couple of tests in the oauth-2.0/common codebase failing on
>>>>> CLI, but succeed in Eclipse, see below for details...
>>>>> 
>>>>> I honestly think that comparing serialised JSON strings is not thebest
>>>>> way to assert two JSON documents are representing exactly the same data, we
>>>>> need to handle that situation...
>>>>> 
>>>>> Does anybody know a best practice to compare json object, such as
>>>>> XMLDiff of something else?
>>>>> I am asking google, in the meanwhile... :)
>>>>> Best,
>>>>> -Simo
>>>>> 
>>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>> 
>>>>> OAuthResponseTest.testErrorResponse:47 expected:<{"[error_uri":"
>>>>> http://example-uri","error":"error","param":"value","realm":"album","state":"ok","error_description":"error_description]"}>
>>>>> but
>>>>> was:<{"[param":"value","error_description":"error_description","realm":"album","state":"ok","error":"error","error_uri":"
>>>>> http://example-uri]"}>
>>>>> 
>>>>>  WWWAuthHeaderParametersApplierTest.testApplyOAuthParameters:60
>>>>> expected:<...ope="s1 s2 s3",error[_uri="http://www.example.com/error",error="invalid_token]">
>>>>> but was:<...ope="s1 s2 s3",error[="invalid_token",error_uri="
>>>>> http://www.example.com/error]">
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://twitter.com/simonetripodi
>>>>> 
>>>> 
>>>> 
>>> 
>> 


Re: JSON comparison in test case best practice

Posted by Simone Tripodi <si...@apache.org>.
patch attached! :P

http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi

On Fri, Dec 5, 2014 at 11:56 AM, Simone Tripodi <si...@apache.org>
wrote:

> last message, promised: I followed up on OLTU-164
>
> best,
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://twitter.com/simonetripodi
>
> On Fri, Dec 5, 2014 at 11:51 AM, Simone Tripodi <si...@apache.org>
> wrote:
>
>> just for the record: yes, I noticed it, WWWAuthHeaderParametersApplierTest
>> does not handle JSON at all :P
>> please apologise! :D
>> -Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://twitter.com/simonetripodi
>>
>> On Fri, Dec 5, 2014 at 11:44 AM, Simone Tripodi <simonetripodi@apache.org
>> > wrote:
>>
>>> Looks like there's a nice tool called JSONAssert that does the legwork -
>>> and I am not surprised someone already thought on doing that :)
>>> I am fixing broken tests to make them working but will let the
>>> discussion open in order to find a general agreement... please join!
>>> All the best,
>>> -Simo
>>>
>>> [1] http://jsonassert.skyscreamer.org/
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://twitter.com/simonetripodi
>>>
>>> On Fri, Dec 5, 2014 at 11:39 AM, Simone Tripodi <
>>> simonetripodi@apache.org> wrote:
>>>
>>>> Hi all mates,
>>>>
>>>> there are a couple of tests in the oauth-2.0/common codebase failing on
>>>> CLI, but succeed in Eclipse, see below for details...
>>>>
>>>> I honestly think that comparing serialised JSON strings is not thebest
>>>> way to assert two JSON documents are representing exactly the same data, we
>>>> need to handle that situation...
>>>>
>>>> Does anybody know a best practice to compare json object, such as
>>>> XMLDiff of something else?
>>>> I am asking google, in the meanwhile... :)
>>>> Best,
>>>> -Simo
>>>>
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>> OAuthResponseTest.testErrorResponse:47 expected:<{"[error_uri":"
>>>> http://example-uri","error":"error","param":"value","realm":"album","state":"ok","error_description":"error_description]"}>
>>>> but
>>>> was:<{"[param":"value","error_description":"error_description","realm":"album","state":"ok","error":"error","error_uri":"
>>>> http://example-uri]"}>
>>>>
>>>>   WWWAuthHeaderParametersApplierTest.testApplyOAuthParameters:60
>>>> expected:<...ope="s1 s2 s3",error[_uri="http://www.example.com/error",error="invalid_token]">
>>>> but was:<...ope="s1 s2 s3",error[="invalid_token",error_uri="
>>>> http://www.example.com/error]">
>>>> http://people.apache.org/~simonetripodi/
>>>> http://twitter.com/simonetripodi
>>>>
>>>
>>>
>>
>

Re: JSON comparison in test case best practice

Posted by Simone Tripodi <si...@apache.org>.
last message, promised: I followed up on OLTU-164

best,
-Simo

http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi

On Fri, Dec 5, 2014 at 11:51 AM, Simone Tripodi <si...@apache.org>
wrote:

> just for the record: yes, I noticed it, WWWAuthHeaderParametersApplierTest
> does not handle JSON at all :P
> please apologise! :D
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://twitter.com/simonetripodi
>
> On Fri, Dec 5, 2014 at 11:44 AM, Simone Tripodi <si...@apache.org>
> wrote:
>
>> Looks like there's a nice tool called JSONAssert that does the legwork -
>> and I am not surprised someone already thought on doing that :)
>> I am fixing broken tests to make them working but will let the discussion
>> open in order to find a general agreement... please join!
>> All the best,
>> -Simo
>>
>> [1] http://jsonassert.skyscreamer.org/
>>
>> http://people.apache.org/~simonetripodi/
>> http://twitter.com/simonetripodi
>>
>> On Fri, Dec 5, 2014 at 11:39 AM, Simone Tripodi <simonetripodi@apache.org
>> > wrote:
>>
>>> Hi all mates,
>>>
>>> there are a couple of tests in the oauth-2.0/common codebase failing on
>>> CLI, but succeed in Eclipse, see below for details...
>>>
>>> I honestly think that comparing serialised JSON strings is not thebest
>>> way to assert two JSON documents are representing exactly the same data, we
>>> need to handle that situation...
>>>
>>> Does anybody know a best practice to compare json object, such as
>>> XMLDiff of something else?
>>> I am asking google, in the meanwhile... :)
>>> Best,
>>> -Simo
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> OAuthResponseTest.testErrorResponse:47 expected:<{"[error_uri":"
>>> http://example-uri","error":"error","param":"value","realm":"album","state":"ok","error_description":"error_description]"}>
>>> but
>>> was:<{"[param":"value","error_description":"error_description","realm":"album","state":"ok","error":"error","error_uri":"
>>> http://example-uri]"}>
>>>
>>>   WWWAuthHeaderParametersApplierTest.testApplyOAuthParameters:60
>>> expected:<...ope="s1 s2 s3",error[_uri="http://www.example.com/error",error="invalid_token]">
>>> but was:<...ope="s1 s2 s3",error[="invalid_token",error_uri="
>>> http://www.example.com/error]">
>>> http://people.apache.org/~simonetripodi/
>>> http://twitter.com/simonetripodi
>>>
>>
>>
>

Re: JSON comparison in test case best practice

Posted by Simone Tripodi <si...@apache.org>.
just for the record: yes, I noticed it, WWWAuthHeaderParametersApplierTest
does not handle JSON at all :P
please apologise! :D
-Simo

http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi

On Fri, Dec 5, 2014 at 11:44 AM, Simone Tripodi <si...@apache.org>
wrote:

> Looks like there's a nice tool called JSONAssert that does the legwork -
> and I am not surprised someone already thought on doing that :)
> I am fixing broken tests to make them working but will let the discussion
> open in order to find a general agreement... please join!
> All the best,
> -Simo
>
> [1] http://jsonassert.skyscreamer.org/
>
> http://people.apache.org/~simonetripodi/
> http://twitter.com/simonetripodi
>
> On Fri, Dec 5, 2014 at 11:39 AM, Simone Tripodi <si...@apache.org>
> wrote:
>
>> Hi all mates,
>>
>> there are a couple of tests in the oauth-2.0/common codebase failing on
>> CLI, but succeed in Eclipse, see below for details...
>>
>> I honestly think that comparing serialised JSON strings is not thebest
>> way to assert two JSON documents are representing exactly the same data, we
>> need to handle that situation...
>>
>> Does anybody know a best practice to compare json object, such as XMLDiff
>> of something else?
>> I am asking google, in the meanwhile... :)
>> Best,
>> -Simo
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> OAuthResponseTest.testErrorResponse:47 expected:<{"[error_uri":"
>> http://example-uri","error":"error","param":"value","realm":"album","state":"ok","error_description":"error_description]"}>
>> but
>> was:<{"[param":"value","error_description":"error_description","realm":"album","state":"ok","error":"error","error_uri":"
>> http://example-uri]"}>
>>
>>   WWWAuthHeaderParametersApplierTest.testApplyOAuthParameters:60
>> expected:<...ope="s1 s2 s3",error[_uri="http://www.example.com/error",error="invalid_token]">
>> but was:<...ope="s1 s2 s3",error[="invalid_token",error_uri="
>> http://www.example.com/error]">
>> http://people.apache.org/~simonetripodi/
>> http://twitter.com/simonetripodi
>>
>
>

Re: JSON comparison in test case best practice

Posted by Simone Tripodi <si...@apache.org>.
Looks like there's a nice tool called JSONAssert that does the legwork -
and I am not surprised someone already thought on doing that :)
I am fixing broken tests to make them working but will let the discussion
open in order to find a general agreement... please join!
All the best,
-Simo

[1] http://jsonassert.skyscreamer.org/

http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi

On Fri, Dec 5, 2014 at 11:39 AM, Simone Tripodi <si...@apache.org>
wrote:

> Hi all mates,
>
> there are a couple of tests in the oauth-2.0/common codebase failing on
> CLI, but succeed in Eclipse, see below for details...
>
> I honestly think that comparing serialised JSON strings is not thebest way
> to assert two JSON documents are representing exactly the same data, we
> need to handle that situation...
>
> Does anybody know a best practice to compare json object, such as XMLDiff
> of something else?
> I am asking google, in the meanwhile... :)
> Best,
> -Simo
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> OAuthResponseTest.testErrorResponse:47 expected:<{"[error_uri":"
> http://example-uri","error":"error","param":"value","realm":"album","state":"ok","error_description":"error_description]"}>
> but
> was:<{"[param":"value","error_description":"error_description","realm":"album","state":"ok","error":"error","error_uri":"
> http://example-uri]"}>
>
>   WWWAuthHeaderParametersApplierTest.testApplyOAuthParameters:60
> expected:<...ope="s1 s2 s3",error[_uri="http://www.example.com/error",error="invalid_token]">
> but was:<...ope="s1 s2 s3",error[="invalid_token",error_uri="
> http://www.example.com/error]">
> http://people.apache.org/~simonetripodi/
> http://twitter.com/simonetripodi
>