/razpub/test_src/razie/assets/test/TestXpAssets.scala

http://razpub.googlecode.com/ · Scala · 122 lines · 75 code · 23 blank · 24 comment · 0 complexity · 92b1a0e9cff6e69d3416888dae45702b MD5 · raw file

  1. package razie.assets.test
  2. //import com.razie.pub.agent._
  3. //import com.razie.pub.agent.test._
  4. //import com.razie.agent._
  5. //import com.razie.assets._
  6. import com.razie.pub.base.data._
  7. import com.razie.pub.base._
  8. import com.razie.pub.base.log._
  9. import com.razie.pub.comms._
  10. import com.razie.pub.lightsoa._
  11. import com.razie.pub.assets._
  12. //import com.razie.pub.actionables._
  13. //import com.razie.pub.actionables.library._
  14. import org.scalatest.junit._
  15. import razie._
  16. import razie.assets._
  17. object S {
  18. val (p, c1, c2) = (new TestParentC("p1"), new TestChildC("c1") , new TestChildC("c2"))
  19. }
  20. /**
  21. * this is a blank asset - use it any way you see fit, to simplify testing - find its uses in our tests
  22. */
  23. @SoaAsset(descr = "parent with reflected child", bindings=Array("http"))
  24. class TestParentC (key:String) extends BlankAsset ("TestParentC", key, AA("kuku", "p1c")) with HasMeta {
  25. override def metaSpec = new MetaSpec (new Meta (AI cmdicon("TestParentC", "/public/pics/web.png"), null),
  26. List(new MetaAssoc("pcc", "TestParentC", "TestChildC", "composition", "1-*", "parent", "children")))
  27. def children = List (S.c1, S.c2)
  28. }
  29. /**
  30. * this is a blank asset - use it any way you see fit, to simplify testing - find its uses in our tests
  31. */
  32. @SoaAsset(descr = "parent with reflected child", bindings=Array("http"))
  33. class TestChildC(key:String) extends BlankAsset ("TestChildC", key, null) with HasMeta {
  34. def parent = S.p
  35. }
  36. /** test asset definition samples, complete with bindings */
  37. class TestXpAssets extends JUnit3Suite {
  38. override def setUp = {
  39. ExecutionContext.resetJVM
  40. AssetMgr.init (new InventoryAssetMgr)
  41. razie.Assets.manage(new BlankAsset ("blankie1", "first", razie.AA("kuku", "kiki1")))
  42. razie.Assets.manage(new BlankAsset ("blankie1", "second", razie.AA("kuku", "kiki2")))
  43. // association stuff
  44. razie.Assets manage new BlankAsset ("TestParentB", "p1", razie.AA("kuku", "p1"))
  45. razie.Assets manage new BlankAsset ("TestChildB", "c1", razie.AA("kuku", "c1"))
  46. razie.Assets manage new BlankAsset ("TestChildB", "c2", razie.AA("kuku", "c2"))
  47. razie.Assets manage new BlankAsset ("TestFriendB", "f1", razie.AA("kuku", "f1"))
  48. razie.Assets manage new BlankAsset ("TestFriendB", "f2", razie.AA("kuku", "f2"))
  49. razie.Metas.addAssoc (new MetaAssoc("c", "TestParentB", "TestChildB", "composition", "1-*"))
  50. razie.Metas.addAssoc (new MetaAssoc("a", "TestChildB", "TestFriendB", "association", "*"))
  51. razie.Assets.associate (razie.Asset("TestParentB:p1"), razie.Asset("TestChildB:c1"))
  52. razie.Assets.associate (razie.Asset("TestParentB:p1"), razie.Asset("TestChildB:c2"))
  53. razie.Assets.associate (razie.Asset("TestChildB:c1"), razie.Asset("TestFriendB:f1"))
  54. razie.Assets.associate (razie.Asset("TestChildB:c2"), razie.Asset("TestFriendB:f2"))
  55. List (S.p, S.c1, S.c2).foreach(razie.Assets.manage(_))
  56. // }
  57. }
  58. def testSimpleAsset = expect (2) {
  59. (Assets xpl ("/blankie1")).size
  60. }
  61. def testSimpleCond = expect (Some("kiki1")) {
  62. val r = Assets xpe ("/blankie1[@kuku=='kiki1']")
  63. razie.AA.sa(r, "kuku")
  64. }
  65. def testAllCond = {
  66. expect ("kiki1") { Assets xpa ("/blankie1[@kuku!='kiki2']/@kuku") }
  67. expect ("kiki1") { Assets xpa ("/blankie1[@kuku~='kiki1']/@kuku") }
  68. expect ("kiki1") { Assets xpa ("/blankie1[@kuku=='kiki1']/@kuku") }
  69. expect ("kiki1") { Assets xpa ("/blankie1[@kuku == 'kiki1']/@kuku") }
  70. expect ("kiki1") { Assets xpa ("/blankie1[kuku=='kiki1']/@kuku") }
  71. expect ("kiki1") { Assets xpa ("/blankie1[kuku==kiki1]/@kuku") }
  72. }
  73. def testAttr = expect ("kiki1") { Assets xpa ("/blankie1[@kuku=='kiki1']/@kuku") }
  74. // key is a reserved attribute
  75. def testAttrKey = expect ("first") { Assets xpa ("/blankie1[key==first]/@key") }
  76. def testassoc1JustTestxpl = expect (2) { (Assets xpl "/TestParentB/TestChildB").size }
  77. def testassoc1 = expect (List("c1", "c2")) { Assets xpla "/TestParentB/TestChildB/@kuku" }
  78. def testassoc1r = expect (List("p1", "p1")) { Assets xpla "/TestChildB/TestParentB/@kuku" }
  79. def testassoc1a = expect (List("c1", "c2")) { Assets xpla "/TestParentB/{c}TestChildB/@kuku" }
  80. def testassoc2 = expect ("f1") { Assets xpa "/TestChildB[kuku==c1]/TestFriendB/@kuku" }
  81. def testassoc2a = expect ("f1") { Assets xpa "/TestChildB[kuku==c1]/{a}TestFriendB/@kuku" }
  82. def testassoc3 = expect ("f1") { Assets xpa "/TestParentB/TestChildB[kuku==c1]/TestFriendB/@kuku" }
  83. def testassoc3a = expect ("f1") { Assets xpa "/TestParentB/{c}TestChildB[kuku==c1]/{a}TestFriendB/@kuku" }
  84. def testreflectedassoc1 = expect ("c1") {Assets xpa "/TestParentC/TestChildC[key==c1]/@key" }
  85. def testreflectedassoc11 = expect ("c1") { Assets xpa "/TestParentC/TestChildC[key==c1]/@key" }
  86. def testreflectedassoc12 = expect ("c1") { Assets xpa "/TestParentC/TestChildC[key==c1]/@key" }
  87. def testreflectedassoc2 = expect ("p1") { Assets xpa "/TestChildC[key==c1]/TestParentC/@key" }
  88. def testreflectedassoc3 = expect ("c1") { Assets xpa "/TestChildC[key==c1]/@key" }
  89. override def tearDown = {
  90. // super.tearDown
  91. }
  92. }
  93. /**
  94. * the expressions we support:
  95. * <ul>
  96. * <li> "/TestParentB/TestChildB" - must have exactly one TestParentB -> {composition} -> TestChildB
  97. * <li> "/TestChildB/TestFriendB" - must have exactly one TestChildB -> {association} -> TestFriendB
  98. * <li> "/TestChildB/{D}/TestFriendD" - must have exactly one TestChildB -> {association:name=D} -> TestFriendB
  99. */