Partial OPENDJ-3106 Migrate Entry
Entry.java:
getAllAttributes(String) now returns Iterable<Attribute>.
| | |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.CoreSchema; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.forgerock.opendj.server.config.server.TrustStoreBackendCfg; |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.server.api.Backend; |
| | |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.LDIFImportResult; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.opends.server.types.RestoreConfig; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.util.CertificateManager; |
| | |
| | | } |
| | | else |
| | | { |
| | | List<Attribute> certAttrs = entry.getAllAttributes( |
| | | ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE); |
| | | if (certAttrs.isEmpty()) |
| | | Iterator<Attribute> certAttrs = entry.getAllAttributes(ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE).iterator(); |
| | | if (!certAttrs.hasNext()) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_TRUSTSTORE_ENTRY_MISSING_CERT_ATTR.get(entryDN, ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE); |
| | | throw new DirectoryException( |
| | | DirectoryServer.getServerErrorResultCode(), message); |
| | | } |
| | | if (certAttrs.size() != 1) |
| | | Attribute certAttr = certAttrs.next(); |
| | | if (certAttrs.hasNext()) |
| | | { |
| | | LocalizableMessage message = |
| | | ERR_TRUSTSTORE_ENTRY_HAS_MULTIPLE_CERT_ATTRS.get(entryDN, ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE); |
| | |
| | | DirectoryServer.getServerErrorResultCode(), message); |
| | | } |
| | | |
| | | Attribute certAttr = certAttrs.get(0); |
| | | Iterator<ByteString> i = certAttr.iterator(); |
| | | |
| | | if (!i.hasNext()) |
| | |
| | | private String getAttributeValue(String attributeName, boolean isRequired) |
| | | throws InitializationException |
| | | { |
| | | List<Attribute> attrList = taskEntry.getAllAttributes(attributeName); |
| | | if (attrList.isEmpty()) |
| | | Iterator<Attribute> attrList = taskEntry.getAllAttributes(attributeName).iterator(); |
| | | if (!attrList.hasNext()) |
| | | { |
| | | if (isRequired) |
| | | { |
| | |
| | | return null; |
| | | } |
| | | |
| | | if (attrList.size() > 1) |
| | | final Iterator<ByteString> values = attrList.next().iterator(); |
| | | if (attrList.hasNext()) |
| | | { |
| | | throw new InitializationException(ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get(attributeName, taskEntry.getName())); |
| | | } |
| | | |
| | | Iterator<ByteString> iterator = attrList.get(0).iterator(); |
| | | if (! iterator.hasNext()) |
| | | if (!values.hasNext()) |
| | | { |
| | | if (isRequired) |
| | | { |
| | |
| | | return null; |
| | | } |
| | | |
| | | ByteString value = iterator.next(); |
| | | if (iterator.hasNext()) |
| | | ByteString value = values.next(); |
| | | if (values.hasNext()) |
| | | { |
| | | throw new InitializationException(ERR_TASK_MULTIPLE_VALUES_FOR_ATTR.get(attributeName, taskEntry.getName())); |
| | | } |
| | |
| | | */ |
| | | private LinkedList<String> getAttributeValues(String attributeName) throws InitializationException |
| | | { |
| | | LinkedList<String> valueStrings = new LinkedList<>(); |
| | | List<Attribute> attrList = taskEntry.getAllAttributes(attributeName); |
| | | if (attrList.isEmpty()) |
| | | final LinkedList<String> valueStrings = new LinkedList<>(); |
| | | final Iterator<Attribute> attrList = taskEntry.getAllAttributes(attributeName).iterator(); |
| | | if (!attrList.hasNext()) |
| | | { |
| | | return valueStrings; |
| | | } |
| | | if (attrList.size() > 1) |
| | | final Iterator<ByteString> values = attrList.next().iterator(); |
| | | if (attrList.hasNext()) |
| | | { |
| | | throw new InitializationException(ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get(attributeName, taskEntry.getName())); |
| | | } |
| | | |
| | | Iterator<ByteString> iterator = attrList.get(0).iterator(); |
| | | while (iterator.hasNext()) |
| | | while (values.hasNext()) |
| | | { |
| | | valueStrings.add(iterator.next().toString()); |
| | | valueStrings.add(values.next().toString()); |
| | | } |
| | | return valueStrings; |
| | | } |
| | |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.*; |
| | | import static org.opends.messages.ReplicationMessages.*; |
| | | import static org.opends.server.replication.plugin.HistAttrModificationKey.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | |
| | | public static EntryHistorical newInstanceFromEntry(Entry entry) |
| | | { |
| | | // Read the DB historical attribute from the entry |
| | | List<Attribute> histAttrWithOptionsFromEntry = getHistoricalAttr(entry); |
| | | Iterable<Attribute> histAttrWithOptionsFromEntry = getHistoricalAttr(entry); |
| | | |
| | | // Now we'll build the Historical object we want to construct |
| | | final EntryHistorical newHistorical = new EntryHistorical(); |
| | | if (histAttrWithOptionsFromEntry.isEmpty()) |
| | | if (isEmpty(histAttrWithOptionsFromEntry)) |
| | | { |
| | | // No historical attribute in the entry, return empty object |
| | | return newHistorical; |
| | |
| | | * Several values on the list if several options for this attribute. |
| | | * Null if not present. |
| | | */ |
| | | public static List<Attribute> getHistoricalAttr(Entry entry) |
| | | public static Iterable<Attribute> getHistoricalAttr(Entry entry) |
| | | { |
| | | return entry.getAllAttributes(HISTORICAL_ATTRIBUTE_NAME); |
| | | } |
| | |
| | | SearchResultEntry resultEntry = result.get(0); |
| | | if (resultEntry != null) |
| | | { |
| | | List<Attribute> attrs = resultEntry.getAllAttributes(REPLICATION_GENERATION_ID); |
| | | if (!attrs.isEmpty()) |
| | | Iterator<Attribute> attrs = resultEntry.getAllAttributes(REPLICATION_GENERATION_ID).iterator(); |
| | | if (attrs.hasNext()) |
| | | { |
| | | Attribute attr = attrs.get(0); |
| | | Attribute attr = attrs.next(); |
| | | if (attr.size()>1) |
| | | { |
| | | String errorMsg = "#Values=" + attr.size() + " Must be exactly 1 in entry " + resultEntry.toLDIFString(); |
| | |
| | | package org.opends.server.tools; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | |
| | | */ |
| | | public static String getStringSingleValuedAttribute(Entry entry, String attrName) |
| | | { |
| | | List<Attribute> attributes = entry.getAllAttributes(attrName); |
| | | if (!attributes.isEmpty()) |
| | | Iterator<Attribute> attributes = entry.getAllAttributes(attrName).iterator(); |
| | | if (attributes.hasNext()) |
| | | { |
| | | Attribute attribute = attributes.get(0); |
| | | Attribute attribute = attributes.next(); |
| | | for (ByteString byteString : attribute) |
| | | { |
| | | return byteString.toString(); |
| | |
| | | { |
| | | try |
| | | { |
| | | List<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN); |
| | | if (!attributes.isEmpty()) |
| | | Iterator<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN).iterator(); |
| | | if (attributes.hasNext()) |
| | | { |
| | | Attribute attribute = attributes.get(0); |
| | | Attribute attribute = attributes.next(); |
| | | List<DN> dns = new ArrayList<>(); |
| | | for (ByteString byteString : attribute) |
| | | { |
| | |
| | | Set<DN> baseDNs = new TreeSet<>(); |
| | | try |
| | | { |
| | | List<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN); |
| | | if (!attributes.isEmpty()) |
| | | Iterator<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN).iterator(); |
| | | if (attributes.hasNext()) |
| | | { |
| | | Attribute attribute = attributes.get(0); |
| | | Attribute attribute = attributes.next(); |
| | | for (ByteString byteString : attribute) |
| | | { |
| | | baseDNs.add(DN.valueOf(byteString.toString())); |
| | |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | |
| | | } |
| | | |
| | | private String getSingleStringValue(Entry entry, String attrName) { |
| | | List<Attribute> attrList = entry.getAllAttributes(attrName); |
| | | if (attrList.size() == 1) { |
| | | Attribute attr = attrList.get(0); |
| | | Iterator<Attribute> attrs = entry.getAllAttributes(attrName).iterator(); |
| | | if (attrs.hasNext()) { |
| | | Attribute attr = attrs.next(); |
| | | if (attrs.hasNext()) { |
| | | return ""; |
| | | } |
| | | if (!attr.isEmpty()) { |
| | | return attr.iterator().next().toString(); |
| | | } |
| | |
| | | * attribute type, or an empty list if the specified |
| | | * attribute type is not present in this entry. |
| | | */ |
| | | public List<Attribute> getAllAttributes(String nameOrOID) |
| | | public Iterable<Attribute> getAllAttributes(String nameOrOID) |
| | | { |
| | | for (AttributeType attr : userAttributes.keySet()) |
| | | { |
| | |
| | | public AttributeParser parseAttribute(String attributeDescription) |
| | | throws LocalizedIllegalArgumentException, NullPointerException |
| | | { |
| | | final List<Attribute> attribute = getAllAttributes(attributeDescription); |
| | | return AttributeParser.parseAttribute(!attribute.isEmpty() ? attribute.get(0) : null); |
| | | final Iterable<Attribute> attribute = getAllAttributes(attributeDescription); |
| | | Iterator<Attribute> it = attribute.iterator(); |
| | | return AttributeParser.parseAttribute(it.hasNext() ? it.next() : null); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | package org.opends.server.authorization.dseecompat; |
| | | |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.StringReader; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.Hashtable; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.naming.NamingException; |
| | | import javax.naming.NoPermissionException; |
| | |
| | | import javax.naming.directory.InitialDirContext; |
| | | import javax.naming.directory.ModificationItem; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.DirectoryServerTestCase; |
| | |
| | | import org.opends.server.tools.LDAPPasswordModify; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.Assert; |
| | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | @Test(groups = {"precommit", "dseecompat"}, sequential = true) |
| | | public abstract class AciTestCase extends DirectoryServerTestCase { |
| | |
| | | |
| | | // Save Global ACI. |
| | | Entry e = DirectoryServer.getEntry(DN.valueOf(ACCESS_HANDLER_DN)); |
| | | List<Attribute> attrs = e.getAllAttributes(ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI); |
| | | if (!attrs.isEmpty()) |
| | | Iterator<Attribute> attrs = e.getAllAttributes(ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI).iterator(); |
| | | if (attrs.hasNext()) |
| | | { |
| | | Reporter.log("Saved global ACI attribute"); |
| | | |
| | | globalACIAttribute = attrs.iterator().next(); |
| | | globalACIAttribute = attrs.next(); |
| | | } |
| | | } |
| | | |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private String readCookieFromNthEntry(List<SearchResultEntry> entries, int i) |
| | | { |
| | | SearchResultEntry entry = entries.get(i); |
| | | return entry.getAllAttributes("changelogcookie").get(0).iterator().next().toString(); |
| | | Attribute attr = entry.getAllAttributes("changelogcookie").iterator().next(); |
| | | return attr.iterator().next().toString(); |
| | | } |
| | | |
| | | private String assertEntriesContainsCSNsAndReadLastCookie(String test, List<SearchResultEntry> entries, |
| | |
| | | |
| | | private static String getAttributeValue(Entry entry, String attrName) |
| | | { |
| | | List<Attribute> attrs = entry.getAllAttributes(attrName); |
| | | if (attrs.isEmpty()) |
| | | Iterator<Attribute> attrs = entry.getAllAttributes(attrName).iterator(); |
| | | if (!attrs.hasNext()) |
| | | { |
| | | return null; |
| | | } |
| | | Attribute attr = attrs.iterator().next(); |
| | | Attribute attr = attrs.next(); |
| | | ByteString value = attr.iterator().next(); |
| | | return value.toString(); |
| | | } |
| | |
| | | retrieveCompletedOperationElements(addOperation); |
| | | |
| | | Entry e = DirectoryServer.getEntry(DN.valueOf("ou=People,o=test")); |
| | | List<Attribute> attrList = e.getAllAttributes("ou"); |
| | | Iterable<Attribute> attrList = e.getAllAttributes("ou"); |
| | | assertThat(attrList).isNotEmpty(); |
| | | } |
| | | |
| | |
| | | // @formatter:on |
| | | |
| | | e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test")); |
| | | List<Attribute> attrList = e.getAllAttributes("userpassword"); |
| | | assertThat(attrList).hasSize(1); |
| | | assertFalse(attrList.get(0).getAttributeDescription().hasOptions()); |
| | | assertThat(attrList.get(0)).hasSize(1); |
| | | Iterable<Attribute> attrs = e.getAllAttributes("userpassword"); |
| | | assertThat(attrs).hasSize(1); |
| | | Attribute attr = attrs.iterator().next(); |
| | | assertFalse(attr.getAttributeDescription().hasOptions()); |
| | | assertThat(attr).hasSize(1); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @formatter:on |
| | | |
| | | e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test")); |
| | | List<Attribute> attrList = e.getAllAttributes("userpassword"); |
| | | assertThat(attrList).hasSize(1); |
| | | assertFalse(attrList.get(0).getAttributeDescription().hasOptions()); |
| | | assertThat(attrList.get(0)).hasSize(1); |
| | | Iterable<Attribute> attrs = e.getAllAttributes("userpassword"); |
| | | assertThat(attrs).hasSize(1); |
| | | Attribute attr = attrs.iterator().next(); |
| | | assertFalse(attr.getAttributeDescription().hasOptions()); |
| | | assertThat(attr).hasSize(1); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @formatter:on |
| | | |
| | | Entry e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test")); |
| | | List<Attribute> attrList = e.getAllAttributes("userpassword"); |
| | | assertThat(attrList).hasSize(1); |
| | | assertFalse(attrList.get(0).getAttributeDescription().hasOptions()); |
| | | assertThat(attrList.get(0)).hasSize(1); |
| | | Iterable<Attribute> attrs = e.getAllAttributes("userpassword"); |
| | | assertThat(attrs).hasSize(1); |
| | | Attribute attr = attrs.iterator().next(); |
| | | assertFalse(attr.getAttributeDescription().hasOptions()); |
| | | assertThat(attr).hasSize(1); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @formatter:on |
| | | |
| | | Entry e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test")); |
| | | List<Attribute> attrList = e.getAllAttributes("userpassword"); |
| | | assertThat(attrList).hasSize(1); |
| | | assertFalse(attrList.get(0).getAttributeDescription().hasOptions()); |
| | | assertThat(attrList.get(0)).hasSize(1); |
| | | Iterable<Attribute> attrs = e.getAllAttributes("userpassword"); |
| | | assertThat(attrs).hasSize(1); |
| | | Attribute attr = attrs.iterator().next(); |
| | | assertFalse(attr.getAttributeDescription().hasOptions()); |
| | | assertThat(attr).hasSize(1); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class SearchOperationTestCase extends OperationTestCase |
| | | { |
| | |
| | | { |
| | | for (String attrType : virtualAttrTypes) |
| | | { |
| | | List<Attribute> attrList = entry.getAllAttributes(attrType); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(attrType); |
| | | |
| | | if (stripVirtualAttributes) |
| | | { |
| | | if (!attrList.isEmpty()) |
| | | if (!isEmpty(attrs)) |
| | | { |
| | | messages.add("Unexpected virtual attribute: " + attrType); |
| | | } |
| | | } |
| | | else if (filterType == AttributeFilterType.DEFAULT) |
| | | { |
| | | if (!attrList.isEmpty()) |
| | | if (!isEmpty(attrs)) |
| | | { |
| | | messages.add("Unexpected operational attribute: " + attrType); |
| | | } |
| | |
| | | else if ("ismemberof".equals(attrType)) |
| | | { |
| | | // isMemberOf should never be returned as user is not in any groups. |
| | | if (!attrList.isEmpty()) |
| | | if (!isEmpty(attrs)) |
| | | { |
| | | messages.add("Unexpected isMemberOf attribute"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (attrList.isEmpty()) |
| | | Iterator<Attribute> attrsIt = attrs.iterator(); |
| | | if (!attrsIt.hasNext()) |
| | | { |
| | | messages.add("Missing virtual attribute: " + attrType); |
| | | } |
| | | else |
| | | { |
| | | Attribute attr = attrList.get(0); |
| | | Attribute attr = attrsIt.next(); |
| | | if (typesOnly) |
| | | { |
| | | if (!attr.isEmpty()) |
| | |
| | | { |
| | | for (String attrType : realAttrTypes) |
| | | { |
| | | List<Attribute> attrList = entry.getAllAttributes(attrType); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(attrType); |
| | | |
| | | if (stripRealAttributes) |
| | | { |
| | | if (!attrList.isEmpty()) |
| | | if (!isEmpty(attrs)) |
| | | { |
| | | messages.add("Unexpected real attribute: " + attrType); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (attrList.isEmpty()) |
| | | Iterator<Attribute> attrsIt = attrs.iterator(); |
| | | if (!attrsIt.hasNext()) |
| | | { |
| | | messages.add("Missing real attribute: " + attrType); |
| | | } |
| | | else |
| | | { |
| | | Attribute attr = attrList.get(0); |
| | | Attribute attr = attrsIt.next(); |
| | | if (typesOnly) |
| | | { |
| | | if (!attr.isEmpty()) |
| | |
| | | |
| | | package org.opends.server.core; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | import org.testng.annotations.BeforeMethod; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class SubentryManagerTestCase extends CoreTestCase |
| | | { |
| | |
| | | Entry e = DirectoryServer.getEntry(DN.valueOf("uid=normal user,ou=people,o=test")); |
| | | assertNotNull(e); |
| | | |
| | | List<Attribute> description = e.getAllAttributes("description"); |
| | | Iterable<Attribute> description = e.getAllAttributes("description"); |
| | | assertThat(description).isEmpty(); |
| | | |
| | | // Collective user will inherit the collective description attribute. |
| | |
| | | |
| | | description = e.getAllAttributes("description"); |
| | | assertThat(description).hasSize(1); |
| | | Attribute attribute = description.get(0); |
| | | Attribute attribute = description.iterator().next(); |
| | | assertEquals(attribute.size(), 1); |
| | | assertFalse(attribute.getAttributeDescription().hasOptions()); |
| | | assertTrue(attribute.contains(ByteString.valueOfUtf8("inherited description"))); |
| | |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | import org.testng.annotations.BeforeMethod; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class PasswordExpirationTimeVirtualAttributeProviderTestCase |
| | | extends ExtensionsTestCase |
| | |
| | | SearchResultEntry entry = entries.get(0); |
| | | assertNotNull(entry); |
| | | |
| | | List<Attribute> attrs = entry.getAllAttributes(attributeName); |
| | | assertEquals(attrs.size(), 1); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(attributeName); |
| | | assertThat(attrs).hasSize(1); |
| | | |
| | | Attribute attr = attrs.get(0); |
| | | Attribute attr = attrs.iterator().next(); |
| | | assertNotNull(attr); |
| | | |
| | | Iterator<ByteString> it = attr.iterator(); |
| | |
| | | List<SearchResultEntry> entries = searchOperation.getSearchEntries(); |
| | | SearchResultEntry e = entries.get(0); |
| | | assertNotNull(e); |
| | | List<Attribute> attrs = e.getAllAttributes("usercertificate"); |
| | | Attribute a = attrs.get(0); |
| | | Attribute a = e.getAllAttributes("usercertificate").iterator().next(); |
| | | assertNotNull(a); |
| | | assertThat(a.getAttributeDescription().getOptions()).contains("binary"); |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.replication; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.opends.server.backends.task.TaskState.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.opends.server.backends.task.TaskState.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** An abstract class that all Replication unit test should extend. */ |
| | | @SuppressWarnings("javadoc") |
| | | @Test(groups = { "precommit", "replication" }, sequential = true) |
| | |
| | | { |
| | | final Entry newEntry = DirectoryServer.getEntry(dn); |
| | | assertNotNull(newEntry); |
| | | List<Attribute> attrList = newEntry.getAllAttributes(attrTypeStr); |
| | | Assertions.assertThat(attrList).isNotEmpty(); |
| | | Attribute attr = attrList.get(0); |
| | | Iterable<Attribute> attrs = newEntry.getAllAttributes(attrTypeStr); |
| | | Assertions.assertThat(attrs).isNotEmpty(); |
| | | Attribute attr = attrs.iterator().next(); |
| | | boolean foundAttributeValue = attr.contains(ByteString.valueOfUtf8(valueString)); |
| | | assertEquals(foundAttributeValue, expectedAttributeValueFound, foundMsg); |
| | | return null; |
| | |
| | | { |
| | | Entry newEntry = DirectoryServer.getEntry(dn); |
| | | assertNotNull(newEntry); |
| | | Attribute attribute = newEntry.getAllAttributes("entryuuid").get(0); |
| | | String found = attribute.iterator().next().toString(); |
| | | Attribute attribute = newEntry.getAllAttributes("entryuuid").iterator().next(); |
| | | ByteString found = attribute.iterator().next(); |
| | | assertNotNull(found, "Entry: " + dn + " Could not be found."); |
| | | return found; |
| | | return found.toString(); |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.replication; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.replication.plugin.LDAPReplicationDomain.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.net.SocketTimeoutException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.replication.plugin.LDAPReplicationDomain.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * Test synchronization of update operations on the directory server and through |
| | | * the replication server broker interface. |
| | |
| | | */ |
| | | private boolean assertConflictAttributeExists(Entry entry) |
| | | { |
| | | return !entry.getAllAttributes("ds-sync-confict").isEmpty(); |
| | | return !isEmpty(entry.getAllAttributes("ds-sync-confict")); |
| | | } |
| | | |
| | | @DataProvider(name="assured") |
| | |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | |
| | | throw new Exception("Unknown assured type"); |
| | | } |
| | | |
| | | List<Attribute> attrs = entry.getAllAttributes(assuredAttr); |
| | | if (attrs.isEmpty()) |
| | | Iterator<Attribute> attrs = entry.getAllAttributes(assuredAttr).iterator(); |
| | | if (!attrs.hasNext()) |
| | | { |
| | | return Collections.emptyMap(); |
| | | } |
| | | |
| | | // Parse and store values |
| | | Map<Integer,Integer> resultMap = new HashMap<>(); |
| | | for (ByteString val : attrs.get(0)) |
| | | for (ByteString val : attrs.next()) |
| | | { |
| | | StringTokenizer strtok = new StringTokenizer(val.toString(), ":"); |
| | | |
| | |
| | | replServerPort = TestCaseUtils.findFreePort(); |
| | | } |
| | | |
| | | /** |
| | | * Returns a bunch of single values for fractional-exclude configuration |
| | | * attribute |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | @DataProvider(name = "testExcludePrecommitProvider") |
| | | /** Returns a bunch of single values for fractional-exclude configuration attribute. */ |
| | | @DataProvider |
| | | private Object[][] testExcludePrecommitProvider() |
| | | { |
| | | return new Object[][] |
| | |
| | | */ |
| | | private static void checkEntryAttributeValue(Entry entry, String attributeName, String attributeValue) |
| | | { |
| | | List<Attribute> attrs = entry.getAllAttributes(attributeName); |
| | | assertThat(attrs).as("Was expecting attribute " + attributeName + "=" + attributeValue).hasSize(1); |
| | | Attribute attr = attrs.get(0); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(attributeName); |
| | | assertThat(attrs) |
| | | .as("Was expecting attribute " + attributeName + "=" + attributeValue) |
| | | .hasSize(1); |
| | | Attribute attr = attrs.iterator().next(); |
| | | Iterator<ByteString> attrValues = attr.iterator(); |
| | | assertTrue(attrValues.hasNext()); |
| | | ByteString attrValue = attrValues.next(); |
| | |
| | | */ |
| | | package org.opends.server.replication.plugin; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.Callable; |
| | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** Tests the Historical class. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class HistoricalTest extends ReplicationTestCase |
| | |
| | | DN dn = DN.valueOf("uid=user.1," + TEST_ROOT_DN_STRING); |
| | | Entry entry = DirectoryServer.getEntry(dn); |
| | | |
| | | List<Attribute> attrs = EntryHistorical.getHistoricalAttr(entry); |
| | | Attribute before = attrs.get(0); |
| | | Iterable<Attribute> attrs = EntryHistorical.getHistoricalAttr(entry); |
| | | Attribute before = attrs.iterator().next(); |
| | | |
| | | // Check that encoding and decoding preserves the history information. |
| | | EntryHistorical hist = EntryHistorical.newInstanceFromEntry(entry); |
| | |
| | | assertEquals(mod.getAttribute(), values3and4); |
| | | |
| | | // check that the entry now contains value1 and value2 and no other values. |
| | | Attribute resultEntryAttr = entry.getAllAttributes(DESCRIPTION).get(0); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(DESCRIPTION); |
| | | assertThat(attrs).hasSize(1); |
| | | Attribute resultEntryAttr = attrs.iterator().next(); |
| | | assertEquals(resultEntryAttr, values1and2); |
| | | |
| | | Attribute attr = buildSyncHist(DESCRIPTION, |
| | |
| | | assertEquals(hist.encodeAndPurge(), attr); |
| | | |
| | | // The entry should have no value |
| | | List<Attribute> attrs = entry.getAllAttributes(DESCRIPTION); |
| | | assertEquals(attrs.get(0), Attributes.create(DESCRIPTION, "value2", "value3", "value4")); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(DESCRIPTION); |
| | | assertThat(attrs).containsOnly(Attributes.create(DESCRIPTION, "value2", "value3", "value4")); |
| | | } |
| | | |
| | | /** |
| | |
| | | assertEquals(hist.encodeAndPurge(), attr); |
| | | |
| | | // The entry should have no value |
| | | List<Attribute> attrs = entry.getAllAttributes(DESCRIPTION); |
| | | assertEquals(attrs.get(0), Attributes.create(DESCRIPTION, "value3", "value4")); |
| | | Iterable<Attribute> attrs = entry.getAllAttributes(DESCRIPTION); |
| | | assertThat(attrs).containsOnly(Attributes.create(DESCRIPTION, "value3", "value4")); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | package org.opends.server.schema; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** Test the LDAPSyntaxDescriptionSyntax. */ |
| | | @RemoveOnceSDKSchemaIsUsed |
| | | @SuppressWarnings("javadoc") |
| | |
| | | assertThat(entries).isNotEmpty(); |
| | | SearchResultEntry e = entries.get(0); |
| | | assertNotNull(e); |
| | | Attribute attr = e.getAllAttributes("ldapsyntaxes").get(0); |
| | | Attribute attr = e.getAllAttributes("ldapsyntaxes").iterator().next(); |
| | | |
| | | //There are other ways of doing it but we will extract the OID |
| | | //from the attribute values and then check to see if our |
| | |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** A set of test cases for the MakeLDIF tool. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class MakeLDIFTestCase extends ToolsTestCase |
| | |
| | | |
| | | Entry e = readEntry(outLdifFilePath); |
| | | assertNotNull(e); |
| | | List<Attribute> attrs = e.getAllAttributes(attrName); |
| | | assertFalse(attrs.isEmpty()); |
| | | Attribute a = attrs.get(0); |
| | | Iterable<Attribute> attrs = e.getAllAttributes(attrName); |
| | | assertThat(attrs).isNotEmpty(); |
| | | Attribute a = attrs.iterator().next(); |
| | | Attribute expectedRes = Attributes.create(attrName, expectedValue); |
| | | assertEquals(a, expectedRes); |
| | | } |
| | |
| | | |
| | | Entry e = readEntry(outLdifFilePath); |
| | | assertNotNull(e); |
| | | List<Attribute> attrs = e.getAllAttributes("cn"); |
| | | assertFalse(attrs.isEmpty()); |
| | | Attribute a = attrs.get(0); |
| | | Iterable<Attribute> attrs = e.getAllAttributes("cn"); |
| | | assertThat(attrs).isNotEmpty(); |
| | | Attribute a = attrs.iterator().next(); |
| | | assertTrue(a.iterator().next().toString().matches("Foo <[A-Z]>\\{1\\}Bar"), |
| | | "cn value doesn't match the expected value"); |
| | | } |