// ĠCopyright Ġ 2 0 0 0 - 2 0 1 8 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . internal . statistics Ċ Ċ import Ġcom . google . gson . JsonObject Ċ import Ġcom . google . gson . Json Parser Ċ import Ġcom . intellij . internal . statistic . event Log .* Ċ import Ġcom . intellij . openapi . util . io . File Util Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertNull Ċ import Ġkotlin . test . assertTrue Ċ Ċ class ĠFeature Event Log Serialization Test Ġ{ ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Without Data () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" test - event - type "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event WithData () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id "," test - event - type ") ĊĠĠĠ Ġevent . event . addData (" param ", Ġ 2 3 L ) ĊĠĠĠ Ġtest Event Serialization ( event , Ġfalse , Ġ" param ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Recorder With Spaces () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder Ġid ", Ġ" test - event - type "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Recorder With Spaces Esc aping () Ġ{ ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder Ġid ", Ġ" test - event - type "), Ġ" recorder _ id ", Ġ" test - event - type ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Tab () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" event \ t type "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Tab Esc aping () Ġ{ ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event \ t type "), Ġ" recorder - id ", Ġ" event _ type ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Quotes () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" event \" type "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Quotes Esc aping () Ġ{ ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event \" type "), Ġ" recorder - id ", Ġ" event type ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Tab In Data Key () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" my Ġkey ", Ġ" value ") ĊĠĠĠ Ġtest Event Serialization ( event , Ġfalse , Ġ" my _ key ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Tab In Data Key Esc aping () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" my Ġkey ", Ġ" value ") ĊĊĠĠĠ Ġval Ġdata Ġ= ĠHashMap < String , ĠAny >() ĊĠĠĠ Ġdata [" my _ key "] Ġ= Ġ" value " ĊĠĠĠ Ġtest Event Esc aping ( event , Ġ" recorder - id ", Ġ" event - type ", Ġdata ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Tab In Data Value () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" key ", Ġ" my Ġvalue ") ĊĠĠĠ Ġtest Event Serialization ( event , Ġfalse , Ġ" key ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Tab In Data Value Esc aping () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" key ", Ġ" my Ġvalue ") ĊĊĠĠĠ Ġval Ġdata Ġ= ĠHashMap < String , ĠAny >() ĊĠĠĠ Ġdata [" key "] Ġ= Ġ" my _ value " ĊĠĠĠ Ġtest Event Esc aping ( event , Ġ" recorder - id ", Ġ" event - type ", Ġdata ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest GroupId With Unicode () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id \ u 7 A 9 7 \ u 0 1 3 C ", Ġ" event - id "), Ġfalse ) ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder \ u 5 F 3 9 id ", Ġ" event - id "), Ġfalse ) ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id \ u 0 2 BE ", Ġ" event - id "), Ġfalse ) ĊĠĠĠ Ġtest Event Serialization ( new Event (" ï¿½ï¿½ recorder - id ", Ġ" event - id "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest GroupId With Unicode Esc aping () Ġ{ ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id \ u 7 A 9 7 \ u 0 1 3 C ", Ġ" event - id "), Ġ" recorder - id ?? ", Ġ" event - id ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder \ u 5 F 3 9 id ", Ġ" event - id "), Ġ" recorder ? id ", Ġ" event - id ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id \ u 0 2 BE ", Ġ" event - id "), Ġ" recorder - id ?", Ġ" event - id ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" ï¿½ï¿½ recorder - id ", Ġ" event - id "), Ġ" ?? recorder - id ", Ġ" event - id ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Unicode () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" event \ u 7 A 9 7 type "), Ġfalse ) ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" event \ u 5 F 3 9 type \ u 0 2 BE \ u 0 1 3 C "), Ġfalse ) ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" event \ u 0 2 BE "), Ġfalse ) ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ"\ uFF FD \ uFF FD \ u FFF De vent "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Unicode Esc aping () Ġ{ ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event \ u 7 A 9 7 type "), Ġ" recorder - id ", Ġ" event ? type ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event å¼¹ type Ê ¾ Ä ¼ "), Ġ" recorder - id ", Ġ" event ? type ?? ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event Ê ¾ "), Ġ" recorder - id ", Ġ" event ?") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ"\ uFF FD \ uFF FD \ u FFF De vent "), Ġ" recorder - id ", Ġ" ??? event ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event - 1 2 "), Ġ" recorder - id ", Ġ" event - 1 2 ") ĊĠĠĠ Ġtest Event Esc aping ( new Event (" recorder - id ", Ġ" event @ 1 2 "), Ġ" recorder - id ", Ġ" event @ 1 2 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Unicode In Data Key () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" my \ uFF FD key ", Ġ" value ") ĊĠĠĠ Ġevent . event . addData (" some \ u 0 1 3 C \ u 0 2 BE \ u 0 3 7 C ", Ġ" value ") ĊĠĠĠ Ġevent . event . addData ("\ u 0 1 3 C \ u 0 3 7 C key ", Ġ" value ") ĊĠĠĠ Ġtest Event Serialization ( event , Ġfalse , Ġ" my ? key ", Ġ" some ?? ?", Ġ" ?? key ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Unicode In Data Key Esc aping () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" my \ uFF FD key ", Ġ" value ") ĊĠĠĠ Ġevent . event . addData (" some \ u 0 1 3 C \ u 0 2 BE \ u 0 3 7 C ", Ġ" value ") ĊĠĠĠ Ġevent . event . addData ("\ u 0 1 3 C \ u 0 3 7 C key ", Ġ" value ") ĊĊĠĠĠ Ġval Ġdata Ġ= ĠHashMap < String , ĠAny >() ĊĠĠĠ Ġdata [" my ? key "] Ġ= Ġ" value " ĊĠĠĠ Ġdata [" some ??? "] Ġ= Ġ" value " ĊĠĠĠ Ġdata [" ?? key "] Ġ= Ġ" value " ĊĠĠĠ Ġtest Event Esc aping ( event , Ġ" recorder - id ", Ġ" event - type ", Ġdata ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Unicode In Data Value () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" first - key ", Ġ" my \ uFF FD value ") ĊĠĠĠ Ġevent . event . addData (" second - key ", Ġ" some \ u 0 1 3 C \ u 0 2 BE \ u 0 3 7 C ") ĊĠĠĠ Ġevent . event . addData (" third - key ", Ġ"\ u 0 1 3 C \ u 0 3 7 C value ") ĊĠĠĠ Ġtest Event Serialization ( event , Ġfalse , Ġ" first - key ", Ġ" second - key ", Ġ" third - key ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Action With Unicode In Data Value Esc aping () Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġnew Event (" recorder - id ", Ġ" event - type ") ĊĠĠĠ Ġevent . event . addData (" first - key ", Ġ" my \ uFF FD value ") ĊĠĠĠ Ġevent . event . addData (" second - key ", Ġ" some \ u 0 1 3 C \ u 0 2 BE \ u 0 3 7 C ") ĊĠĠĠ Ġevent . event . addData (" third - key ", Ġ"\ u 0 1 3 C \ u 0 3 7 C value ") ĊĊĠĠĠ Ġval Ġdata Ġ= ĠHashMap < String , ĠAny >() ĊĠĠĠ Ġdata [" first - key "] Ġ= Ġ" my ? value " ĊĠĠĠ Ġdata [" second - key "] Ġ= Ġ" some ?? ?" ĊĠĠĠ Ġdata [" third - key "] Ġ= Ġ" ?? value " ĊĠĠĠ Ġtest Event Esc aping ( event , Ġ" recorder - id ", Ġ" event - type ", Ġdata ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Request With Single Record () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id "," IU ", Ġ" generated - device - id ", Ġfalse , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IU ", Ġ" generated - device - id ", Ġfalse , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Request With Multiple Records () Ġ{ ĊĠĠĠ Ġval Ġfirst Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġfirst . add ( new Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġfirst . add ( new Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĠĠĠ Ġval Ġsecond Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġsecond . add ( new Event (" recorder - id ", Ġ" third - type ")) ĊĠĠĠ Ġsecond . add ( new Event (" recorder - id - 2 ", Ġ" for th - type ")) ĊĠĠĠ Ġval Ġrecords Ġ= ĠArrayList < Log Event Record >() ĊĠĠĠ Ġrecords . add ( Log Event Record ( first )) ĊĠĠĠ Ġrecords . add ( Log Event Record ( second )) ĊĊĠĠĠ Ġval Ġrequest Ġ= ĠLog Event Record Request (" recorder - id "," IU ", Ġ" generated - device - id ", Ġrecords , Ġfalse ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IU ", Ġ" generated - device - id ", Ġfalse , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Request With Custom Product Code () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id "," IC ", Ġ" generated - device - id ", Ġfalse , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IC ", Ġ" generated - device - id ", Ġfalse , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Request With Custom DeviceId () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id "," IU ", Ġ" my - test - id ", Ġfalse , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IU ", Ġ" my - test - id ", Ġfalse , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Request With Internal () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id "," IU ", Ġ" generated - device - id ", Ġtrue , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IU ", Ġ" generated - device - id ", Ġtrue , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Custom Request () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id "," PY ", Ġ" abcdef g ", Ġtrue , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" PY ", Ġ" abcdef g ", Ġtrue , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Request With State Events () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( newState Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( newState Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id ", Ġ" IU ", Ġ" generated - device - id ", Ġfalse , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IU ", Ġ" generated - device - id ", Ġfalse , Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event Custom Request With State Events () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( newState Event (" recorder - id ", Ġ" first - type ")) ĊĠĠĠ Ġevents . add ( newState Event (" recorder - id - 2 ", Ġ" second - type ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= Ġrequest By Events (" recorder - id ", Ġ" IC ", Ġ" abcdef g ", Ġtrue , Ġevents ) ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( request )). as JsonObject ĊĠĠĠ Ġassert Log Event Content IsValid ( json , Ġ" recorder - id ", Ġ" IC ", Ġ" abcdef g ", Ġtrue , Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event With Build Number () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( new Event (" recorder - id ", Ġ" test - event - type ", Ġbuild =" 1 8 2 . 2 5 6 7 . 1 "), Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest State Event () Ġ{ ĊĠĠĠ Ġtest Event Serialization ( newState Event (" config - recorder ", Ġ" my - config ", Ġbuild =" 1 8 2 . 2 5 6 7 . 1 "), Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Deserialization No Events () Ġ{ ĊĠĠĠ Ġtest Deserialization () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Deserialization Single Event () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" test - event - type ")) ĊĊĠĠĠ Ġtest Deserialization ( events ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Deserialization Single Batch () Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġevents . add ( new Event (" recorder - id ", Ġ" first ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 1 ", Ġ" second ")) ĊĠĠĠ Ġevents . add ( new Event (" recorder - id - 2 ", Ġ" third ")) ĊĊĠĠĠ Ġtest Deserialization ( events ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Deserialization Two Complete B atches () Ġ{ ĊĠĠĠ Ġval Ġfirst Batch Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġval Ġsecond Batch Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġfirst Batch . add ( new Event (" recorder - id ", Ġ" first ")) ĊĠĠĠ Ġfirst Batch . add ( new Event (" recorder - id - 1 ", Ġ" second ")) ĊĠĠĠ Ġfirst Batch . add ( new Event (" recorder - id - 2 ", Ġ" third ")) ĊĠĠĠ Ġsecond Batch . add ( new Event (" recorder - id ", Ġ" four th ")) ĊĠĠĠ Ġsecond Batch . add ( new Event (" recorder - id - 1 ", Ġ" f ifth ")) ĊĠĠĠ Ġsecond Batch . add ( new Event (" recorder - id - 2 ", Ġ" six th ")) ĊĊĠĠĠ Ġtest Deserialization ( first Batch , Ġsecond Batch ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Deserialization Incomplete Batch () Ġ{ ĊĠĠĠ Ġval Ġfirst Batch Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġval Ġsecond Batch Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġfirst Batch . add ( new Event (" recorder - id ", Ġ" first ")) ĊĠĠĠ Ġfirst Batch . add ( new Event (" recorder - id - 1 ", Ġ" second ")) ĊĠĠĠ Ġfirst Batch . add ( new Event (" recorder - id - 2 ", Ġ" third ")) ĊĠĠĠ Ġsecond Batch . add ( new Event (" recorder - id ", Ġ" four th ")) ĊĊĠĠĠ Ġtest Deserialization ( first Batch , Ġsecond Batch ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Invalid Event Without Session () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= ĊĠĠĠĠĠ Ġ"{\" build \":\" 1 8 3 . 0 \",\" bucket \":\" - 1 \",\" time \": 1 5 2 9 4 2 8 0 4 5 3 2 2 ," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" group \":{\" id \":\" lifecycle \",\" version \":\" 2 \" }," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" event \":{\" count \": 1 ,\" data \": {}, \" id \":\" idea app . started \" }" Ġ+ ĊĠĠĠĠĠ Ġ" }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Invalid Event With Time AsString () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= ĊĠĠĠĠĠ Ġ"{\" session \": 1 2 3 4 5 ,\" build \":\" 1 8 3 . 0 \",\" bucket \":\" - 1 \",\" time \":\" current - time \ "," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" group \":{\" id \":\" lifecycle \",\" version \":\" 2 \" }," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" event \":{\" count \": 1 ,\" data \": {}, \" id \":\" idea app . started \" }" Ġ+ ĊĠĠĠĠĠ Ġ" }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Invalid Event Without Group () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= ĊĠĠĠĠĠ Ġ"{\" session \": 1 2 3 4 5 ,\" build \":\" 1 8 3 . 0 \",\" bucket \":\" - 1 \",\" time \": 1 5 2 9 4 2 8 0 4 5 3 2 2 ," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" event \":{\" count \": 1 ,\" data \": {}, \" id \":\" idea app . started \" }" Ġ+ ĊĠĠĠĠĠ Ġ" }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Invalid Event Without Event () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= ĊĠĠĠĠĠ Ġ"{\" session \": 1 2 3 4 5 ,\" build \":\" 1 8 3 . 0 \",\" bucket \":\" - 1 \",\" time \": 1 5 2 9 4 2 8 0 4 5 3 2 2 ," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" group \":{\" id \":\" lifecycle \",\" version \":\" 2 \" }" Ġ+ ĊĠĠĠĠĠ Ġ" }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Event In Old Format () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= ĊĠĠĠĠĠ Ġ"{\" session \":\" e 4 d 6 2 3 6 d 6 2 f 8 \",\" bucket \":\" - 1 \",\" time \": 1 5 2 8 8 8 5 5 7 6 0 2 0 ," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" recorder \":{\" id \":\" action - stats \",\" version \":\" 2 \" }," Ġ+ ĊĠĠĠĠĠĠĠ Ġ"\" action \":{\" data \": {}, \" id \":\" Run \" }" Ġ+ ĊĠĠĠĠĠ Ġ" }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Invalid Json Event () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= Ġ"\" session \": 1 2 3 4 5 ,\" build \":\" 1 8 3 . 0 \",\" bucket \":\" - 1 \",\" time \": 1 5 2 9 4 2 8 0 4 5 3 2 2 }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Invalid Event () Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= Ġ"{\" a \": 1 2 3 4 5 ,\" b \":\" 1 8 3 . 0 \",\" d \":\" - 1 \" }" ĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( json ) ĊĠĠĠ ĠassertNull ( de serialized ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtest Deserialization ( var arg Ġbatches : ĠList < Log Event >) Ġ{ ĊĠĠĠ Ġval Ġevents Ġ= ĠArrayList < Log Event >() ĊĠĠĠ Ġval Ġrecords Ġ= ĠArrayList < Log Event Record >() ĊĠĠĠ Ġfor Ġ( batch Ġin Ġbatches ) Ġ{ ĊĠĠĠĠĠ Ġevents . addAll ( batch ) ĊĠĠĠĠĠ Ġrecords . add ( Log Event Record ( batch )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġexpected Ġ= ĠLog Event Record Request (" recorder - id "," IU ", Ġ" user - id ", Ġrecords , Ġfalse ) ĊĊĠĠĠ Ġval Ġlog Ġ= ĠFile Util . create TempFile (" feature - event - log ", Ġ". log ") ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġval Ġout Ġ= ĠStringBuilder () ĊĠĠĠĠĠ Ġfor Ġ( event Ġin Ġevents ) Ġ{ ĊĠĠĠĠĠĠĠ Ġout . append ( Log Event Serializer . toString ( event )). append ("\ n ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠFile Util . write ToFile ( log , Ġout . toString ()) ĊĠĠĠĠĠ Ġval Ġactual Ġ= ĠLog Event Record Request . create ( log , Ġ" recorder - id ", Ġ" IU ", Ġ" user - id ", Ġ 6 0 0 , ĠLog Event True Filter , Ġfalse ) ĊĠĠĠĠĠ ĠassertEquals ( expected , Ġactual ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġfinally Ġ{ ĊĠĠĠĠĠ ĠFile Util . delete ( log ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtest Event Serialization ( event : ĠLog Event , Ġis State : ĠBoolean , Ġvar arg Ġdata Options : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġline Ġ= ĠLog Event Serializer . toString ( event ) ĊĠĠĠ Ġassert Log Event IsValid ( Json Parser (). parse ( line ). as JsonObject , Ġis State , Ġ* data Options ) ĊĊĠĠĠ Ġval Ġdeserialized Ġ= ĠLog Event Serializer . fromString ( line ) ĊĠĠĠ ĠassertEquals ( event , Ġdeserialized ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtest Event Esc aping ( event : ĠLog Event , Ġexpected GroupId : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexpected EventId : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexpected Data : ĠMap < String , ĠAny > Ġ= ĠHashMap ()) Ġ{ ĊĠĠĠ Ġval Ġjson Ġ= ĠJson Parser (). parse ( Log Event Serializer . toString ( event )). as JsonObject ĊĠĠĠ Ġassert Log Event IsValid ( json , Ġfalse ) ĊĊĠĠĠ ĠassertEquals ( expected GroupId , Ġjson . getAs JsonObject (" group "). get (" id "). asString ) ĊĠĠĠ ĠassertEquals ( expected EventId , Ġjson . getAs JsonObject (" event "). get (" id "). asString ) ĊĊĠĠĠ Ġval Ġobj Ġ= Ġjson . getAs JsonObject (" event "). get (" data "). as JsonObject ĊĠĠĠ Ġfor Ġ( option Ġin Ġexpected Data . keys ) Ġ{ ĊĠĠĠĠĠ ĠassertTrue ( isValid ( option )) ĊĠĠĠĠĠ ĠassertTrue ( obj . get ( option ). is Json Primitive ) ĊĠĠĠĠĠ ĠassertEquals ( obj . get ( option ). asString , Ġexpected Data [ option ]) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Log Event Content IsValid ( json : ĠJsonObject , Ġrecorder : ĠString , Ġproduct : ĠString , Ġdevice : ĠString , Ġinternal : ĠBoolean , Ġis State : ĠBoolean ) Ġ{ ĊĠĠĠ ĠassertTrue ( json . get (" device "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . get (" device "). asString )) ĊĠĠĠ ĠassertEquals ( device , Ġjson . get (" device "). asString ) ĊĊĠĠĠ ĠassertTrue ( json . get (" product "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . get (" product "). asString )) ĊĠĠĠ ĠassertEquals ( product , Ġjson . get (" product "). asString ) ĊĊĠĠĠ ĠassertTrue ( json . get (" recorder "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . get (" recorder "). asString )) ĊĠĠĠ ĠassertEquals ( recorder , Ġjson . get (" recorder "). asString ) ĊĊĠĠĠ ĠassertEquals ( internal , Ġjson . has (" internal ")) ĊĠĠĠ Ġif Ġ( internal ) Ġ{ ĊĠĠĠĠĠ ĠassertTrue ( json . get (" internal "). as Boolean ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertTrue ( json . get (" records "). is JsonArray ) ĊĠĠĠ Ġval Ġrecords Ġ= Ġjson . get (" records "). as JsonArray ĊĠĠĠ Ġfor Ġ( record Ġin Ġrecords ) Ġ{ ĊĠĠĠĠĠ ĠassertTrue ( record . is JsonObject ) ĊĠĠĠĠĠ ĠassertTrue ( record . as JsonObject . get (" events "). is JsonArray ) ĊĠĠĠĠĠ Ġval Ġevents Ġ= Ġrecord . as JsonObject . get (" events "). as JsonArray ĊĠĠĠĠĠ Ġfor Ġ( event Ġin Ġevents ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertTrue ( event . is JsonObject ) ĊĠĠĠĠĠĠĠ Ġassert Log Event IsValid ( event . as JsonObject , Ġis State ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Log Event IsValid ( json : ĠJsonObject , Ġis State : ĠBoolean , Ġvar arg Ġdata Options : ĠString ) Ġ{ ĊĠĠĠ ĠassertTrue ( json . get (" time "). is Json Primitive ) ĊĊĠĠĠ ĠassertTrue ( json . get (" session "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . get (" session "). asString )) ĊĊĠĠĠ ĠassertTrue ( json . get (" bucket "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . get (" bucket "). asString )) ĊĊĠĠĠ ĠassertTrue ( json . get (" build "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . get (" build "). asString )) ĊĊĠĠĠ ĠassertTrue ( json . get (" group "). is JsonObject ) ĊĠĠĠ ĠassertTrue ( json . getAs JsonObject (" group "). get (" id "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( json . getAs JsonObject (" group "). get (" version "). is Json Primitive ) ĊĠĠĠ ĠassertTrue ( isValid ( json . getAs JsonObject (" group "). get (" id "). asString )) ĊĠĠĠ ĠassertTrue ( isValid ( json . getAs JsonObject (" group "). get (" version "). asString )) ĊĊĠĠĠ ĠassertTrue ( json . get (" event "). is JsonObject ) ĊĠĠĠ ĠassertTrue ( json . getAs JsonObject (" event "). get (" id "). is Json Primitive ) ĊĠĠĠ ĠassertEquals ( is State , Ġjson . getAs JsonObject (" event "). has (" state ")) ĊĠĠĠ Ġif Ġ( is State ) Ġ{ ĊĠĠĠĠĠ ĠassertTrue ( json . getAs JsonObject (" event "). get (" state "). as Boolean ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertEquals (! is State , Ġjson . getAs JsonObject (" event "). has (" count ")) ĊĠĠĠ Ġif Ġ(! is State ) Ġ{ ĊĠĠĠĠĠ ĠassertTrue ( json . getAs JsonObject (" event "). get (" count "). as Json Primitive . isNumber ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertTrue ( json . getAs JsonObject (" event "). get (" data "). is JsonObject ) ĊĠĠĠ ĠassertTrue ( isValid ( json . getAs JsonObject (" event "). get (" id "). asString )) ĊĊĠĠĠ Ġval Ġobj Ġ= Ġjson . getAs JsonObject (" event "). get (" data "). as JsonObject ĊĠĠĠ Ġfor Ġ( option Ġin Ġdata Options ) Ġ{ ĊĠĠĠĠĠ ĠassertTrue ( isValid ( option )) ĊĠĠĠĠĠ ĠassertTrue ( obj . get ( option ). is Json Primitive ) ĊĠĠĠĠĠ ĠassertTrue ( isValid ( obj . get ( option ). asString )) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠisValid ( str Ġ: ĠString ) Ġ: ĠBoolean Ġ{ ĊĠĠĠ Ġval Ġno Tabs Or Spaces Ġ= Ġstr . indexOf (" Ġ") Ġ== Ġ- 1 Ġ&& Ġstr . indexOf ("\ t ") Ġ== Ġ- 1 Ġ&& Ġstr . indexOf ("\" ") Ġ== Ġ- 1 ĊĠĠĠ Ġreturn Ġno Tabs Or Spaces Ġ&& Ġstr . matches ("[ \\ p { ASCII } ]* ". to Regex ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġrequest By Events ( recorder : ĠString , Ġproduct : ĠString , Ġdevice : ĠString , Ġinternal : ĠBoolean , Ġevents : ĠList < Log Event >) Ġ: ĠLog Event Record Request Ġ{ ĊĠĠĠ Ġval Ġrecords Ġ= ĠArrayList < Log Event Record >() ĊĠĠĠ Ġrecords . add ( Log Event Record ( events )) ĊĠĠĠ Ġreturn ĠLog Event Record Request ( recorder , Ġproduct , Ġdevice , Ġrecords , Ġinternal ) ĊĠ Ġ} Ċ }