1 21 package com.db4o.db4ounit.common.soda.experiments; 22 25 import com.db4o.db4ounit.common.soda.*; 26 import com.db4o.db4ounit.common.soda.classes.simple.*; 27 import com.db4o.db4ounit.common.soda.classes.typedhierarchy.*; 28 import com.db4o.db4ounit.common.soda.wrapper.untyped.*; 29 import com.db4o.query.*; 30 31 32 33 34 35 36 37 public class STMagicTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements STInterface { 39 40 public String str; 41 42 public STMagicTestCase() { 43 } 44 45 private STMagicTestCase(String str) { 46 this.str = str; 47 } 48 49 public String toString() { 50 return "STMagicTestCase: " + str; 51 } 52 53 54 public Object returnSomething() { 55 return str; 56 } 57 58 public Object [] createData() { 59 return new Object [] { new STMagicTestCase("aaa"), new STMagicTestCase("aaax")}; 60 } 61 62 68 public void testUnconstrainedClass() { 69 Query q = newQuery(); 70 q.descend("str").constrain("aaa"); 71 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect( 72 q, 73 new Object [] { new STMagicTestCase("aaa"), new STStringTestCase("aaa"), new STStringUTestCase("aaa")}); 74 } 75 76 81 public void testMultiClass() { 82 Query q = newQuery(); 83 q.constrain(STDoubleTestCase.class).or(q.constrain(STStringTestCase.class)); 84 Object [] stDoubles = new STDoubleTestCase().createData(); 85 Object [] stStrings = new STStringTestCase().createData(); 86 Object [] res = new Object [stDoubles.length + stStrings.length]; 87 System.arraycopy(stDoubles, 0, res, 0, stDoubles.length); 88 System.arraycopy(stStrings, 0, res, stDoubles.length, stStrings.length); 89 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(q, res); 90 } 91 92 97 public void testExecuteAnyNode() { 98 Query q = newQuery(); 99 q.constrain(new STTH1TestCase().createData()[5]); 100 q = q.descend("h2").descend("h3"); 101 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STTH3("str3")); 104 } 105 106 113 126 132 public void testInterface() { 133 Query q = newQuery(); 134 q.constrain(STInterface.class); 135 q.constrain(new Evaluation() { 136 public void evaluate(Candidate candidate) { 137 STInterface sti = (STInterface) candidate.getObject(); 138 candidate.include(sti.returnSomething().equals("aaa")); 139 } 140 }); 141 com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(q, new Object [] { new STMagicTestCase("aaa"), new STStringTestCase("aaa")}); 142 } 143 144 145 } 146 | Popular Tags |