1 package org.apache.ojb.broker; 2 3 17 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 21 import org.apache.ojb.broker.query.Criteria; 22 import org.apache.ojb.broker.query.QueryByCriteria; 23 import org.apache.ojb.broker.query.QueryFactory; 24 import org.apache.ojb.broker.query.Query; 25 import org.apache.ojb.junit.PBTestCase; 26 27 33 public class EmptyTableTest extends PBTestCase 34 { 35 public EmptyTableTest(String name) 36 { 37 super(name); 38 } 39 40 public static void main(String [] args) 41 { 42 final String [] arr = {EmptyTableTest.class.getName()}; 43 junit.textui.TestRunner.main(arr); 44 } 45 46 public void setUp() throws Exception 47 { 48 super.setUp(); 49 QueryByCriteria query = QueryFactory.newQuery(TestObject.class, new Criteria()); 50 broker.deleteByQuery(query); 51 broker.clearCache(); 52 } 53 54 public void testObjectByQuery_1() throws Exception 55 { 56 String dummy = "nothing_to_find"; 57 Criteria criteria = new Criteria(); 58 criteria.addEqualTo("name", dummy); 59 QueryByCriteria query = QueryFactory.newQuery(TestObject.class, criteria); 60 Object result = broker.getObjectByQuery(query); 61 assertNull("We don't expect a result object", result); 62 } 63 64 public void testObjectByExample_1() throws Exception 65 { 66 String dummy = "nothing_to_find"; 67 TestObject t = new TestObject(); 68 t.setId(new Integer (1234)); 69 t.setName(dummy); 70 Query query = QueryFactory.newQuery(t); 71 Object result = broker.getObjectByQuery(query); 72 assertNull("We don't expect a result object", result); 73 } 74 75 public void testCollectionByQuery_1() throws Exception 76 { 77 String dummy = "nothing_to_find"; 78 Criteria criteria = new Criteria(); 79 criteria.addEqualTo("name", dummy); 80 Query query = QueryFactory.newQuery(TestObject.class, criteria); 81 Collection result = broker.getCollectionByQuery(query); 82 for(Iterator iterator = result.iterator(); iterator.hasNext();) 83 { 84 iterator.next(); 85 fail("We don't expect any result objects"); 86 } 87 } 88 89 public void testCollectionByQuery_2() throws Exception 90 { 91 String dummy = "nothing_to_find"; 92 Criteria criteria = new Criteria(); 93 criteria.addEqualTo("name", dummy); 94 Query query = QueryFactory.newQuery(TestObject.class, criteria); 95 query.setStartAtIndex(1); 97 query.setEndAtIndex(20); 98 Collection result = broker.getCollectionByQuery(query); 99 for(Iterator iterator = result.iterator(); iterator.hasNext();) 100 { 101 iterator.next(); 102 fail("We don't expect any result objects"); 103 } 104 } 105 106 public void testIteratorByQuery_1() throws Exception 107 { 108 String dummy = "nothing_to_find"; 109 Criteria criteria = new Criteria(); 110 criteria.addEqualTo("name", dummy); 111 Query query = QueryFactory.newQuery(TestObject.class, criteria); 112 Iterator result = broker.getIteratorByQuery(query); 113 while(result.hasNext()) 114 { 115 result.next(); 116 fail("We don't expect any result objects"); 117 } 118 } 119 120 public void testIteratorByQuery_2() throws Exception 121 { 122 String dummy = "nothing_to_find"; 123 Criteria criteria = new Criteria(); 124 criteria.addEqualTo("name", dummy); 125 Query query = QueryFactory.newQuery(TestObject.class, criteria); 126 query.setStartAtIndex(1); 127 query.setEndAtIndex(20); 128 Iterator result = broker.getIteratorByQuery(query); 129 while(result.hasNext()) 130 { 131 result.next(); 132 fail("We don't expect any result objects"); 133 } 134 } 135 136 137 138 139 143 public static class TestObject 144 { 145 private Integer id; 146 private String name; 147 148 public Integer getId() 149 { 150 return id; 151 } 152 153 public void setId(Integer id) 154 { 155 this.id = id; 156 } 157 158 public String getName() 159 { 160 return name; 161 } 162 163 public void setName(String name) 164 { 165 this.name = name; 166 } 167 } 168 } 169 | Popular Tags |