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.core.jndi;
21  
22  
23  import org.apache.directory.server.core.DirectoryService;
24  import org.apache.directory.server.core.integ.CiRunner;
25  import static org.apache.directory.server.core.integ.IntegrationUtils.*;
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.assertTrue;
28  import static org.junit.Assert.assertNotNull;
29  import org.junit.Test;
30  import org.junit.runner.RunWith;
31  
32  import javax.naming.directory.Attribute;
33  import javax.naming.directory.Attributes;
34  import javax.naming.ldap.LdapContext;
35  import java.util.ArrayList;
36  
37  
38  /**
39   * Tests to validate whatever functionality we have for complying with
40   * <a href="http://www.faqs.org/rfcs/rfc2713.html">RFC 2713</a>.
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   * @version $Rev: 613608 $
44   */
45  @RunWith ( CiRunner.class )
46  public class RFC2713IT
47  {
48      public static DirectoryService service;
49      
50  
51      @Test
52      @SuppressWarnings("unchecked")
53      public void testSerializatin() throws Exception
54      {
55          LdapContext sysRoot = getSystemContext( service );
56  
57          ArrayList<String> colors = new ArrayList<String>();
58          colors.add( "red" );
59          colors.add( "white" );
60          colors.add( "blue" );
61          sysRoot.bind( "cn=colors", colors );
62  
63          Object obj = sysRoot.lookup( "cn=colors" );
64          assertTrue( obj instanceof ArrayList );
65          colors = ( ArrayList<String> ) obj;
66          assertEquals( 3, colors.size() );
67          assertTrue( colors.contains( "red" ) );
68          assertTrue( colors.contains( "white" ) );
69          assertTrue( colors.contains( "blue" ) );
70  
71          Attributes attrs = sysRoot.getAttributes( "cn=colors" );
72          Attribute attr = attrs.get( "objectClass" );
73          assertNotNull( attr );
74          assertEquals( 4, attr.size() );
75          assertTrue( attr.contains( "top" ) );
76          assertTrue( attr.contains( "javaObject" ) );
77          assertTrue( attr.contains( "javaContainer" ) );
78          assertTrue( attr.contains( "javaSerializedObject" ) );
79          attr = attrs.get( "javaClassName" );
80          assertNotNull( attr );
81          assertEquals( 1, attr.size() );
82          assertTrue( attr.contains( "java.util.ArrayList" ) );
83  
84          attr = attrs.get( "javaSerializedData" );
85          assertNotNull( attr );
86          assertEquals( 1, attr.size() );
87      }
88  }