Prep work for OPENDJ-1342: align APIs for DNs
DN.getRDN(int) => DN.rdn(int)
server's DN now implements Iterable<RDN>
*Test*.java:
Fixed ambiguity with assertThat() methods and the use of DNs.
| | |
| | | int diff = dn.size() - rdns.length; |
| | | for (int i=0; i < rdns.length; i++) |
| | | { |
| | | rdns[i] = dn.getRDN(i + diff); |
| | | rdns[i] = dn.rdn(i + diff); |
| | | } |
| | | final DN parentToAddDN = new DN(rdns); |
| | | boolean mustAddParent = true; |
| | |
| | | int keepRDNCount=keyRDNCount - oldRDNCount; |
| | | RDN[] newRDNs = new RDN[keepRDNCount + newRDNCount]; |
| | | for (int i=0; i < keepRDNCount; i++) { |
| | | newRDNs[i] = hashEntry.getKey().getRDN(i); |
| | | newRDNs[i] = hashEntry.getKey().rdn(i); |
| | | } |
| | | for (int i=keepRDNCount, j=0; j < newRDNCount; i++,j++) { |
| | | newRDNs[i] = newDN.getRDN(j); |
| | | newRDNs[i] = newDN.rdn(j); |
| | | } |
| | | DN relocateDN=new DN(newRDNs); |
| | | List<Aci> acis = new LinkedList<>(); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.authorization.dseecompat; |
| | | |
| | |
| | | |
| | | for (int i = 0; i < dn.size(); i++) |
| | | { |
| | | if (!equality[i].matchesRDN(dn.getRDN(i))) |
| | | if (!equality[i].matchesRDN(dn.rdn(i))) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | |
| | | for (; pos < initialLength; pos++) |
| | | { |
| | | if (!subInitial[pos].matchesRDN(dn.getRDN(pos))) |
| | | if (!subInitial[pos].matchesRDN(dn.rdn(pos))) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | boolean match = false; |
| | | for (; pos < end; pos++) |
| | | { |
| | | if (element[0].matchesRDN(dn.getRDN(pos))) |
| | | if (element[0].matchesRDN(dn.rdn(pos))) |
| | | { |
| | | if (subMatch(dn, pos, element, anyLength)) |
| | | { |
| | |
| | | pos = valueLength - finalLength; |
| | | for (int i=0; i < finalLength; i++,pos++) |
| | | { |
| | | if (!subFinal[i].matchesRDN(dn.getRDN(pos))) |
| | | if (!subFinal[i].matchesRDN(dn.rdn(pos))) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | { |
| | | for (int i = 1; i < length; i++) |
| | | { |
| | | if (!element[i].matchesRDN(dn.getRDN(pos + i))) |
| | | if (!element[i].matchesRDN(dn.rdn(pos + i))) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | for (int i = startSize; i >= 0; i--) |
| | | { |
| | | builder.appendByte(DN.NORMALIZED_RDN_SEPARATOR); |
| | | dn.getRDN(i).toNormalizedByteString(builder); |
| | | dn.rdn(i).toNormalizedByteString(builder); |
| | | } |
| | | return builder.toByteString(); |
| | | } |
| | |
| | | RDN[] newDNComponents = new RDN[oldDNKeepComponents+newSuffixDNComponents]; |
| | | for (int i=0; i < oldDNKeepComponents; i++) |
| | | { |
| | | newDNComponents[i] = oldDN.getRDN(i); |
| | | newDNComponents[i] = oldDN.rdn(i); |
| | | } |
| | | |
| | | for (int i=oldDNKeepComponents, j=0; j < newSuffixDNComponents; i++,j++) |
| | | { |
| | | newDNComponents[i] = newSuffixDN.getRDN(j); |
| | | newDNComponents[i] = newSuffixDN.rdn(j); |
| | | } |
| | | |
| | | return new DN(newDNComponents); |
| | |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.IndexType; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | |
| | |
| | | } |
| | | |
| | | LinkedList<SearchFilter> filterComps = new LinkedList<>(); |
| | | for (int i=0; i < peerDN.size(); i++) |
| | | for (RDN rdn : peerDN) |
| | | { |
| | | for (AVA ava : peerDN.getRDN(i)) |
| | | for (AVA ava : rdn) |
| | | { |
| | | String lowerName = toLowerCase(ava.getAttributeName()); |
| | | |
| | |
| | | { |
| | | int count = Math.min(numComponents, dn.size()); |
| | | |
| | | templateValue.getValue().append(dn.getRDN(0)); |
| | | templateValue.getValue().append(dn.rdn(0)); |
| | | for (int i = 1; i < count; i++) |
| | | { |
| | | templateValue.append(","); |
| | | templateValue.getValue().append(dn.getRDN(i)); |
| | | templateValue.getValue().append(dn.rdn(i)); |
| | | } |
| | | } |
| | | else |
| | |
| | | int sz = dn.size(); |
| | | int count = Math.min(Math.abs(numComponents), sz); |
| | | |
| | | templateValue.getValue().append(dn.getRDN(sz - count)); |
| | | templateValue.getValue().append(dn.rdn(sz - count)); |
| | | for (int i = 1; i < count; i++) |
| | | { |
| | | templateValue.append(","); |
| | | templateValue.getValue().append(dn.getRDN(sz - count + i)); |
| | | templateValue.getValue().append(dn.rdn(sz - count + i)); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (numComponents == 0) |
| | | { |
| | | templateValue.getValue().append(dn.getRDN(0)); |
| | | templateValue.getValue().append(dn.rdn(0)); |
| | | for (int i=1; i < dn.size(); i++) |
| | | { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(dn.getRDN(i)); |
| | | templateValue.getValue().append(dn.rdn(i)); |
| | | } |
| | | } |
| | | else if (numComponents > 0) |
| | | { |
| | | int count = Math.min(numComponents, dn.size()); |
| | | |
| | | templateValue.getValue().append(dn.getRDN(0)); |
| | | templateValue.getValue().append(dn.rdn(0)); |
| | | for (int i = 1; i < count; i++) |
| | | { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(dn.getRDN(i)); |
| | | templateValue.getValue().append(dn.rdn(i)); |
| | | } |
| | | } |
| | | else |
| | |
| | | int sz = dn.size(); |
| | | int count = Math.min(Math.abs(numComponents), sz); |
| | | |
| | | templateValue.getValue().append(dn.getRDN(sz - count)); |
| | | templateValue.getValue().append(dn.rdn(sz - count)); |
| | | for (int i = 1; i < count; i++) { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(dn.getRDN(sz - count + i)); |
| | | templateValue.getValue().append(dn.rdn(sz - count + i)); |
| | | } |
| | | } |
| | | |
| | |
| | | return TagResult.SUCCESS_RESULT; |
| | | } |
| | | |
| | | templateValue.getValue().append(parentDN.getRDN(0)); |
| | | templateValue.getValue().append(parentDN.rdn(0)); |
| | | for (int i=1; i < parentDN.size(); i++) |
| | | { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(parentDN.getRDN(i)); |
| | | templateValue.getValue().append(parentDN.rdn(i)); |
| | | } |
| | | |
| | | return TagResult.SUCCESS_RESULT; |
| | |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Arrays; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | |
| | | mayInstantiate=true, |
| | | mayExtend=false, |
| | | mayInvoke=true) |
| | | public final class DN implements Comparable<DN>, Serializable |
| | | public final class DN implements Comparable<DN>, Iterable<RDN>, Serializable |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | /** A singleton instance of the root/null DN (a DN with no components). */ |
| | |
| | | * @return The RDN component at the specified position in the set |
| | | * of components for this DN. |
| | | */ |
| | | public RDN getRDN(int pos) |
| | | public RDN rdn(int pos) |
| | | { |
| | | return rdnComponents[pos]; |
| | | } |
| | |
| | | return toNormalizedByteString().compareTo(other.toNormalizedByteString()); |
| | | } |
| | | |
| | | @Override |
| | | public Iterator<RDN> iterator() |
| | | { |
| | | return Arrays.asList(rdnComponents).iterator(); |
| | | } |
| | | } |
| | | |
| | |
| | | // attributes, then do so. |
| | | if (dnAttributes) |
| | | { |
| | | DN entryDN = entry.getName(); |
| | | int count = entryDN.size(); |
| | | for (int rdnIndex = 0; rdnIndex < count; rdnIndex++) |
| | | for (RDN rdn : entry.getName()) |
| | | { |
| | | for (AVA ava : entryDN.getRDN(rdnIndex)) |
| | | for (AVA ava : rdn) |
| | | { |
| | | try |
| | | { |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2007-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.admin.client.ldap; |
| | | |
| | |
| | | |
| | | // Create required glue entries. |
| | | for (int i = 0; i < entryDN.size() - 1; i++) { |
| | | RDN rdn = entryDN.getRDN(entryDN.size() - i - 1); |
| | | RDN rdn = entryDN.rdn(entryDN.size() - i - 1); |
| | | DN dn = parent.getDN().child(rdn); |
| | | |
| | | if (!entries.containsKey(dn)) { |
| | |
| | | { |
| | | DN actualDN = resultEntry.getName(); |
| | | DN expectedDN = DN.valueOf("changenumber=" + changeNumber + ",cn=changelog"); |
| | | assertThat(actualDN).isEqualTo(expectedDN); |
| | | assertThat((Object) actualDN).isEqualTo(expectedDN); |
| | | } |
| | | |
| | | private void assertDNWithCSN(SearchResultEntry resultEntry, CSN csn) throws Exception |
| | | { |
| | | DN actualDN = resultEntry.getName(); |
| | | DN expectedDN = DN.valueOf("replicationcsn=" + csn + "," + DN_OTEST + ",cn=changelog"); |
| | | assertThat(actualDN).isEqualTo(expectedDN); |
| | | assertThat((Object) actualDN).isEqualTo(expectedDN); |
| | | } |
| | | |
| | | /** |
| | |
| | | backend.search(createSearchOperation( |
| | | newEntry.getName().parent(), SearchScope.WHOLE_SUBTREE, "(&(sn=Smith)(jpegphoto=foo))", returnedEntries)); |
| | | assertThat(returnedEntries).hasSize(1); |
| | | assertThat(returnedEntries.get(0).getName()).isEqualTo(newEntry.getName()); |
| | | assertThat((Object) returnedEntries.get(0).getName()).isEqualTo(newEntry.getName()); |
| | | } |
| | | |
| | | private SearchOperation createSearchOperation(DN baseDN, SearchScope scope, String searchFilter, |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | * Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2014 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.replication.server.changelog.file; |
| | |
| | | final ChangeNumberIndexRecord record = allValues.get(i); |
| | | // check content in order |
| | | String desc2 = "actual was:<" + record + ">, but expected was:<" + expectedMsg + ">"; |
| | | assertThat(record.getBaseDN()).as(desc2).isEqualTo(expectedMsg.getBaseDN()); |
| | | assertThat((Object) record.getBaseDN()).as(desc2).isEqualTo(expectedMsg.getBaseDN()); |
| | | assertThat(record.getCSN()).as(desc2).isEqualTo(expectedMsg.getCSN()); |
| | | } |
| | | } |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | * Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.replication.server.changelog.file; |
| | | |
| | |
| | | private void assertMessagesInOrder(DN baseDN, UpdateMsg msg1, UpdateMsg msg2) throws Exception |
| | | { |
| | | assertThat(eclCursor.getRecord()).isNull(); |
| | | assertThat(eclCursor.getData()).isNull(); |
| | | assertThat((Object) eclCursor.getData()).isNull(); |
| | | |
| | | if (msg1 != null) |
| | | { |
| | | assertThat(eclCursor.next()).isTrue(); |
| | | assertThat(eclCursor.getRecord()).isEqualTo(msg1); |
| | | assertThat(eclCursor.getData()).isEqualTo(baseDN); |
| | | assertThat((Object) eclCursor.getData()).isEqualTo(baseDN); |
| | | } |
| | | if (msg2 != null) |
| | | { |
| | | assertThat(eclCursor.next()).isTrue(); |
| | | assertThat(eclCursor.getRecord()).isEqualTo(msg2); |
| | | assertThat(eclCursor.getData()).isEqualTo(baseDN); |
| | | assertThat((Object) eclCursor.getData()).isEqualTo(baseDN); |
| | | } |
| | | |
| | | assertThat(eclCursor.next()).isFalse(); |
| | | assertThat(eclCursor.getRecord()).isNull(); |
| | | assertThat(eclCursor.getData()).isNull(); |
| | | assertThat((Object) eclCursor.getData()).isNull(); |
| | | } |
| | | |
| | | private void addDomainCursorToCursor(DN baseDN, SequentialDBCursor cursor) throws ChangelogException |
| | |
| | | |
| | | assertThat(record).isNotNull(); |
| | | assertThat(record.getKey()).isEqualTo(msg.getChangeNumber()); |
| | | assertThat(record.getValue().getBaseDN()).isEqualTo(msg.getBaseDN()); |
| | | assertThat((Object) record.getValue().getBaseDN()).isEqualTo(msg.getBaseDN()); |
| | | assertThat(record.getValue().getCSN()).isEqualTo(msg.getCSN()); |
| | | } |
| | | |
| | |
| | | assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); |
| | | List<SearchResultEntry> entries = searchOperation.getSearchEntries(); |
| | | assertThat(entries).as("expected one entry to be returned").isNotEmpty(); |
| | | assertThat(entries.get(0).getName()).isEqualTo(DN.valueOf("cn=test1,o=test")); |
| | | assertThat((Object) entries.get(0).getName()).isEqualTo(DN.valueOf("cn=test1,o=test")); |
| | | } |
| | | finally |
| | | { |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.testng.Assert; |
| | |
| | | |
| | | assertEquals(p.rdn(), RDN.valueOf("dc=bar")); |
| | | |
| | | assertEquals(p.getRDN(0), RDN.valueOf("dc=bar")); |
| | | assertEquals(p.getRDN(1), RDN.valueOf("dc=opends")); |
| | | assertEquals(p.getRDN(2), RDN.valueOf("dc=org")); |
| | | assertEquals(p.rdn(0), RDN.valueOf("dc=bar")); |
| | | assertEquals(p.rdn(1), RDN.valueOf("dc=opends")); |
| | | assertEquals(p.rdn(2), RDN.valueOf("dc=org")); |
| | | |
| | | assertEquals(p.parent(), DN.valueOf("dc=opends,dc=org")); |
| | | assertEquals(p.parent(), e.parent()); |
| | |
| | | DN dn = DN.valueOf(s); |
| | | RDN rdn = RDN.valueOf(r); |
| | | |
| | | assertEquals(dn.getRDN(i), rdn, "For DN " + s); |
| | | assertEquals(dn.rdn(i), rdn, "For DN " + s); |
| | | } |
| | | |
| | | |
| | |
| | | DN dn = DN.valueOf(s); |
| | | |
| | | // Shoudld throw. |
| | | dn.getRDN(i); |
| | | dn.rdn(i); |
| | | |
| | | Assert.fail("Excepted exception for RDN index " + i + " in DN " + s); |
| | | } |
| | |
| | | |
| | | assertEquals(c.rdn(), RDN.valueOf("dc=foo")); |
| | | |
| | | assertEquals(c.getRDN(0), RDN.valueOf("dc=foo")); |
| | | assertEquals(c.getRDN(1), RDN.valueOf("dc=bar")); |
| | | assertEquals(c.getRDN(2), RDN.valueOf("dc=opends")); |
| | | assertEquals(c.getRDN(3), RDN.valueOf("dc=org")); |
| | | assertEquals(c.rdn(0), RDN.valueOf("dc=foo")); |
| | | assertEquals(c.rdn(1), RDN.valueOf("dc=bar")); |
| | | assertEquals(c.rdn(2), RDN.valueOf("dc=opends")); |
| | | assertEquals(c.rdn(3), RDN.valueOf("dc=org")); |
| | | |
| | | assertEquals(c.parent(), DN.valueOf("dc=bar,dc=opends,dc=org")); |
| | | assertEquals(c.parent(), e.parent()); |
| | |
| | | { |
| | | DN dn = DN.valueOf(dnString); |
| | | DN renamed = dn.rename(DN.valueOf(fromDN), DN.valueOf(toDN)); |
| | | |
| | | assertThat(renamed).isEqualTo(DN.valueOf(expectedDN)); |
| | | assertThat((Object) renamed).isEqualTo(DN.valueOf(expectedDN)); |
| | | } |
| | | } |
| | | |