/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* This class defines a set of tests for the
* {@link org.opends.server.util.LDIFReader} class.
*/
// Top object class.
// Person object class.
// Object class attribute type.
// Common name attribute type.
// Surname attribute type.
// Description attribute type.
// Telephone number attribute type.
// Temporary file containing an attribute value.
// Temporary file content.
// Temporary file LDIF.
+ "changetype: add\n" + "objectClass: top\n"
+ "objectClass: person\n" + "cn: john\n" + "sn: smith\n"
+ "description:< file:///";
/**
* String of valid LDIF change records.
*
* Take from example 6 in the LDIF RFC + a couple of additions.
*/
+ "# 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"
+ "\n"
+ "# Delete an existing entry\n"
+ "dn: cn=Robert Jensen, ou=Marketing, dc=airius, dc=com\n"
+ "changetype: delete\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"
+ "# 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: modrdn\n"
+ "newrdn: ou=Product Development Accountants\n"
+ "deleteoldrdn: 0\n"
+ "newsuperior: ou=Accounting, dc=airius, dc=com\n"
+ "\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"
+ "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"
+ "# 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"
+ "\n"
+ "# Modify rootDSE.\n"
+ "dn: \n"
+ "changetype: modify\n"
+ "delete: description\n"
+ "-\n"
+ "\n"
+ "# Modify base64 DN.\n"
+ "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz\n"
+ "# dn:: uid=<uid>,ou=<JapaneseOU>,o=Airius\n"
+ "changetype:: bW9kaWZ5\n"
+ "delete: description\n"
+ "-\n"
+ "\n";
/**
* Once-only initialization.
*
* @throws Exception
* If an unexpected error occurred.
*/
// This test suite depends on having the schema available, so we'll
// start the server.
// Initialize schema bits.
// Create a temporary file containing an attribute value.
try {
} finally {
}
}
}
/**
* Once-only tear-down.
*
* @throws Exception
* If an unexpected error occurred.
*/
}
}
/**
* Check the initial state of an LDIF reader.
*
* @throws Exception
* If the test failed unexpectedly.
*/
@Test
try {
} finally {
}
}
/**
* Attempt to read an entry from an empty LDIF stream.
*
* @throws Exception
* If the test failed unexpectedly.
*/
@Test
try {
} finally {
}
}
/**
* Attempt to read an entry from an empty LDIF stream containing just
* the LDIF version.
*
* @throws Exception
* If the test failed unexpectedly.
*/
try {
} finally {
}
}
/**
* Attempt to read a change record from an empty LDIF stream.
*
* @throws Exception
* If the test failed unexpectedly.
*/
@Test
try {
} finally {
}
}
/**
* Attempt to read a single entry.
*
* @throws Exception
* If the test failed unexpectedly.
*/
+ "objectClass: top\n" + "objectClass: person\n" + "cn: john\n"
+ "sn: smith\n";
try {
.decode("cn=john, dc=foo, dc=com"));
AT_CN, "john")));
AT_SN, "smith")));
} finally {
}
}
/**
* Attempt to read an entry containing a folded line.
*
* @throws Exception
* If the test failed unexpectedly.
*/
+ "objectClass: top\n" + "objectClass: person\n" + "cn: john\n"
+ "sn: smith\n" + "description: once upon a time\n"
+ " in the west\n";
try {
AT_DESCR, "once upon a time in the west")));
} finally {
}
}
/**
* Attempt to read an entry containing a base64 line.
*
* @throws Exception
* If the test failed unexpectedly.
*/
+ "objectClass: top\n" + "objectClass: person\n" + "cn: john\n"
+ "sn: smith\n"
+ "description:: b25jZSB1cG9uIGEgdGltZSBpbiB0aGUgd2VzdA==\n";
try {
AT_DESCR, "once upon a time in the west")));
} finally {
}
}
/**
* Attempt to read multiple entries.
*
* @throws Exception
* If the test failed unexpectedly.
*/
+ "objectClass: top\n" + "objectClass: person\n" + "cn: john\n"
+ "sn: smith\n" + "\n" + "dn: cn=anne, dc=foo, dc=com\n"
+ "objectClass: top\n" + "objectClass: person\n" + "cn: anne\n"
+ "sn: other\n" + "\n";
try {
.decode("cn=anne, dc=foo, dc=com"));
AT_CN, "anne")));
AT_SN, "other")));
} finally {
}
}
/**
* Attempt to read multiple changes.
*
* @throws Exception
* If the test failed unexpectedly.
*/
try {
// Change record #1.
// Change record #2.
// Change record #3.
.decode("cn=Paul Jensen, ou=Product Development, dc=airius, dc=com");
// Change record #4.
.decode("ou=PD Accountants, ou=Product Development, dc=airius, dc=com");
// Change record #5.
.decode("cn=Paula Jensen, ou=Product Development, dc=airius, dc=com");
"123 Anystreet $ Sunnyvale, CA $ 94086");
// Change record #6.
.decode("cn=Ingrid Jensen, ou=Product Support, dc=airius, dc=com");
.getAttributeType("postaladdress"));
// Change record #7.
// Change record #8.
// Check final state.
} finally {
}
}
/**
* Attempt to read multiple changes and rejects one.
*
* @throws Exception
* If the test failed unexpectedly.
*/
try {
reader.readChangeRecord(false);
reader.readChangeRecord(false);
reader.readChangeRecord(false);
reader.readChangeRecord(false);
reader.readChangeRecord(false);
reader.readChangeRecord(false);
reader.readChangeRecord(false);
reader.readChangeRecord(false);
// Check final state.
} finally {
}
}
/**
* Attempt to read a change containing a file-based attribute.
*
* @throws Exception
* If the test failed unexpectedly.
*/
try {
// Check final state.
} finally {
}
}
/**
* LDIF change reader - invalid data provider.
*
* @return Returns an array of invalid LDIF change records.
*/
return new Object[][] {
{
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
": cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"x: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: foo\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn,=john smith, dc=com\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"chaxxngetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: foo\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype:: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
": add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype:\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"xxxx\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n" +
"cn: john\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
": top\n" +
"objectClass: person\n" +
"cn: john\n" +
"objectClass: person\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectclass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n" +
"description:: YnJva2VuIGJhc2U2NA*=="
},
{
"dn:: YnJva2VuIGJhc2U2NA*==" +
"changetype: add\n" +
"objectclass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn:: Y249YnJva2VuIGJhc2U2NCBkbix4" +
"changetype: add\n" +
"objectclass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectclass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n" +
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: add\n" +
"objectclass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n" +
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: delete\n" +
"objectclass: top\n" +
"objectClass: person\n" +
"cn: john\n" +
"sn: smith\n" +
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n" +
"newrdn: x\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n" +
"newrdn: cn=foo\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n" +
"newrdn: cn=foo\n" +
"deleteoldxx: xxx\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n" +
"newrdn: cn=foo\n" +
"deleteoldrdn: xxx\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n" +
"newrdn: cn=foo\n" +
"deleteoldrdn: 0\n" +
"newsu: xxxx\n"
},
{
"dn: cn=john smith, dc=com\n" +
"changetype: modrdn\n" +
"newrdn: cn=foo\n" +
"deleteoldrdn: 0\n" +
"newsuperior: xxxx\n"
},
};
}
/**
* Tests the read change record method against invalid LDIF records.
*
* @param ldifString
* The invalid LDIF change record.
* @throws Exception
* If the test failed unexpectedly.
*/
expectedExceptions = { LDIFException.class })
try {
} finally {
}
}
/**
* Create an LDIF reader from a string of LDIF.
*
* @param ldifString
* The string of LDIF. *
* @return Returns the LDIF reader.
* @throws Exception
* If an error occurred.
*/
new ByteArrayInputStream(bytes)));
return reader;
}
}