PageRenderTime 28ms CodeModel.GetById 12ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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