modifyAnAttribute.java revision 1fb669628faa2eb90d370eb249980b3a1807baba
a23fd118e437af0a7877dd313db8fdaa3537c675yl * CDDL HEADER START
a23fd118e437af0a7877dd313db8fdaa3537c675yl * The contents of this file are subject to the terms of the
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Common Development and Distribution License, Version 1.0 only
a23fd118e437af0a7877dd313db8fdaa3537c675yl * (the "License"). You may not use this file except in compliance
a23fd118e437af0a7877dd313db8fdaa3537c675yl * with the License.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * You can obtain a copy of the license at
a23fd118e437af0a7877dd313db8fdaa3537c675yl * See the License for the specific language governing permissions
a23fd118e437af0a7877dd313db8fdaa3537c675yl * and limitations under the License.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * When distributing Covered Code, include this CDDL HEADER in each
a23fd118e437af0a7877dd313db8fdaa3537c675yl * file and include the License file at
a23fd118e437af0a7877dd313db8fdaa3537c675yl * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
a23fd118e437af0a7877dd313db8fdaa3537c675yl * add the following below this CDDL HEADER, with the fields enclosed
a23fd118e437af0a7877dd313db8fdaa3537c675yl * by brackets "[]" replaced with your own identifying information:
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Portions Copyright [yyyy] [name of copyright owner]
a23fd118e437af0a7877dd313db8fdaa3537c675yl * CDDL HEADER END
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Portions Copyright 2007 Sun Microsystems, Inc.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * modify an entry with an attribute
a23fd118e437af0a7877dd313db8fdaa3537c675yl * the operation can be a replace, delete or a add new attribute
a23fd118e437af0a7877dd313db8fdaa3537c675yl * if expectedErrorCode is set, we compare it with the ldap error code returned in the exception
a23fd118e437af0a7877dd313db8fdaa3537c675yl * the function returns 0 if the code are equals
a23fd118e437af0a7877dd313db8fdaa3537c675yl * otherwise, returns 1
a23fd118e437af0a7877dd313db8fdaa3537c675ylpublic class modifyAnAttribute {
a23fd118e437af0a7877dd313db8fdaa3537c675yl if ( attributeToModify != null && newAttributeValue != null ) {
a23fd118e437af0a7877dd313db8fdaa3537c675yl newAttributeValue=newAttributeValue.replaceAll("QUOT","\\\"");
a23fd118e437af0a7877dd313db8fdaa3537c675yl String provider = "ldap://" + hostname + ":" + ldapPort + "/";
a23fd118e437af0a7877dd313db8fdaa3537c675yl envLdap.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");
a23fd118e437af0a7877dd313db8fdaa3537c675yl System.out.println(changetype + " attribute " + attributeToModify + " for entry " + dnToModify);
a23fd118e437af0a7877dd313db8fdaa3537c675yl // connect to server
a23fd118e437af0a7877dd313db8fdaa3537c675yl // replace attribute
a23fd118e437af0a7877dd313db8fdaa3537c675yl ctx.modifyAttributes(entryDN, LdapContext.REPLACE_ATTRIBUTE , attributes);
a23fd118e437af0a7877dd313db8fdaa3537c675yl // add attribute
a23fd118e437af0a7877dd313db8fdaa3537c675yl ctx.modifyAttributes(entryDN, LdapContext.ADD_ATTRIBUTE , attributes);
a23fd118e437af0a7877dd313db8fdaa3537c675yl // add attribute
a23fd118e437af0a7877dd313db8fdaa3537c675yl ctx.modifyAttributes(entryDN, LdapContext.REMOVE_ATTRIBUTE , attributes);
a23fd118e437af0a7877dd313db8fdaa3537c675yl // No error, the modify is success
a23fd118e437af0a7877dd313db8fdaa3537c675yl // Compare the errorCode and the expected error Code
a23fd118e437af0a7877dd313db8fdaa3537c675yl // Got the expected error Code. The test is success
a23fd118e437af0a7877dd313db8fdaa3537c675yl System.out.println ("Error: modify request didn't return the expected error Code");
a23fd118e437af0a7877dd313db8fdaa3537c675yl System.out.println ("Expected " + expectedErrorCode + "; Got" + errorCode);