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.operations.extended;
21  
22  
23  import javax.naming.CommunicationException;
24  import javax.naming.NamingException;
25  import javax.naming.ldap.ExtendedRequest;
26  import javax.naming.ldap.ExtendedResponse;
27  import javax.naming.ldap.LdapContext;
28  
29  import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
30  
31  import org.apache.directory.server.core.integ.Level;
32  import org.apache.directory.server.core.integ.annotations.CleanupLevel;
33  import org.apache.directory.server.integ.SiRunner;
34  import org.apache.directory.server.ldap.LdapService;
35  import org.junit.Test;
36  import org.junit.runner.RunWith;
37  
38  import static org.junit.Assert.fail;
39  
40  
41  /**
42   * Various extended operation tests.
43   * 
44   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45   * @version $Rev: 545029 $
46   */
47  @RunWith ( SiRunner.class ) 
48  @CleanupLevel ( Level.SUITE )
49  public class ExtendedIT 
50  {
51      public static LdapService ldapService;
52      
53  
54      /**
55       * Calls an extended exception, which does not exist. Expected behaviour is
56       * a CommunicationException.
57       * Check the behaviour of the server for an unknown extended operation. Created
58       * to demonstrate DIREVE-256 ("Extended operation causes client to hang.").
59       * 
60       * @throws NamingException 
61       */
62      @Test
63      public void testUnknownExtendedOperation() throws Exception
64      {
65          LdapContext ctx = ( LdapContext ) getWiredContext( ldapService ).lookup( "ou=system" );
66          try
67          {
68              ctx.extendedOperation( new UnknownExtendedOperationRequest() );
69              fail( "Calling an unknown extended operation should fail." );
70          }
71          catch ( CommunicationException ce )
72          {
73              // expected behaviour
74          }
75      }
76  
77      
78      /**
79       * Class for the request of an extended operation which does not exist.
80       */
81      private class UnknownExtendedOperationRequest implements ExtendedRequest
82      {
83  
84          private static final long serialVersionUID = 1L;
85  
86  
87          public String getID()
88          {
89              return "1.1"; // Never an OID for an extended operation
90          }
91  
92  
93          public byte[] getEncodedValue()
94          {
95              return null;
96          }
97  
98  
99          public ExtendedResponse createExtendedResponse( String id, byte[] berValue, int offset, int length )
100             throws NamingException
101         {
102             return null;
103         }
104     }
105 
106 }