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.mitosis.service.protocol.codec;
21  
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import javax.naming.InvalidNameException;
27  import javax.naming.NamingException;
28  
29  import org.apache.directory.mitosis.common.DefaultCSN;
30  import org.apache.directory.mitosis.operation.AddAttributeOperation;
31  import org.apache.directory.mitosis.service.protocol.codec.LogEntryMessageDecoder;
32  import org.apache.directory.mitosis.service.protocol.codec.LogEntryMessageEncoder;
33  import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
34  import org.apache.directory.mitosis.service.protocol.message.LogEntryMessage;
35  import org.apache.directory.server.core.DefaultDirectoryService;
36  import org.apache.directory.server.core.entry.DefaultServerAttribute;
37  import org.apache.directory.shared.ldap.name.LdapDN;
38  import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
39  import org.apache.directory.shared.ldap.schema.OidNormalizer;
40  
41  
42  public class LogEntryMessageCodecTest extends AbstractMessageCodecTest
43  {
44      private static Map<String, OidNormalizer> oids = new HashMap<String, OidNormalizer>();
45  
46      private static DefaultDirectoryService service;
47      
48      static 
49      {
50          oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
51          oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
52          oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
53          service = new DefaultDirectoryService();        
54      }
55      
56      
57  
58      public LogEntryMessageCodecTest() throws InvalidNameException, NamingException
59      {
60          super(
61              new LogEntryMessage( 
62                  1234, 
63                  new AddAttributeOperation( 
64                      service.getRegistries(),
65                      new DefaultCSN( System.currentTimeMillis(),
66                          "testReplica0", 1234 ), 
67                      new LdapDN( "ou=system" ).normalize( oids ),
68                      new DefaultServerAttribute( "ou", 
69                          service.getRegistries().getAttributeTypeRegistry().lookup( "ou" ), "Test" ) ) ), 
70              new LogEntryMessageEncoder(), 
71              new LogEntryMessageDecoder() );
72      }
73  
74  
75      protected boolean compare( BaseMessage expected0, BaseMessage actual0 )
76      {
77          LogEntryMessage expected = ( LogEntryMessage ) expected0;
78          LogEntryMessage actual = ( LogEntryMessage ) actual0;
79  
80          // We don't compare operation here because it is {@link OperationCodec}'s
81          // duty to serialize and deserialize Invocations.
82          return expected.getType() == actual.getType() && expected.getSequence() == actual.getSequence()
83              && expected.getOperation().getCSN().equals( actual.getOperation().getCSN() )
84              && expected.getOperation().getClass() == actual.getOperation().getClass();
85      }
86  }