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