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