本文整理汇总了Java中org.apache.directory.api.ldap.model.entry.ModificationOperation.ADD_ATTRIBUTE属性的典型用法代码示例。如果您正苦于以下问题:Java ModificationOperation.ADD_ATTRIBUTE属性的具体用法?Java ModificationOperation.ADD_ATTRIBUTE怎么用?Java ModificationOperation.ADD_ATTRIBUTE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.directory.api.ldap.model.entry.ModificationOperation
的用法示例。
在下文中一共展示了ModificationOperation.ADD_ATTRIBUTE属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateServerModification
@Test
public void testCreateServerModification() throws LdapException
{
Attribute attribute = new DefaultAttribute( "cn", cnAT );
attribute.add( "test1", "test2" );
Modification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
Modification clone = mod.clone();
attribute.remove( "test2" );
Attribute clonedAttribute = clone.getAttribute();
assertEquals( 1, mod.getAttribute().size() );
assertTrue( mod.getAttribute().contains( "TEST1" ) );
assertEquals( 2, clonedAttribute.size() );
assertTrue( clone.getAttribute().contains( "test1" ) );
assertTrue( clone.getAttribute().contains( "test2" ) );
}
示例2: testCreateServerModification
@Test
public void testCreateServerModification() throws LdapException
{
Attribute attribute = new DefaultAttribute( "cn" );
attribute.add( "test1", "test2" );
Modification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
Modification clone = mod.clone();
attribute.remove( "test2" );
Attribute clonedAttribute = clone.getAttribute();
assertEquals( 1, mod.getAttribute().size() );
assertTrue( mod.getAttribute().contains( "test1" ) );
assertEquals( 2, clonedAttribute.size() );
assertTrue( clone.getAttribute().contains( "test1" ) );
assertTrue( clone.getAttribute().contains( "test2" ) );
}
示例3: testApplyAddModificationToEntry
/**
* Test a addModification applied to an entry
*/
@Test
public void testApplyAddModificationToEntry() throws LdapException
{
Entry entry = new DefaultEntry();
entry.add( "dc", "apache" );
assertEquals( 1, entry.size() );
Attribute attr = new DefaultAttribute( "cn", "test" );
Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
AttributeUtils.applyModification( entry, modification );
assertNotNull( entry.get( "cn" ) );
assertEquals( 2, entry.size() );
assertEquals( attr, entry.get( "cn" ) );
}
示例4: testNotEqualDiffModCount
/**
* Test for inequality when only the number of mods are different.
*/
@Test
public void testNotEqualDiffModCount() throws LdapException
{
ModifyRequestImpl req0 = getRequest();
Attribute attr = new DefaultAttribute( "attr3" );
attr.add( "val0" );
attr.add( "val1" );
attr.add( "val2" );
Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
req0.addModification( item );
ModifyRequestImpl req1 = getRequest();
assertFalse( req0.equals( req1 ) );
assertFalse( req1.equals( req0 ) );
}
示例5: testSerializationModificationADD
@Test
public void testSerializationModificationADD() throws ClassNotFoundException, IOException,
LdapInvalidAttributeValueException
{
Attribute attribute = new DefaultAttribute( "cn", cnAT );
attribute.add( "test1", "test2" );
DefaultModification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
Modification modSer = deserializeValue( serializeValue( mod ) );
assertEquals( mod, modSer );
}
示例6: testSerializationModificationADD
@Test
public void testSerializationModificationADD() throws ClassNotFoundException, IOException, LdapException
{
Attribute attribute = new DefaultAttribute( "cn" );
attribute.add( "test1", "test2" );
DefaultModification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
Modification modSer = deserializeValue( serializeValue( mod ) );
assertEquals( mod, modSer );
}
示例7: testApplyAddModificationToEmptyEntry
/**
* Test a addModification applied to an empty entry
*/
@Test
public void testApplyAddModificationToEmptyEntry() throws LdapException
{
Entry entry = new DefaultEntry();
Attribute attr = new DefaultAttribute( "cn", "test" );
Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
AttributeUtils.applyModification( entry, modification );
assertNotNull( entry.get( "cn" ) );
assertEquals( 1, entry.size() );
assertEquals( attr, entry.get( "cn" ) );
}
示例8: testApplyAddModificationToEntryWithValues
/**
* Test a addModification applied to an entry with the same attribute
* but with another value
*/
@Test
public void testApplyAddModificationToEntryWithValues() throws LdapException
{
Entry entry = new DefaultEntry();
entry.put( "cn", "apache" );
assertEquals( 1, entry.size() );
Attribute attr = new DefaultAttribute( "cn", "test" );
Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
AttributeUtils.applyModification( entry, modification );
assertNotNull( entry.get( "cn" ) );
assertEquals( 1, entry.size() );
Attribute attribute = entry.get( "cn" );
assertTrue( attribute.size() != 0 );
Set<String> expectedValues = new HashSet<String>();
expectedValues.add( "apache" );
expectedValues.add( "test" );
for ( Value value : attribute )
{
String valueStr = value.getValue();
assertTrue( expectedValues.contains( valueStr ) );
expectedValues.remove( valueStr );
}
assertEquals( 0, expectedValues.size() );
}
示例9: testApplyAddModificationToEntryWithSameValue
/**
* Test a addModification applied to an entry with the same attribute
* and the same value
*/
@Test
public void testApplyAddModificationToEntryWithSameValue() throws LdapException
{
Entry entry = new DefaultEntry();
entry.put( "cn", "test", "apache" );
assertEquals( 1, entry.size() );
Attribute attr = new DefaultAttribute( "cn", "test" );
Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
AttributeUtils.applyModification( entry, modification );
assertNotNull( entry.get( "cn" ) );
assertEquals( 1, entry.size() );
Attribute cnAttr = entry.get( "cn" );
assertTrue( cnAttr.size() != 0 );
Set<String> expectedValues = new HashSet<String>();
expectedValues.add( "apache" );
expectedValues.add( "test" );
for ( Value value : cnAttr )
{
String valueStr = value.getValue();
assertTrue( expectedValues.contains( valueStr ) );
expectedValues.remove( valueStr );
}
assertEquals( 0, expectedValues.size() );
}
示例10: toServerModification
/**
* Convert a ModificationItem to an instance of a ServerModification object
*
* @param modificationImpl the modification instance to convert
* @param attributeType the associated attributeType
* @return a instance of a ServerModification object
*/
private static Modification toServerModification( ModificationItem modificationImpl, AttributeType attributeType )
throws LdapException
{
ModificationOperation operation;
switch ( modificationImpl.getModificationOp() )
{
case DirContext.REMOVE_ATTRIBUTE:
operation = ModificationOperation.REMOVE_ATTRIBUTE;
break;
case DirContext.REPLACE_ATTRIBUTE:
operation = ModificationOperation.REPLACE_ATTRIBUTE;
break;
case DirContext.ADD_ATTRIBUTE:
default:
operation = ModificationOperation.ADD_ATTRIBUTE;
break;
}
Modification modification = new DefaultModification(
operation,
ServerEntryUtils.toServerAttribute( modificationImpl.getAttribute(), attributeType ) );
return modification;
}
示例11: toDsml
/**
* {@inheritDoc}
*/
@Override
public Element toDsml( Element root )
{
Element element = super.toDsml( root );
ModifyRequest request = getDecorated();
// Dn
if ( request.getName() != null )
{
element.addAttribute( "dn", request.getName().getName() );
}
// Modifications
Collection<Modification> modifications = request.getModifications();
for ( Modification modification : modifications )
{
Element modElement = element.addElement( "modification" );
if ( modification.getAttribute() != null )
{
modElement.addAttribute( "name", modification.getAttribute().getId() );
for ( Value value : modification.getAttribute() )
{
if ( value.getValue() != null )
{
if ( ParserUtils.needsBase64Encoding( value.getValue() ) )
{
Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
element.getDocument().getRootElement().add( xsdNamespace );
element.getDocument().getRootElement().add( xsiNamespace );
Element valueElement = modElement.addElement( "value" ).addText(
ParserUtils.base64Encode( value.getValue() ) );
valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:"
+ ParserUtils.BASE64BINARY );
}
else
{
modElement.addElement( "value" ).setText( value.getValue() );
}
}
}
}
ModificationOperation operation = modification.getOperation();
if ( operation == ModificationOperation.ADD_ATTRIBUTE )
{
modElement.addAttribute( "operation", "add" );
}
else if ( operation == ModificationOperation.REPLACE_ATTRIBUTE )
{
modElement.addAttribute( "operation", "replace" );
}
else if ( operation == ModificationOperation.REMOVE_ATTRIBUTE )
{
modElement.addAttribute( "operation", "delete" );
}
}
return element;
}