001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.server.core; 021 022 023 import org.apache.directory.server.core.DirectoryService; 024 import org.apache.directory.server.core.entry.ClonedServerEntry; 025 import org.apache.directory.server.core.filtering.EntryFilteringCursor; 026 import org.apache.directory.server.core.interceptor.Interceptor; 027 import org.apache.directory.server.core.interceptor.InterceptorChain; 028 import org.apache.directory.server.core.interceptor.NextInterceptor; 029 import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext; 030 import org.apache.directory.server.core.interceptor.context.AddOperationContext; 031 import org.apache.directory.server.core.interceptor.context.BindOperationContext; 032 import org.apache.directory.server.core.interceptor.context.CompareOperationContext; 033 import org.apache.directory.server.core.interceptor.context.DeleteOperationContext; 034 import org.apache.directory.server.core.interceptor.context.EntryOperationContext; 035 import org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext; 036 import org.apache.directory.server.core.interceptor.context.GetRootDSEOperationContext; 037 import org.apache.directory.server.core.interceptor.context.GetSuffixOperationContext; 038 import org.apache.directory.server.core.interceptor.context.ListOperationContext; 039 import org.apache.directory.server.core.interceptor.context.ListSuffixOperationContext; 040 import org.apache.directory.server.core.interceptor.context.LookupOperationContext; 041 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext; 042 import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext; 043 import org.apache.directory.server.core.interceptor.context.MoveOperationContext; 044 import org.apache.directory.server.core.interceptor.context.RemoveContextPartitionOperationContext; 045 import org.apache.directory.server.core.interceptor.context.RenameOperationContext; 046 import org.apache.directory.server.core.interceptor.context.SearchOperationContext; 047 import org.apache.directory.server.core.interceptor.context.UnbindOperationContext; 048 import org.apache.directory.shared.ldap.name.DN; 049 050 import javax.naming.NamingException; 051 052 import java.util.ArrayList; 053 import java.util.List; 054 import java.util.Set; 055 056 057 public class MockInterceptor implements Interceptor 058 { 059 private static final int INTERCEPTOR_COUNT = 5; 060 List<MockInterceptor> interceptors = new ArrayList<MockInterceptor>( INTERCEPTOR_COUNT ); 061 InterceptorChain test; 062 String name; 063 064 065 public void setName( String name ) 066 { 067 this.name = name; 068 } 069 070 071 public void setTest( InterceptorChain test ) 072 { 073 this.test = test; 074 } 075 076 077 public String getName() 078 { 079 return this.name; 080 } 081 082 083 public void init( DirectoryService directoryService ) 084 throws NamingException 085 { 086 } 087 088 089 public void destroy() 090 { 091 } 092 093 094 public ClonedServerEntry getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws Exception 095 { 096 interceptors.add( this ); 097 return next.getRootDSE( opContext ); 098 } 099 100 101 public DN getMatchedName ( NextInterceptor next, GetMatchedNameOperationContext opContext ) throws Exception 102 { 103 interceptors.add( this ); 104 return next.getMatchedName( opContext ); 105 } 106 107 108 public DN getSuffix ( NextInterceptor next, GetSuffixOperationContext opContext ) throws Exception 109 { 110 interceptors.add( this ); 111 return next.getSuffix( opContext ); 112 } 113 114 115 public Set<String> listSuffixes ( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception 116 { 117 interceptors.add( this ); 118 return next.listSuffixes( opContext ); 119 } 120 121 122 public void addContextPartition( NextInterceptor next, AddContextPartitionOperationContext opContext ) 123 throws Exception 124 { 125 interceptors.add( this ); 126 next.addContextPartition( opContext ); 127 } 128 129 130 public void removeContextPartition( NextInterceptor next, RemoveContextPartitionOperationContext opContext ) throws Exception 131 { 132 interceptors.add( this ); 133 next.removeContextPartition( opContext ); 134 } 135 136 137 public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws Exception 138 { 139 interceptors.add( this ); 140 return next.compare( opContext ); 141 } 142 143 144 public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws Exception 145 { 146 interceptors.add( this ); 147 next.delete( opContext ); 148 } 149 150 151 public void add( NextInterceptor next, AddOperationContext opContext ) 152 throws Exception 153 { 154 interceptors.add( this ); 155 next.add( opContext ); 156 } 157 158 159 public void modify( NextInterceptor next, ModifyOperationContext opContext ) throws Exception 160 { 161 interceptors.add( this ); 162 next.modify( opContext ); 163 } 164 165 166 public EntryFilteringCursor list( NextInterceptor next, ListOperationContext opContext ) throws Exception 167 { 168 interceptors.add( this ); 169 return next.list( opContext ); 170 } 171 172 173 public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext opContext ) throws Exception 174 { 175 interceptors.add( this ); 176 return next.search( opContext ); 177 } 178 179 180 public ClonedServerEntry lookup( NextInterceptor next, LookupOperationContext opContext ) throws Exception 181 { 182 interceptors.add( this ); 183 return next.lookup( opContext ); 184 } 185 186 187 public boolean hasEntry( NextInterceptor next, EntryOperationContext opContext ) throws Exception 188 { 189 interceptors.add( this ); 190 return next.hasEntry( opContext ); 191 } 192 193 194 public void rename( NextInterceptor next, RenameOperationContext opContext ) 195 throws Exception 196 { 197 interceptors.add( this ); 198 next.rename( opContext ); 199 } 200 201 202 public void move( NextInterceptor next, MoveOperationContext opContext ) throws Exception 203 { 204 interceptors.add( this ); 205 next.move( opContext ); 206 } 207 208 209 public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) 210 throws Exception 211 { 212 interceptors.add( this ); 213 next.moveAndRename( opContext ); 214 } 215 216 217 public void bind( NextInterceptor next, BindOperationContext opContext ) 218 throws Exception 219 { 220 interceptors.add( this ); 221 next.bind( opContext ); 222 } 223 224 225 public void unbind( NextInterceptor next, UnbindOperationContext opContext ) throws Exception 226 { 227 interceptors.add( this ); 228 next.unbind( opContext ); 229 } 230 231 232 public String toString() 233 { 234 return name; 235 } 236 }