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.modifydn;
21  
22  
23  import javax.naming.NamingEnumeration;
24  import javax.naming.directory.SearchControls;
25  import javax.naming.directory.SearchResult;
26  import javax.naming.ldap.LdapContext;
27  
28  import org.apache.directory.server.core.integ.Level;
29  import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
30  import org.apache.directory.server.core.integ.annotations.CleanupLevel;
31  import org.apache.directory.server.integ.SiRunner;
32  import org.apache.directory.server.ldap.LdapService;
33  import org.junit.Test;
34  import org.junit.runner.RunWith;
35  
36  import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
37  import static org.junit.Assert.assertEquals;
38  import static org.junit.Assert.assertNotNull;
39  import static org.junit.Assert.assertTrue;
40  
41  
42  /**
43   * Test case with different modify DN operations which move the entry under a 
44   * new superior.
45   * 
46   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
47   * @version $Rev: 679049 $
48   */
49  @RunWith ( SiRunner.class ) 
50  @CleanupLevel ( Level.SUITE )
51  @ApplyLdifs( {
52      // Entry # 1
53      "dn: uid=akarasulu,ou=users,ou=system\n" +
54      "objectClass: uidObject\n" +
55      "objectClass: person\n" +
56      "objectClass: top\n" +
57      "uid: akarasulu\n" +
58      "cn: Alex Karasulu\n" +
59      "sn: karasulu\n\n" + 
60      // Entry # 2
61      "dn: ou=NewSuperior,ou=system\n" +
62      "objectClass: organizationalUnit\n" +
63      "objectClass: top\n" +
64      "ou: NewSuperior\n\n"
65      }
66  )
67  public class MoveIT 
68  {
69      private static final String DN = "uid=akarasulu,ou=users,ou=system";
70      private static final String NEW_DN = "uid=akarasulu,ou=NewSuperior,ou=system";
71      private static final String NEW_DN2 = "uid=elecharny,ou=NewSuperior,ou=system";
72      
73      public static LdapService ldapService;
74      
75  
76      @Test
77      public void testMoveNoRdnChange() throws Exception
78      {
79          LdapContext ctx = getWiredContext( ldapService );
80          ctx.rename( DN, NEW_DN );
81          
82          SearchControls controls = new SearchControls();
83          controls.setSearchScope( SearchControls.OBJECT_SCOPE );
84          
85          NamingEnumeration<SearchResult> results = 
86              ctx.search( NEW_DN, "(objectClass=*)", controls );
87          assertNotNull( results );
88          assertTrue( "Could not find entry after move.", results.hasMore() );
89          SearchResult result = results.next();
90          assertNotNull( result );
91          assertEquals( NEW_DN, result.getNameInNamespace() );
92          
93          results.close();
94          ctx.close();
95      }
96      
97  
98      @Test
99      public void testMoveAndRdnChange() throws Exception
100     {
101         LdapContext ctx = getWiredContext( ldapService );
102         ctx.rename( DN, NEW_DN2 );
103         
104         SearchControls controls = new SearchControls();
105         controls.setSearchScope( SearchControls.OBJECT_SCOPE );
106         
107         NamingEnumeration<SearchResult> results = 
108             ctx.search( NEW_DN2, "(objectClass=*)", controls );
109         assertNotNull( results );
110         assertTrue( "Could not find entry after move.", results.hasMore() );
111         SearchResult result = results.next();
112         assertNotNull( result );
113         assertEquals( NEW_DN2, result.getNameInNamespace() );
114         
115         results.close();
116         ctx.close();
117     }
118     
119     @Test
120     public void testDummy()
121     {
122         
123     }
124 }