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 2010/06/13 02:39:22 UTC
svn commit: r954149 [2/2] - in /directory/shared/trunk/ldap-ldif/src:
main/java/org/apache/directory/shared/ldap/ldif/
test/java/org/apache/directory/shared/ldap/ldif/
Modified: directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java?rev=954149&r1=954148&r2=954149&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java (original)
+++ directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java Sun Jun 13 00:39:22 2010
@@ -49,6 +49,8 @@ import org.junit.runner.RunWith;
/**
+ * Test the LdifReader class
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@RunWith(ConcurrentJunitRunner.class)
@@ -139,7 +141,12 @@ public class LdifReaderTest
@Test
public void testLdifComments() throws Exception
{
- String ldif = "#Comment 1\r" + "#\r" + " th\n" + " is is still a comment\n" + "\n";
+ String ldif =
+ "#Comment 1\r" +
+ "#\r" +
+ " th\n" +
+ " is is still a comment\n" +
+ "\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -152,8 +159,15 @@ public class LdifReaderTest
@Test
public void testLdifVersion() throws Exception
{
- String ldif = "#Comment 1\r" + "#\r" + " th\n" + " is is still a comment\n" + "\n" + "version:\n" + " 1\n"
- + "# end";
+ String ldif =
+ "#Comment 1\r" +
+ "#\r" +
+ " th\n" +
+ " is is still a comment\n" +
+ "\n" +
+ "version:\n" +
+ " 1\n" +
+ "# end";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -167,9 +181,17 @@ public class LdifReaderTest
@Test
public void testLdifVersionStart() throws Exception
{
- String ldif = "version:\n" + " 1\n" + "\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n"
- + "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n"
- + "dependencies:\n" + "envVars:";
+ String ldif =
+ "version:\n" +
+ " 1\n" +
+ "\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -178,9 +200,9 @@ public class LdifReaderTest
assertEquals( 1, reader.getVersion() );
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -196,7 +218,13 @@ public class LdifReaderTest
@Test
public void testLdifWithoutVersion() throws Exception
{
- String ldif = "#Comment 1\r" + "#\r" + " th\n" + " is is still a comment\n" + "\n" + "# end";
+ String ldif =
+ "#Comment 1\r" +
+ "#\r" +
+ " th\n" +
+ " is is still a comment\n" +
+ "\n" +
+ "# end";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -215,9 +243,15 @@ public class LdifReaderTest
@Test
public void testLdifParserEndSpaces() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn: app1\n"
- + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n"
- + "envVars:";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
@@ -226,9 +260,9 @@ public class LdifReaderTest
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -242,14 +276,25 @@ public class LdifReaderTest
public void testLdifParserAddAttrCaseInsensitiveAttrId() throws Exception
{
// test that mixed case attr ids work at all
- String ldif = "version: 1\n" + "dn: dc=example,dc=com\n" + "changetype: modify\n"
- + "add: administrativeRole\n" + "administrativeRole: accessControlSpecificArea\n" + "-";
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: modify\n" +
+ "add: administrativeRole\n" +
+ "administrativeRole: accessControlSpecificArea\n" +
+ "-";
testReaderAttrIdCaseInsensitive( ldif );
+
// test that attr id comparisons are case insensitive and that the version in the add: line is used.
// See DIRSERVER-1029 for some discussion.
- ldif = "version: 1\n" + "dn: dc=example,dc=com\n" + "changetype: modify\n" + "add: administrativeRole\n"
- + "administrativerole: accessControlSpecificArea\n" + "-";
+ ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: modify\n" +
+ "add: administrativeRole\n" +
+ "administrativerole: accessControlSpecificArea\n" +
+ "-";
testReaderAttrIdCaseInsensitive( ldif );
}
@@ -263,7 +308,7 @@ public class LdifReaderTest
assertNotNull( entries );
reader.close();
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertTrue( entry.isChangeModify() );
@@ -285,13 +330,23 @@ public class LdifReaderTest
@Test
public void testLdifParserCombinedEntriesChanges() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn: app1\n"
- + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n"
- + "envVars:\n" + "\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: 1.2.840.11A556.1.4.805 true\n"
- + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:\n" +
+ "\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: 1.2.840.11A556.1.4.805 true\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
@@ -319,12 +374,22 @@ public class LdifReaderTest
@Test
public void testLdifParserCombinedEntriesChanges2() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn: app1\n"
- + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n"
- + "envVars:\n" + "\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:\n" +
+ "\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
@@ -352,13 +417,23 @@ public class LdifReaderTest
@Test
public void testLdifParserCombinedChangesEntries() throws Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: 1.2.840.11A556.1.4.805 true\n"
- + "changetype: delete\n" + "\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn: app1\n"
- + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n"
- + "envVars:\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: 1.2.840.11A556.1.4.805 true\n" +
+ "changetype: delete\n" +
+ "\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:\n";
LdifReader reader = new LdifReader();
@@ -386,12 +461,22 @@ public class LdifReaderTest
@Test
public void testLdifParserCombinedChangesEntries2() throws Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "changetype: delete\n" + "\n"
- + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn: app1\n" + "objectClass: top\n"
- + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n" + "envVars:\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "changetype: delete\n" +
+ "\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:\n";
LdifReader reader = new LdifReader();
@@ -414,9 +499,15 @@ public class LdifReaderTest
@Test
public void testLdifParser() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn: app1\n"
- + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n"
- + "envVars:";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1 \n" +
+ "dependencies:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -424,8 +515,8 @@ public class LdifReaderTest
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -450,10 +541,19 @@ public class LdifReaderTest
@Test
public void testLdifParserMuiltiLineComments() throws Exception
{
- String ldif = "#comment\n" + " still a comment\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n"
- + "cn: app1#another comment\n" + "objectClass: top\n" + "objectClass: apApplication\n"
- + "displayName: app1\n" + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n"
- + "startupOptions:\n" + "envVars:";
+ String ldif =
+ "#comment\n" +
+ " still a comment\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1#another comment\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1\n" +
+ "serviceType: http\n" +
+ "dependencies:\n" +
+ "httpHeaders:\n" +
+ "startupOptions:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -461,8 +561,8 @@ public class LdifReaderTest
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -487,10 +587,19 @@ public class LdifReaderTest
@Test
public void testLdifParserMultiLineEntries() throws Exception
{
- String ldif = "#comment\n" + "dn: cn=app1,ou=appli\n" + " cations,ou=conf,dc=apache,dc=org\n"
- + "cn: app1#another comment\n" + "objectClass: top\n" + "objectClass: apApplication\n"
- + "displayName: app1\n" + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n"
- + "startupOptions:\n" + "envVars:";
+ String ldif =
+ "#comment\n" +
+ "dn: cn=app1,ou=appli\n" +
+ " cations,ou=conf,dc=apache,dc=org\n" +
+ "cn: app1#another comment\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1\n" +
+ "serviceType: http\n" +
+ "dependencies:\n" +
+ "httpHeaders:\n" +
+ "startupOptions:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -498,8 +607,8 @@ public class LdifReaderTest
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -524,10 +633,18 @@ public class LdifReaderTest
@Test
public void testLdifParserBase64() throws Exception, UnsupportedEncodingException
{
- String ldif = "#comment\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n"
- + "cn:: RW1tYW51ZWwgTMOpY2hhcm55\n" + "objectClass: top\n" + "objectClass: apApplication\n"
- + "displayName: app1\n" + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n"
- + "startupOptions:\n" + "envVars:";
+ String ldif =
+ "#comment\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn:: RW1tYW51ZWwgTMOpY2hhcm55\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1\n" +
+ "serviceType: http\n" +
+ "dependencies:\n" +
+ "httpHeaders:\n" +
+ "startupOptions:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -535,8 +652,8 @@ public class LdifReaderTest
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -561,9 +678,19 @@ public class LdifReaderTest
@Test
public void testLdifParserBase64MultiLine() throws Exception, UnsupportedEncodingException
{
- String ldif = "#comment\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn:: RW1tYW51ZWwg\n"
- + " TMOpY2hhcm55ICA=\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1\n"
- + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n" + "startupOptions:\n" + "envVars:";
+ String ldif =
+ "#comment\n" +
+ "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
+ "cn:: RW1tYW51ZWwg\n" +
+ " TMOpY2hhcm55ICA=\n" +
+ "objectClass: top\n" +
+ "objectClass: apApplication\n" +
+ "displayName: app1\n" +
+ "serviceType: http\n" +
+ "dependencies:\n" +
+ "httpHeaders:\n" +
+ "startupOptions:\n" +
+ "envVars:";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -571,8 +698,8 @@ public class LdifReaderTest
assertNotNull( entries );
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() );
@@ -597,13 +724,27 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample1() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Barbara Jensen\n" + "cn: Barbara J Jensen\n" + "cn: Babs Jensen\n" + "sn: Jensen\n"
- + "uid: bjensen\n" + "telephonenumber: +1 408 555 1212\n" + "description: A big sailing fan.\n" + "\n"
- + "dn: cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com\n" + "objectclass: top\n"
- + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Bjorn Jensen\n" + "sn: Jensen\n"
- + "telephonenumber: +1 408 555 1212";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Barbara Jensen\n" +
+ "cn: Barbara J Jensen\n" +
+ "cn: Babs Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: bjensen\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "description: A big sailing fan.\n" +
+ "\n" +
+ "dn: cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Bjorn Jensen\n" +
+ "sn: Jensen\n" +
+ "telephonenumber: +1 408 555 1212";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -612,8 +753,8 @@ public class LdifReaderTest
assertEquals( 2, entries.size() );
// Entry 1
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com", entry.getDn().getName() );
@@ -640,8 +781,8 @@ public class LdifReaderTest
assertTrue( attr.contains( "A big sailing fan." ) );
// Entry 2
- entry = ( LdifEntry ) entries.get( 1 );
- assertTrue( entry.isChangeAdd() );
+ entry = entries.get( 1 );
+ assertTrue( entry.isLdifContent() );
attr = entry.get( "dn" );
assertEquals( "cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com", entry.getDn().getName() );
@@ -665,12 +806,21 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample2() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Barbara Jensen\n" + "cn: Barbara J Jensen\n" + "cn: Babs Jensen\n" + "sn: Jensen\n"
- + "uid: bjensen\n" + "telephonenumber: +1 408 555 1212\n"
- + "description:Babs is a big sailing fan, and travels extensively in sea\n"
- + " rch of perfect sailing conditions.\n" + "title:Product Manager, Rod and Reel Division";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Barbara Jensen\n" +
+ "cn: Barbara J Jensen\n" +
+ "cn: Babs Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: bjensen\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "description:Babs is a big sailing fan, and travels extensively in sea\n" +
+ " rch of perfect sailing conditions.\n" +
+ "title:Product Manager, Rod and Reel Division";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -679,8 +829,8 @@ public class LdifReaderTest
assertEquals( 1, entries.size() );
// Entry 1
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com", entry.getDn().getName() );
@@ -715,13 +865,21 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample3() throws Exception, Exception
{
- String ldif = "version: 1\n" + "dn: cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Gern Jensen\n" + "cn: Gern O Jensen\n" + "sn: Jensen\n" + "uid: gernj\n"
- + "telephonenumber: +1 408 555 1212\n"
- + "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n"
- + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n"
- + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Gern Jensen\n" +
+ "cn: Gern O Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: gernj\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" +
+ " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" +
+ " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" +
+ " b3V0IG1vcmUu";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -730,8 +888,8 @@ public class LdifReaderTest
assertEquals( 1, entries.size() );
// Entry 1
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com", entry.getDn().getName() );
@@ -763,13 +921,21 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample3VariousSpacing() throws Exception, Exception
{
- String ldif = "version:1\n" + "dn:cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com \n"
- + "objectclass:top\n" + "objectclass: person \n" + "objectclass:organizationalPerson\n"
- + "cn:Gern Jensen\n" + "cn:Gern O Jensen\n" + "sn:Jensen\n" + "uid:gernj\n"
- + "telephonenumber:+1 408 555 1212 \n"
- + "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n"
- + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n"
- + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu ";
+ String ldif =
+ "version:1\n" +
+ "dn:cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com \n" +
+ "objectclass:top\n" +
+ "objectclass: person \n" +
+ "objectclass:organizationalPerson\n" +
+ "cn:Gern Jensen\n" +
+ "cn:Gern O Jensen\n" +
+ "sn:Jensen\n" +
+ "uid:gernj\n" +
+ "telephonenumber:+1 408 555 1212 \n" +
+ "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" +
+ " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" +
+ " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" +
+ " b3V0IG1vcmUu ";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -778,8 +944,8 @@ public class LdifReaderTest
assertEquals( 1, entries.size() );
// Entry 1
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
assertEquals( "cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com", entry.getDn().getName() );
@@ -811,57 +977,60 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample4() throws Exception, Exception
{
- String ldif = "version: 1\n"
- + "dn:: b3U95Za25qWt6YOoLG89QWlyaXVz\n"
- + "# dn:: ou=���������,o=Airius\n"
- + "objectclass: top\n"
- + "objectclass: organizationalUnit\n"
- + "ou:: 5Za25qWt6YOo\n"
- + "# ou:: ���������\n"
- + "ou;lang-ja:: 5Za25qWt6YOo\n"
- + "# ou;lang-ja:: ���������\n"
- + "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n"
- + "# ou;lang-ja:: ������������������\n"
- + "ou;lang-en: Sales\n"
- + "description: Japanese office\n"
- + "\n"
- + "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz\n"
- + "# dn:: uid=rogasawara,ou=���������,o=Airius\n"
- + "userpassword: {SHA}O3HSv1MusyL4kTjP+HKI5uxuNoM=\n"
- + "objectclass: top\n"
- + "objectclass: person\n"
- + "objectclass: organizationalPerson\n"
- + "objectclass: inetOrgPerson\n"
- + "uid: rogasawara\n"
- + "mail: rogasawara@airius.co.jp\n"
- + "givenname;lang-ja:: 44Ot44OJ44OL44O8\n"
- + "# givenname;lang-ja:: ������������\n"
- + "sn;lang-ja:: 5bCP56yg5Y6f\n"
- + "# sn;lang-ja:: ���������\n"
- + "cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n"
- + "# cn;lang-ja:: ��������� ������������\n"
- + "title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==\n"
- + "# title;lang-ja:: ��������� ������\n"
- + "preferredlanguage: ja\n"
- + "givenname:: 44Ot44OJ44OL44O8\n"
- + "# givenname:: ������������\n"
- + "sn:: 5bCP56yg5Y6f\n"
- + "# sn:: ���������\n"
- + "cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n"
- + "# cn:: ��������� ������������\n"
- + "title:: 5Za25qWt6YOoIOmDqOmVtw==\n"
- + "# title:: ��������� ������\n"
- + "givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8\n"
- + "# givenname;lang-ja;phonetic:: ������������\n"
- + "sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ\n"
- + "# sn;lang-ja;phonetic:: ���������������\n"
- + "cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==\n"
- + "# cn;lang-ja;phonetic:: ��������������� ������������\n"
- + "title;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==\n"
- + "# title;lang-ja;phonetic::\n"
- + "# ������������������ ������������\n"
- + "givenname;lang-en: Rodney\n" + "sn;lang-en: Ogasawara\n" + "cn;lang-en: Rodney Ogasawara\n"
- + "title;lang-en: Sales, Director\n";
+ String ldif =
+ "version: 1\n" +
+ "dn:: b3U95Za25qWt6YOoLG89QWlyaXVz\n" +
+ "# dn:: ou=���������,o=Airius\n" +
+ "objectclass: top\n" +
+ "objectclass: organizationalUnit\n" +
+ "ou:: 5Za25qWt6YOo\n" +
+ "# ou:: ���������\n" +
+ "ou;lang-ja:: 5Za25qWt6YOo\n" +
+ "# ou;lang-ja:: ���������\n" +
+ "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n" +
+ "# ou;lang-ja:: ������������������\n" +
+ "ou;lang-en: Sales\n" +
+ "description: Japanese office\n" +
+ "\n" +
+ "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz\n" +
+ "# dn:: uid=rogasawara,ou=���������,o=Airius\n" +
+ "userpassword: {SHA}O3HSv1MusyL4kTjP+HKI5uxuNoM=\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "objectclass: inetOrgPerson\n" +
+ "uid: rogasawara\n" +
+ "mail: rogasawara@airius.co.jp\n" +
+ "givenname;lang-ja:: 44Ot44OJ44OL44O8\n" +
+ "# givenname;lang-ja:: ������������\n" +
+ "sn;lang-ja:: 5bCP56yg5Y6f\n" +
+ "# sn;lang-ja:: ���������\n" +
+ "cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n" +
+ "# cn;lang-ja:: ��������� ������������\n" +
+ "title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==\n" +
+ "# title;lang-ja:: ��������� ������\n" +
+ "preferredlanguage: ja\n" +
+ "givenname:: 44Ot44OJ44OL44O8\n" +
+ "# givenname:: ������������\n" +
+ "sn:: 5bCP56yg5Y6f\n" +
+ "# sn:: ���������\n" +
+ "cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n" +
+ "# cn:: ��������� ������������\n" +
+ "title:: 5Za25qWt6YOoIOmDqOmVtw==\n" +
+ "# title:: ��������� ������\n" +
+ "givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8\n" +
+ "# givenname;lang-ja;phonetic:: ������������\n" +
+ "sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ\n" +
+ "# sn;lang-ja;phonetic:: ���������������\n" +
+ "cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==\n" +
+ "# cn;lang-ja;phonetic:: ��������������� ������������\n" +
+ "title;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==\n" +
+ "# title;lang-ja;phonetic::\n" +
+ "# ������������������ ������������\n" +
+ "givenname;lang-en: Rodney\n" +
+ "sn;lang-en: Ogasawara\n" +
+ "cn;lang-en: Rodney Ogasawara\n" +
+ "title;lang-en: Sales, Director\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -911,8 +1080,8 @@ public class LdifReaderTest
// Entry 1
for ( int i = 0; i < entries.size(); i++ )
{
- LdifEntry entry = ( LdifEntry ) entries.get( i );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( i );
+ assertTrue( entry.isLdifContent() );
for ( int j = 0; j < values[i].length; j++ )
{
@@ -941,10 +1110,20 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample5() throws Exception, Exception
{
- String ldif = "version: 1\n" + "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n"
- + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Horatio Jensen\n" +
+ "cn: Horatio N Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: hjensen\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "jpegphoto:< file:" +
+ HJENSEN_JPEG_FILE.getAbsolutePath() +
+ "\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -966,8 +1145,8 @@ public class LdifReaderTest
assertEquals( 1, entries.size() );
// Entry 1
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
- assertTrue( entry.isChangeAdd() );
+ LdifEntry entry = entries.get( 0 );
+ assertTrue( entry.isLdifContent() );
for ( int i = 0; i < values.length; i++ )
{
@@ -1000,10 +1179,20 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample5WithSizeLimit() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n"
- + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Horatio Jensen\n" +
+ "cn: Horatio N Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: hjensen\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "jpegphoto:< file:" +
+ HJENSEN_JPEG_FILE.getAbsolutePath() +
+ "\n";
LdifReader reader = new LdifReader();
reader.setSizeLimit( 128 );
@@ -1024,71 +1213,81 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample6() throws Exception, Exception
{
- String ldif = "version: 1\n"
- +
+ String ldif =
+ "version: 1\n" +
// First entry modification : ADD
- "# Add a new entry\n" + "dn: cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com\n" + "changetype: add\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Fiona Jensen\n" + "sn: Jensen\n" + "uid: fiona\n" + "telephonenumber: +1 408 555 1212\n"
- + "jpegphoto:< file:"
- + FIONA_JPEG_FILE.getAbsolutePath()
- + "\n"
- + "\n"
+ "# Add a new entry\n" +
+ "dn: cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com\n" +
+ "changetype: add\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Fiona Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: fiona\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "jpegphoto:< file:" +
+ FIONA_JPEG_FILE.getAbsolutePath() +
+ "\n" +
+ "\n"
+
// Second entry modification : DELETE
- "# Delete an existing entry\n"
- + "dn: cn=Robert Jensen, ou=Marketing, dc=airius, dc=com\n"
- + "changetype: delete\n"
- + "\n"
+ "# Delete an existing entry\n" +
+ "dn: cn=Robert Jensen, ou=Marketing, dc=airius, dc=com\n" +
+ "changetype: delete\n" +
+ "\n"
+
// Third entry modification : MODRDN
- "# Modify an entry's relative distinguished name\n"
- + "dn: cn=Paul Jensen, ou=Product Development, dc=airius, dc=com\n"
- + "changetype: modrdn\n"
- + "newrdn: cn=Paula Jensen\n"
- + "deleteoldrdn: 1\n"
- + "\n"
+ "# Modify an entry's relative distinguished name\n" +
+ "dn: cn=Paul Jensen, ou=Product Development, dc=airius, dc=com\n" +
+ "changetype: modrdn\n" +
+ "newrdn: cn=Paula Jensen\n" +
+ "deleteoldrdn: 1\n" +
+ "\n"
+
// Forth entry modification : MODRDN
- "# Rename an entry and move all of its children to a new location in\n"
- + "# the directory tree (only implemented by LDAPv3 servers).\n"
- + "dn: ou=PD Accountants, ou=Product Development, dc=airius, dc=com\n"
- + "changetype: moddn\n"
- + "newrdn: ou=Product Development Accountants\n"
- + "deleteoldrdn: 0\n"
- + "newsuperior: ou=Accounting, dc=airius, dc=com\n"
- + "# Modify an entry: add an additional value to the postaladdress\n"
- + "# attribute, completely delete the description attribute, replace\n"
- + "# the telephonenumber attribute with two values, and delete a specific\n"
- + "# value from the facsimiletelephonenumber attribute\n"
- + "\n"
+ "# Rename an entry and move all of its children to a new location in\n" +
+ "# the directory tree (only implemented by LDAPv3 servers).\n" +
+ "dn: ou=PD Accountants, ou=Product Development, dc=airius, dc=com\n" +
+ "changetype: moddn\n" +
+ "newrdn: ou=Product Development Accountants\n" +
+ "deleteoldrdn: 0\n" +
+ "newsuperior: ou=Accounting, dc=airius, dc=com\n" +
+ "# Modify an entry: add an additional value to the postaladdress\n" +
+ "# attribute, completely delete the description attribute, replace\n" +
+ "# the telephonenumber attribute with two values, and delete a specific\n" +
+ "# value from the facsimiletelephonenumber attribute\n" +
+ "\n"
+
// Fitfh entry modification : MODIFY
- "dn: cn=Paula Jensen, ou=Product Development, dc=airius, dc=com\n"
- + "changetype: modify\n"
- + "add: postaladdress\n"
- + "postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086\n"
- + "-\n"
- + "delete: description\n"
- + "-\n"
- + "replace: telephonenumber\n"
- + "telephonenumber: +1 408 555 1234\n"
- + "telephonenumber: +1 408 555 5678\n"
- + "-\n"
- + "delete: facsimiletelephonenumber\n"
- + "facsimiletelephonenumber: +1 408 555 9876\n"
- + "-\n"
- + "\n"
+ "dn: cn=Paula Jensen, ou=Product Development, dc=airius, dc=com\n" +
+ "changetype: modify\n" +
+ "add: postaladdress\n" +
+ "postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086\n" +
+ "-\n" +
+ "delete: description\n" +
+ "-\n" +
+ "replace: telephonenumber\n" +
+ "telephonenumber: +1 408 555 1234\n" +
+ "telephonenumber: +1 408 555 5678\n" +
+ "-\n" +
+ "delete: facsimiletelephonenumber\n" +
+ "facsimiletelephonenumber: +1 408 555 9876\n" +
+ "-\n" +
+ "\n"
+
// Sixth entry modification : MODIFY
- "# Modify an entry: replace the postaladdress attribute with an empty\n"
- + "# set of values (which will cause the attribute to be removed), and\n"
- + "# delete the entire description attribute. Note that the first will\n"
- + "# always succeed, while the second will only succeed if at least\n"
- + "# one value for the description attribute is present.\n"
- + "dn: cn=Ingrid Jensen, ou=Product Support, dc=airius, dc=com\n"
- + "changetype: modify\n"
- + "replace: postaladdress\n" + "-\n" + "delete: description\n" + "-\n";
+ "# Modify an entry: replace the postaladdress attribute with an empty\n" +
+ "# set of values (which will cause the attribute to be removed), and\n" +
+ "# delete the entire description attribute. Note that the first will\n" +
+ "# always succeed, while the second will only succeed if at least\n" +
+ "# one value for the description attribute is present.\n" +
+ "dn: cn=Ingrid Jensen, ou=Product Support, dc=airius, dc=com\n" +
+ "changetype: modify\n" +
+ "replace: postaladdress\n" +
+ "-\n" +
+ "delete: description\n" +
+ "-\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -1138,7 +1337,7 @@ public class LdifReaderTest
// delete
{ "description" } } };
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertTrue( entry.isChangeAdd() );
for ( int i = 0; i < values.length; i++ )
@@ -1168,19 +1367,19 @@ public class LdifReaderTest
}
// Second entry
- entry = ( LdifEntry ) entries.get( 1 );
+ entry = entries.get( 1 );
assertTrue( entry.isChangeDelete() );
assertEquals( values[1][0][1], entry.getDn().getName() );
// Third entry
- entry = ( LdifEntry ) entries.get( 2 );
+ entry = entries.get( 2 );
assertTrue( entry.isChangeModRdn() );
assertEquals( values[2][0][1], entry.getDn().getName() );
assertEquals( values[2][1][0], entry.getNewRdn() );
assertTrue( entry.isDeleteOldRdn() );
// Forth entry
- entry = ( LdifEntry ) entries.get( 3 );
+ entry = entries.get( 3 );
assertTrue( entry.isChangeModDn() );
assertEquals( values[3][0][1], entry.getDn().getName() );
assertEquals( values[3][1][0], entry.getNewRdn() );
@@ -1188,7 +1387,7 @@ public class LdifReaderTest
assertEquals( values[3][2][0], entry.getNewSuperior() );
// Fifth entry
- entry = ( LdifEntry ) entries.get( 4 );
+ entry = entries.get( 4 );
List<Modification> modifs = entry.getModificationItems();
assertTrue( entry.isChangeModify() );
@@ -1196,20 +1395,20 @@ public class LdifReaderTest
// "add: postaladdress"
// "postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086"
- Modification item = ( Modification ) modifs.get( 0 );
+ Modification item = modifs.get( 0 );
assertEquals( ModificationOperation.ADD_ATTRIBUTE, item.getOperation() );
assertEquals( values[4][1][0], item.getAttribute().getId() );
assertTrue( item.getAttribute().contains( values[4][1][1] ) );
// "delete: description\n" +
- item = ( Modification ) modifs.get( 1 );
+ item = modifs.get( 1 );
assertEquals( ModificationOperation.REMOVE_ATTRIBUTE, item.getOperation() );
assertEquals( values[4][2][0], item.getAttribute().getId() );
// "replace: telephonenumber"
// "telephonenumber: +1 408 555 1234"
// "telephonenumber: +1 408 555 5678"
- item = ( Modification ) modifs.get( 2 );
+ item = modifs.get( 2 );
assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, item.getOperation() );
assertEquals( values[4][3][0], item.getAttribute().getId() );
@@ -1217,7 +1416,7 @@ public class LdifReaderTest
// "delete: facsimiletelephonenumber"
// "facsimiletelephonenumber: +1 408 555 9876"
- item = ( Modification ) modifs.get( 3 );
+ item = modifs.get( 3 );
assertEquals( ModificationOperation.REMOVE_ATTRIBUTE, item.getOperation() );
@@ -1225,19 +1424,19 @@ public class LdifReaderTest
assertTrue( item.getAttribute().contains( values[4][4][1] ) );
// Sixth entry
- entry = ( LdifEntry ) entries.get( 5 );
+ entry = entries.get( 5 );
modifs = entry.getModificationItems();
assertTrue( entry.isChangeModify() );
assertEquals( values[5][0][1], entry.getDn().getName() );
// "replace: postaladdress"
- item = ( Modification ) modifs.get( 0 );
+ item = modifs.get( 0 );
assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, item.getOperation() );
assertEquals( values[5][1][0], item.getAttribute().getId() );
// "delete: description"
- item = ( Modification ) modifs.get( 1 );
+ item = modifs.get( 1 );
assertEquals( ModificationOperation.REMOVE_ATTRIBUTE, item.getOperation() );
assertEquals( values[5][2][0], item.getAttribute().getId() );
}
@@ -1246,23 +1445,27 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample7() throws Exception, Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: 1.2.840.113556.1.4.805 true\n"
- + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: 1.2.840.113556.1.4.805 true\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
reader.close();
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertEquals( "ou=Product Development, dc=airius, dc=com", entry.getDn().getName() );
assertTrue( entry.isChangeDelete() );
// Check the control
- Control control = entry.getControl();
+ Control control = entry.getControl( "1.2.840.113556.1.4.805" );
assertEquals( "1.2.840.113556.1.4.805", control.getOid() );
assertTrue( control.isCritical() );
@@ -1272,25 +1475,29 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample7NoValueNoCritical() throws Exception, Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: 1.2.840.11556.1.4.805\n"
- + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: 1.2.840.113556.1.4.805\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
reader.close();
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertEquals( "ou=Product Development, dc=airius, dc=com", entry.getDn().getName() );
assertTrue( entry.isChangeDelete() );
// Check the control
- Control control = entry.getControl();
+ Control control = entry.getControl( "1.2.840.113556.1.4.805" );
- assertEquals( "1.2.840.11556.1.4.805", control.getOid() );
+ assertEquals( "1.2.840.113556.1.4.805", control.getOid() );
assertFalse( control.isCritical() );
}
@@ -1298,25 +1505,29 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample7NoCritical() throws Exception, Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: 1.2.840.11556.1.4.805:control-value\n"
- + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: 1.2.840.113556.1.4.805:control-value\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
reader.close();
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertEquals( "ou=Product Development, dc=airius, dc=com", entry.getDn().getName() );
assertTrue( entry.isChangeDelete() );
// Check the control
- Control control = entry.getControl();
+ Control control = entry.getControl( "1.2.840.113556.1.4.805" );
- assertEquals( "1.2.840.11556.1.4.805", control.getOid() );
+ assertEquals( "1.2.840.113556.1.4.805", control.getOid() );
assertFalse( control.isCritical() );
assertEquals( "control-value", StringTools.utf8ToString( control.getValue() ) );
}
@@ -1325,10 +1536,15 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample7NoOid() throws Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: true\n" + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: true\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
@@ -1351,11 +1567,15 @@ public class LdifReaderTest
@Test
public void testLdifParserRFC2849Sample7BadOid() throws Exception
{
- String ldif = "version: 1\n" + "# Delete an entry. The operation will attach the LDAPv3\n"
- + "# Tree Delete Control defined in [9]. The criticality\n"
- + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n"
- + "dn: ou=Product Development, dc=airius, dc=com\n" + "control: 1.2.840.11A556.1.4.805 true\n"
- + "changetype: delete\n";
+ String ldif =
+ "version: 1\n" +
+ "# Delete an entry. The operation will attach the LDAPv3\n" +
+ "# Tree Delete Control defined in [9]. The criticality\n" +
+ "# field is \"true\" and the controlValue field is\n" +
+ "# absent, as required by [9].\n" +
+ "dn: ou=Product Development, dc=airius, dc=com\n" +
+ "control: 1.2.840.11A556.1.4.805 true\n" +
+ "changetype: delete\n";
LdifReader reader = new LdifReader();
@@ -1378,32 +1598,44 @@ public class LdifReaderTest
@Test
public void testLdifReaderDirServer() throws Exception, Exception
{
- String ldif = "# -------------------------------------------------------------------\n" + "#\n"
- + "# Licensed to the Apache Software Foundation (ASF) under one\n"
- + "# or more contributor license agreements. See the NOTICE file\n"
- + "# distributed with this work for additional information\n"
- + "# regarding copyright ownership. The ASF licenses this file\n"
- + "# to you under the Apache License, Version 2.0 (the\n"
- + "# \"License\"); you may not use this file except in compliance\n"
- + "# with the License. You may obtain a copy of the License at\n" + "# \n"
- + "# http://www.apache.org/licenses/LICENSE-2.0\n" + "# \n"
- + "# Unless required by applicable law or agreed to in writing,\n"
- + "# software distributed under the License is distributed on an\n"
- + "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n"
- + "# KIND, either express or implied. See the License for the\n"
- + "# specific language governing permissions and limitations\n" + "# under the License. \n" + "# \n"
- + "#\n" + "# EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" + "#\n"
- + "# http://www.rfc-editor.org/rfc/rfc2606.txt\n" + "#\n"
- + "# -------------------------------------------------------------------\n" + "\n"
- + "dn: ou=Users, dc=example, dc=com\n" + "objectclass: top\n" + "objectclass: organizationalunit\n"
- + "ou: Users";
+ String ldif =
+ "# -------------------------------------------------------------------\n" +
+ "#\n" +
+ "# Licensed to the Apache Software Foundation (ASF) under one\n" +
+ "# or more contributor license agreements. See the NOTICE file\n" +
+ "# distributed with this work for additional information\n" +
+ "# regarding copyright ownership. The ASF licenses this file\n" +
+ "# to you under the Apache License, Version 2.0 (the\n" +
+ "# \"License\"); you may not use this file except in compliance\n" +
+ "# with the License. You may obtain a copy of the License at\n" +
+ "# \n" +
+ "# http://www.apache.org/licenses/LICENSE-2.0\n" +
+ "# \n" +
+ "# Unless required by applicable law or agreed to in writing,\n" +
+ "# software distributed under the License is distributed on an\n" +
+ "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+ "# KIND, either express or implied. See the License for the\n" +
+ "# specific language governing permissions and limitations\n" +
+ "# under the License. \n" +
+ "# \n" +
+ "#\n" +
+ "# EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" +
+ "#\n" +
+ "# http://www.rfc-editor.org/rfc/rfc2606.txt\n" +
+ "#\n" +
+ "# -------------------------------------------------------------------\n" +
+ "\n" +
+ "dn: ou=Users, dc=example, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: organizationalunit\n" +
+ "ou: Users";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
reader.close();
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertEquals( "ou=Users, dc=example, dc=com", entry.getDn().getName() );
@@ -1419,50 +1651,51 @@ public class LdifReaderTest
@Test
public void testLdifParserCommentsEmptyLines() throws Exception, Exception
{
- String ldif = "#\n"
- + "# Licensed to the Apache Software Foundation (ASF) under one\n"
- + "# or more contributor license agreements. See the NOTICE file\n"
- + "# distributed with this work for additional information\n"
- + "# regarding copyright ownership. The ASF licenses this file\n"
- + "# to you under the Apache License, Version 2.0 (the\n"
- + "# \"License\"); you may not use this file except in compliance\n"
- + "# with the License. You may obtain a copy of the License at\n"
- + "# \n"
- + "# http://www.apache.org/licenses/LICENSE-2.0\n"
- + "# \n"
- + "# Unless required by applicable law or agreed to in writing,\n"
- + "# software distributed under the License is distributed on an\n"
- + "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n"
- + "# KIND, either express or implied. See the License for the\n"
- + "# specific language governing permissions and limitations\n"
- + "# under the License. \n"
- + "# \n"
- + "#\n"
- + "#\n"
- + "# EXAMPLE.COM is freely and reserved for testing according to this RFC:\n"
- + "#\n"
- + "# http://www.rfc-editor.org/rfc/rfc2606.txt\n"
- + "#\n"
- + "#\n"
- + "\n"
- + "#\n"
- + "# This ACI allows brouse access to the root suffix and one level below that to anyone.\n"
- + "# At this level there is nothing critical exposed. Everything that matters is one or\n"
- + "# more levels below this.\n"
- + "#\n"
- + "\n"
- + "dn: cn=browseRootAci,dc=example,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: subentry\n"
- + "objectClass: accessControlSubentry\n"
- + "subtreeSpecification: { maximum 1 }\n"
- + "prescriptiveACI: { identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }\n";
+ String ldif =
+ "#\n" +
+ "# Licensed to the Apache Software Foundation (ASF) under one\n" +
+ "# or more contributor license agreements. See the NOTICE file\n" +
+ "# distributed with this work for additional information\n" +
+ "# regarding copyright ownership. The ASF licenses this file\n" +
+ "# to you under the Apache License, Version 2.0 (the\n" +
+ "# \"License\"); you may not use this file except in compliance\n" +
+ "# with the License. You may obtain a copy of the License at\n" +
+ "# \n" +
+ "# http://www.apache.org/licenses/LICENSE-2.0\n" +
+ "# \n" +
+ "# Unless required by applicable law or agreed to in writing,\n" +
+ "# software distributed under the License is distributed on an\n" +
+ "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+ "# KIND, either express or implied. See the License for the\n" +
+ "# specific language governing permissions and limitations\n" +
+ "# under the License. \n" +
+ "# \n" +
+ "#\n" +
+ "#\n" +
+ "# EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" +
+ "#\n" +
+ "# http://www.rfc-editor.org/rfc/rfc2606.txt\n" +
+ "#\n" +
+ "#\n" +
+ "\n" +
+ "#\n" +
+ "# This ACI allows brouse access to the root suffix and one level below that to anyone.\n" +
+ "# At this level there is nothing critical exposed. Everything that matters is one or\n" +
+ "# more levels below this.\n" +
+ "#\n" +
+ "\n" +
+ "dn: cn=browseRootAci,dc=example,dc=com\n" +
+ "objectClass: top\n" +
+ "objectClass: subentry\n" +
+ "objectClass: accessControlSubentry\n" +
+ "subtreeSpecification: { maximum 1 }\n" +
+ "prescriptiveACI: { identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
reader.close();
- LdifEntry entry = ( LdifEntry ) entries.get( 0 );
+ LdifEntry entry = entries.get( 0 );
assertEquals( "cn=browseRootAci,dc=example,dc=com", entry.getDn().getName() );
EntryAttribute attr = entry.get( "objectClass" );
@@ -1482,10 +1715,20 @@ public class LdifReaderTest
@Test
public void testRemoveAttribute() throws Exception
{
- String ldif = "version: 1\n" + "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n"
- + "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n"
- + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n"
- + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
+ String ldif =
+ "version: 1\n" +
+ "dn: cn=Horatio Jensen, ou=Product Testing, dc=airius, dc=com\n" +
+ "objectclass: top\n" +
+ "objectclass: person\n" +
+ "objectclass: organizationalPerson\n" +
+ "cn: Horatio Jensen\n" +
+ "cn: Horatio N Jensen\n" +
+ "sn: Jensen\n" +
+ "uid: hjensen\n" +
+ "telephonenumber: +1 408 555 1212\n" +
+ "jpegphoto:< file:" +
+ HJENSEN_JPEG_FILE.getAbsolutePath() +
+ "\n";
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
@@ -1497,4 +1740,268 @@ public class LdifReaderTest
assertNotNull( entry.removeAttribute( "uid" ) );
assertNull( entry.get( "uid" ) );
}
+
+
+ @Test
+ public void testChangeTypeAdd() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: add\n" +
+ "attr1: ATTR1\n";
+
+ LdifReader reader = new LdifReader();
+ List<LdifEntry> entries = reader.parseLdif( ldif );
+ reader.close();
+
+ assertEquals( 1, entries.size() );
+
+ // Entry
+ LdifEntry entry = entries.get( 0 );
+
+ assertEquals( "dc=example,dc=com", entry.getDn().getName() );
+
+ assertTrue( entry.isLdifChange() );
+ assertTrue( entry.isChangeAdd() );
+
+ assertEquals( 1, entry.getEntry().size() );
+
+ EntryAttribute attr = entry.get( "attr1" );
+ assertTrue( attr.contains( "ATTR1" ) );
+ }
+
+
+ @Test
+ public void testChangeTypeAddAttrs2Values() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: add\n" +
+ "attr1: ATTR1\n" +
+ "attr1: ATTR2\n";
+
+ LdifReader reader = new LdifReader();
+ List<LdifEntry> entries = reader.parseLdif( ldif );
+ reader.close();
+
+ assertEquals( 1, entries.size() );
+
+ // Entry
+ LdifEntry entry = entries.get( 0 );
+
+ assertEquals( "dc=example,dc=com", entry.getDn().getName() );
+
+ assertTrue( entry.isLdifChange() );
+ assertTrue( entry.isChangeAdd() );
+
+ assertEquals( 1, entry.getEntry().size() );
+
+ EntryAttribute attr = entry.get( "attr1" );
+ assertEquals( 2, attr.size() );
+ assertTrue( attr.contains( "ATTR1" ) );
+ assertTrue( attr.contains( "ATTR2" ) );
+ }
+
+
+ @Test
+ public void testChangeTypeAdd2Attrs2Values() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: add\n" +
+ "attr1: ATTR1\n" +
+ "attr1: ATTR2\n" +
+ "attr2: ATTR1\n";
+
+ LdifReader reader = new LdifReader();
+ List<LdifEntry> entries = reader.parseLdif( ldif );
+ reader.close();
+
+ assertEquals( 1, entries.size() );
+
+ // Entry
+ LdifEntry entry = entries.get( 0 );
+
+ assertEquals( "dc=example,dc=com", entry.getDn().getName() );
+
+ assertTrue( entry.isLdifChange() );
+ assertTrue( entry.isChangeAdd() );
+
+ assertEquals( 2, entry.getEntry().size() );
+
+ EntryAttribute attr = entry.get( "attr1" );
+ assertEquals( 2, attr.size() );
+ assertTrue( attr.contains( "ATTR1" ) );
+ assertTrue( attr.contains( "ATTR2" ) );
+
+ EntryAttribute attr2 = entry.get( "attr2" );
+ assertEquals( 1, attr2.size() );
+ assertTrue( attr2.contains( "ATTR1" ) );
+ }
+
+
+ @Test
+ public void testChangeTypeDelete() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: delete\n";
+
+ LdifReader reader = new LdifReader();
+ List<LdifEntry> entries = reader.parseLdif( ldif );
+ reader.close();
+
+ assertEquals( 1, entries.size() );
+
+ // Entry
+ LdifEntry entry = entries.get( 0 );
+
+ assertEquals( "dc=example,dc=com", entry.getDn().getName() );
+
+ assertTrue( entry.isLdifChange() );
+ assertTrue( entry.isChangeDelete() );
+ }
+
+
+ @Test
+ public void testLdifChangeDeleteWithControl() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "control: 1.1.1\n" +
+ "changetype: delete\n";
+
+ LdifReader reader = new LdifReader();
+ List<LdifEntry> entries = reader.parseLdif( ldif );
+ reader.close();
+
+ assertEquals( 1, entries.size() );
+
+ // Entry
+ LdifEntry entry = entries.get( 0 );
+
+ assertEquals( "dc=example,dc=com", entry.getDn().getName() );
+
+ assertTrue( entry.isLdifChange() );
+ assertTrue( entry.isChangeDelete() );
+
+ assertTrue( entry.hasControls() );
+ assertEquals( 1, entry.getControls().size() );
+
+ Control control = entry.getControl( "1.1.1" );
+
+ assertEquals( "1.1.1", control.getOid() );
+ assertFalse( control.isCritical() );
+ assertNull( control.getValue() );
+ }
+
+
+ @Test
+ public void testLdifChangeDeleteWithControls() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "control: 1.1.1\n" +
+ "control: 1.1.2 true\n" +
+ "control: 1.1.3:ABCDEF\n" +
+ "control: 1.1.4 true:ABCDEF\n" +
+ "control: 1.1.5::RW1tYW51ZWwgTMOpY2hhcm55\n" +
+ "control: 1.1.6 true::RW1tYW51ZWwgTMOpY2hhcm55\n" +
+ "changetype: delete\n";
+
+ LdifReader reader = new LdifReader();
+ List<LdifEntry> entries = reader.parseLdif( ldif );
+ reader.close();
+
+ assertEquals( 1, entries.size() );
+
+ // Entry
+ LdifEntry entry = entries.get( 0 );
+
+ assertEquals( "dc=example,dc=com", entry.getDn().getName() );
+
+ assertTrue( entry.isLdifChange() );
+ assertTrue( entry.isChangeDelete() );
+
+ assertTrue( entry.hasControls() );
+ assertEquals( 6, entry.getControls().size() );
+
+ // First control
+ Control control = entry.getControl( "1.1.1" );
+
+ assertEquals( "1.1.1", control.getOid() );
+ assertFalse( control.isCritical() );
+ assertNull( control.getValue() );
+
+ // Second control
+ control = entry.getControl( "1.1.2" );
+
+ assertEquals( "1.1.2", control.getOid() );
+ assertTrue( control.isCritical() );
+ assertNull( control.getValue() );
+
+ // Third control
+ control = entry.getControl( "1.1.3" );
+
+ assertEquals( "1.1.3", control.getOid() );
+ assertFalse( control.isCritical() );
+ assertEquals( "ABCDEF", StringTools.utf8ToString( control.getValue() ) );
+
+ // Forth control
+ control = entry.getControl( "1.1.4" );
+
+ assertEquals( "1.1.4", control.getOid() );
+ assertTrue( control.isCritical() );
+ assertEquals( "ABCDEF", StringTools.utf8ToString( control.getValue() ) );
+
+ // Fifth control
+ control = entry.getControl( "1.1.5" );
+
+ assertEquals( "1.1.5", control.getOid() );
+ assertFalse( control.isCritical() );
+ assertEquals( "Emmanuel L\u00e9charny", StringTools.utf8ToString( control.getValue() ) );
+
+ // Sixth control
+ control = entry.getControl( "1.1.6" );
+
+ assertEquals( "1.1.6", control.getOid() );
+ assertTrue( control.isCritical() );
+ assertEquals( "Emmanuel L\u00e9charny", StringTools.utf8ToString( control.getValue() ) );
+ }
+
+
+ @Test( expected=LdapLdifException.class )
+ public void testChangeTypeDeleteBadEntry() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "changetype: delete\n" +
+ "attr1: test";
+
+ LdifReader reader = new LdifReader();
+
+ reader.parseLdif( ldif );
+ }
+
+
+ @Test( expected=LdapLdifException.class )
+ public void testLdifContentWithControl() throws Exception
+ {
+ String ldif =
+ "version: 1\n" +
+ "dn: dc=example,dc=com\n" +
+ "control: 1.1.1\n" +
+ "attr1: test";
+
+ LdifReader reader = new LdifReader();
+
+ reader.parseLdif( ldif );
+ }
}
Modified: directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=954149&r1=954148&r2=954149&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java (original)
+++ directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java Sun Jun 13 00:39:22 2010
@@ -36,6 +36,7 @@ import javax.naming.directory.BasicAttri
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControl;
import org.apache.directory.shared.ldap.entry.DefaultEntry;
import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
import org.apache.directory.shared.ldap.entry.Entry;
@@ -357,8 +358,6 @@ public class LdifUtilsTest
entry.addAttribute( "sn", "test" );
LdifUtils.convertToLdif( entry, 15 );
- //Attributes result = LdifUtils.convertFromLdif( ldif );
- //assertEquals( entry, result );
}
@@ -484,4 +483,66 @@ public class LdifUtilsTest
assertTrue( true );
}
}
+
+
+ @Test
+ public void testConvertEntryNoControls() throws Exception
+ {
+ String expected =
+ "dn: ou=test\n" +
+ "ObjectClass: top\n" +
+ "ObjectClass: metaTop\n" +
+ "ObjectClass: metaSyntax\n" +
+ "m-oid: 1.2.3.4\n" +
+ "m-description: description\n\n";
+
+ LdifEntry entry = new LdifEntry();
+
+ entry.setDn( "ou=test" );
+ entry.addAttribute( "ObjectClass", "top" );
+ entry.addAttribute( "ObjectClass", "metaTop" );
+ entry.addAttribute( "ObjectClass", "metaSyntax" );
+ entry.addAttribute( "m-oid", "1.2.3.4" );
+ entry.addAttribute( "m-description", "description" );
+
+ String converted = LdifUtils.convertToLdif( entry );
+
+ assertNotNull( converted );
+ assertEquals( expected, converted );
+ }
+
+
+
+
+ @Test
+ public void testConvertEntryOneControl() throws Exception
+ {
+ String expected =
+ "dn: ou=test\n" +
+ "control: 2.16.840.1.113730.3.4.2 false\n" +
+ "changetype: add\n" +
+ "ObjectClass: top\n" +
+ "ObjectClass: metaTop\n" +
+ "ObjectClass: metaSyntax\n" +
+ "m-oid: 1.2.3.4\n" +
+ "m-description: description\n\n";
+
+ LdifEntry entry = new LdifEntry();
+
+ entry.setDn( "ou=test" );
+ entry.addAttribute( "ObjectClass", "top" );
+ entry.addAttribute( "ObjectClass", "metaTop" );
+ entry.addAttribute( "ObjectClass", "metaSyntax" );
+ entry.addAttribute( "m-oid", "1.2.3.4" );
+ entry.addAttribute( "m-description", "description" );
+
+ ManageDsaITControl control = new ManageDsaITControl();
+
+ entry.addControl( control );
+
+ String converted = LdifUtils.convertToLdif( entry );
+
+ assertNotNull( converted );
+ assertEquals( expected, converted );
+ }
}