1   /*
2    *   @(#) $Id: MicroOperationFilterTest.java 321394 2005-10-15 17:54:41Z akarasulu $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   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, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   *
18   */
19  package org.apache.ldap.server.authz.support;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  import junit.framework.Assert;
28  import junit.framework.TestCase;
29  
30  import org.apache.ldap.common.aci.ACITuple;
31  import org.apache.ldap.common.aci.AuthenticationLevel;
32  import org.apache.ldap.common.aci.MicroOperation;
33  
34  /***
35   * Tests {@link MicroOperationFilter}.
36   *
37   * @author The Apache Directory Project
38   * @version $Rev: 321394 $, $Date: 2005-10-15 13:54:41 -0400 (Sat, 15 Oct 2005) $
39   */
40  public class MicroOperationFilterTest extends TestCase
41  {
42      private static final Collection EMPTY_COLLECTION =
43          Collections.unmodifiableCollection( new ArrayList() );
44      private static final Set EMPTY_SET =
45          Collections.unmodifiableSet( new HashSet() );
46      
47      private static final Set USER_OPERATIONS_A = new HashSet();
48      private static final Set USER_OPERATIONS_B = new HashSet();
49      private static final Set TUPLE_OPERATIONS = new HashSet();
50      
51      static
52      {
53          USER_OPERATIONS_A.add( MicroOperation.ADD );
54          USER_OPERATIONS_A.add( MicroOperation.BROWSE );
55          USER_OPERATIONS_B.add( MicroOperation.COMPARE );
56          USER_OPERATIONS_B.add( MicroOperation.DISCLOSE_ON_ERROR );
57          TUPLE_OPERATIONS.add( MicroOperation.ADD );
58          TUPLE_OPERATIONS.add( MicroOperation.BROWSE );
59          TUPLE_OPERATIONS.add( MicroOperation.EXPORT );
60      }
61  
62      public void testZeroTuple() throws Exception
63      {
64          MicroOperationFilter filter = new MicroOperationFilter();
65          
66          Assert.assertEquals(
67                  0, filter.filter(
68                          EMPTY_COLLECTION, OperationScope.ATTRIBUTE_TYPE_AND_VALUE,
69                          null, null, null, null, null, null, null, null, null, null ).size() );
70      }
71      
72      public void testOneTuple() throws Exception
73      {
74          MicroOperationFilter filter = new MicroOperationFilter();
75          Collection tuples = new ArrayList();
76          tuples.add( new ACITuple(
77                  EMPTY_COLLECTION, AuthenticationLevel.NONE, EMPTY_SET,
78                  TUPLE_OPERATIONS, true, 0 ) );
79          
80          Assert.assertEquals(
81                  1, filter.filter(
82                          tuples, OperationScope.ENTRY, null, null, null,
83                          null, null, null, null, null, null, USER_OPERATIONS_A ).size() );
84          Assert.assertEquals(
85                  0, filter.filter(
86                          tuples, OperationScope.ENTRY, null, null, null,
87                          null, null, null, null, null, null, USER_OPERATIONS_B ).size() );
88      }
89  }