本文整理汇总了Java中org.apache.directory.api.ldap.model.entry.Entry.add方法的典型用法代码示例。如果您正苦于以下问题:Java Entry.add方法的具体用法?Java Entry.add怎么用?Java Entry.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.directory.api.ldap.model.entry.Entry
的用法示例。
在下文中一共展示了Entry.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testApplyAddModificationToEntry
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* 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" ) );
}
示例2: testContainsEntryAttributeArray
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for contains( EntryAttribute... )
*/
@Test
public void testContainsEntryAttributeArray() throws LdapException
{
Entry entry = new DefaultEntry( exampleDn );
Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );
assertFalse( entry.contains( attrOC, attrCN ) );
entry.add( attrOC, attrCN );
assertTrue( entry.contains( attrOC, attrCN ) );
assertFalse( entry.contains( attrOC, attrCN, attrSN ) );
entry.add( attrSN, attrPWD );
assertTrue( entry.contains( attrSN, attrPWD ) );
}
示例3: testContainsStringStringArray
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for contains( String, String... )
*/
@Test
public void testContainsStringStringArray() throws LdapException
{
Entry entry = new DefaultEntry( exampleDn );
assertFalse( entry.containsAttribute( "objectClass" ) );
Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2", ( String ) null );
Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );
entry.add( attrOC, attrCN, attrSN, attrPWD );
assertTrue( entry.contains( "OBJECTCLASS", "top", "person" ) );
assertTrue( entry.contains( " cn ", "test1", "test2" ) );
assertTrue( entry.contains( "Sn", "Test1", "Test2", ( String ) null ) );
assertTrue( entry.contains( " userPASSWORD ", "ab", "b" ) );
assertFalse( entry.contains( "OBJECTCLASS", "PERSON" ) );
assertFalse( entry.contains( " cn ", "test1", "test3" ) );
assertFalse( entry.contains( "Sn", "Test" ) );
assertFalse( entry.contains( " userPASSWORD ", ( String ) null ) );
}
示例4: testGet
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for get( String )
*/
@Test
public void testGet() throws LdapException
{
Entry entry = new DefaultEntry( exampleDn );
assertNull( entry.get( "objectClass" ) );
Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );
entry.add( attrOC, attrCN, attrSN, attrPWD );
assertNotNull( entry.get( " CN " ) );
Attribute attribute = entry.get( "cN" );
assertEquals( attribute, attrCN );
assertNull( entry.get( ( String ) null ) );
assertNull( entry.get( " " ) );
assertNull( entry.get( "l" ) );
}
示例5: testUserCertificateBinary
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for userCertificate;binary AT
*/
@Test
public void testUserCertificateBinary() throws LdapException
{
Entry entry = new DefaultEntry( schemaManager );
entry.add( "objectClass", "top", "person", "inetorgPerson" );
entry.add( "cn", "test1", "test2" );
entry.add( "sn", "Test1", "Test2" );
entry.add( "userPassword", BYTES1, BYTES2 );
entry.add( "userCertificate;binary", Strings.getBytesUtf8( "secret" ) );
assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
assertTrue( entry.containsAttribute( "userCertificate" ) );
entry.removeAttributes( "userCertificate;binary" );
assertFalse( entry.containsAttribute( "userCertificate;binary" ) );
assertFalse( entry.containsAttribute( "userCertificate" ) );
entry.add( "userCertificate", Strings.getBytesUtf8( "secret" ) );
assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
assertTrue( entry.containsAttribute( "userCertificate" ) );
}
示例6: testHasObjectClass
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for hasObjectClass( String )
*/
@Test
public void testHasObjectClass() throws LdapException
{
Entry entry = new DefaultEntry( exampleDn );
assertFalse( entry.containsAttribute( "objectClass" ) );
assertFalse( entry.hasObjectClass( "top" ) );
entry.add( new DefaultAttribute( "objectClass", "top", "person" ) );
assertTrue( entry.hasObjectClass( "top" ) );
assertTrue( entry.hasObjectClass( "person" ) );
assertFalse( entry.hasObjectClass( "inetorgperson" ) );
assertFalse( entry.hasObjectClass( ( String ) null ) );
assertFalse( entry.hasObjectClass( "" ) );
}
示例7: testRemoveStringByteArrayArray
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for remove(String, byte[]... )
*/
@Test
public void testRemoveStringByteArrayArray() throws LdapException
{
Entry entry = new DefaultEntry( exampleDn );
Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, ( byte[] ) null, BYTES2 );
entry.put( attrPWD );
assertTrue( entry.remove( "userPassword", ( byte[] ) null ) );
assertTrue( entry.remove( "userPassword", BYTES1, BYTES2 ) );
assertFalse( entry.containsAttribute( "userPassword" ) );
entry.add( "userPassword", BYTES1, ( byte[] ) null, BYTES2 );
assertTrue( entry.remove( "userPassword", ( byte[] ) null ) );
assertEquals( 2, entry.get( "userPassword" ).size() );
assertTrue( entry.remove( "userPassword", BYTES1, BYTES3 ) );
assertEquals( 1, entry.get( "userPassword" ).size() );
assertTrue( Arrays.equals( BYTES2, entry.get( "userPassword" ).getBytes() ) );
assertFalse( entry.remove( "userPassword", BYTES3 ) );
assertFalse( entry.remove( "void", "whatever" ) );
}
示例8: testRemoveStringStringArray
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for remove( String, String... )
*/
@Test
public void testRemoveStringStringArray() throws LdapException
{
Entry entry = createEntry();
assertTrue( entry.remove( "cn", "test1" ) );
assertTrue( entry.remove( "cn", "test2" ) );
assertFalse( entry.containsAttribute( "cn" ) );
entry.add( "cn", "test1", ( String ) null, "test2" );
assertTrue( entry.remove( "cn", ( String ) null ) );
assertEquals( 2, entry.get( "cn" ).size() );
assertTrue( entry.remove( "cn", "test1", "test3" ) );
assertEquals( 1, entry.get( "cn" ).size() );
assertEquals( "test2", entry.get( "cn" ).get().getValue() );
assertFalse( entry.remove( "cn", "test3" ) );
assertFalse( entry.remove( "void", "whatever" ) );
}
示例9: testSize
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for size()
*/
@Test
public void testSize() throws LdapException
{
Entry entry = new DefaultEntry( exampleDn );
assertEquals( 0, entry.size() );
entry.add( "ObjectClass", "top", "person" );
entry.add( "cn", "test" );
entry.add( "sn", "Test" );
assertEquals( 3, entry.size() );
entry.clear();
assertEquals( 0, entry.size() );
}
示例10: testSerializeCompleteEntry
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test the serialization of a complete entry
*/
@Test
public void testSerializeCompleteEntry() throws LdapException, IOException, ClassNotFoundException
{
Dn dn = new Dn( schemaManager, "ou=system" );
byte[] password = Strings.getBytesUtf8( "secret" );
Entry entry = new DefaultEntry( dn );
entry.add( "ObjectClass", "top", "person" );
entry.add( "cn", "test1" );
entry.add( "userPassword", password );
Entry entrySer = deserializeValue( serializeValue( entry ) );
assertEquals( entry, entrySer );
}
示例11: testSerializeEntryWithNoDN
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test the serialization of an entry with no Dn
*/
@Test
public void testSerializeEntryWithNoDN() throws LdapException, IOException, ClassNotFoundException
{
byte[] password = Strings.getBytesUtf8( "secret" );
Entry entry = new DefaultEntry();
entry.add( "ObjectClass", "top", "person" );
entry.add( "cn", "test1" );
entry.add( "userPassword", password );
Entry entrySer = deserializeValue( serializeValue( entry ) );
assertEquals( entry, entrySer );
}
示例12: doInit
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Partition initialization - loads schema entries from the files on classpath.
*
* @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
*/
@Override
protected void doInit() throws InvalidNameException, Exception {
if (initialized)
return;
LOG.debug("Initializing schema partition " + getId());
suffixDn.apply(schemaManager);
super.doInit();
// load schema
final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
for (String resourcePath : new TreeSet<>(resMap.keySet())) {
if (resourcePath.endsWith(".ldif")) {
URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
LdifReader reader = new LdifReader(resource.openStream());
LdifEntry ldifEntry = reader.next();
reader.close();
Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
// add mandatory attributes
if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
}
if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
}
AddOperationContext addContext = new AddOperationContext(null, entry);
super.add(addContext);
}
}
}
示例13: injectCommon
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
private void injectCommon( SchemaObject object, Entry entry, SchemaManager schemaManager )
throws LdapException
{
injectNames( object.getNames(), entry, schemaManager );
entry.put( MetaSchemaConstants.M_OBSOLETE_AT, getBoolean( object.isObsolete() ) );
entry.put( MetaSchemaConstants.M_OID_AT, object.getOid() );
if ( object.getDescription() != null )
{
entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, object.getDescription() );
}
// The extensions
Map<String, List<String>> extensions = object.getExtensions();
if ( extensions != null )
{
for ( Map.Entry<String, List<String>> mapEntry : extensions.entrySet() )
{
String key = mapEntry.getKey();
List<String> values = mapEntry.getValue();
for ( String value : values )
{
entry.add( key, value );
}
}
}
}
示例14: testAddStringValueArray
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test method for add( String, Value... )
*/
@Test
public void testAddStringValueArray() throws LdapException
{
Entry entry = new DefaultEntry();
Value value = new Value( ( String ) null );
entry.add( "cn", value );
assertEquals( 1, entry.size() );
Attribute attributeCN = entry.get( "cn" );
assertEquals( 1, attributeCN.size() );
assertNotNull( attributeCN.get() );
assertNull( attributeCN.get().getValue() );
Value value1 = new Value( "test1" );
Value value2 = new Value( "test2" );
Value value3 = new Value( "test1" );
entry.add( "sn", value1, value2, value3 );
assertEquals( 2, entry.size() );
Attribute attributeSN = entry.get( "sn" );
assertEquals( 2, attributeSN.size() );
assertNotNull( attributeSN.get() );
assertTrue( attributeSN.contains( value1 ) );
assertTrue( attributeSN.contains( value2 ) );
Value value4 = new Value( BYTES1 );
entry.add( "l", value1, value4 );
assertEquals( 3, entry.size() );
Attribute attributeL = entry.get( "l" );
assertEquals( 2, attributeL.size() );
assertNotNull( attributeL.get() );
assertTrue( attributeL.contains( value1 ) );
// The byte[] value must have been transformed to a String
assertTrue( attributeL.contains( "ab" ) );
}
示例15: testReverseModifyDNDeleteOldRdnSuperior
import org.apache.directory.api.ldap.model.entry.Entry; //导入方法依赖的package包/类
/**
* Test a reversed ModifyDN with a deleteOldRdn, rdn change, and a superior
*
* @throws NamingException on error
*/
@Test
public void testReverseModifyDNDeleteOldRdnSuperior() throws LdapException
{
Dn dn = new Dn( "cn=john doe, dc=example, dc=com" );
Dn newSuperior = new Dn( "ou=system" );
Entry entry = new DefaultEntry( dn );
entry.add( "objectClass", "person", "uidObject" );
entry.add( "cn", "john doe" );
entry.add( "sn", "doe" );
entry.add( "uid", "jdoe" );
List<LdifEntry> reverseds = LdifRevertor.reverseMoveAndRename( entry, newSuperior, new Rdn( "cn=jack doe" ),
false );
assertNotNull( reverseds );
assertEquals( 1, reverseds.size() );
LdifEntry reversed = reverseds.get( 0 );
assertEquals( "cn=jack doe,ou=system", reversed.getDn().getName() );
assertEquals( ChangeType.ModRdn, reversed.getChangeType() );
assertTrue( reversed.isDeleteOldRdn() );
assertEquals( "cn=john doe", reversed.getNewRdn() );
assertEquals( "dc=example, dc=com", Strings.trim( reversed.getNewSuperior() ) );
assertNull( reversed.getEntry() );
}