You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/03/04 19:36:40 UTC
svn commit: r1078090 [2/2] - in /directory/shared/trunk:
integ/src/test/java/org/apache/directory/shared/ldap/entry/
ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/
ldap/model/src/main/java/org/apache/directory/shared/ldap/model/...
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntrySerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntrySerializerTest.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntrySerializerTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntrySerializerTest.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.model.entry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the Entry Serialization
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class EntrySerializerTest
+{
+ @Test
+ public void testEntryFullSerialization() throws IOException, LdapException
+ {
+ Entry entry1 = LdifUtils.createEntry(
+ "dc=example, dc=com",
+ "ObjectClass: top",
+ "ObjectClass: domain",
+ "dc: example",
+ "l: test" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntrySerializer.serialize( entry1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ Entry entry2 = EntrySerializer.deserialize( null, in );
+
+ assertEquals( entry1, entry2 );
+ assertTrue( entry2.contains( "ObjectClass", "top", "domain" ) );
+ }
+
+
+ @Test
+ public void testEntryNoDnSerialization() throws IOException, LdapException
+ {
+ Entry entry1 = LdifUtils.createEntry(
+ "",
+ "ObjectClass: top",
+ "ObjectClass: domain",
+ "dc: example",
+ "l: test" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntrySerializer.serialize( entry1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ Entry entry2 = EntrySerializer.deserialize( null, in );
+
+ assertEquals( entry1, entry2 );
+ assertTrue( entry2.contains( "ObjectClass", "top", "domain" ) );
+ assertEquals( "", entry2.getDn().toString() );
+ }
+
+
+ @Test
+ public void testEntryNoAttributesSerialization() throws IOException, LdapException
+ {
+ Entry entry1 = LdifUtils.createEntry( "dc=example, dc=com" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntrySerializer.serialize( entry1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ Entry entry2 = EntrySerializer.deserialize( null, in );
+
+ assertEquals( entry1, entry2 );
+ assertEquals( 0, entry2.size() );
+ }
+}
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java Fri Mar 4 18:36:39 2011
@@ -106,7 +106,7 @@ public class StringValueAttributeTypeTes
try
{
oOut = new ObjectOutputStream( out );
- value.serialize( oOut );
+ StringValue.serialize( value, oOut );
}
catch ( IOException ioe )
{
@@ -135,7 +135,7 @@ public class StringValueAttributeTypeTes
/**
* Deserialize a StringValue
*/
- private StringValue deserializeValue( ByteArrayOutputStream out, AttributeType at ) throws IOException, ClassNotFoundException
+ private StringValue deserializeValue( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
{
ObjectInputStream oIn = null;
ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
@@ -144,8 +144,7 @@ public class StringValueAttributeTypeTes
{
oIn = new ObjectInputStream( in );
- StringValue value = new StringValue( at );
- value.deserialize( oIn );
+ StringValue value = StringValue.deserialize( null, oIn );
return value;
}
@@ -691,7 +690,7 @@ public class StringValueAttributeTypeTes
assertEquals( "test test", normalized );
assertEquals( " Test Test ", ssv.getString() );
- StringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
+ StringValue ssvSer = deserializeValue( serializeValue( ssv ) );
assertEquals( ssv, ssvSer );
}
@@ -711,7 +710,7 @@ public class StringValueAttributeTypeTes
assertEquals( "test", normalized );
assertEquals( "test", ssv.getString() );
- StringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
+ StringValue ssvSer = deserializeValue( serializeValue( ssv ) );
assertEquals( ssv, ssvSer );
}
@@ -731,7 +730,7 @@ public class StringValueAttributeTypeTes
assertNull( normalized );
assertNull( ssv.get() );
- StringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
+ StringValue ssvSer = deserializeValue( serializeValue( ssv ) );
assertEquals( ssv, ssvSer );
}
@@ -751,7 +750,7 @@ public class StringValueAttributeTypeTes
assertEquals( "", normalized );
assertEquals( "", ssv.getString() );
- StringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
+ StringValue ssvSer = deserializeValue( serializeValue( ssv ) );
assertEquals( ssv, ssvSer );
}
@@ -763,11 +762,11 @@ public class StringValueAttributeTypeTes
@Test public void testStringValueEmptyNormalizedSerialization() throws LdapException, IOException, ClassNotFoundException
{
// First check with a value which will be normalized
- StringValue ssv = new StringValue( at, " " );
+ StringValue ssv = new StringValue( " " );
assertEquals( " ", ssv.getString() );
- StringValue ssvSer = deserializeValue( serializeValue( ssv ), at );
+ StringValue ssvSer = deserializeValue( serializeValue( ssv ) );
assertEquals( ssv, ssvSer );
}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ValueSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ValueSerializerTest.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ValueSerializerTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ValueSerializerTest.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.model.entry;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.util.StringConstants;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the Value Serialization
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class ValueSerializerTest
+{
+ private static byte[] data = new byte[] {0x01, 0x02, 0x03, 0x04};
+ BinaryValue bv1 = new BinaryValue( data );
+ BinaryValue bv2 = new BinaryValue( StringConstants.EMPTY_BYTES );
+ BinaryValue bv3 = new BinaryValue();
+ BinaryValue bv1n = new BinaryValue( data );
+ BinaryValue bv2n = new BinaryValue( StringConstants.EMPTY_BYTES );
+ BinaryValue bv3n = new BinaryValue();
+ StringValue sv1 = new StringValue( "test" );
+ StringValue sv2 = new StringValue( "" );
+ StringValue sv3 = new StringValue();
+ StringValue sv1n = new StringValue( "test" );
+ StringValue sv2n = new StringValue( "" );
+ StringValue sv3n = new StringValue();
+
+
+ @Test
+ public void testBinaryValueWithDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ BinaryValue.serialize( bv1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv1, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueWithEmptyDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ BinaryValue.serialize( bv2, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv2, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueNoDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ BinaryValue.serialize( bv3, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv3, bvDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ StringValue.serialize( sv1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv1, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithEmptyDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ StringValue.serialize( sv2, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv2, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueNoDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ StringValue.serialize( sv3, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv3, svDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueWithDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ bv1n.normalize();
+
+ BinaryValue.serialize( bv1n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv1n, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ bv2n.normalize();
+
+ BinaryValue.serialize( bv2n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv2n, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueNoDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ bv3n.normalize();
+
+ BinaryValue.serialize( bv3n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv3n, bvDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ sv1n.normalize();
+
+ StringValue.serialize( sv1n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv1n, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ sv2n.normalize();
+
+ StringValue.serialize( sv2n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv2n, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueNoDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ sv3n.normalize();
+
+ StringValue.serialize( sv3n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv3n, svDeser );
+ }
+}