1 package org.jacorb.test.notification; 2 3 import java.util.Iterator ; 4 5 import junit.framework.Test; 6 7 import org.jacorb.notification.AbstractMessage; 8 import org.jacorb.notification.filter.AbstractFilter; 9 import org.jacorb.notification.filter.ConstraintEntry; 10 import org.jacorb.notification.filter.etcl.ETCLFilter; 11 import org.jacorb.notification.impl.DefaultEvaluationContextFactory; 12 import org.jacorb.notification.impl.DefaultMessageFactory; 13 import org.omg.CosNotification.EventType; 14 import org.omg.CosNotifyFilter.ConstraintExp; 15 import org.omg.CosNotifyFilter.ConstraintInfo; 16 17 20 21 public class FilterImplTest extends NotificationTestCase { 22 23 private AbstractFilter objectUnderTest_; 24 25 27 public FilterImplTest(String test, NotificationTestCaseSetup setup) { 28 super(test, setup); 29 } 30 31 33 public void setUpTest() throws Exception { 34 objectUnderTest_ = new ETCLFilter(getConfiguration(), new DefaultEvaluationContextFactory(getEvaluator()), new DefaultMessageFactory(getConfiguration()), getORB(), getPOA()); 35 } 36 37 38 public void testIterator() throws Exception { 39 ConstraintExp[] _exp = new ConstraintExp[1]; 40 41 for (int x=0; x<_exp.length; ++x) { 42 _exp[x] = new ConstraintExp(); 43 } 44 45 EventType[] _eventType = new EventType[2]; 46 _eventType[0] = new EventType("*", "*"); 47 _eventType[1] = new EventType("domain*", "type*"); 48 _exp[0] = new ConstraintExp(_eventType, "1"); 49 objectUnderTest_.add_constraints(_exp); 50 51 Iterator _i = 52 objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain1", "type1")); 53 54 int _count = 0; 55 while (_i.hasNext()) { 56 _count++; 57 _i.next(); 58 } 59 assertEquals(2, _count); 60 } 61 62 63 71 public void testIteratorBug() throws Exception { 72 ConstraintExp[] _exp = new ConstraintExp[1]; 73 74 for (int x=0; x<_exp.length; ++x) { 75 _exp[x] = new ConstraintExp(); 76 } 77 78 EventType[] _eventType = new EventType[2]; 79 _eventType[0] = new EventType("domain1", "type1"); 80 _eventType[1] = new EventType("domain2", "type2"); 81 _exp[0] = new ConstraintExp(_eventType, "1"); 82 objectUnderTest_.add_constraints(_exp); 83 84 Iterator _i = 85 objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain3", "type3")); 86 87 while (_i.hasNext()) { 88 _i.next(); 89 } 90 } 91 92 93 public void testEmptyIteratorThrowsException() throws Exception { 94 ConstraintExp[] _exp = new ConstraintExp[1]; 95 96 for (int x=0; x<_exp.length; ++x) { 97 _exp[x] = new ConstraintExp(); 98 } 99 100 EventType[] _eventType = new EventType[2]; 101 _eventType[0] = new EventType("domain1", "type1"); 102 _eventType[1] = new EventType("domain2", "type2"); 103 _exp[0] = new ConstraintExp(_eventType, "1"); 104 objectUnderTest_.add_constraints(_exp); 105 106 Iterator _i = 107 objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain3", "type3")); 108 109 try { 110 _i.next(); 111 fail("Calling Iterator.next() on an empty Iterator should fail!"); 112 } catch (Exception e) { 113 } 115 } 116 117 118 public void testIterator2() throws Exception { 119 ConstraintExp[] _exp = new ConstraintExp[1]; 120 for (int x=0; x<_exp.length; ++x) { 121 _exp[x] = new ConstraintExp(); 122 } 123 124 EventType[] _eventType = new EventType[2]; 125 _eventType[0] = new EventType("*", "*"); 126 _eventType[1] = new EventType("domain*", "type*"); 127 _exp[0] = new ConstraintExp(_eventType, "1"); 128 objectUnderTest_.add_constraints(_exp); 129 130 Iterator _i = 131 objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain1", "type1")); 132 133 int _count = 0; 134 while (_i.hasNext()) { 135 _count++; 136 ConstraintEntry _e = (ConstraintEntry)_i.next(); 137 assertEquals("1", _e.getConstraintInfo().constraint_expression.constraint_expr); 138 } 139 assertTrue(_count == 2); 140 141 ConstraintExp[] _exp2 = new ConstraintExp[1]; 142 _exp2[0] = new ConstraintExp(); 143 144 EventType[] _eventType2 = new EventType[2]; 145 _eventType2[0] = new EventType("*", "*"); 146 _eventType2[1] = new EventType("domain*", "type*"); 147 _exp2[0] = new ConstraintExp(_eventType2, "2"); 148 objectUnderTest_.add_constraints(_exp2); 149 150 _i = objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain1", "type1")); 151 _count = 0; 152 153 while (_i.hasNext()) { 154 _count++; 155 ConstraintEntry _e = (ConstraintEntry)_i.next(); 156 assertTrue(_e.getConstraintExpression().equals("1") || 157 _e.getConstraintExpression().equals("2")); 158 } 159 assertEquals(4, _count); 160 } 161 162 163 public void testAddRemove() throws Exception { 164 ConstraintExp[] _exp = new ConstraintExp[1]; 165 for (int x=0; x<_exp.length; ++x) { 166 _exp[x] = new ConstraintExp(); 167 } 168 169 EventType[] _eventType = new EventType[2]; 170 _eventType[0] = new EventType("*", "*"); 171 _eventType[1] = new EventType("domain*", "type*"); 172 _exp[0] = new ConstraintExp(_eventType, "1"); 173 objectUnderTest_.add_constraints(_exp); 174 175 ConstraintExp[] _exp2 = new ConstraintExp[1]; 176 _exp2[0] = new ConstraintExp(); 177 178 EventType[] _eventType2 = new EventType[2]; 179 _eventType2[0] = new EventType("*", "*"); 180 _eventType2[1] = new EventType("domain*", "type*"); 181 _exp2[0] = new ConstraintExp(_eventType2, "2"); 182 183 ConstraintInfo[] _info = objectUnderTest_.add_constraints(_exp2); 184 185 Iterator _i = objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain1", "type1")); 186 int _count = 0; 187 188 while (_i.hasNext()) { 189 _count++; 190 ConstraintEntry _e = (ConstraintEntry)_i.next(); 191 assertTrue(_e.getConstraintExpression().equals("1") || 192 _e.getConstraintExpression().equals("2")); 193 } 194 assertEquals(4, _count); 195 196 int[] _delete_ids = new int[_info.length]; 197 for (int x=0; x<_delete_ids.length; ++x) { 198 _delete_ids[x] = _info[x].constraint_id; 199 } 200 objectUnderTest_.modify_constraints(_delete_ids, new ConstraintInfo[0]); 201 202 _i = objectUnderTest_.getIterator(AbstractMessage.calcConstraintKey("domain1", "type1")); 203 _count = 0; 204 while (_i.hasNext()) { 205 _count++; 206 ConstraintEntry _e = (ConstraintEntry)_i.next(); 207 assertTrue(_e.getConstraintExpression().equals("1")); 208 } 209 assertEquals(2, _count); 210 } 211 212 213 public static Test suite() throws Exception { 214 return NotificationTestCase.suite(FilterImplTest.class); 215 } 216 } 217 | Popular Tags |