// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 Ġ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 . workspace . api . p storage Ċ Ċ import Ġorg . junit . Assert .* Ċ import Ġorg . junit . Test ĊĊ Ċ class ĠExternal Entity Index Test Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġconst Ġval ĠINDEX _ ID Ġ= Ġ" External Entity Index Test " ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` base Ġindex Ġtest `() Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠP Entity Storage Builder . create () ĊĊĠĠĠ Ġval Ġindex Ġ= Ġbuilder . get OrCreate External Index < Int >( INDEX _ ID ) ĊĠĠĠ Ġval Ġentity Ġ= Ġbuilder . add P Source Entity (" hello ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ Ġindex . index ( entity , Ġ 1 ) ĊĠĠĠ Ġindex . index ( entity , Ġ 2 ) ĊĠĠĠ ĠassertEquals ( 2 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ Ġindex . remove ( entity ) ĊĠĠĠ ĠassertNull ( index . getData By Entity ( entity )) ĊĠĠĠ Ġindex . index ( entity , Ġ 3 ) ĊĠĠĠ ĠassertEquals ( 3 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġstorage Ġ= Ġbuilder . to Storage () ĊĠĠĠ Ġval Ġnew Index Ġ= Ġstorage . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( new Index ) ĊĠĠĠ ĠassertEquals ( 3 , Ġnew Index !!. getData By Entity ( entity )) ĊĠĠĠ ĠassertEquals ( entity , Ġnew Index . get Entities ( 3 )?. get ( 0 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` update Ġin Ġdiff Ġtest `() Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠP Entity Storage Builder . create () ĊĊĠĠĠ Ġval Ġindex Ġ= Ġbuilder . get OrCreate External Index < Int >( INDEX _ ID ) ĊĠĠĠ Ġval Ġentity Ġ= Ġbuilder . add P Source Entity (" hello ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ Ġindex . index ( entity , Ġ 1 ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġdiff Ġ= ĠP Entity Storage Builder . from ( builder . to Storage ()) ĊĠĠĠ Ġval Ġexternal Index Ġ= Ġdiff . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( external Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġexternal Index ) ĊĠĠĠ ĠassertEquals ( 1 , Ġexternal Index !!. getData By Entity ( entity )) ĊĠĠĠ Ġexternal Index . index ( entity , Ġ 2 ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ ĠassertEquals ( 2 , Ġexternal Index . getData By Entity ( entity )) ĊĊĠĠĠ Ġbuilder . add Diff ( diff ) ĊĠĠĠ ĠassertEquals ( 2 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġstorage Ġ= Ġbuilder . to Storage () ĊĠĠĠ Ġval Ġnew Index Ġ= Ġstorage . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( new Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġnew Index ) ĊĠĠĠ ĠassertEquals ( 2 , Ġnew Index !!. getData By Entity ( entity )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` remove Ġfrom Ġdiff Ġtest `() Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠP Entity Storage Builder . create () ĊĊĠĠĠ Ġval Ġindex Ġ= Ġbuilder . get OrCreate External Index < Int >( INDEX _ ID ) ĊĠĠĠ Ġval Ġentity Ġ= Ġbuilder . add P Source Entity (" hello ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ Ġindex . index ( entity , Ġ 1 ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġdiff Ġ= ĠP Entity Storage Builder . from ( builder . to Storage ()) ĊĠĠĠ Ġval Ġexternal Index Ġ= Ġdiff . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( external Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġexternal Index ) ĊĠĠĠ ĠassertEquals ( 1 , Ġexternal Index !!. getData By Entity ( entity )) ĊĠĠĠ Ġexternal Index . remove ( entity ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ ĠassertNull ( external Index . getData By Entity ( entity )) ĊĊĠĠĠ Ġbuilder . add Diff ( diff ) ĊĠĠĠ ĠassertNull ( index . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġstorage Ġ= Ġbuilder . to Storage () ĊĠĠĠ Ġval Ġnew Index Ġ= Ġstorage . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( new Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġnew Index ) ĊĠĠĠ ĠassertNull ( new Index !!. getData By Entity ( entity )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` add Ġto Ġdiff Ġtest `() Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠP Entity Storage Builder . create () ĊĊĠĠĠ Ġval Ġindex Ġ= Ġbuilder . get OrCreate External Index < Int >( INDEX _ ID ) ĊĠĠĠ Ġval Ġentity Ġ= Ġbuilder . add P Source Entity (" hello ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ Ġindex . index ( entity , Ġ 1 ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġdiff Ġ= ĠP Entity Storage Builder . from ( builder . to Storage ()) ĊĠĠĠ Ġval Ġnew Entity Ġ= Ġbuilder . add P Source Entity (" world ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ Ġval Ġexternal Index Ġ= Ġdiff . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( external Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġexternal Index ) ĊĠĠĠ ĠassertEquals ( 1 , Ġexternal Index !!. getData By Entity ( entity )) ĊĠĠĠ Ġexternal Index . index ( new Entity , Ġ 2 ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ ĠassertEquals ( 1 , Ġexternal Index . getData By Entity ( entity )) ĊĠĠĠ ĠassertEquals ( 2 , Ġexternal Index . getData By Entity ( new Entity )) ĊĊĠĠĠ Ġbuilder . add Diff ( diff ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ ĠassertEquals ( 2 , Ġindex . getData By Entity ( new Entity )) ĊĊĠĠĠ Ġval Ġstorage Ġ= Ġbuilder . to Storage () ĊĠĠĠ Ġval Ġnew Index Ġ= Ġstorage . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( new Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġnew Index ) ĊĠĠĠ ĠassertEquals ( 1 , Ġnew Index !!. getData By Entity ( entity )) ĊĠĠĠ ĠassertEquals ( 2 , Ġnew Index . getData By Entity ( new Entity )) ĊĠĠĠ ĠassertEquals ( entity , Ġnew Index . get Entities ( 1 )?. get ( 0 )) ĊĠĠĠ ĠassertEquals ( new Entity , Ġnew Index . get Entities ( 2 )?. get ( 0 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` remove Ġindex Ġfrom Ġdiff Ġtest `() Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠP Entity Storage Builder . create () ĊĊĠĠĠ Ġval Ġindex Ġ= Ġbuilder . get OrCreate External Index < Int >( INDEX _ ID ) ĊĠĠĠ Ġval Ġentity Ġ= Ġbuilder . add P Source Entity (" hello ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ Ġindex . index ( entity , Ġ 1 ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġdiff Ġ= ĠP Entity Storage Builder . from ( builder . to Storage ()) ĊĠĠĠ Ġdiff . remove External Index ( INDEX _ ID ) ĊĠĠĠ ĠassertNull ( diff . get External Index < Int >( INDEX _ ID )) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġbuilder . add Diff ( diff ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ ĠassertNull ( builder . get External Index < Int >( INDEX _ ID )) ĊĊĠĠĠ Ġval Ġstorage Ġ= Ġbuilder . to Storage () ĊĠĠĠ ĠassertNull ( storage . get External Index < Int >( INDEX _ ID )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` add Ġindex Ġto Ġdiff Ġtest `() Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠP Entity Storage Builder . create () ĊĊĠĠĠ Ġval Ġentity Ġ= Ġbuilder . add P Source Entity (" hello ", ĠP Sample Entity Source (" source ")) ĊĠĠĠ ĠassertNull ( builder . get External Index < Int >( INDEX _ ID )) ĊĊĠĠĠ Ġval Ġdiff Ġ= ĠP Entity Storage Builder . from ( builder . to Storage ()) ĊĠĠĠ Ġval Ġindex Ġ= Ġdiff . get OrCreate External Index < Int >( INDEX _ ID ) ĊĠĠĠ Ġindex . index ( entity , Ġ 1 ) ĊĠĠĠ ĠassertNull ( builder . get External Index < Int >( INDEX _ ID )) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĊĠĠĠ Ġbuilder . add Diff ( diff ) ĊĠĠĠ ĠassertEquals ( 1 , Ġindex . getData By Entity ( entity )) ĊĠĠĠ Ġval Ġentity Index Ġ= Ġbuilder . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( entity Index ) ĊĠĠĠ Ġassert Not Equals ( index , Ġentity Index ) ĊĠĠĠ ĠassertEquals ( 1 , Ġentity Index !!. getData By Entity ( entity )) ĊĊĠĠĠ Ġval Ġstorage Ġ= Ġbuilder . to Storage () ĊĠĠĠ Ġval Ġnew Index Ġ= Ġstorage . get External Index < Int >( INDEX _ ID ) ĊĠĠĠ ĠassertNotNull ( new Index ) ĊĠĠĠ Ġassert Not Equals ( entity Index , Ġnew Index ) ĊĠĠĠ ĠassertEquals ( 1 , Ġnew Index !!. getData By Entity ( entity )) ĊĠ Ġ} Ċ }