Checkpoint commit for OPENDJ-1235 : Migrate configuration framework
Refactor ClassPropertyDefinition and AttributeTypePropertyDefinition classes to
replace static setup methods by dynamic setup through new argument in methods
* Introduce new class PropertyDefinitionsOptions to hold options
** Provide an immutable version with no validation as constant of the class as it is
needed in tests and some classes.
* Pass PropertyDefinitionsOptions as argument to PropertyDefinition#decodeValue
and PropertyDefinition#validateValue methods
* Update all classes using PropertyDefinition#decodeValue and
PropertyDefinition#validateValue methods
** For server classes, inject PropertyDefinitionsOptions to ServerManagementContext
and propagate to classes needing options
** For client classes, inject PropertyDefinitionsOptions to LDAPManagementContext
and LDAPDriver classes and propagate to classes needing options
** Exception for three classes - use an immutable PropertyDefinitionsOptions object
with no validation, as primary purpose is not validation of value :
*** Class DefaultManagedObject : call decodeValue to copy value
*** Class Reference : call decodeValue to normalize value
*** Class ContainsCondition : call decode value to compare value
* Update all test classes to use dynamic setup through PropertyDefinitionsOptions
when needed instead of static call in setup method
54 files modified
1 files added
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Aci value) { |
| | | public void validateValue(Aci value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Aci decodeValue(String value) { |
| | | public Aci decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) { |
| | | public String decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value); |
| | | validateValue(value, options); |
| | | return value; |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) { |
| | | public void validateValue(String value, PropertyDefinitionsOptions options) { |
| | | try { |
| | | Reference.parseName(parentPath, relationDefinition, value); |
| | | } catch (IllegalArgumentException e) { |
| | |
| | | } |
| | | } |
| | | |
| | | // Flag indicating whether or not attribute type names should be |
| | | // validated against the schema. |
| | | private static boolean isCheckSchema = true; |
| | | |
| | | /** |
| | | * Create a attribute type property definition builder. |
| | | * |
| | |
| | | return new Builder(d, propertyName); |
| | | } |
| | | |
| | | /** |
| | | * Determines whether or not attribute type names should be validated |
| | | * against the schema. |
| | | * |
| | | * @return Returns <code>true</code> if attribute type names should be |
| | | * validated against the schema. |
| | | */ |
| | | public static boolean isCheckSchema() { |
| | | return isCheckSchema; |
| | | } |
| | | |
| | | /** |
| | | * Specify whether or not attribute type names should be validated against |
| | | * the schema. |
| | | * <p> |
| | | * By default validation is switched on. |
| | | * |
| | | * @param value |
| | | * <code>true</code> if attribute type names should be validated |
| | | * against the schema. |
| | | */ |
| | | public static void setCheckSchema(boolean value) { |
| | | isCheckSchema = value; |
| | | } |
| | | |
| | | // Private constructor. |
| | | private AttributeTypePropertyDefinition(AbstractManagedObjectDefinition<?, ?> d, String propertyName, |
| | | EnumSet<PropertyOption> options, AdministratorAction adminAction, |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public AttributeType decodeValue(String value) { |
| | | public AttributeType decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | String name = value.trim().toLowerCase(); |
| | | AttributeType type = DirectoryServer.getAttributeType(name, !isCheckSchema); |
| | | AttributeType type = DirectoryServer.getAttributeType(name, !options.checkSchemaForAttributes()); |
| | | |
| | | if (type == null) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } else { |
| | | try { |
| | | validateValue(type); |
| | | validateValue(type, options); |
| | | return type; |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(AttributeType value) { |
| | | public void validateValue(AttributeType value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No implementation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Boolean value) { |
| | | public void validateValue(Boolean value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Boolean decodeValue(String value) { |
| | | public Boolean decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | |
| | | * Note that in a client/server environment, the client is probably not capable |
| | | * of validating the Java class (e.g. it will not be able to load it nor have |
| | | * access to the interfaces it is supposed to implement). For this reason, it is |
| | | * possible to switch off validation in the client by calling the static method |
| | | * {@link #setAllowClassValidation(boolean)}. |
| | | * possible to switch off validation in the client by using the appropriate |
| | | * {@link PropertyDefinitionsOptions}. |
| | | */ |
| | | public final class ClassPropertyDefinition extends PropertyDefinition<String> { |
| | | |
| | |
| | | throw new IllegalArgumentException("\"" + value + "\" is not a valid Java class name"); |
| | | } |
| | | |
| | | /* |
| | | * If possible try and load the class in order to perform additional |
| | | * validation. |
| | | */ |
| | | if (isAllowClassValidation()) { |
| | | /* |
| | | * Check that the class can be loaded so that validation can be |
| | | * performed. |
| | | */ |
| | | try { |
| | | loadClass(value, true); |
| | | } catch (ClassNotFoundException e) { |
| | | // TODO: can we do something better here? |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | instanceOfInterfaces.add(value); |
| | | } |
| | | |
| | |
| | | // Regular expression for validating class names. |
| | | private static final String CLASS_RE = "^([A-Za-z][A-Za-z0-9_]*\\.)*[A-Za-z][A-Za-z0-9_]*(\\$[A-Za-z0-9_]+)*$"; |
| | | |
| | | /* |
| | | * Flag indicating whether class property values should be validated. |
| | | */ |
| | | private static boolean allowClassValidation = true; |
| | | |
| | | /** |
| | | * Create a class property definition builder. |
| | | * |
| | |
| | | return new Builder(d, propertyName); |
| | | } |
| | | |
| | | /** |
| | | * Determine whether or not class property definitions should validate class |
| | | * name property values. Validation involves checking that the class exists |
| | | * and that it implements the required interfaces. |
| | | * |
| | | * @return Returns <code>true</code> if class property definitions should |
| | | * validate class name property values. |
| | | */ |
| | | public static boolean isAllowClassValidation() { |
| | | return allowClassValidation; |
| | | } |
| | | |
| | | /** |
| | | * Specify whether or not class property definitions should validate class |
| | | * name property values. Validation involves checking that the class exists |
| | | * and that it implements the required interfaces. |
| | | * <p> |
| | | * By default validation is switched on. |
| | | * |
| | | * @param value |
| | | * <code>true</code> if class property definitions should |
| | | * validate class name property values. |
| | | */ |
| | | public static void setAllowClassValidation(boolean value) { |
| | | allowClassValidation = value; |
| | | } |
| | | |
| | | // Load a named class. |
| | | private static Class<?> loadClass(String className, boolean initialize) throws ClassNotFoundException { |
| | | return Class.forName(className, initialize, ClassLoaderProvider.getInstance().getClassLoader()); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) { |
| | | public String decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value); |
| | | validateValue(value, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value, e.getCause()); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) { |
| | | public void validateValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Always make sure the name is a valid class name. |
| | |
| | | * If additional validation is enabled then attempt to load the class |
| | | * and check the interfaces that it implements/extends. |
| | | */ |
| | | if (allowClassValidation) { |
| | | if (options.allowClassValidation()) { |
| | | validateClassInterfaces(value, false); |
| | | } |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(DN value) { |
| | | public void validateValue(DN value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (baseDN != null) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public DN decodeValue(String value) { |
| | | public DN decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | // TODO: is it correct to replace server DN.decode by SDK valueOf ? |
| | | DN dn = DN.valueOf(value); |
| | | validateValue(dn); |
| | | validateValue(dn, options); |
| | | return dn; |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | |
| | | List<String> stringValues = propertyStringValues.get(pd.getName()); |
| | | if (stringValues != null) { |
| | | for (String stringValue : stringValues) { |
| | | values.add(pd.decodeValue(stringValue)); |
| | | // TODO : is it correct to have no validation ? |
| | | values.add(pd.decodeValue(stringValue, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS)); |
| | | } |
| | | } |
| | | return values; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Long value) { |
| | | public void validateValue(Long value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | long nvalue = baseUnit.toMilliSeconds(value); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long decodeValue(String value) { |
| | | public Long decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | |
| | | // Convert the value a long in the property's required unit. |
| | | Long i = (long) baseUnit.fromMilliSeconds(ms); |
| | | try { |
| | | validateValue(i); |
| | | validateValue(i, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public E decodeValue(String value) { |
| | | public E decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | String nvalue = value.trim().toLowerCase(); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(E value) { |
| | | public void validateValue(E value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(AddressMask value) { |
| | | public void validateValue(AddressMask value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public AddressMask decodeValue(String value) { |
| | | public AddressMask decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(InetAddress value) { |
| | | public void validateValue(InetAddress value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // No additional validation required. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public InetAddress decodeValue(String value) { |
| | | public InetAddress decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Integer value) { |
| | | public void validateValue(Integer value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Integer decodeValue(String value) { |
| | | public Integer decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (allowUnlimited) { |
| | |
| | | } |
| | | |
| | | try { |
| | | validateValue(i); |
| | | validateValue(i, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } |
| | |
| | | * <p> |
| | | * This method only casts the object to the required type; it does not |
| | | * validate the value once it has been cast. Subsequent validation should be |
| | | * performed using the method {@link #validateValue(Object)}. |
| | | * performed using the method {@link #validateValue(Object, PropertyDefinitionsOptions)}. |
| | | * <p> |
| | | * This method guarantees the following expression is always |
| | | * <code>true</code>: |
| | |
| | | * |
| | | * @param value |
| | | * The property string value (must not be <code>null</code>). |
| | | * @param options |
| | | * Options to use when decoding value. |
| | | * @return Returns the decoded property value. |
| | | * @throws IllegalPropertyValueStringException |
| | | * If the property value string is invalid. |
| | | */ |
| | | public abstract T decodeValue(String value); |
| | | public abstract T decodeValue(String value, PropertyDefinitionsOptions options); |
| | | |
| | | /** |
| | | * Encode the provided property value into its string representation. |
| | |
| | | * This method may throw an exception if the provided value is invalid. |
| | | * However, applications should not assume that implementations of this |
| | | * method will always validate a value. This task is the responsibility of |
| | | * {@link #validateValue(Object)}. |
| | | * {@link #validateValue(Object, PropertyDefinitionsOptions)}. |
| | | * <p> |
| | | * This default implementation simply returns the string representation of |
| | | * the provided value. Sub-classes might want to override this method if |
| | |
| | | * |
| | | * @param value |
| | | * The property value (must not be <code>null</code>). |
| | | * @param options |
| | | * Options to use when decoding value. |
| | | * @throws IllegalPropertyValueException |
| | | * If the property value is invalid. |
| | | */ |
| | | public abstract void validateValue(T value); |
| | | public abstract void validateValue(T value, PropertyDefinitionsOptions options); |
| | | |
| | | /** |
| | | * Performs any run-time initialization required by this property |
| New file |
| | |
| | | /* |
| | | * 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 |
| | | * or http://forgerock.org/license/CDDLv1.0.html. |
| | | * 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 2013 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.admin; |
| | | |
| | | /** |
| | | * Provides options for {@code PropertyDefinition property definitions}. |
| | | * <p> |
| | | * These options are used by some {@code PropertyDefinition} methods to define |
| | | * strategy used when processing value(s) of a property definition. |
| | | */ |
| | | public final class PropertyDefinitionsOptions { |
| | | |
| | | /** Immutable options with no validation of java classes or LDAP attributes. */ |
| | | public static final PropertyDefinitionsOptions NO_VALIDATION_OPTIONS = new PropertyDefinitionsOptions(). |
| | | setAllowClassValidation(false). |
| | | setCheckSchemaForAttributes(false). |
| | | freeze(); |
| | | |
| | | /** By default, class validation is enabled. */ |
| | | private boolean allowClassValidation = true; |
| | | |
| | | /** By default, attributes validation against the schema is enabled. */ |
| | | private boolean checkSchemaForAttributes = true; |
| | | |
| | | /** |
| | | * If true, then the instance is frozen so state can't be changed (object is |
| | | * immutable). |
| | | */ |
| | | private boolean isFrozen = false; |
| | | |
| | | /** |
| | | * Creates a new set of properties options with default settings. By |
| | | * default, class validation and attributes checking are enabled. |
| | | */ |
| | | public PropertyDefinitionsOptions() { |
| | | // empty implementation |
| | | } |
| | | |
| | | /** |
| | | * Determine whether or not class property definitions should validate class |
| | | * name property values. Validation involves checking that the class exists |
| | | * and that it implements the required interfaces. |
| | | * |
| | | * @return Returns <code>true</code> if class property definitions should |
| | | * validate class name property values. |
| | | */ |
| | | public boolean allowClassValidation() { |
| | | return allowClassValidation; |
| | | } |
| | | |
| | | /** |
| | | * Specify whether or not class property definitions should validate class |
| | | * name property values. Validation involves checking that the class exists |
| | | * and that it implements the required interfaces. |
| | | * <p> |
| | | * By default validation is switched on. |
| | | * |
| | | * @param value |
| | | * <code>true</code> if class property definitions should |
| | | * validate class name property values. |
| | | * @return A reference to this definitions options. |
| | | */ |
| | | public PropertyDefinitionsOptions setAllowClassValidation(boolean value) { |
| | | if (isFrozen) { |
| | | throw new IllegalStateException("This object is frozen, it can't be changed"); |
| | | } |
| | | allowClassValidation = value; |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * Determines whether or not attribute type names should be validated |
| | | * against the schema. |
| | | * |
| | | * @return Returns <code>true</code> if attribute type names should be |
| | | * validated against the schema. |
| | | */ |
| | | public boolean checkSchemaForAttributes() { |
| | | return checkSchemaForAttributes; |
| | | } |
| | | |
| | | /** |
| | | * Specify whether or not attribute type names should be validated against |
| | | * the schema. |
| | | * <p> |
| | | * By default validation is switched on. |
| | | * |
| | | * @param value |
| | | * <code>true</code> if attribute type names should be validated |
| | | * against the schema. |
| | | * @return A reference to this definitions options. |
| | | */ |
| | | public PropertyDefinitionsOptions setCheckSchemaForAttributes(boolean value) { |
| | | if (isFrozen) { |
| | | throw new IllegalStateException("This object is frozen, it can't be changed"); |
| | | } |
| | | checkSchemaForAttributes = value; |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * Freeze this object, making it effectively immutable. |
| | | * <p> |
| | | * Once this method is called, all {@code set} methods will throw |
| | | * an IllegalStateException if called. |
| | | * |
| | | * @return A reference to this definitions options. |
| | | */ |
| | | public PropertyDefinitionsOptions freeze() { |
| | | isFrozen = true; |
| | | return this; |
| | | } |
| | | |
| | | } |
| | |
| | | private <T> String normalizeName(PropertyDefinition<T> pd) { |
| | | if (pd != null) { |
| | | try { |
| | | T tvalue = pd.decodeValue(name); |
| | | // TODO : is it correct to have no validation ? |
| | | T tvalue = pd.decodeValue(name, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | return pd.normalizeValue(tvalue); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | // Fall through to default normalization. |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(Long value) { |
| | | public void validateValue(Long value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (!allowUnlimited && value < lowerLimit) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long decodeValue(String value) { |
| | | public Long decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | |
| | | } |
| | | |
| | | try { |
| | | validateValue(i); |
| | | validateValue(i, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String decodeValue(String value) { |
| | | public String decodeValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | try { |
| | | validateValue(value); |
| | | validateValue(value, options); |
| | | } catch (IllegalPropertyValueException e) { |
| | | throw new IllegalPropertyValueStringException(this, value); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void validateValue(String value) { |
| | | public void validateValue(String value, PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (pattern != null) { |
| | |
| | | import org.opends.server.admin.OperationsException; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionUsageBuilder; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | |
| | | /** |
| | | * Thrown when an attempt is made to create a new managed object with an illegal |
| | |
| | | private static final long serialVersionUID = 7491748228684293291L; |
| | | |
| | | /** Create the message. */ |
| | | // @Checkstyle:ignore |
| | | private static LocalizableMessage createMessage(String illegalName, PropertyDefinition<?> namingPropertyDefinition) { |
| | | private static LocalizableMessage createMessage(String illegalName, PropertyDefinition<?> namingPropertyDefinition, |
| | | PropertyDefinitionsOptions options) { |
| | | if (illegalName.length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_EMPTY.get(); |
| | | } else if (illegalName.trim().length() == 0) { |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_BLANK.get(); |
| | | } else if (namingPropertyDefinition != null) { |
| | | try { |
| | | namingPropertyDefinition.decodeValue(illegalName); |
| | | namingPropertyDefinition.decodeValue(illegalName, options); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | PropertyDefinitionUsageBuilder builder = new PropertyDefinitionUsageBuilder(true); |
| | | return ERR_ILLEGAL_MANAGED_OBJECT_NAME_EXCEPTION_SYNTAX.get(illegalName, |
| | |
| | | * The illegal managed object name. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName) { |
| | | this(illegalName, null); |
| | | this(illegalName, null, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * The illegal managed object name. |
| | | * @param namingPropertyDefinition |
| | | * The naming property definition. |
| | | * @param options |
| | | * Options to decode property definition values. |
| | | */ |
| | | public IllegalManagedObjectNameException(String illegalName, PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(createMessage(illegalName, namingPropertyDefinition)); |
| | | public IllegalManagedObjectNameException(String illegalName, PropertyDefinition<?> namingPropertyDefinition, |
| | | PropertyDefinitionsOptions options) { |
| | | super(createMessage(illegalName, namingPropertyDefinition, options)); |
| | | |
| | | this.illegalName = illegalName; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionVisitor; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | import org.opends.server.admin.PropertyIsSingleValuedException; |
| | |
| | | */ |
| | | private static final class ValueDecoder extends PropertyDefinitionVisitor<Object, String> { |
| | | |
| | | private final PropertyDefinitionsOptions options; |
| | | |
| | | /** |
| | | * Decodes the provided property LDAP value. |
| | | * |
| | |
| | | * The property definition. |
| | | * @param value |
| | | * The LDAP string representation. |
| | | * @param options |
| | | * Decoding options for property definitions. |
| | | * @return Returns the decoded LDAP value. |
| | | * @throws IllegalPropertyValueStringException |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | | public static <P> P decode(PropertyDefinition<P> pd, Object value) { |
| | | public static <P> P decode(PropertyDefinition<P> pd, Object value, PropertyDefinitionsOptions options) { |
| | | String s = String.valueOf(value); |
| | | return pd.castValue(pd.accept(new ValueDecoder(), s)); |
| | | return pd.castValue(pd.accept(new ValueDecoder(options), s)); |
| | | } |
| | | |
| | | // Prevent instantiation. |
| | | private ValueDecoder() { |
| | | // No implementation required. |
| | | private ValueDecoder(PropertyDefinitionsOptions options) { |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public <T> Object visitUnknown(PropertyDefinition<T> d, String p) { |
| | | // By default the property definition's decoder will do. |
| | | return d.decodeValue(p); |
| | | return d.decodeValue(p, options); |
| | | } |
| | | } |
| | | |
| | | // The LDAP connection. |
| | | private LDAPManagementContext context; |
| | | |
| | | private final LDAPConnection connection; |
| | | |
| | | // The LDAP management context. |
| | | private final LDAPManagementContext context; |
| | | |
| | | // The LDAP profile which should be used to construct LDAP |
| | | // requests and decode LDAP responses. |
| | | private final LDAPProfile profile; |
| | |
| | | * Creates a new LDAP driver using the specified LDAP connection and |
| | | * profile. |
| | | * |
| | | * @param context |
| | | * The LDAP management context. |
| | | * @param connection |
| | | * The LDAP connection. |
| | | * @param profile |
| | | * The LDAP profile. |
| | | * @param propertyDefOptions |
| | | * Options used to validate property definitions values |
| | | */ |
| | | public LDAPDriver(LDAPManagementContext context, LDAPConnection connection, LDAPProfile profile) { |
| | | this.context = context; |
| | | public LDAPDriver(LDAPConnection connection, LDAPProfile profile, PropertyDefinitionsOptions propertyDefOptions) { |
| | | super(propertyDefOptions); |
| | | this.connection = connection; |
| | | this.profile = profile; |
| | | } |
| | | |
| | | void setManagementContext(LDAPManagementContext context) { |
| | | this.context = context; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | |
| | | |
| | | // Decode the values. |
| | | SortedSet<P> values = new TreeSet<P>(propertyDef); |
| | | PropertyDefinitionsOptions options = context.getPropertyDefOptions(); |
| | | if (attribute != null) { |
| | | for (ByteString byteValue : attribute) { |
| | | P value = ValueDecoder.decode(propertyDef, byteValue); |
| | | P value = ValueDecoder.decode(propertyDef, byteValue, options); |
| | | values.add(value); |
| | | } |
| | | } |
| | |
| | | |
| | | // Get the property's active values. |
| | | SortedSet<P> activeValues = new TreeSet<P>(propertyDef); |
| | | PropertyDefinitionsOptions options = context.getPropertyDefOptions(); |
| | | if (attribute != null) { |
| | | for (ByteString byteValue : attribute) { |
| | | P value = ValueDecoder.decode(propertyDef, byteValue); |
| | | P value = ValueDecoder.decode(propertyDef, byteValue, options); |
| | | activeValues.add(value); |
| | | } |
| | | } |
| | |
| | | LDAPManagedObject(LDAPDriver driver, ManagedObjectDefinition<T, ? extends Configuration> d, |
| | | ManagedObjectPath<T, ? extends Configuration> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | super(d, path, properties, existsOnServer, namingPropertyDefinition); |
| | | super(d, path, properties, existsOnServer, namingPropertyDefinition, |
| | | driver.getManagementContext().getPropertyDefOptions()); |
| | | this.driver = driver; |
| | | } |
| | | |
| | |
| | | package org.opends.server.admin.client.ldap; |
| | | |
| | | import org.opends.server.admin.LDAPProfile; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.client.ManagementContext; |
| | | import org.opends.server.admin.client.spi.Driver; |
| | | |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param connection |
| | | * The LDAP connection. |
| | | * @param profile |
| | | * The LDAP profile. |
| | | * @param options |
| | | * Options to decode values of property definitions. |
| | | * @return Returns the new management context. |
| | | */ |
| | | public static ManagementContext createFromContext(LDAPConnection connection) { |
| | | Reject.ifNull(connection); |
| | | return new LDAPManagementContext(connection, LDAPProfile.getInstance()); |
| | | public static ManagementContext createFromContext(LDAPConnection connection, LDAPProfile profile, |
| | | PropertyDefinitionsOptions options) { |
| | | Reject.ifNull(connection, profile, options); |
| | | LDAPDriver driver = new LDAPDriver(connection, profile, options); |
| | | LDAPManagementContext context = new LDAPManagementContext(driver, options); |
| | | driver.setManagementContext(context); |
| | | return context; |
| | | } |
| | | |
| | | // The LDAP management context driver. |
| | | /** The LDAP management context driver. */ |
| | | private final LDAPDriver driver; |
| | | |
| | | // Private constructor. |
| | | private LDAPManagementContext(LDAPConnection connection, LDAPProfile profile) { |
| | | this.driver = new LDAPDriver(this, connection, profile); |
| | | /** Options to validate and decode values of property definitions. */ |
| | | private final PropertyDefinitionsOptions options; |
| | | |
| | | /** Private constructor. */ |
| | | private LDAPManagementContext(LDAPDriver driver, PropertyDefinitionsOptions options) { |
| | | this.driver = driver; |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected Driver getDriver() { |
| | | return driver; |
| | | } |
| | | |
| | | /** |
| | | * Returns the property definitions options. |
| | | * |
| | | * @return the options to validate and decode values of property |
| | | * definitions. |
| | | */ |
| | | protected PropertyDefinitionsOptions getPropertyDefOptions() { |
| | | return options; |
| | | } |
| | | } |
| | |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.OptionalRelationDefinition; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | import org.opends.server.admin.PropertyIsReadOnlyException; |
| | | import org.opends.server.admin.PropertyOption; |
| | |
| | | // The managed object's properties. |
| | | private final PropertySet properties; |
| | | |
| | | /** Decoding options for property definitions values. */ |
| | | private final PropertyDefinitionsOptions propertyDefOptions; |
| | | |
| | | /** |
| | | * Creates a new abstract managed object. |
| | | * |
| | |
| | | * committed). |
| | | * @param namingPropertyDefinition |
| | | * Optional naming property definition. |
| | | * @param propertyDefOptions TODO |
| | | */ |
| | | protected AbstractManagedObject(ManagedObjectDefinition<T, ? extends Configuration> d, |
| | | ManagedObjectPath<T, ? extends Configuration> path, PropertySet properties, boolean existsOnServer, |
| | | PropertyDefinition<?> namingPropertyDefinition) { |
| | | PropertyDefinition<?> namingPropertyDefinition, PropertyDefinitionsOptions propertyDefOptions) { |
| | | this.definition = d; |
| | | this.path = path; |
| | | this.properties = properties; |
| | | this.existsOnServer = existsOnServer; |
| | | this.namingPropertyDefinition = namingPropertyDefinition; |
| | | this.propertyDefOptions = propertyDefOptions; |
| | | } |
| | | |
| | | /** |
| | |
| | | PropertyDefinition<?> pd = r.getNamingPropertyDefinition(); |
| | | if (pd != null) { |
| | | try { |
| | | pd.decodeValue(name); |
| | | pd.decodeValue(name, propertyDefOptions); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | throw new IllegalManagedObjectNameException(name, pd); |
| | | throw new IllegalManagedObjectNameException(name, pd, propertyDefOptions); |
| | | } |
| | | } |
| | | |
| | |
| | | throw new PropertyIsReadOnlyException(pd); |
| | | } |
| | | |
| | | properties.setPropertyValues(pd, values); |
| | | properties.setPropertyValues(pd, values, propertyDefOptions); |
| | | |
| | | // If this is a naming property then update the name. |
| | | if (pd.equals(namingPropertyDefinition)) { |
| | |
| | | |
| | | // Set the naming property if there is one. |
| | | if (namingPropertyDefinition != null) { |
| | | P value = namingPropertyDefinition.decodeValue(name); |
| | | childProperties.setPropertyValues(namingPropertyDefinition, Collections.singleton(value)); |
| | | P value = namingPropertyDefinition.decodeValue(name, propertyDefOptions); |
| | | childProperties.setPropertyValues(namingPropertyDefinition, Collections.singleton(value), |
| | | propertyDefOptions); |
| | | } |
| | | |
| | | return newInstance(d, p, childProperties, false, namingPropertyDefinition); |
| | |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.OptionalRelationDefinition; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.PropertyIsSingleValuedException; |
| | | import org.opends.server.admin.PropertyNotFoundException; |
| | |
| | | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | | values.add(nextProperty.decodeValue(stringValue)); |
| | | values.add(nextProperty.decodeValue(stringValue, propertyDefOptions)); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | exception = new DefaultBehaviorException(nextProperty, e); |
| | | break; |
| | |
| | | Collection<T> tmp = find(target, pd2); |
| | | Collection<T> values = new ArrayList<T>(tmp.size()); |
| | | for (T value : tmp) { |
| | | pd1.validateValue(value); |
| | | pd1.validateValue(value, propertyDefOptions); |
| | | values.add(value); |
| | | } |
| | | return values; |
| | |
| | | } |
| | | }; |
| | | |
| | | private final PropertyDefinitionsOptions propertyDefOptions; |
| | | |
| | | /** |
| | | * Creates a new abstract management context. |
| | | * Creates a new abstract driver. |
| | | * |
| | | * @param propertyDefOptions |
| | | * Decoding options for property definitions values. |
| | | */ |
| | | protected Driver() { |
| | | // No implementation required. |
| | | protected Driver(PropertyDefinitionsOptions propertyDefOptions) { |
| | | this.propertyDefOptions = propertyDefOptions; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import org.opends.server.admin.IllegalPropertyValueException; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | import org.opends.server.admin.PropertyIsSingleValuedException; |
| | | import org.opends.server.admin.PropertyOption; |
| | |
| | | * property (an empty set indicates that the property should be |
| | | * reset to its default behavior). The set will not be referenced |
| | | * by this managed object. |
| | | * @param options |
| | | * Options to validate property definitions values. |
| | | * @throws IllegalPropertyValueException |
| | | * If a new pending value is deemed to be invalid according to |
| | | * the property definition. |
| | |
| | | * If the specified property definition is not associated with |
| | | * this managed object. |
| | | */ |
| | | <T> void setPropertyValues(PropertyDefinition<T> d, Collection<T> values) { |
| | | <T> void setPropertyValues(PropertyDefinition<T> d, Collection<T> values, |
| | | PropertyDefinitionsOptions options) { |
| | | MyProperty<T> property = (MyProperty<T>) getProperty(d); |
| | | |
| | | if (values.size() > 1 && !d.hasOption(PropertyOption.MULTI_VALUED)) { |
| | |
| | | throw new NullPointerException(); |
| | | } |
| | | |
| | | d.validateValue(e); |
| | | d.validateValue(e, options); |
| | | } |
| | | |
| | | // Update the property. |
| | |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.server.admin.AbstractManagedObjectDefinition; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.client.ManagementContext; |
| | | import org.opends.server.admin.server.ServerManagedObject; |
| | |
| | | |
| | | // Creates the new private implementation. |
| | | private <T> void buildImpl(PropertyDefinition<T> pd) { |
| | | T value = pd.decodeValue(propertyStringValue); |
| | | T value = pd.decodeValue(propertyStringValue, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | this.impl = new Impl<T>(pd, value); |
| | | } |
| | | |
| | |
| | | e.printStackTrace(); |
| | | System.exit(1); |
| | | } |
| | | // Switch off class name validation in client. |
| | | ClassPropertyDefinition.setAllowClassValidation(false); |
| | | // Switch off attribute type name validation in client. |
| | | AttributeTypePropertyDefinition.setCheckSchema(false); |
| | | |
| | | // Build a sorted list of top managed objects |
| | | TopCfgDefn topCfg = TopCfgDefn.getInstance(); |
| | |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionVisitor; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | | import org.opends.server.admin.PropertyIsSingleValuedException; |
| | |
| | | |
| | | for (String stringValue : stringValues) { |
| | | try { |
| | | values.add(nextProperty.decodeValue(stringValue)); |
| | | values.add(nextProperty.decodeValue(stringValue, propertyDefOptions)); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | exception = new DefaultBehaviorException(nextProperty, e); |
| | | break; |
| | |
| | | if (attributeValues.size() > 0) { |
| | | Collection<T> pvalues = new ArrayList<T>(); |
| | | for (String value : attributeValues) { |
| | | pvalues.add(ValueDecoder.decode(propDef1, value)); |
| | | pvalues.add(ValueDecoder.decode(propDef1, value, propertyDefOptions)); |
| | | } |
| | | return pvalues; |
| | | } else { |
| | |
| | | Collection<T> tmp = find(target, propDef2); |
| | | Collection<T> pvalues = new ArrayList<T>(tmp.size()); |
| | | for (T value : tmp) { |
| | | propDef1.validateValue(value); |
| | | propDef1.validateValue(value, propertyDefOptions); |
| | | pvalues.add(value); |
| | | } |
| | | return pvalues; |
| | |
| | | */ |
| | | private static final class ValueDecoder extends PropertyDefinitionVisitor<Object, String> { |
| | | |
| | | private final PropertyDefinitionsOptions options; |
| | | |
| | | /** |
| | | * Decodes the provided property LDAP value. |
| | | * |
| | |
| | | * The property definition. |
| | | * @param value |
| | | * The LDAP string representation. |
| | | * @param options |
| | | * Options to decode property definitions values. |
| | | * @return Returns the decoded LDAP value. |
| | | * @throws IllegalPropertyValueStringException |
| | | * If the property value could not be decoded because it was |
| | | * invalid. |
| | | */ |
| | | public static <P> P decode(PropertyDefinition<P> propertyDef, String value) { |
| | | return propertyDef.castValue(propertyDef.accept(new ValueDecoder(), value)); |
| | | public static <P> P decode(PropertyDefinition<P> propertyDef, String value, |
| | | PropertyDefinitionsOptions options) { |
| | | return propertyDef.castValue(propertyDef.accept(new ValueDecoder(options), value)); |
| | | } |
| | | |
| | | // Prevent instantiation. |
| | | private ValueDecoder() { |
| | | // No implementation required. |
| | | private ValueDecoder(PropertyDefinitionsOptions options) { |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public <T> Object visitUnknown(PropertyDefinition<T> d, String p) { |
| | | // By default the property definition's decoder will do. |
| | | return d.decodeValue(p); |
| | | return d.decodeValue(p, options); |
| | | } |
| | | } |
| | | |
| | |
| | | private final ConfigurationRepository configRepository; |
| | | |
| | | /** |
| | | * Options to use when decoding and validating values of property |
| | | * definitions. |
| | | */ |
| | | private final PropertyDefinitionsOptions propertyDefOptions; |
| | | |
| | | /** |
| | | * Creates a context from the provided configuration repository. |
| | | * |
| | | * @param repository |
| | | * The repository of configuration entries. |
| | | * @param propertyDefOptions |
| | | * Options to use when decoding and validating values |
| | | * of property definitions. |
| | | */ |
| | | ServerManagementContext(ConfigurationRepository repository) { |
| | | ServerManagementContext(ConfigurationRepository repository, PropertyDefinitionsOptions propertyDefOptions) { |
| | | configRepository = repository; |
| | | this.propertyDefOptions = propertyDefOptions; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return the root configuration server managed object |
| | | */ |
| | | public ServerManagedObject<RootCfg> getRootConfigurationManagedObject() { |
| | | // Use lazy initialisation because it needs a reference to this server |
| | | // context. |
| | | // Use lazy initialisation |
| | | // because it needs a reference to this server context. |
| | | ServerManagedObject<RootCfg> rootObject = root; |
| | | if (rootObject == null) { |
| | | synchronized (this) { |
| | |
| | | // The property has values defined for it. |
| | | for (String value : attributeValues) { |
| | | try { |
| | | pvalues.add(ValueDecoder.decode(propertyDef, value)); |
| | | pvalues.add(ValueDecoder.decode(propertyDef, value, propertyDefOptions)); |
| | | } catch (IllegalPropertyValueStringException e) { |
| | | exception = e; |
| | | } |
| | |
| | | package org.forgerock.opendj.config; |
| | | |
| | | import org.forgerock.opendj.ldap.SdkTestCase; |
| | | import org.opends.server.admin.ClassPropertyDefinition; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Test(groups = { "precommit", "config" }) |
| | | public abstract class ConfigTestCase extends SdkTestCase { |
| | | |
| | | protected void disableClassValidationForProperties() { |
| | | ClassPropertyDefinition.setAllowClassValidation(false); |
| | | } |
| | | |
| | | protected void enableClassValidationForProperties() { |
| | | ClassPropertyDefinition.setAllowClassValidation(true); |
| | | } |
| | | // no implementation |
| | | } |
| | |
| | | import org.opends.server.admin.DefinedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.ManagedObjectDefinition; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyOption; |
| | | import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider; |
| | | import org.opends.server.admin.UndefinedDefaultBehaviorProvider; |
| | |
| | | * Example: |
| | | * |
| | | * <pre> |
| | | * { |
| | | * @code |
| | | * LDAPConnectionHandlerCfg mockCfg = mockCfg(LDAPConnectionHandlerCfg.class); |
| | | * assertThat(mockCfg.getMaxRequestSize()).isEqualTo(5 * 1000 * 1000); |
| | | * } |
| | | * </pre> |
| | | */ |
| | | public final class ConfigurationMock { |
| | |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | private <T> Object getDefaultValue(ManagedObjectDefinition<?, ?> definition, |
| | | Method getPropertyDefMethod, Class<T> propertyReturnClass) throws Exception { |
| | | Method getPropertyDefMethod, @SuppressWarnings("unused") Class<T> propertyReturnClass) |
| | | throws Exception { |
| | | PropertyDefinition<T> propertyDefinition = (PropertyDefinition<T>) getPropertyDefMethod.invoke(definition); |
| | | DefaultBehaviorProvider<T> defaultBehaviorProvider = (DefaultBehaviorProvider<T>) propertyDefinition |
| | | .getClass().getMethod("getDefaultBehaviorProvider").invoke(propertyDefinition); |
| | |
| | | public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> provider, Void p) { |
| | | SortedSet<T> values = new TreeSet<T>(); |
| | | for (String stringValue : provider.getDefaultValues()) { |
| | | values.add(propertyDef.decodeValue(stringValue)); |
| | | values.add(propertyDef.decodeValue(stringValue, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS)); |
| | | } |
| | | return values; |
| | | } |
| | |
| | | import org.forgerock.opendj.admin.server.GoverningStructureRuleVirtualAttributeCfg; |
| | | import org.forgerock.opendj.admin.server.LDAPConnectionHandlerCfg; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.opends.server.admin.AttributeTypePropertyDefinition; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | |
| | | @SuppressWarnings("javadoc") |
| | | public class ConfigurationMockTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | void setup() { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @AfterClass |
| | | void cleanup() { |
| | | enableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testPropertyWithStringReturnValue() { |
| | | GoverningStructureRuleVirtualAttributeCfg mock = mockCfg(GoverningStructureRuleVirtualAttributeCfg.class); |
| | |
| | | |
| | | @Test |
| | | public void testPropertyWithAttributeTypeReturnValue() throws Exception { |
| | | AttributeTypePropertyDefinition.setCheckSchema(false); // attribute type is not in default schema |
| | | CollectiveAttributeSubentriesVirtualAttributeCfg mock = |
| | | mockCfg(CollectiveAttributeSubentriesVirtualAttributeCfg.class); |
| | | assertThat(mock.getAttributeType()).isEqualTo( |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | return configRepository; |
| | | } |
| | | |
| | | /** Returns the name used for this entry (the value of the cn attribute) */ |
| | | /** Returns the name used for the provided entry (the value of the cn attribute) */ |
| | | protected final String entryName(final Entry entry) { |
| | | return entry.getName().rdn().getFirstAVA().getAttributeValue().toString(); |
| | | } |
| | | |
| | | /** Gets the named parent configuration corresponding to the entry */ |
| | | /** Gets the named parent configuration corresponding to the provided entry */ |
| | | protected final TestParentCfg getParentCfg(final Entry entry, final ServerManagementContext serverContext) |
| | | throws Exception { |
| | | return getParentCfg(entryName(entry), serverContext); |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class AttributeTypePropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testValidateValue() { |
| | | AttributeTypePropertyDefinition.setCheckSchema(true); |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | propertyDef.validateValue(Schema.getDefaultSchema().getAttributeType("cn")); |
| | | propertyDef.validateValue(Schema.getDefaultSchema().getAttributeType("cn"), new PropertyDefinitionsOptions()); |
| | | } |
| | | |
| | | @DataProvider(name = "valueLegalData") |
| | |
| | | |
| | | @Test(dataProvider = "valueLegalData") |
| | | public void testDecodeValue(String value) { |
| | | AttributeTypePropertyDefinition.setCheckSchema(true); |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | AttributeType expected = Schema.getDefaultSchema().getAttributeType(value); |
| | | assertEquals(propertyDef.decodeValue(value), expected); |
| | | assertEquals(propertyDef.decodeValue(value, new PropertyDefinitionsOptions()), expected); |
| | | } |
| | | |
| | | @Test(dataProvider = "valueLegalData") |
| | | public void testEncodeValue(String value) { |
| | | AttributeTypePropertyDefinition.setCheckSchema(true); |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | assertEquals(propertyDef.encodeValue(propertyDef.decodeValue(value)), value); |
| | | assertEquals(propertyDef.encodeValue(propertyDef.decodeValue(value, new PropertyDefinitionsOptions())), value); |
| | | } |
| | | |
| | | @DataProvider(name = "valueIllegalData") |
| | |
| | | |
| | | @Test(dataProvider = "valueIllegalData", expectedExceptions = { IllegalPropertyValueStringException.class }) |
| | | public void testDecodeValueIllegal(String value) { |
| | | AttributeTypePropertyDefinition.setCheckSchema(true); |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | propertyDef.decodeValue(value); |
| | | propertyDef.decodeValue(value, new PropertyDefinitionsOptions()); |
| | | } |
| | | |
| | | @Test(dataProvider = "valueIllegalData") |
| | | public void testDecodeValueIllegalNoSchemaCheck(String value) { |
| | | AttributeTypePropertyDefinition.setCheckSchema(false); |
| | | AttributeTypePropertyDefinition propertyDef = createPropertyDefinition(); |
| | | AttributeType type = propertyDef.decodeValue(value); |
| | | AttributeType type = propertyDef.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | assertEquals(type.getNameOrOID(), value); |
| | | |
| | | // Make sure to turn schema checking back on |
| | | // so that other tests which depend on it don't fail. |
| | | AttributeTypePropertyDefinition.setCheckSchema(true); |
| | | } |
| | | |
| | | // Create a new definition. |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | builder = BooleanPropertyDefinition.createBuilder(RootCfgDefn.getInstance(), "test-property"); |
| | | } |
| | | |
| | | @Test |
| | | public void testValidateValue() { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.validateValue(Boolean.TRUE); |
| | | def.validateValue(Boolean.TRUE, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | | public void testValidateValueIllegal() { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.validateValue(null); |
| | | def.validateValue(null, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "decodeValueData") |
| | |
| | | @Test(dataProvider = "decodeValueData") |
| | | public void testDecodeValue(String value, Boolean expected) { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | assertEquals(def.decodeValue(value), expected); |
| | | assertEquals(def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS), expected); |
| | | } |
| | | |
| | | @DataProvider(name = "decodeValueDataIllegal") |
| | |
| | | IllegalPropertyValueStringException.class }) |
| | | public void testDecodeValueIllegal(String value) { |
| | | BooleanPropertyDefinition def = createPropertyDefinition(); |
| | | def.decodeValue(value); |
| | | def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | private BooleanPropertyDefinition createPropertyDefinition() { |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class ClassPropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | // Dummy class used in tests. |
| | | public static final class Dummy { |
| | | public class X { |
| | |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class DNPropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @DataProvider(name = "baseDN") |
| | | public Object[][] createBuilderSetBaseDN() { |
| | | return new Object[][] { |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate)); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate), PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = IllegalPropertyValueException.class) |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate)); |
| | | propertyDef.validateValue(DN.valueOf(valueToValidate), PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(dataProvider = "legalValues") |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.decodeValue(valueToValidate); |
| | | propertyDef.decodeValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(dataProvider = "illegalValues", expectedExceptions = IllegalPropertyValueStringException.class) |
| | |
| | | "test-property"); |
| | | localBuilder.setBaseDN(baseDN); |
| | | DNPropertyDefinition propertyDef = localBuilder.getInstance(); |
| | | propertyDef.decodeValue(valueToValidate); |
| | | propertyDef.decodeValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | } |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class DurationPropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testCreateBuilder() { |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(true); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.decodeValue("unlimited"); |
| | | def.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueStringException.class) |
| | |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.decodeValue("unlimited"); |
| | | def.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueException.class) |
| | |
| | | DurationPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.validateValue(-1L); |
| | | def.validateValue(-1L, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "validateValueData") |
| | |
| | | builder.setUpperLimit(higherLimitInMillis); |
| | | builder.setAllowUnlimited(isAllowUnlimited); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.validateValue(valueInSeconds); |
| | | def.validateValue(valueInSeconds, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValidateValueData") |
| | |
| | | builder.setUpperLimit(highLimitInMillis); |
| | | builder.setAllowUnlimited(isAllowUnlimited); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.validateValue(valueInSeconds); |
| | | def.validateValue(valueInSeconds, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "encodeValueData") |
| | |
| | | builder.setMaximumUnit(DurationUnit.DAYS); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | |
| | | assertThat(def.decodeValue(valueToDecode)).isEqualTo(expectedValue); |
| | | assertThat(def.decodeValue(valueToDecode, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS)). |
| | | isEqualTo(expectedValue); |
| | | } |
| | | |
| | | @DataProvider(name = "decodeValueDataIllegal") |
| | |
| | | builder.setLowerLimit(5L); |
| | | builder.setUpperLimit(10L); |
| | | DurationPropertyDefinition def = buildTestDefinition(builder); |
| | | def.decodeValue(valueToDecode); |
| | | def.decodeValue(valueToDecode, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | private DurationPropertyDefinition.Builder createTestBuilder() { |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() { |
| | | disableClassValidationForProperties(); |
| | | builder = EnumPropertyDefinition.createBuilder(RootCfgDefn.getInstance(), "test-property"); |
| | | builder.setEnumClass(TestEnum.class); |
| | | } |
| | |
| | | @Test(dataProvider = "decodeValueData") |
| | | public void testDecodeValue(String value, TestEnum expectedValue) { |
| | | EnumPropertyDefinition<?> def = builder.getInstance(); |
| | | assertEquals(def.decodeValue(value), expectedValue); |
| | | assertEquals(def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS), expectedValue); |
| | | } |
| | | |
| | | /** |
| | |
| | | IllegalPropertyValueStringException.class }) |
| | | public void testDecodeValueIllegalData(String value) { |
| | | EnumPropertyDefinition<?> def = builder.getInstance(); |
| | | def.decodeValue(value); |
| | | def.decodeValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Test |
| | | public void testValidateValue() { |
| | | EnumPropertyDefinition<TestEnum> def = builder.getInstance(); |
| | | def.validateValue(TestEnum.ONE); |
| | | def.validateValue(TestEnum.ONE, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class IntegerPropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testCreateBuilder() { |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(true); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited"); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueStringException.class) |
| | |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited"); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueException.class) |
| | |
| | | IntegerPropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(-1); |
| | | propertyDef.validateValue(-1, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "validateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(allowUnlimited); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(valueToValidate); |
| | | propertyDef.validateValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValidateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(allowUnlimited); |
| | | IntegerPropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(value); |
| | | propertyDef.validateValue(value, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "encodeValueData") |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.GlobalCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class LDAPProfileTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | /** Makes sure the returned list contains "top" */ |
| | | @Test |
| | | public void testGetObjectClasses() { |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() { |
| | | disableClassValidationForProperties(); |
| | | definitionI18NResource = ManagedObjectDefinitionI18NResource.getInstanceForProfile("ldap"); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.admin.server.LDAPConnectionHandlerCfg; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class ManagedObjectPathTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testEmptyPathIsEmpty() { |
| | | ManagedObjectPath<?, ?> path = ManagedObjectPath.emptyPath(); |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() { |
| | | disableClassValidationForProperties(); |
| | | parentDefinition = TestParentCfgDefn.getInstance(); |
| | | this.defaultBehaviorProvider = new RelativeInheritedDefaultBehaviorProvider<Boolean>( |
| | | parentDefinition, |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class SizePropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testCreateBuilder() { |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(true); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited"); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueStringException.class) |
| | |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.decodeValue("unlimited"); |
| | | propertyDef.decodeValue("unlimited", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test(expectedExceptions = IllegalPropertyValueException.class) |
| | |
| | | SizePropertyDefinition.Builder builder = createTestBuilder(); |
| | | builder.setAllowUnlimited(false); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(-1L); |
| | | propertyDef.validateValue(-1L, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "validateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(isAllowUnlimited); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(valueToValidate); |
| | | propertyDef.validateValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "illegalValidateValueData") |
| | |
| | | builder.setUpperLimit(high); |
| | | builder.setAllowUnlimited(allowUnlimited); |
| | | SizePropertyDefinition propertyDef = buildTestDefinition(builder); |
| | | propertyDef.validateValue(valueToValidate); |
| | | propertyDef.validateValue(valueToValidate, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @DataProvider(name = "encodeValueData") |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class StringPropertyDefinitionTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testValidateValueNoPattern() { |
| | | StringPropertyDefinition d = getDefinition(true, null); |
| | | d.validateValue("abc"); |
| | | d.validateValue("abc", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test |
| | | public void testValidateValuePatternMatches() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.validateValue("abc"); |
| | | d.validateValue("abc", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | // TODO : I18N problem |
| | | @Test(enabled = false, expectedExceptions = IllegalPropertyValueException.class) |
| | | public void testValidateValuePatternDoesNotMatch() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.validateValue("abc123"); |
| | | d.validateValue("abc123", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | @Test |
| | | public void testDecodeValuePatternMatches() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | assertEquals(d.decodeValue("abc"), "abc"); |
| | | assertEquals(d.decodeValue("abc", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS), "abc"); |
| | | } |
| | | |
| | | // TODO : I18N problem |
| | | @Test(enabled = false, expectedExceptions = IllegalPropertyValueStringException.class) |
| | | public void testDecodeValuePatternDoesNotMatch() { |
| | | StringPropertyDefinition d = getDefinition(true, "^[a-z]+$"); |
| | | d.decodeValue("abc123"); |
| | | d.decodeValue("abc123", PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | } |
| | | |
| | | // Create a string property definition. |
| | |
| | | |
| | | import org.forgerock.opendj.admin.meta.RootCfgDefn; |
| | | import org.forgerock.opendj.config.ConfigTestCase; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | |
| | |
| | | @Test(singleThreaded = true) |
| | | public class TestTopCfgDefnTest extends ConfigTestCase { |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | } |
| | | |
| | | @Test |
| | | public void testGetInstance() { |
| | | assertNotNull(TopCfgDefn.getInstance()); |
| | |
| | | |
| | | @BeforeClass |
| | | public void setup() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.admin.client.RootCfgClient; |
| | | import org.opends.server.admin.AdminTestCase; |
| | | import org.opends.server.admin.IllegalPropertyValueStringException; |
| | | import org.opends.server.admin.LDAPProfile; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.TestCfg; |
| | | import org.opends.server.admin.TestChildCfgClient; |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | public void testAggregationEmpty() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 1"); |
| | | assertSetEquals(child.getAggregationProperty(), new String[0]); |
| | |
| | | public void testAggregationSingle() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | |
| | |
| | | public void testAggregationMultiple() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 3"); |
| | | assertSetEquals(child.getAggregationProperty(), "LDAPS Connection Handler", "LDAP Connection Handler"); |
| | |
| | | public void testAggregationBadBaseDN() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | |
| | | try { |
| | |
| | | c.addExpectedAttribute("ds-cfg-rotation-policy", |
| | | "cn=LDAP Connection Handler,cn=connection handlers, cn=config"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | |
| | | c.addExpectedModification("ds-cfg-rotation-policy", |
| | | "cn=HTTP Connection Handler,cn=connection handlers, cn=config", |
| | | "cn=JMX Connection Handler,cn=connection handlers, cn=config"); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setAggregationProperty(Arrays.asList("JMX Connection Handler", "HTTP Connection Handler")); |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.opends.server.admin.AdminTestCase; |
| | | import org.opends.server.admin.Constraint; |
| | | import org.opends.server.admin.LDAPProfile; |
| | | import org.opends.server.admin.ManagedObjectAlreadyExistsException; |
| | | import org.opends.server.admin.ManagedObjectNotFoundException; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.TestCfg; |
| | | import org.opends.server.admin.TestChildCfgClient; |
| | | import org.opends.server.admin.TestChildCfgDefn; |
| | |
| | | @Test(singleThreaded = true) |
| | | public final class LDAPClientTest extends AdminTestCase { |
| | | |
| | | // Test LDIF. |
| | | // @Checkstyle:off |
| | | private static final String[] TEST_LDIF = new String[] { |
| | | // Base entries. |
| | | "dn: cn=config", |
| | |
| | | "objectclass: ds-cfg-test-child-dummy", "cn: test child 1", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "", }; |
| | | // @Checkstyle:on |
| | | |
| | | /** |
| | | * Provide valid naming exception to client API exception mappings. |
| | |
| | | @DataProvider(name = "createManagedObjectExceptions") |
| | | public Object[][] createManagedObjectExceptions() { |
| | | return new Object[][] { |
| | | // result code corresponding to exception thrown, expected exception, expected code result |
| | | // result code corresponding to exception thrown, expected |
| | | // exception, expected code result |
| | | { ResultCode.PROTOCOL_ERROR, ErrorResultException.class, ResultCode.PROTOCOL_ERROR }, |
| | | { ResultCode.UNAVAILABLE , ErrorResultException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.ENTRY_ALREADY_EXISTS, ManagedObjectAlreadyExistsException.class, null }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, ErrorResultException.class, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, OperationRejectedException.class, null } |
| | | }; |
| | | { ResultCode.UNWILLING_TO_PERFORM, OperationRejectedException.class, null } }; |
| | | } |
| | | |
| | | /** |
| | |
| | | @DataProvider(name = "getManagedObjectExceptions") |
| | | public Object[][] getManagedObjectExceptions() { |
| | | return new Object[][] { |
| | | // result code corresponding to exception thrown, expected exception, expected code result |
| | | // result code corresponding to exception thrown, expected |
| | | // exception, expected code result |
| | | { ResultCode.PROTOCOL_ERROR, ErrorResultException.class, ResultCode.PROTOCOL_ERROR }, |
| | | { ResultCode.UNAVAILABLE, ErrorResultException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.NO_SUCH_OBJECT, ManagedObjectNotFoundException.class, null }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, ErrorResultException.class, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, ErrorResultException.class, |
| | | ResultCode.UNWILLING_TO_PERFORM } |
| | | }; |
| | | { ResultCode.UNWILLING_TO_PERFORM, ErrorResultException.class, ResultCode.UNWILLING_TO_PERFORM } }; |
| | | } |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | | |
| | | @AfterClass |
| | | public void tearDown() { |
| | | TestCfg.cleanup(); |
| | |
| | | */ |
| | | @Test |
| | | public void testCreateChildManagedObject() throws Exception { |
| | | CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection( |
| | | CreateEntryMockLDAPConnection c = |
| | | new CreateEntryMockLDAPConnection( |
| | | "cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedAttribute("cn", "test child new"); |
| | |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | |
| | | |
| | | }; |
| | | conn.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(conn); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(conn, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | try { |
| | | TestParentCfgClient parent = createTestParent(ctx, "test parent new"); |
| | | parent.setMandatoryBooleanProperty(true); |
| | |
| | | */ |
| | | @Test |
| | | public void testCreateTopLevelManagedObject() throws Exception { |
| | | CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection( |
| | | "cn=test parent new,cn=test parents,cn=config"); |
| | | CreateEntryMockLDAPConnection c = |
| | | new CreateEntryMockLDAPConnection("cn=test parent new,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedAttribute("cn", "test parent new"); |
| | | c.addExpectedAttribute("objectClass", "top", "ds-cfg-test-parent-dummy"); |
| | | c.addExpectedAttribute("ds-cfg-enabled", "true"); |
| | | c.addExpectedAttribute("ds-cfg-java-class", |
| | | "org.opends.server.extensions.SomeVirtualAttributeProvider"); |
| | | c.addExpectedAttribute("ds-cfg-java-class", "org.opends.server.extensions.SomeVirtualAttributeProvider"); |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = createTestParent(ctx, "test parent new"); |
| | | parent.setMandatoryBooleanProperty(true); |
| | | parent.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer.getAttributeType("description")); |
| | |
| | | public void testGetChildManagedObject() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 3"); |
| | | Assert.assertEquals(child.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | |
| | | public void testGetChildManagedObjectDefault() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 1"); |
| | | Assert.assertEquals(child.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | |
| | | |
| | | }; |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | try { |
| | | getTestParent(ctx, "test parent 2"); |
| | | } catch (Exception e) { |
| | |
| | | public void testGetTopLevelManagedObject() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 2"); |
| | | Assert.assertEquals(parent.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | | Assert.assertEquals(parent.getMandatoryClassProperty(), |
| | |
| | | public void testGetTopLevelManagedObjectDefault() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | Assert.assertEquals(parent.isMandatoryBooleanProperty(), Boolean.TRUE); |
| | | Assert.assertEquals(parent.getMandatoryClassProperty(), |
| | |
| | | */ |
| | | @Test |
| | | public void testInheritedDefaultValues1() throws Exception { |
| | | CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection( |
| | | CreateEntryMockLDAPConnection c = |
| | | new CreateEntryMockLDAPConnection( |
| | | "cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedAttribute("cn", "test child new"); |
| | |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testInheritedDefaultValues2() throws Exception { |
| | | CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection( |
| | | CreateEntryMockLDAPConnection c = |
| | | new CreateEntryMockLDAPConnection( |
| | | "cn=test child new,cn=test children,cn=test parent 2,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedAttribute("cn", "test child new"); |
| | |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 2"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | |
| | |
| | | public void testListChildManagedObjects() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | String[] actual = parent.listTestChildren(); |
| | | String[] expected = new String[] { "test child 1", "test child 2", "test child 3" }; |
| | |
| | | public void testListChildManagedObjectsEmpty() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 3"); |
| | | String[] actual = parent.listTestChildren(); |
| | | String[] expected = new String[] {}; |
| | |
| | | public void testListTopLevelManagedObjects() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | String[] actual = listTestParents(ctx); |
| | | String[] expected = new String[] { "test parent 1", "test parent 2", "test parent 3" }; |
| | | Assert.assertEqualsNoOrder(actual, expected); |
| | |
| | | @Test |
| | | public void testListTopLevelManagedObjectsEmpty() throws Exception { |
| | | MockLDAPConnection c = new MockLDAPConnection(); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | String[] actual = listTestParents(ctx); |
| | | String[] expected = new String[] {}; |
| | | Assert.assertEqualsNoOrder(actual, expected); |
| | |
| | | */ |
| | | @Test |
| | | public void testModifyChildManagedObjectResetToDefault() throws Exception { |
| | | ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection( |
| | | ModifyEntryMockLDAPConnection c = |
| | | new ModifyEntryMockLDAPConnection( |
| | | "cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-base-dn"); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet()); |
| | |
| | | */ |
| | | @Test |
| | | public void testModifyTopLevelManagedObjectNoChanges() throws Exception { |
| | | ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection( |
| | | "cn=test parent 1,cn=test parents,cn=config"); |
| | | ModifyEntryMockLDAPConnection c = |
| | | new ModifyEntryMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.commit(); |
| | | Assert.assertFalse(c.isEntryModified()); |
| | |
| | | */ |
| | | @Test |
| | | public void testModifyTopLevelManagedObjectWithChanges() throws Exception { |
| | | ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection( |
| | | "cn=test parent 1,cn=test parents,cn=config"); |
| | | ModifyEntryMockLDAPConnection c = |
| | | new ModifyEntryMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-enabled", "false"); |
| | | c.addExpectedModification("ds-cfg-base-dn", "dc=mod1,dc=com", "dc=mod2,dc=com"); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.setMandatoryBooleanProperty(false); |
| | | parent.setOptionalMultiValuedDNProperty(Arrays.asList(DN.valueOf("dc=mod1,dc=com"), |
| | |
| | | */ |
| | | @Test |
| | | public void testRemoveChildManagedObject() throws Exception { |
| | | DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection( |
| | | DeleteSubtreeMockLDAPConnection c = |
| | | new DeleteSubtreeMockLDAPConnection( |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.removeTestChild("test child 1"); |
| | | c.assertSubtreeIsDeleted(); |
| | |
| | | */ |
| | | @Test |
| | | public void testRemoveTopLevelManagedObject() throws Exception { |
| | | DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection( |
| | | "cn=test parent 1,cn=test parents,cn=config"); |
| | | DeleteSubtreeMockLDAPConnection c = |
| | | new DeleteSubtreeMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | removeTestParent(ctx, "test parent 1"); |
| | | c.assertSubtreeIsDeleted(); |
| | | } |
| | |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | | CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection( |
| | | CreateEntryMockLDAPConnection c = |
| | | new CreateEntryMockLDAPConnection( |
| | | "cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedAttribute("cn", "test child new"); |
| | |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | c.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | | CreateEntryMockLDAPConnection conn = new CreateEntryMockLDAPConnection( |
| | | CreateEntryMockLDAPConnection conn = |
| | | new CreateEntryMockLDAPConnection( |
| | | "cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | conn.importLDIF(TEST_LDIF); |
| | | conn.addExpectedAttribute("cn", "test child new"); |
| | |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | conn.addExpectedAttribute("ds-cfg-attribute-type", "description"); |
| | | |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(conn); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(conn, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null); |
| | | child.setMandatoryBooleanProperty(true); |
| | |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | | DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection( |
| | | DeleteSubtreeMockLDAPConnection c = |
| | | new DeleteSubtreeMockLDAPConnection( |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.removeTestChild("test child 1"); |
| | | c.assertSubtreeIsDeleted(); |
| | |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | | DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection( |
| | | DeleteSubtreeMockLDAPConnection c = |
| | | new DeleteSubtreeMockLDAPConnection( |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | parent.removeTestChild("test child 1"); |
| | | Assert.fail("The remove constraint failed to prevent removal of the managed object"); |
| | |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | | ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection( |
| | | ModifyEntryMockLDAPConnection c = |
| | | new ModifyEntryMockLDAPConnection( |
| | | "cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-base-dn"); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet()); |
| | |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | | ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection( |
| | | ModifyEntryMockLDAPConnection c = |
| | | new ModifyEntryMockLDAPConnection( |
| | | "cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config"); |
| | | c.importLDIF(TEST_LDIF); |
| | | c.addExpectedModification("ds-cfg-base-dn"); |
| | | ManagementContext ctx = LDAPManagementContext.createFromContext(c); |
| | | ManagementContext ctx = |
| | | LDAPManagementContext.createFromContext(c, LDAPProfile.getInstance(), |
| | | PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfgClient parent = getTestParent(ctx, "test parent 1"); |
| | | TestChildCfgClient child = parent.getTestChild("test child 2"); |
| | | child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet()); |
| | |
| | | } |
| | | |
| | | // Create the named test parent managed object. |
| | | private TestParentCfgClient createTestParent(ManagementContext context, String name) |
| | | throws Exception { |
| | | private TestParentCfgClient createTestParent(ManagementContext context, String name) throws Exception { |
| | | ManagedObject<RootCfgClient> root = context.getRootConfigurationManagedObject(); |
| | | return root.createChild(TestCfg.getTestOneToManyParentRelationDefinition(), TestParentCfgDefn.getInstance(), |
| | | name, null).getConfiguration(); |
| | | } |
| | | |
| | | // Retrieve the named test parent managed object. |
| | | private TestParentCfgClient getTestParent(ManagementContext context, String name) |
| | | throws Exception { |
| | | private TestParentCfgClient getTestParent(ManagementContext context, String name) throws Exception { |
| | | ManagedObject<RootCfgClient> root = context.getRootConfigurationManagedObject(); |
| | | return root.getChild(TestCfg.getTestOneToManyParentRelationDefinition(), name).getConfiguration(); |
| | | } |
| | |
| | | import org.opends.server.admin.AdministratorAction; |
| | | import org.opends.server.admin.AggregationPropertyDefinition; |
| | | import org.opends.server.admin.IllegalPropertyValueStringException; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.PropertyOption; |
| | | import org.opends.server.admin.TestCfg; |
| | |
| | | } |
| | | } |
| | | |
| | | // @Checkstyle:off |
| | | private static final Entry TEST_CHILD_1 = makeEntry( |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 1", "ds-cfg-enabled: true", |
| | | "cn: test child 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real"); |
| | |
| | | "dn: cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 2", "ds-cfg-enabled: true", |
| | | "cn: test child 2", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real", |
| | |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 5", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "ds-cfg-conflict-behavior: virtual-overrides-real", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real", |
| | | "ds-cfg-rotation-policy: cn=BAD Connection Handler 1, cn=connection handlers, cn=config", |
| | | "ds-cfg-rotation-policy: cn=BAD Connection Handler 2, cn=connection handlers, cn=config", |
| | | "ds-cfg-rotation-policy: cn=LDAP Connection Handler, cn=connection handlers, cn=config"); |
| | |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 6", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "ds-cfg-conflict-behavior: virtual-overrides-real", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real", |
| | | "ds-cfg-rotation-policy: cn=Test Connection Handler, cn=connection handlers, cn=config"); |
| | | |
| | | private static final Entry TEST_CHILD_7 = makeEntry( |
| | |
| | | "ds-cfg-java-class: org.opends.server.protocols.ldap.LDAPConnectionHandler", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-listen-address: 0.0.0.0", "ds-cfg-listen-port: 389"); |
| | | // @Checkstyle:on |
| | | |
| | | // @Checkstyle:off |
| | | /** |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | |
| | | // Save the aggregation property definition so that it can be |
| | | // replaced and restored later. |
| | | aggregationPropertyDefinitionDefault = TestChildCfgDefn.getInstance() |
| | | .getAggregationPropertyPropertyDefinition(); |
| | | aggregationPropertyDefinitionDefault = |
| | | TestChildCfgDefn.getInstance().getAggregationPropertyPropertyDefinition(); |
| | | |
| | | // Create the two test aggregation properties. |
| | | AggregationPropertyDefinition.Builder<ConnectionHandlerCfgClient, ConnectionHandlerCfg> builder; |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationBadBaseDN() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_3, |
| | | LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_3, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | try { |
| | | parentCfg.getTestChild(entryName(TEST_CHILD_3)); |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationDanglingReference() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | TEST_PARENT_1, TEST_CHILD_5, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_5, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | |
| | | try { |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationDisabledReference1() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | TEST_PARENT_1, TEST_CHILD_6, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_6, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationDisabledReference2() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | TEST_PARENT_1, TEST_CHILD_7, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_7, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationDisabledReference3() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | TEST_PARENT_1, TEST_CHILD_6, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_6, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | |
| | | registerAggregationDefinitionWithTargetAndSourceEnabled(); |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationDisabledReference4() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | TEST_PARENT_1, TEST_CHILD_7, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_7, TEST_CONNECTION_HANDLER_ENTRY_DISABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | |
| | | registerAggregationDefinitionWithTargetAndSourceEnabled(); |
| | | |
| | |
| | | @Test |
| | | public void testAggregationEmpty() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_1)); |
| | | |
| | | assertEquals(testChildCfg.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | assertEquals(testChildCfg.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | Schema.getDefaultSchema().getAttributeType("description")); |
| | | assertEquals(testChildCfg.getMandatoryReadOnlyAttributeTypeProperty(), Schema.getDefaultSchema() |
| | | .getAttributeType("description")); |
| | | assertSetEquals(testChildCfg.getAggregationProperty(), new String[0]); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationMultipleValues() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_4, |
| | | LDAP_CONN_HANDLER_ENTRY, LDAPS_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_4, LDAP_CONN_HANDLER_ENTRY, |
| | | LDAPS_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_4)); |
| | | |
| | | assertEquals(testChildCfg.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | assertEquals(testChildCfg.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | Schema.getDefaultSchema().getAttributeType("description")); |
| | | assertSetEquals(testChildCfg.getAggregationProperty(), |
| | | "LDAPS Connection Handler", "LDAP Connection Handler"); |
| | | assertEquals(testChildCfg.getMandatoryReadOnlyAttributeTypeProperty(), Schema.getDefaultSchema() |
| | | .getAttributeType("description")); |
| | | assertSetEquals(testChildCfg.getAggregationProperty(), "LDAPS Connection Handler", "LDAP Connection Handler"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Test |
| | | public void testAggregationSingle() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_2, |
| | | LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_2, LDAP_CONN_HANDLER_ENTRY); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg testChildCfg = parentCfg.getTestChild(entryName(TEST_CHILD_2)); |
| | | |
| | | assertEquals(testChildCfg.getMandatoryClassProperty(), |
| | | "org.opends.server.extensions.UserDefinedVirtualAttributeProvider"); |
| | | assertEquals(testChildCfg.getMandatoryReadOnlyAttributeTypeProperty(), |
| | | Schema.getDefaultSchema().getAttributeType("description")); |
| | | assertEquals(testChildCfg.getMandatoryReadOnlyAttributeTypeProperty(), Schema.getDefaultSchema() |
| | | .getAttributeType("description")); |
| | | |
| | | // Test normalization. |
| | | assertSetEquals(testChildCfg.getAggregationProperty(), "LDAP Connection Handler"); |
| | |
| | | */ |
| | | @Test |
| | | public void testCannotDeleteReferencedComponent() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENTS, TEST_PARENT_1, |
| | | TEST_BASE_CHILD, TEST_CHILD_7, CONN_HANDLER_ENTRY, TEST_CONNECTION_HANDLER_ENTRY_ENABLED); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENTS, TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_7, |
| | | CONN_HANDLER_ENTRY, TEST_CONNECTION_HANDLER_ENTRY_ENABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | registeredListener.capture()); |
| | | |
| | | // Now simulate the delete ofthe referenced connection handler. |
| | | assertThat(registeredListener.getValue(). |
| | | configDeleteIsAcceptable(TEST_CONNECTION_HANDLER_ENTRY_ENABLED, new LocalizableMessageBuilder())). |
| | | isFalse(); |
| | | assertThat( |
| | | registeredListener.getValue().configDeleteIsAcceptable(TEST_CONNECTION_HANDLER_ENTRY_ENABLED, |
| | | new LocalizableMessageBuilder())).isFalse(); |
| | | |
| | | } finally { |
| | | putBackDefaultAggregationDefinitionFromTargetEnabled(); |
| | |
| | | */ |
| | | @Test |
| | | public void testCannotDisableReferencedComponent() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENTS, TEST_PARENT_1, |
| | | TEST_BASE_CHILD, TEST_CHILD_7, CONN_HANDLER_ENTRY, TEST_CONNECTION_HANDLER_ENTRY_ENABLED); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENTS, TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_7, |
| | | CONN_HANDLER_ENTRY, TEST_CONNECTION_HANDLER_ENTRY_ENABLED); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | |
| | | registerAggregationDefinitionWithTargetEnabled(); |
| | | |
| | |
| | | verify(configRepository).registerChangeListener(eq(TEST_CHILD_7.getName()), registeredListener.capture()); |
| | | |
| | | // Now simulate the disabling ofthe referenced connection handler. |
| | | assertThat(registeredListener.getValue(). |
| | | configChangeIsAcceptable(TEST_CONNECTION_HANDLER_ENTRY_DISABLED, new LocalizableMessageBuilder())). |
| | | isFalse(); |
| | | assertThat( |
| | | registeredListener.getValue().configChangeIsAcceptable(TEST_CONNECTION_HANDLER_ENTRY_DISABLED, |
| | | new LocalizableMessageBuilder())).isFalse(); |
| | | |
| | | } finally { |
| | | putBackDefaultAggregationDefinitionFromTargetEnabled(); |
| | |
| | | |
| | | /** Asserts that the actual set of DNs contains the expected values. */ |
| | | private void assertSetEquals(SortedSet<String> actual, String... expected) { |
| | | SortedSet<String> values = new TreeSet<String>(TestChildCfgDefn.getInstance() |
| | | .getAggregationPropertyPropertyDefinition()); |
| | | SortedSet<String> values = |
| | | new TreeSet<String>(TestChildCfgDefn.getInstance().getAggregationPropertyPropertyDefinition()); |
| | | if (expected != null) { |
| | | for (String value : expected) { |
| | | values.add(value); |
| | |
| | | import org.forgerock.opendj.ldif.LDIF; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.opends.server.admin.AdminTestCase; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.TestCfg; |
| | | import org.opends.server.admin.TestChildCfg; |
| | | import org.opends.server.admin.TestChildCfgDefn; |
| | |
| | | |
| | | } |
| | | |
| | | // @Checkstyle:off |
| | | private static final Entry TEST_CHILD_1 = LDIF.makeEntry( |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config", "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", "cn: test child 1", "ds-cfg-enabled: true", |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", |
| | | "cn: test child 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "ds-cfg-conflict-behavior: virtual-overrides-real"); |
| | | |
| | | private static final Entry NEW_TEST_CHILD_1 = LDIF.makeEntry( |
| | | "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config", "objectclass: top", |
| | | "objectclass: ds-cfg-test-child-dummy", "cn: test child 1", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "ds-cfg-conflict-behavior: virtual-overrides-real", |
| | | "ds-cfg-base-dn: dc=new value 1,dc=com", |
| | | "ds-cfg-base-dn: dc=new value 2,dc=com", |
| | | "ds-cfg-group-dn: dc=new value 3,dc=com", |
| | | "ds-cfg-group-dn: dc=new value 4,dc=com"); |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real"); |
| | | |
| | | private static final Entry TEST_BASE_CHILD = LDIF.makeEntry( |
| | | "dn:cn=test children,cn=test parent 1,cn=test parents,cn=config", |
| | |
| | | // Parent 1 - uses default values for |
| | | // optional-multi-valued-dn-property. |
| | | private static final Entry TEST_PARENT_1 = LDIF.makeEntry( |
| | | "dn: cn=test parent 1,cn=test parents,cn=config", "objectclass: top", |
| | | "objectclass: ds-cfg-test-parent-dummy", "cn: test parent 1", "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", "ds-cfg-conflict-behavior: virtual-overrides-real"); |
| | | |
| | | private static final String[] TEST_LDIF = new String[] { |
| | | // Base entries. |
| | | "dn: cn=test parents,cn=config", |
| | | "dn: cn=test parent 1,cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | "cn: test parents", |
| | | ""}; |
| | | "objectclass: ds-cfg-test-parent-dummy", |
| | | "cn: test parent 1", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider", |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real"); |
| | | |
| | | // @Checkstyle:on |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | @Test |
| | | public void testGetManagedObjectSuccess() throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, |
| | | TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | MockConstraint constraint = new MockConstraint(true, false, configRepository); |
| | | try { |
| | | TestCfg.addConstraint(constraint); |
| | |
| | | @Test |
| | | public void testGetManagedObjectFail() throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, |
| | | TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | MockConstraint constraint = new MockConstraint(false, true, configRepository); |
| | | try { |
| | | TestCfg.addConstraint(constraint); |
| | |
| | | @Test(dataProvider = "constraintValues") |
| | | public void testAddConstraint(boolean isUsableConstraint) throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, |
| | | TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | parentCfg.addTestChildAddListener(new AddListener()); |
| | | MockConstraint constraint = new MockConstraint(isUsableConstraint, false, configRepository); |
| | |
| | | @Test(dataProvider = "constraintValues") |
| | | public void testDeleteConstraint(boolean isDeleteAllowedConstraint) throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, |
| | | TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | parentCfg.addTestChildDeleteListener(new DeleteListener()); |
| | | MockConstraint constraint = new MockConstraint(false, isDeleteAllowedConstraint, configRepository); |
| | |
| | | @Test(dataProvider = "constraintValues") |
| | | public void testChangeConstraint(boolean isUsableConstraint) throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, |
| | | TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_BASE_CHILD, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | MockConstraint constraint = new MockConstraint(isUsableConstraint, false, configRepository); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg childCfg = parentCfg.getTestChild(entryName(TEST_CHILD_1)); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Simulate an entry add by triggering configAddIsAcceptable method of last registered add listener. |
| | | * Simulate an entry add by triggering configAddIsAcceptable method of last |
| | | * registered add listener. |
| | | * |
| | | * @return true if add is acceptable, false otherwise. |
| | | */ |
| | | private boolean simulateEntryAdd(Entry entry, ConfigurationRepository configRepository) throws IOException { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Simulate an entry delete by triggering configDeleteIsAcceptable method of last registered add listener. |
| | | * Simulate an entry delete by triggering configDeleteIsAcceptable method of |
| | | * last registered add listener. |
| | | * |
| | | * @return true if delete is acceptable, false otherwise. |
| | | */ |
| | | private boolean simulateEntryDelete(Entry entry, ConfigurationRepository configRepository) throws IOException { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Simulate an entry change by triggering configChangeIsAcceptable method on last registered change listener. |
| | | * Simulate an entry change by triggering configChangeIsAcceptable method on |
| | | * last registered change listener. |
| | | * |
| | | * @return true if change is acceptable, false otherwise. |
| | | */ |
| | | private boolean simulateEntryChange(Entry newEntry, ConfigurationRepository configRepository) { |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.opends.server.admin.AdminTestCase; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.TestCfg; |
| | | import org.opends.server.admin.TestChildCfg; |
| | | import org.opends.server.admin.TestParentCfg; |
| | |
| | | } |
| | | } |
| | | |
| | | // @Checkstyle:off |
| | | static final Entry CONFIG = makeEntry( |
| | | "dn: cn=config", |
| | | "objectClass: top", |
| | |
| | | "ds-cfg-attribute-type: description", |
| | | "ds-cfg-conflict-behavior: virtual-overrides-real"); |
| | | |
| | | // @Checkstyle:on |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | |
| | | { TEST_PARENT_2, TEST_CHILD_BASE_2, TEST_CHILD_4, |
| | | Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com"), |
| | | Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com") } |
| | | }; |
| | | Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com") } }; |
| | | } |
| | | |
| | | /** |
| | | * Test that a child config have correct values when accessed from its parent config. |
| | | * Test that a child config have correct values when accessed from its |
| | | * parent config. |
| | | */ |
| | | @Test(dataProvider = "childConfigurationsValues") |
| | | public void testChildValues(Entry testParent, Entry testBaseChild, Entry testChild, |
| | | List<String> valuesForOptionalDNProperty1, List<String> valuesForOptionalDNProperty2) throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | testParent, testBaseChild, testChild); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(testParent, testBaseChild, testChild); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(testParent, context); |
| | | |
| | | // assert |
| | |
| | | } |
| | | |
| | | /** |
| | | * Test that a child config have correct values when accessed through an add listener. |
| | | * Test that a child config have correct values when accessed through an add |
| | | * listener. |
| | | */ |
| | | @Test(dataProvider = "childConfigurationsValues") |
| | | public void testAddListenerChildValues(Entry testParent, Entry testBaseChild, Entry testChild, |
| | | List<String> valuesForOptionalDNProperty1, List<String> valuesForOptionalDNProperty2) throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | testParent, testBaseChild, testChild); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(testParent, testBaseChild, testChild); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(testParent, context); |
| | | TestConfigurationAddListener addListener = new TestConfigurationAddListener(); |
| | | parentCfg.addTestChildAddListener(addListener); |
| | |
| | | @DataProvider |
| | | Object[][] childConfigurationsValuesForChangeListener() { |
| | | return new Object[][] { |
| | | // new entry after change, expected first dn property values, expected second dn property values |
| | | // new entry after change, expected first dn property values, |
| | | // expected second dn property values |
| | | { makeEntryFrom(LDIF_TEST_CHILD_1, NEW_ATTRS_1), |
| | | Arrays.asList("dc=new value 1,dc=com", "dc=new value 2,dc=com"), |
| | | Arrays.asList("dc=new value 3,dc=com", "dc=new value 4,dc=com") }, |
| | |
| | | |
| | | { makeEntryFrom(LDIF_TEST_PARENT_1, NEW_ATTRS_2), |
| | | Arrays.asList("dc=new value 1,dc=com", "dc=new value 2,dc=com"), |
| | | Arrays.asList("dc=new value 1,dc=com", "dc=new value 2,dc=com") } |
| | | }; |
| | | Arrays.asList("dc=new value 1,dc=com", "dc=new value 2,dc=com") } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests that a child config have correct values when accessed through an change listener. |
| | | * The defaulted properties are replaced with some real values. |
| | | * Tests that a child config have correct values when accessed through an |
| | | * change listener. The defaulted properties are replaced with some real |
| | | * values. |
| | | */ |
| | | @Test(dataProvider = "childConfigurationsValuesForChangeListener") |
| | | public void testChangeListenerChildValues(Entry newEntry, List<String> valuesForOptionalDNProperty1, |
| | | List<String> valuesForOptionalDNProperty2) throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries( |
| | | TEST_PARENT_1, TEST_CHILD_BASE_1, TEST_CHILD_1); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ConfigurationRepository configRepository = |
| | | createConfigRepositoryWithEntries(TEST_PARENT_1, TEST_CHILD_BASE_1, TEST_CHILD_1); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parentCfg = getParentCfg(TEST_PARENT_1, context); |
| | | TestChildCfg childCfg = parentCfg.getTestChild(entryName(TEST_CHILD_1)); |
| | | TestConfigurationChangeListener changeListener = new TestConfigurationChangeListener(); |
| | |
| | | simulateEntryChange(newEntry, configRepository); |
| | | |
| | | // assert |
| | | assertChildHasCorrectValues(changeListener.getChildCfg(entryName(TEST_CHILD_1)), valuesForOptionalDNProperty1, |
| | | valuesForOptionalDNProperty2); |
| | | assertChildHasCorrectValues(changeListener.getChildCfg(entryName(TEST_CHILD_1)), |
| | | valuesForOptionalDNProperty1, valuesForOptionalDNProperty2); |
| | | } |
| | | |
| | | @DataProvider |
| | | Object[][] parentConfigurationsValues() { |
| | | return new Object[][] { |
| | | // parent entry, expected first dn property values, expected second dn property values |
| | | // parent entry, expected first dn property values, expected second |
| | | // dn property values |
| | | { TEST_PARENT_1, Arrays.asList("dc=domain1,dc=com", "dc=domain2,dc=com", "dc=domain3,dc=com") }, |
| | | { TEST_PARENT_2, Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com") } |
| | | }; |
| | | { TEST_PARENT_2, Arrays.asList("dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com") } }; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Test(dataProvider = "parentConfigurationsValues") |
| | | public void testParentValues(Entry parentEntry, List<String> valuesForOptionalDNProperty) throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithEntries(parentEntry); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | TestParentCfg parent = getParentCfg(parentEntry, context); |
| | | |
| | | assertThat(parent.getMandatoryClassProperty()).isEqualTo( |
| | |
| | | assertDNSetEquals(parent.getOptionalMultiValuedDNProperty(), valuesForOptionalDNProperty); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Simulate an entry add by triggering configAddIsAcceptable method of last registered add listener. |
| | | * Simulate an entry add by triggering configAddIsAcceptable method of last |
| | | * registered add listener. |
| | | */ |
| | | private void simulateEntryAdd(Entry entry, ConfigurationRepository configRepository) throws IOException { |
| | | // use argument capture to retrieve the actual listener |
| | |
| | | } |
| | | |
| | | /** |
| | | * Simulate an entry change by triggering configChangeIsAcceptable method on last registered change listener. |
| | | * Simulate an entry change by triggering configChangeIsAcceptable method on |
| | | * last registered change listener. |
| | | */ |
| | | private void simulateEntryChange(Entry newEntry, ConfigurationRepository configRepository) { |
| | | // use argument capture to retrieve the actual listener |
| | |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.opends.server.admin.AdminTestCase; |
| | | import org.opends.server.admin.PropertyDefinitionsOptions; |
| | | import org.opends.server.admin.TestCfg; |
| | | import org.opends.server.admin.TestParentCfg; |
| | | import org.opends.server.api.ConfigAddListener; |
| | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | |
| | | @SuppressWarnings({ "javadoc", "rawtypes", "unchecked" }) |
| | | public class ListenerTest extends AdminTestCase { |
| | | |
| | |
| | | |
| | | @BeforeClass |
| | | public void setUp() throws Exception { |
| | | disableClassValidationForProperties(); |
| | | TestCfg.setUp(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private Entry getTestParentEntry() throws Exception { |
| | | return makeEntry( |
| | | "dn: cn=test parents,cn=config", |
| | | "objectclass: top", |
| | | "objectclass: ds-cfg-branch", |
| | | return makeEntry("dn: cn=test parents,cn=config", "objectclass: top", "objectclass: ds-cfg-branch", |
| | | "cn: test parents"); |
| | | } |
| | | |
| | |
| | | return configRepository; |
| | | } |
| | | |
| | | /** Register a listener for test parent entry and return the actual registered listener */ |
| | | /** |
| | | * Register a listener for test parent entry and return the actual |
| | | * registered listener |
| | | */ |
| | | private ConfigAddListener registerAddListenerForTestParent(ConfigurationRepository configRepository, |
| | | ServerManagedObject<RootCfg> root, ConfigurationAddListener<TestParentCfg> parentListener) |
| | | throws Exception { |
| | | ServerManagedObject<RootCfg> root, ConfigurationAddListener<TestParentCfg> parentListener) throws Exception { |
| | | root.registerAddListener(TestCfg.getTestOneToManyParentRelationDefinition(), parentListener); |
| | | |
| | | ArgumentCaptor<ConfigAddListener> registered = ArgumentCaptor.forClass(ConfigAddListener.class); |
| | |
| | | return registered.getValue(); |
| | | } |
| | | |
| | | /** Register a listener for test parent entry in delayed scenario and return the actual registered listener */ |
| | | private DelayedConfigAddListener registerAddListenerForTestParentDelayed(ConfigurationRepository configRepository, |
| | | ServerManagedObject<RootCfg> root, ConfigurationAddListener<TestParentCfg> parentListener) |
| | | throws Exception { |
| | | /** |
| | | * Register a listener for test parent entry in delayed scenario and return |
| | | * the actual registered listener |
| | | */ |
| | | private DelayedConfigAddListener registerAddListenerForTestParentDelayed( |
| | | ConfigurationRepository configRepository, ServerManagedObject<RootCfg> root, |
| | | ConfigurationAddListener<TestParentCfg> parentListener) throws Exception { |
| | | root.registerAddListener(TestCfg.getTestOneToManyParentRelationDefinition(), parentListener); |
| | | |
| | | ArgumentCaptor<DelayedConfigAddListener> registered = ArgumentCaptor.forClass(DelayedConfigAddListener.class); |
| | |
| | | @Test |
| | | public void testRegisterAddListenerWithInstantiableRelationImmediate() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN, TEST_PARENTS_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerAddListener(TestCfg.getTestOneToManyParentRelationDefinition(), |
| | | mock(ConfigurationAddListener.class)); |
| | | |
| | | verify(configRepository).registerAddListener(eq(TEST_PARENTS_DN), |
| | | isA(ConfigAddListener.class)); |
| | | verify(configRepository).registerAddListener(eq(TEST_PARENTS_DN), isA(ConfigAddListener.class)); |
| | | } |
| | | |
| | | @Test |
| | | public void testRegisterAddListenerWithInstantiableRelationDelayed() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationAddListener<TestParentCfg> parentListener = mock(ConfigurationAddListener.class); |
| | |
| | | @Test |
| | | public void testRegisterAddListenerWithInstantiableRelationDelayedThenActualized() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | // register a listener to root |
| | |
| | | when(configRepository.hasEntry(DN.valueOf(parentDN))).thenReturn(true); |
| | | registered.getValue().applyConfigurationAdd(getTestParentEntry()); |
| | | |
| | | // check that listener is added for target entry and deleted for its parent entry |
| | | // check that listener is added for target entry and deleted for its |
| | | // parent entry |
| | | ConfigAddListenerAdaptor listener = |
| | | (ConfigAddListenerAdaptor<?>) registered.getValue().getDelayedAddListener(); |
| | | verify(configRepository).registerAddListener(DN.valueOf(parentDN), listener); |
| | |
| | | @Test |
| | | public void testRegisterAddListenerWithOptionalRelation() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerAddListener(TestCfg.getTestOneToZeroOrOneParentRelationDefinition(), |
| | | mock(ConfigurationAddListener.class)); |
| | | |
| | | verify(configRepository).registerAddListener(eq(ROOT_CONFIG_DN), |
| | | isA(ConfigAddListener.class)); |
| | | verify(configRepository).registerAddListener(eq(ROOT_CONFIG_DN), isA(ConfigAddListener.class)); |
| | | } |
| | | |
| | | @Test |
| | | public void testRegisterDeleteListenerWithInstantiableRelationImmediate() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN, TEST_PARENTS_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerDeleteListener(TestCfg.getTestOneToManyParentRelationDefinition(), |
| | | mock(ConfigurationDeleteListener.class)); |
| | | |
| | | verify(configRepository).registerDeleteListener(eq(TEST_PARENTS_DN), |
| | | isA(ConfigDeleteListener.class)); |
| | | verify(configRepository).registerDeleteListener(eq(TEST_PARENTS_DN), isA(ConfigDeleteListener.class)); |
| | | } |
| | | |
| | | @Test |
| | | public void testRegisterDeleteListenerWithInstantiableRelationDelayed() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationDeleteListener<TestParentCfg> parentListener = mock(ConfigurationDeleteListener.class); |
| | |
| | | @Test |
| | | public void testRegisterDeleteListenerWithOptionalRelation() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | root.registerDeleteListener(TestCfg.getTestOneToZeroOrOneParentRelationDefinition(), |
| | | mock(ConfigurationDeleteListener.class)); |
| | | |
| | | verify(configRepository).registerDeleteListener(eq(ROOT_CONFIG_DN), |
| | | isA(ConfigDeleteListener.class)); |
| | | verify(configRepository).registerDeleteListener(eq(ROOT_CONFIG_DN), isA(ConfigDeleteListener.class)); |
| | | } |
| | | |
| | | @Test |
| | | public void testRegisterChangeListener() throws Exception { |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | root.setConfigDN(ROOT_CONFIG_DN); |
| | | |
| | | root.registerChangeListener(mock(ConfigurationChangeListener.class)); |
| | | |
| | | verify(configRepository).registerChangeListener(eq(ROOT_CONFIG_DN), |
| | | isA(ConfigChangeListener.class)); |
| | | verify(configRepository).registerChangeListener(eq(ROOT_CONFIG_DN), isA(ConfigChangeListener.class)); |
| | | } |
| | | |
| | | @Test |
| | | public void testDeregisterAddListenerWithInstantiableRelationImmediate() throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN, TEST_PARENTS_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationAddListener<TestParentCfg> parentListener = mock(ConfigurationAddListener.class); |
| | |
| | | public void testDeregisterAddListenerWithInstantiableRelationDelayed() throws Exception { |
| | | // arrange |
| | | ConfigurationRepository configRepository = createConfigRepositoryWithDNs(ROOT_CONFIG_DN); |
| | | ServerManagementContext context = new ServerManagementContext(configRepository); |
| | | ServerManagementContext context = |
| | | new ServerManagementContext(configRepository, PropertyDefinitionsOptions.NO_VALIDATION_OPTIONS); |
| | | ServerManagedObject<RootCfg> root = context.getRootConfigurationManagedObject(); |
| | | |
| | | ConfigurationAddListener<TestParentCfg> parentListener = mock(ConfigurationAddListener.class); |