1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.xdbm.search.impl;
21
22
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.apache.directory.server.xdbm.Store;
26 import org.apache.directory.server.xdbm.ForwardIndexEntry;
27 import org.apache.directory.server.xdbm.tools.StoreUtils;
28 import org.apache.directory.server.schema.registries.*;
29 import org.apache.directory.server.schema.bootstrap.*;
30 import org.apache.directory.server.schema.SerializableComparator;
31 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
32 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
33 import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
34 import org.apache.directory.server.core.entry.ServerEntry;
35 import org.apache.directory.server.core.entry.DefaultServerEntry;
36 import org.apache.directory.server.core.entry.ServerStringValue;
37 import org.apache.directory.shared.ldap.constants.SchemaConstants;
38 import org.apache.directory.shared.ldap.filter.LessEqNode;
39 import org.apache.directory.shared.ldap.schema.*;
40 import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
41 import org.apache.directory.shared.ldap.name.LdapDN;
42 import org.apache.commons.io.FileUtils;
43 import org.junit.Before;
44 import org.junit.After;
45 import org.junit.Test;import static org.junit.Assert.assertTrue;import static org.junit.Assert.assertFalse;
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertNotNull;
48 import static org.junit.Assert.fail;
49
50 import java.io.File;
51 import java.util.*;
52
53
54
55
56
57
58
59
60 public class LessEqTest
61 {
62 public static final Logger LOG = LoggerFactory.getLogger( LessEqTest.class );
63
64
65 File wkdir;
66 Store<ServerEntry> store;
67 Registries registries = null;
68 AttributeTypeRegistry attributeRegistry;
69
70
71 public LessEqTest() throws Exception
72 {
73
74 BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
75 OidRegistry oidRegistry = new DefaultOidRegistry();
76 registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
77 SerializableComparator.setRegistry( registries.getComparatorRegistry() );
78
79
80 Set<Schema> bootstrapSchemas = new HashSet<Schema>();
81 bootstrapSchemas.add( new ApachemetaSchema() );
82 bootstrapSchemas.add( new ApacheSchema() );
83 bootstrapSchemas.add( new CoreSchema() );
84 bootstrapSchemas.add( new SystemSchema() );
85 bootstrapSchemas.add( new CollectiveSchema() );
86 loader.loadWithDependencies( bootstrapSchemas, registries );
87 attributeRegistry = registries.getAttributeTypeRegistry();
88 }
89
90
91 @Before
92 public void createStore() throws Exception
93 {
94 destryStore();
95
96
97 wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
98 wkdir.delete();
99 wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
100 wkdir.mkdirs();
101
102
103 store = new JdbmStore<ServerEntry>();
104 store.setName( "example" );
105 store.setCacheSize( 10 );
106 store.setWorkingDirectory( wkdir );
107 store.setSyncOnWrite( false );
108
109 store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
110 store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
111 store.addIndex( new JdbmIndex( SchemaConstants.POSTALCODE_AT_OID ) );
112
113 StoreUtils.loadExampleData( store, registries );
114 LOG.debug( "Created new store" );
115 }
116
117
118 @After
119 public void destryStore() throws Exception
120 {
121 if ( store != null )
122 {
123 store.destroy();
124 }
125
126 store = null;
127 if ( wkdir != null )
128 {
129 FileUtils.deleteDirectory( wkdir );
130 }
131
132 wkdir = null;
133 }
134
135
136 @Test
137 public void testCursorIndexed() throws Exception
138 {
139 AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTALCODE_AT_OID );
140 LessEqNode node = new LessEqNode( SchemaConstants.POSTALCODE_AT_OID, new ServerStringValue( at, "3" ) );
141 LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
142 LessEqCursor cursor = new LessEqCursor( store, evaluator );
143 assertNotNull( cursor );
144 assertFalse( cursor.available() );
145 assertTrue( cursor.isElementReused() );
146 assertFalse( cursor.isClosed() );
147
148
149
150 try { cursor.get(); fail(); }
151 catch( InvalidCursorPositionException e ) {}
152
153
154
155 cursor.beforeFirst();
156 assertFalse( cursor.available() );
157
158 assertTrue( cursor.next() );
159 assertTrue( cursor.available() );
160 assertEquals( 1L, ( long ) cursor.get().getId() );
161 assertEquals( "1", cursor.get().getValue() );
162
163 assertTrue( cursor.next() );
164 assertTrue( cursor.available() );
165 assertEquals( 2L, ( long ) cursor.get().getId() );
166 assertEquals( "1", cursor.get().getValue() );
167
168 assertTrue( cursor.next() );
169 assertTrue( cursor.available() );
170 assertEquals( 3L, ( long ) cursor.get().getId() );
171 assertEquals( "1", cursor.get().getValue() );
172
173 assertTrue( cursor.next() );
174 assertTrue( cursor.available() );
175 assertEquals( 4L, ( long ) cursor.get().getId() );
176 assertEquals( "2", cursor.get().getValue() );
177
178 assertTrue( cursor.next() );
179 assertTrue( cursor.available() );
180 assertEquals( 5L, ( long ) cursor.get().getId() );
181 assertEquals( "3", cursor.get().getValue() );
182
183 assertFalse( cursor.next() );
184 assertFalse( cursor.available() );
185 cursor.close();
186 assertTrue( cursor.isClosed() );
187
188
189
190 cursor = new LessEqCursor( store, evaluator );
191
192 cursor.first();
193
194 assertTrue( cursor.available() );
195 assertEquals( 1L, ( long ) cursor.get().getId() );
196 assertEquals( "1", cursor.get().getValue() );
197
198 assertTrue( cursor.next() );
199 assertTrue( cursor.available() );
200 assertEquals( 2L, ( long ) cursor.get().getId() );
201 assertEquals( "1", cursor.get().getValue() );
202
203 assertTrue( cursor.next() );
204 assertTrue( cursor.available() );
205 assertEquals( 3L, ( long ) cursor.get().getId() );
206 assertEquals( "1", cursor.get().getValue() );
207
208 assertTrue( cursor.next() );
209 assertTrue( cursor.available() );
210 assertEquals( 4L, ( long ) cursor.get().getId() );
211 assertEquals( "2", cursor.get().getValue() );
212
213 assertTrue( cursor.next() );
214 assertTrue( cursor.available() );
215 assertEquals( 5L, ( long ) cursor.get().getId() );
216 assertEquals( "3", cursor.get().getValue() );
217
218 assertFalse( cursor.next() );
219 assertFalse( cursor.available() );
220 cursor.close();
221 assertTrue( cursor.isClosed() );
222
223
224
225 cursor = new LessEqCursor( store, evaluator );
226
227 cursor.afterLast();
228 assertFalse( cursor.available() );
229
230 assertTrue( cursor.previous() );
231 assertTrue( cursor.available() );
232 assertEquals( 5L, ( long ) cursor.get().getId() );
233 assertEquals( "3", cursor.get().getValue() );
234
235 assertTrue( cursor.previous() );
236 assertTrue( cursor.available() );
237 assertEquals( 4L, ( long ) cursor.get().getId() );
238 assertEquals( "2", cursor.get().getValue() );
239
240 assertTrue( cursor.previous() );
241 assertTrue( cursor.available() );
242 assertEquals( 3L, ( long ) cursor.get().getId() );
243 assertEquals( "1", cursor.get().getValue() );
244
245 assertTrue( cursor.previous() );
246 assertTrue( cursor.available() );
247 assertEquals( 2L, ( long ) cursor.get().getId() );
248 assertEquals( "1", cursor.get().getValue() );
249
250 assertTrue( cursor.previous() );
251 assertTrue( cursor.available() );
252 assertEquals( 1L, ( long ) cursor.get().getId() );
253 assertEquals( "1", cursor.get().getValue() );
254
255 assertFalse( cursor.previous() );
256 assertFalse( cursor.available() );
257 cursor.close();
258 assertTrue( cursor.isClosed() );
259
260
261
262 cursor = new LessEqCursor( store, evaluator );
263
264 cursor.last();
265
266 assertTrue( cursor.available() );
267 assertEquals( 5L, ( long ) cursor.get().getId() );
268 assertEquals( "3", cursor.get().getValue() );
269
270 assertTrue( cursor.previous() );
271 assertTrue( cursor.available() );
272 assertEquals( 4L, ( long ) cursor.get().getId() );
273 assertEquals( "2", cursor.get().getValue() );
274
275 assertTrue( cursor.previous() );
276 assertTrue( cursor.available() );
277 assertEquals( 3L, ( long ) cursor.get().getId() );
278 assertEquals( "1", cursor.get().getValue() );
279
280 assertTrue( cursor.previous() );
281 assertTrue( cursor.available() );
282 assertEquals( 2L, ( long ) cursor.get().getId() );
283 assertEquals( "1", cursor.get().getValue() );
284
285 assertTrue( cursor.previous() );
286 assertTrue( cursor.available() );
287 assertEquals( 1L, ( long ) cursor.get().getId() );
288 assertEquals( "1", cursor.get().getValue() );
289
290 assertFalse( cursor.previous() );
291 assertFalse( cursor.available() );
292 cursor.close();
293 assertTrue( cursor.isClosed() );
294
295
296
297 cursor = new LessEqCursor( store, evaluator );
298 ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
299 indexEntry.setValue( "2" );
300
301 assertFalse( cursor.available() );
302 cursor.before( indexEntry );
303 assertFalse( cursor.available() );
304
305 assertTrue( cursor.next() );
306 assertTrue( cursor.available() );
307 assertEquals( 4L, ( long ) cursor.get().getId() );
308 assertEquals( "2", cursor.get().getValue() );
309
310 assertTrue( cursor.next() );
311 assertTrue( cursor.available() );
312 assertEquals( 5L, ( long ) cursor.get().getId() );
313 assertEquals( "3", cursor.get().getValue() );
314
315 assertFalse( cursor.next() );
316 assertFalse( cursor.available() );
317 cursor.close();
318 assertTrue( cursor.isClosed() );
319
320 cursor = new LessEqCursor( store, evaluator );
321 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
322 indexEntry.setValue( "7" );
323 cursor.before( indexEntry );
324 assertFalse( cursor.available() );
325 assertTrue( cursor.previous() );
326 assertEquals( 5L, ( long ) cursor.get().getId() );
327 assertEquals( "3", cursor.get().getValue() );
328 cursor.close();
329
330 cursor = new LessEqCursor( store, evaluator );
331 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
332 indexEntry.setValue( "3" );
333 cursor.before( indexEntry );
334 assertFalse( cursor.available() );
335 assertTrue( cursor.next() );
336 assertEquals( 5L, ( long ) cursor.get().getId() );
337 assertEquals( "3", cursor.get().getValue() );
338 cursor.close();
339
340
341
342 cursor = new LessEqCursor( store, evaluator );
343 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
344 indexEntry.setValue( "1" );
345
346 assertFalse( cursor.available() );
347 cursor.after( indexEntry );
348 assertFalse( cursor.available() );
349
350 assertTrue( cursor.next() );
351 assertTrue( cursor.available() );
352 assertEquals( 4L, ( long ) cursor.get().getId() );
353 assertEquals( "2", cursor.get().getValue() );
354
355 assertTrue( cursor.next() );
356 assertTrue( cursor.available() );
357 assertEquals( 5L, ( long ) cursor.get().getId() );
358 assertEquals( "3", cursor.get().getValue() );
359
360 assertFalse( cursor.next() );
361 assertFalse( cursor.available() );
362 cursor.close();
363 assertTrue( cursor.isClosed() );
364
365 cursor = new LessEqCursor( store, evaluator );
366 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
367 indexEntry.setValue( "7" );
368 cursor.after( indexEntry );
369 assertFalse( cursor.available() );
370 assertTrue( cursor.previous() );
371 assertEquals( 5L, ( long ) cursor.get().getId() );
372 assertEquals( "3", cursor.get().getValue() );
373 cursor.close();
374
375 cursor = new LessEqCursor( store, evaluator );
376 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
377 indexEntry.setValue( "3" );
378 cursor.after( indexEntry );
379 assertFalse( cursor.available() );
380 assertTrue( cursor.previous() );
381 assertEquals( 5L, ( long ) cursor.get().getId() );
382 assertEquals( "3", cursor.get().getValue() );
383 cursor.close();
384 }
385
386
387 @Test
388 public void testCursorNotIndexed() throws Exception
389 {
390 AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTOFFICEBOX_AT_OID );
391 LessEqNode node = new LessEqNode( SchemaConstants.POSTOFFICEBOX_AT_OID, new ServerStringValue( at, "3" ) );
392 LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
393 LessEqCursor cursor = new LessEqCursor( store, evaluator );
394 assertNotNull( cursor );
395 assertFalse( cursor.available() );
396 assertTrue( cursor.isElementReused() );
397 assertFalse( cursor.isClosed() );
398
399
400
401 try { cursor.get(); fail(); }
402 catch( InvalidCursorPositionException e ) {}
403
404
405
406 cursor.beforeFirst();
407 assertFalse( cursor.available() );
408
409 assertTrue( cursor.next() );
410 assertTrue( cursor.available() );
411 assertEquals( 1L, ( long ) cursor.get().getId() );
412 assertEquals( "1", cursor.get().getValue() );
413
414 assertTrue( cursor.next() );
415 assertTrue( cursor.available() );
416 assertEquals( 3L, ( long ) cursor.get().getId() );
417 assertEquals( "1", cursor.get().getValue() );
418
419 assertTrue( cursor.next() );
420 assertTrue( cursor.available() );
421 assertEquals( 4L, ( long ) cursor.get().getId() );
422 assertEquals( "2", cursor.get().getValue() );
423
424 assertTrue( cursor.next() );
425 assertTrue( cursor.available() );
426 assertEquals( 2L, ( long ) cursor.get().getId() );
427 assertEquals( "1", cursor.get().getValue() );
428
429 assertTrue( cursor.next() );
430 assertTrue( cursor.available() );
431 assertEquals( 5L, ( long ) cursor.get().getId() );
432 assertEquals( "3", cursor.get().getValue() );
433
434 assertFalse( cursor.next() );
435 assertFalse( cursor.available() );
436 assertFalse( cursor.isClosed() );
437 cursor.close();
438 assertTrue( cursor.isClosed() );
439
440
441
442 cursor = new LessEqCursor( store, evaluator );
443 cursor.first();
444
445 assertTrue( cursor.available() );
446 assertEquals( 1L, ( long ) cursor.get().getId() );
447 assertEquals( "1", cursor.get().getValue() );
448
449 assertTrue( cursor.next() );
450 assertTrue( cursor.available() );
451 assertEquals( 3L, ( long ) cursor.get().getId() );
452 assertEquals( "1", cursor.get().getValue() );
453
454 assertTrue( cursor.next() );
455 assertTrue( cursor.available() );
456 assertEquals( 4L, ( long ) cursor.get().getId() );
457 assertEquals( "2", cursor.get().getValue() );
458
459 assertTrue( cursor.next() );
460 assertTrue( cursor.available() );
461 assertEquals( 2L, ( long ) cursor.get().getId() );
462 assertEquals( "1", cursor.get().getValue() );
463
464 assertTrue( cursor.next() );
465 assertTrue( cursor.available() );
466 assertEquals( 5L, ( long ) cursor.get().getId() );
467 assertEquals( "3", cursor.get().getValue() );
468
469 assertFalse( cursor.next() );
470 assertFalse( cursor.available() );
471 assertFalse( cursor.isClosed() );
472 cursor.close();
473 assertTrue( cursor.isClosed() );
474
475
476
477 cursor = new LessEqCursor( store, evaluator );
478 cursor.afterLast();
479 assertFalse( cursor.available() );
480
481 assertTrue( cursor.previous() );
482 assertTrue( cursor.available() );
483 assertEquals( 5L, ( long ) cursor.get().getId() );
484 assertEquals( "3", cursor.get().getValue() );
485
486 assertTrue( cursor.previous() );
487 assertTrue( cursor.available() );
488 assertEquals( 2L, ( long ) cursor.get().getId() );
489 assertEquals( "1", cursor.get().getValue() );
490
491 assertTrue( cursor.previous() );
492 assertTrue( cursor.available() );
493 assertEquals( 4L, ( long ) cursor.get().getId() );
494 assertEquals( "2", cursor.get().getValue() );
495
496 assertTrue( cursor.previous() );
497 assertTrue( cursor.available() );
498 assertEquals( 3L, ( long ) cursor.get().getId() );
499 assertEquals( "1", cursor.get().getValue() );
500
501 assertTrue( cursor.previous() );
502 assertTrue( cursor.available() );
503 assertEquals( 1L, ( long ) cursor.get().getId() );
504 assertEquals( "1", cursor.get().getValue() );
505
506 assertFalse( cursor.previous() );
507 assertFalse( cursor.available() );
508
509
510
511 cursor = new LessEqCursor( store, evaluator );
512 cursor.last();
513
514 assertTrue( cursor.available() );
515 assertEquals( 5L, ( long ) cursor.get().getId() );
516 assertEquals( "3", cursor.get().getValue() );
517
518 assertTrue( cursor.previous() );
519 assertTrue( cursor.available() );
520 assertEquals( 2L, ( long ) cursor.get().getId() );
521 assertEquals( "1", cursor.get().getValue() );
522
523 assertTrue( cursor.previous() );
524 assertTrue( cursor.available() );
525 assertEquals( 4L, ( long ) cursor.get().getId() );
526 assertEquals( "2", cursor.get().getValue() );
527
528 assertTrue( cursor.previous() );
529 assertTrue( cursor.available() );
530 assertEquals( 3L, ( long ) cursor.get().getId() );
531 assertEquals( "1", cursor.get().getValue() );
532
533 assertTrue( cursor.previous() );
534 assertTrue( cursor.available() );
535 assertEquals( 1L, ( long ) cursor.get().getId() );
536 assertEquals( "1", cursor.get().getValue() );
537
538 assertFalse( cursor.previous() );
539 assertFalse( cursor.available() );
540
541
542
543 cursor = new LessEqCursor( store, evaluator );
544 ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
545 indexEntry.setValue( "2" );
546 try { cursor.before( indexEntry ); fail( "Should never get here." );}
547 catch ( UnsupportedOperationException e ) {}
548
549
550
551 cursor = new LessEqCursor( store, evaluator );
552 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
553 indexEntry.setValue( "2" );
554 try { cursor.after( indexEntry ); fail( "Should never get here." );}
555 catch ( UnsupportedOperationException e ) {}
556 }
557
558
559
560
561
562
563
564 @Test
565 public void testEvaluatorIndexed() throws Exception
566 {
567 AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTALCODE_AT_OID );
568 LessEqNode node = new LessEqNode( SchemaConstants.POSTALCODE_AT_OID, new ServerStringValue( at, "3" ) );
569
570 LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
571 ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
572 assertEquals( node, evaluator.getExpression() );
573 assertEquals( SchemaConstants.POSTALCODE_AT_OID, evaluator.getAttributeType().getOid() );
574 assertNotNull( evaluator.getNormalizer() );
575 assertNotNull( evaluator.getComparator() );
576
577 indexEntry.setId( 1L );
578 assertTrue( evaluator.evaluate( indexEntry ) );
579
580 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
581 indexEntry.setId( 4L );
582 assertTrue( evaluator.evaluate( indexEntry ) );
583
584 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
585 indexEntry.setId( 5L );
586 assertTrue( evaluator.evaluate( indexEntry ) );
587
588 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
589 indexEntry.setId( 6L );
590 assertFalse( evaluator.evaluate( indexEntry ) );
591
592 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
593 indexEntry.setId( 7L );
594 assertFalse( evaluator.evaluate( indexEntry ) );
595
596 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
597 indexEntry.setId( 8L );
598 assertFalse( evaluator.evaluate( indexEntry ) );
599
600 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
601 indexEntry.setId( 9L );
602 assertFalse( evaluator.evaluate( indexEntry ) );
603
604 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
605 indexEntry.setId( 10L );
606 assertFalse( evaluator.evaluate( indexEntry ) );
607 }
608
609
610 @Test
611 public void testEvaluatorWithDescendantValue() throws Exception
612 {
613 AttributeType at = attributeRegistry.lookup( SchemaConstants.STREET_AT_OID );
614 LessEqNode node = new LessEqNode( SchemaConstants.STREET_AT_OID, new ServerStringValue( at, "2" ) );
615
616 LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
617 ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
618 assertEquals( node, evaluator.getExpression() );
619 assertEquals( SchemaConstants.STREET_AT_OID, evaluator.getAttributeType().getOid() );
620 assertNotNull( evaluator.getNormalizer() );
621 assertNotNull( evaluator.getComparator() );
622
623 LdapDN dn = new LdapDN( "cn=jane doe,o=good times co." );
624 dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
625 ServerEntry attrs = new DefaultServerEntry( registries, dn );
626 attrs.add( "objectClass", "person" );
627 attrs.add( "c-street", "1" );
628 attrs.add( "cn", "jane doe" );
629 attrs.add( "sn", "doe" );
630 store.add( dn, attrs );
631
632 indexEntry.setId( 12L );
633 assertTrue( evaluator.evaluate( indexEntry ) );
634 }
635
636
637 @Test
638 public void testEvaluatorWithoutDescendants() throws Exception
639 {
640 AttributeType at = attributeRegistry.lookup( SchemaConstants.C_POSTALCODE_AT_OID );
641 LessEqNode node = new LessEqNode( SchemaConstants.C_POSTALCODE_AT_OID, new ServerStringValue( at, "2" ) );
642
643 LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
644 ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
645 assertEquals( node, evaluator.getExpression() );
646 assertEquals( SchemaConstants.C_POSTALCODE_AT_OID, evaluator.getAttributeType().getOid() );
647 assertNotNull( evaluator.getNormalizer() );
648 assertNotNull( evaluator.getComparator() );
649
650 indexEntry.setId( 1L );
651 assertFalse( evaluator.evaluate( indexEntry ) );
652 }
653
654
655 @Test
656 public void testEvaluatorNotIndexed() throws Exception
657 {
658 AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTOFFICEBOX_AT_OID );
659 LessEqNode node = new LessEqNode( SchemaConstants.POSTOFFICEBOX_AT_OID, new ServerStringValue( at, "3" ) );
660
661 LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
662 ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
663 assertEquals( node, evaluator.getExpression() );
664 assertEquals( SchemaConstants.POSTOFFICEBOX_AT_OID, evaluator.getAttributeType().getOid() );
665 assertNotNull( evaluator.getNormalizer() );
666 assertNotNull( evaluator.getComparator() );
667
668 indexEntry.setId( 1L );
669 assertTrue( evaluator.evaluate( indexEntry ) );
670
671 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
672 indexEntry.setId( 4L );
673 assertTrue( evaluator.evaluate( indexEntry ) );
674
675 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
676 indexEntry.setId( 5L );
677 assertTrue( evaluator.evaluate( indexEntry ) );
678
679 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
680 indexEntry.setId( 6L );
681 assertFalse( evaluator.evaluate( indexEntry ) );
682
683 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
684 indexEntry.setId( 7L );
685 assertFalse( evaluator.evaluate( indexEntry ) );
686
687 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
688 indexEntry.setId( 8L );
689 assertFalse( evaluator.evaluate( indexEntry ) );
690
691 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
692 indexEntry.setId( 9L );
693 assertFalse( evaluator.evaluate( indexEntry ) );
694
695 indexEntry = new ForwardIndexEntry<String,ServerEntry>();
696 indexEntry.setId( 10L );
697 assertFalse( evaluator.evaluate( indexEntry ) );
698 }
699
700
701 @Test ( expected = IllegalStateException.class )
702 public void testEvaluatorAttributeNoMatchingRule() throws Exception
703 {
704 AttributeType at = new NoMatchingRuleAttributeType();
705 registries.getAttributeTypeRegistry().register( at );
706
707 LessEqNode node = new LessEqNode( at.getOid(), new ServerStringValue( at, "3" ) );
708
709 new LessEqEvaluator( node, store, registries );
710 registries.getAttributeTypeRegistry().unregister( at.getOid() );
711 }
712
713
714 @Test
715 public void testEvaluatorAttributeOrderingMatchingRule() throws Exception
716 {
717 AttributeType at = new OrderingOnlyMatchingRuleAttributeType();
718 registries.getAttributeTypeRegistry().register( at );
719 registries.getSyntaxRegistry().register( at.getSyntax() );
720 SyntaxCheckerDescription desc = new SyntaxCheckerDescription();
721 desc.setDescription( "bogus" );
722 desc.setFqcn( BogusSyntax.class.getName() );
723 List<String> names = new ArrayList<String>();
724 names.add( "bogus" );
725 desc.setNames( names );
726 desc.setNumericOid( at.getSyntax().getOid() );
727 desc.setObsolete( false );
728 registries.getSyntaxCheckerRegistry().register( desc, at.getSyntax().getSyntaxChecker() );
729
730 LessEqNode node = new LessEqNode( at.getOid(), new ServerStringValue( at, "3" ) );
731 new LessEqEvaluator( node, store, registries );
732 registries.getAttributeTypeRegistry().unregister( at.getOid() );
733 }
734 }