LDAP-258: Deprecated DistinguishedName and associated classes. Removed unnecessary usage in core.

This commit is contained in:
Mattias Hellborg Arthursson
2013-08-30 08:00:38 +02:00
parent c9bf9960b9
commit ed605be49a
49 changed files with 858 additions and 397 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.ldap.core;
import org.junit.Test;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.directory.Attributes;
@@ -36,7 +37,7 @@ public class DirContextAdapterBugTest {
BasicAttributes attrs = new BasicAttributes("myattr", "a");
attrs.get("myattr").add("b");
attrs.get("myattr").add("c");
UpdateAdapter ctx = new UpdateAdapter(attrs, new DistinguishedName());
UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName());
ctx.setAttributeValues("myattr", new String[] { "a", "b" });
ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" });
@@ -49,7 +50,7 @@ public class DirContextAdapterBugTest {
BasicAttributes attrs = new BasicAttributes("myattr", "a");
attrs.get("myattr").add("b");
attrs.get("myattr").add("c");
UpdateAdapter ctx = new UpdateAdapter(attrs, new DistinguishedName());
UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName());
ctx.setAttributeValues("myattr", new String[] { "a", "b", "d" });
ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" });
@@ -68,7 +69,7 @@ public class DirContextAdapterBugTest {
@Test
public void testResetNullAttributeValuesReportedAsModifications() {
BasicAttributes attrs = new BasicAttributes("myattr", null);
UpdateAdapter ctx = new UpdateAdapter(attrs, new DistinguishedName());
UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName());
ctx.setAttributeValues("myattr", new String[] { "a" });
ctx.setAttributeValues("myattr", null);
@@ -79,7 +80,7 @@ public class DirContextAdapterBugTest {
@Test
public void testResetNullAttributeValueNotReportedAsModification() throws Exception {
BasicAttributes attrs = new BasicAttributes("myattr", "b");
UpdateAdapter ctx = new UpdateAdapter(attrs, new DistinguishedName());
UpdateAdapter ctx = new UpdateAdapter(attrs, LdapUtils.emptyLdapName());
ctx.setAttributeValue("myattr", "a");
ctx.setAttributeValue("myattr", "b");

View File

@@ -18,6 +18,7 @@ package org.springframework.ldap.core;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.CompositeName;
import javax.naming.Name;
@@ -28,6 +29,7 @@ import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapName;
import java.util.Iterator;
import java.util.SortedSet;
@@ -46,11 +48,10 @@ import static org.junit.Assert.fail;
* @author Ulrik Sandberg
*/
public class DirContextAdapterTest {
private static final DistinguishedName BASE_NAME = new DistinguishedName(
"dc=jayway, dc=se");
private static final LdapName BASE_NAME = LdapUtils.newLdapName("dc=jayway,dc=se");
private static final DistinguishedName DUMMY_NAME = new DistinguishedName(
"c=SE, dc=jayway, dc=se");
private static final LdapName DUMMY_NAME = LdapUtils.newLdapName(
"c=SE,dc=jayway,dc=se");
private DirContextAdapter tested;
@@ -595,7 +596,7 @@ public class DirContextAdapterTest {
@Test
public void testGetNameInNamespace_BasePath() {
DirContextAdapter tested = new DirContextAdapter(null,
new DistinguishedName("c=SE"), BASE_NAME);
LdapUtils.newLdapName("c=SE"), BASE_NAME);
String result = tested.getNameInNamespace();
assertEquals(DUMMY_NAME.toString(), result);
}
@@ -1220,6 +1221,6 @@ public class DirContextAdapterTest {
@Test
public void testStringConstructor() {
DirContextAdapter tested = new DirContextAdapter("cn=john doe, ou=company");
assertEquals(new DistinguishedName("cn=john doe, ou=company"), tested.getDn());
assertEquals(LdapUtils.newLdapName("cn=john doe, ou=company"), tested.getDn());
}
}

View File

@@ -19,11 +19,13 @@ package org.springframework.ldap.core;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -282,7 +284,7 @@ public class LdapTemplateLookupTest {
BasicAttributes expectedAttributes = new BasicAttributes();
expectedAttributes.put("cn", "Some Name");
DistinguishedName name = new DistinguishedName(DEFAULT_BASE_STRING);
LdapName name = LdapUtils.newLdapName(DEFAULT_BASE_STRING);
DirContextAdapter adapter = new DirContextAdapter(expectedAttributes,
name);
@@ -310,7 +312,7 @@ public class LdapTemplateLookupTest {
when(dirContextMock.getAttributes(DEFAULT_BASE_STRING, attributeNames)).thenReturn(expectedAttributes);
DistinguishedName name = new DistinguishedName(DEFAULT_BASE_STRING);
LdapName name = LdapUtils.newLdapName(DEFAULT_BASE_STRING);
DirContextAdapter adapter = new DirContextAdapter(expectedAttributes,
name);

View File

@@ -26,6 +26,7 @@ import org.springframework.ldap.LimitExceededException;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.PartialResultException;
import org.springframework.ldap.UncategorizedLdapException;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Binding;
import javax.naming.CompositeName;
@@ -37,6 +38,7 @@ import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.LdapName;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -970,9 +972,9 @@ public class LdapTemplateTest {
Binding binding = new Binding("cn=Some name", null);
when(namingEnumerationMock.next()).thenReturn(binding);
DistinguishedName listDn = new DistinguishedName(DEFAULT_BASE_STRING);
LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE_STRING);
when(dirContextMock.listBindings(listDn)).thenReturn(namingEnumerationMock);
DistinguishedName subListDn = new DistinguishedName("cn=Some name, o=example.com");
LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com");
when(dirContextMock.listBindings(subListDn)).thenReturn(namingEnumerationMock);
tested.unbind(new CompositeName(DEFAULT_BASE_STRING), true);
@@ -991,9 +993,9 @@ public class LdapTemplateTest {
Binding binding = new Binding("cn=Some name", null);
when(namingEnumerationMock.next()).thenReturn(binding);
DistinguishedName listDn = new DistinguishedName(DEFAULT_BASE_STRING);
LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE_STRING);
when(dirContextMock.listBindings(listDn)).thenReturn(namingEnumerationMock);
DistinguishedName subListDn = new DistinguishedName("cn=Some name, o=example.com");
LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com");
when(dirContextMock.listBindings(subListDn)).thenReturn(namingEnumerationMock);
tested.unbind(DEFAULT_BASE_STRING, true);
@@ -1265,14 +1267,15 @@ public class LdapTemplateTest {
public void testLookupContextWithName() {
final DirContextAdapter expectedResult = new DirContextAdapter();
LdapTemplate tested = new LdapTemplate() {
final LdapName expectedName = LdapUtils.emptyLdapName();
LdapTemplate tested = new LdapTemplate() {
public Object lookup(Name dn) {
assertSame(DistinguishedName.EMPTY_PATH, dn);
assertSame(dn, dn);
return expectedResult;
}
};
DirContextOperations result = tested.lookupContext(DistinguishedName.EMPTY_PATH);
DirContextOperations result = tested.lookupContext(expectedName);
assertSame(expectedResult, result);
}
@@ -1297,13 +1300,14 @@ public class LdapTemplateTest {
public void testModifyAttributesWithDirContextOperations() throws Exception {
final ModificationItem[] expectedModifications = new ModificationItem[0];
when(dirContextOperationsMock.getDn()).thenReturn(DistinguishedName.EMPTY_PATH);
final LdapName epectedDn = LdapUtils.emptyLdapName();
when(dirContextOperationsMock.getDn()).thenReturn(epectedDn);
when(dirContextOperationsMock.isUpdateMode()).thenReturn(true);
when(dirContextOperationsMock.getModificationItems()).thenReturn(expectedModifications);
LdapTemplate tested = new LdapTemplate() {
public void modifyAttributes(Name dn, ModificationItem[] mods) {
assertSame(DistinguishedName.EMPTY_PATH, dn);
assertSame(epectedDn, dn);
assertSame(expectedModifications, mods);
}
};
@@ -1314,7 +1318,7 @@ public class LdapTemplateTest {
@Test
public void testModifyAttributesWithDirContextOperationsNotInitializedDn() throws Exception {
when(dirContextOperationsMock.getDn()).thenReturn(DistinguishedName.EMPTY_PATH);
when(dirContextOperationsMock.getDn()).thenReturn(LdapUtils.emptyLdapName());
when(dirContextOperationsMock.isUpdateMode()).thenReturn(false);
LdapTemplate tested = new LdapTemplate() {
@@ -1425,8 +1429,8 @@ public class LdapTemplateTest {
public void testAuthenticateWithSingleUserFoundShouldBeSuccessful() throws Exception {
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
Object expectedObject = new DirContextAdapter(new BasicAttributes(), new DistinguishedName("cn=john doe"),
new DistinguishedName("dc=jayway, dc=se"));
Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"),
LdapUtils.newLdapName("dc=jayway, dc=se"));
SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes());
singleSearchResult(searchControlsRecursive(), searchResult);
@@ -1434,7 +1438,7 @@ public class LdapTemplateTest {
when(contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password"))
.thenReturn(authenticatedContextMock);
entryContextCallbackMock.executeWithContext(authenticatedContextMock, new LdapEntryIdentification(
new DistinguishedName("cn=john doe,dc=jayway,dc=se"), new DistinguishedName("cn=john doe")));
LdapUtils.newLdapName("cn=john doe,dc=jayway,dc=se"), LdapUtils.newLdapName("cn=john doe")));
boolean result = tested.authenticate(nameMock, "(ou=somevalue)", "password", entryContextCallbackMock);
@@ -1448,8 +1452,8 @@ public class LdapTemplateTest {
public void testAuthenticateWithTwoUsersFoundShouldThrowException() throws Exception {
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
Object expectedObject = new DirContextAdapter(new BasicAttributes(), new DistinguishedName("cn=john doe"),
new DistinguishedName("dc=jayway, dc=se"));
Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"),
LdapUtils.newLdapName("dc=jayway, dc=se"));
SearchResult searchResult1 = new SearchResult("", expectedObject, new BasicAttributes());
SearchResult searchResult2 = new SearchResult("", expectedObject, new BasicAttributes());
@@ -1483,8 +1487,8 @@ public class LdapTemplateTest {
public void testAuthenticateWithFailedAuthenticationShouldFail() throws Exception {
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
Object expectedObject = new DirContextAdapter(new BasicAttributes(), new DistinguishedName("cn=john doe"),
new DistinguishedName("dc=jayway, dc=se"));
Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"),
LdapUtils.newLdapName("dc=jayway, dc=se"));
SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes());
singleSearchResult(searchControlsRecursive(), searchResult);
@@ -1503,8 +1507,8 @@ public class LdapTemplateTest {
public void testAuthenticateWithErrorInCallbackShouldFail() throws Exception {
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
Object expectedObject = new DirContextAdapter(new BasicAttributes(), new DistinguishedName("cn=john doe"),
new DistinguishedName("dc=jayway, dc=se"));
Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"),
LdapUtils.newLdapName("dc=jayway, dc=se"));
SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes());
singleSearchResult(searchControlsRecursive(), searchResult);
@@ -1514,7 +1518,7 @@ public class LdapTemplateTest {
doThrow(new UncategorizedLdapException("Authentication failed")).when(entryContextCallbackMock)
.executeWithContext(authenticatedContextMock,
new LdapEntryIdentification(
new DistinguishedName("cn=john doe,dc=jayway,dc=se"), new DistinguishedName("cn=john doe")));
LdapUtils.newLdapName("cn=john doe,dc=jayway,dc=se"), LdapUtils.newLdapName("cn=john doe")));
boolean result = tested.authenticate(nameMock, "(ou=somevalue)", "password", entryContextCallbackMock);

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.core.support;
import org.junit.Test;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
/**
* @author Mattias Hellborg Arthursson
*/
public class AbstractContextSourceTest {
@Test
public void testFormatForUrlNormal() throws InvalidNameException {
LdapName ldapName = new LdapName("dc=261consulting, dc=com");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("dc=261consulting,dc=com", result);
}
@Test
public void testFormatForUrlNormalWithQuestionMark() throws InvalidNameException {
LdapName ldapName = new LdapName("dc=261consulting?, dc=com");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("dc=261consulting%3F,dc=com", result);
}
@Test
public void testFormatForUrlWithSpace() throws InvalidNameException {
LdapName ldapName = new LdapName("ou=some department, dc=261consulting, dc=com");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("ou=some%20department,dc=261consulting,dc=com", result);
}
@Test
public void testFormatForUrlEmpty() throws InvalidNameException {
LdapName ldapName = new LdapName("");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("", result);
}
}

View File

@@ -20,6 +20,7 @@ import org.junit.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
@@ -34,18 +35,18 @@ import static org.mockito.Mockito.when;
public class BaseLdapPathBeanPostProcessorTest {
private BaseLdapPathBeanPostProcessor tested;
private BaseLdapPathAware ldapPathAwareMock;
private ApplicationContext applicationContextMock;
private BaseLdapNameAware ldapNameAwareMock;
@Before
public void setUp() throws Exception {
tested = new BaseLdapPathBeanPostProcessor();
ldapPathAwareMock = mock(BaseLdapPathAware.class);
ldapNameAwareMock = mock(BaseLdapNameAware.class);
applicationContextMock = mock(ApplicationContext.class);
applicationContextMock = mock(ApplicationContext.class);
tested.setApplicationContext(applicationContextMock);
}
@@ -62,6 +63,19 @@ public class BaseLdapPathBeanPostProcessorTest {
assertSame(ldapPathAwareMock, result);
}
@Test
public void testPostProcessBeforeInitializationWithLdapNameAwareBasePathSet() throws Exception {
String expectedPath = "dc=example, dc=com";
tested.setBasePath(expectedPath);
Object result = tested.postProcessBeforeInitialization(ldapNameAwareMock, "someName");
verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath));
assertSame(ldapNameAwareMock, result);
}
@Test
public void testPostProcessBeforeInitializationWithLdapPathAwareNoBasePathSet() throws Exception {
final LdapContextSource expectedContextSource = new LdapContextSource();
@@ -81,6 +95,25 @@ public class BaseLdapPathBeanPostProcessorTest {
assertSame(ldapPathAwareMock, result);
}
@Test
public void testPostProcessBeforeInitializationWithLdapNameAwareNoBasePathSet() throws Exception {
final LdapContextSource expectedContextSource = new LdapContextSource();
String expectedPath = "dc=example, dc=com";
expectedContextSource.setBase(expectedPath);
tested = new BaseLdapPathBeanPostProcessor() {
BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() {
return expectedContextSource;
}
};
Object result = tested.postProcessBeforeInitialization(ldapNameAwareMock, "someName");
verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath));
assertSame(ldapNameAwareMock, result);
}
@Test
public void testGetAbstractContextSourceFromApplicationContext() throws Exception {
when(applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class))

View File

@@ -18,7 +18,7 @@ package org.springframework.ldap.core.support;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.CompositeName;
import javax.naming.Context;
@@ -36,7 +36,7 @@ public class DefaultDirObjectFactoryTest {
private Context contextMock;
private static final Name DN = new DistinguishedName("ou=some unit, dc=jayway, dc=se");
private static final Name DN = LdapUtils.newLdapName("ou=some unit, dc=jayway, dc=se");
private static final String DN_STRING = "ou=some unit, dc=jayway, dc=se";
@@ -119,7 +119,7 @@ public class DefaultDirObjectFactoryTest {
when(contextMock2.getNameInNamespace()).thenReturn("dc=jayway, dc=se");
DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, new DistinguishedName(
DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, LdapUtils.newLdapName(
"ou=some unit"), contextMock2, new Hashtable(), expectedAttributes);
verify(contextMock).close();

View File

@@ -18,7 +18,7 @@ package org.springframework.ldap.core.support;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Context;
import java.util.HashMap;
@@ -62,20 +62,20 @@ public class LdapContextSourceTest {
@Test
public void testGetAnonymousEnv() throws Exception {
tested.setBase("dc=example,dc=se");
tested.setBase("dc=some example,dc=se");
tested.setUrl("ldap://ldap.example.com:389");
tested.setPooled(true);
tested.setUserDn("cn=Some User");
tested.setPassword("secret");
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("ldap://ldap.example.com:389/dc=some%20example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertNull(env.get(Context.SECURITY_PRINCIPAL));
assertNull(env.get(Context.SECURITY_CREDENTIALS));
// check that base was added to environment
assertEquals(new DistinguishedName("dc=example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertEquals(LdapUtils.newLdapName("dc=some example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
// Verify that changing values does not change the environment values.
tested.setBase("dc=other,dc=se");
@@ -83,12 +83,12 @@ public class LdapContextSourceTest {
tested.setPooled(false);
env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("ldap://ldap.example.com:389/dc=some%20example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertNull(env.get(Context.SECURITY_PRINCIPAL));
assertNull(env.get(Context.SECURITY_CREDENTIALS));
assertEquals(new DistinguishedName("dc=example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertEquals(LdapUtils.newLdapName("dc=some example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
}
@Test
@@ -198,7 +198,7 @@ public class LdapContextSourceTest {
assertEquals("secret", env.get(Context.SECURITY_CREDENTIALS));
// check that base was added to environment
assertEquals(new DistinguishedName("dc=example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertEquals(LdapUtils.newLdapName("dc=example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
}
@Test

View File

@@ -21,11 +21,15 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.NoSuchAttributeException;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import java.util.LinkedList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -33,7 +37,8 @@ import static org.mockito.Mockito.verify;
public class LdapUtilsTest {
private AttributeValueCallbackHandler handlerMock;
private static final String EXPECTED_DN_STRING = "cn=john.doe, OU=Users,OU=SE,OU=G,OU=I,OU=M";
private AttributeValueCallbackHandler handlerMock;
@Before
public void setUp() throws Exception {
@@ -225,4 +230,52 @@ public class LdapUtilsTest {
assertEquals("i=" + i + ",", expectedSid[i], result[i]);
}
}
@Test
public void testNewLdapNameFromLdapName() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.newLdapName(ldapName);
assertEquals(ldapName, result);
}
@Test
public void testNewLdapNameFromCompositeName() throws InvalidNameException {
LdapName result = LdapUtils.newLdapName(new CompositeName(EXPECTED_DN_STRING));
assertEquals(new LdapName(EXPECTED_DN_STRING), result);
}
@Test
public void testEmptyLdapName() {
LdapName ldapName = LdapUtils.emptyLdapName();
assertEquals("", ldapName.toString());
}
@Test
public void testRemoveFirst() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=I,OU=M"));
assertNotSame(ldapName, result);
assertEquals(new LdapName("cn=john.doe, OU=Users,OU=SE,OU=G"), result);
}
@Test
public void testRemoveFirstNoMatch() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=oooooo,OU=M"));
assertNotSame(ldapName, result);
assertEquals(ldapName, result);
}
@Test
public void testRemoveFirstEmptyBase() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.removeFirst(ldapName, LdapUtils.emptyLdapName());
assertNotSame(ldapName, result);
assertEquals(ldapName, result);
}
}

View File

@@ -17,10 +17,11 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -36,7 +37,7 @@ public class BindOperationExecutorTest {
@Test
public void testPerformOperation() {
DistinguishedName expectedDn = new DistinguishedName("cn=john doe");
LdapName expectedDn = LdapUtils.newLdapName("cn=john doe");
Object expectedObject = new Object();
BasicAttributes expectedAttributes = new BasicAttributes();
BindOperationExecutor tested = new BindOperationExecutor(
@@ -51,7 +52,7 @@ public class BindOperationExecutorTest {
@Test
public void testCommit() {
DistinguishedName expectedDn = new DistinguishedName("cn=john doe");
LdapName expectedDn = LdapUtils.newLdapName("cn=john doe");
Object expectedObject = new Object();
BasicAttributes expectedAttributes = new BasicAttributes();
BindOperationExecutor tested = new BindOperationExecutor(
@@ -66,7 +67,7 @@ public class BindOperationExecutorTest {
@Test
public void testRollback() {
DistinguishedName expectedDn = new DistinguishedName("cn=john doe");
LdapName expectedDn = LdapUtils.newLdapName("cn=john doe");
BindOperationExecutor tested = new BindOperationExecutor(
ldapOperationsMock, expectedDn, null, null);

View File

@@ -17,11 +17,12 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
@@ -38,10 +39,10 @@ public class BindOperationRecorderTest {
}
@Test
public void testRecordOperation_DistinguishedName() {
public void testRecordOperation_Name() {
BindOperationRecorder tested = new BindOperationRecorder(
ldapOperationsMock);
DistinguishedName expectedDn = new DistinguishedName("cn=John Doe");
LdapName expectedDn = LdapUtils.newLdapName("cn=John Doe");
Object expectedObject = new Object();
BasicAttributes expectedAttributes = new BasicAttributes();

View File

@@ -17,8 +17,8 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.directory.ModificationItem;
@@ -40,7 +40,7 @@ public class ModifyAttributesOperationExecutorTest {
ModificationItem[] expectedCompensatingItems = new ModificationItem[0];
ModificationItem[] expectedActualItems = new ModificationItem[0];
Name expectedDn = new DistinguishedName("cn=john doe");
Name expectedDn = LdapUtils.newLdapName("cn=john doe");
ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor(ldapOperationsMock,
expectedDn, expectedActualItems, expectedCompensatingItems);
@@ -56,7 +56,7 @@ public class ModifyAttributesOperationExecutorTest {
ModificationItem[] expectedCompensatingItems = new ModificationItem[0];
ModificationItem[] expectedActualItems = new ModificationItem[0];
Name expectedDn = new DistinguishedName("cn=john doe");
Name expectedDn = LdapUtils.newLdapName("cn=john doe");
ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor(ldapOperationsMock,
expectedDn, expectedActualItems, expectedCompensatingItems);
@@ -73,7 +73,7 @@ public class ModifyAttributesOperationExecutorTest {
ModificationItem[] expectedCompensatingItems = new ModificationItem[0];
ModificationItem[] expectedActualItems = new ModificationItem[0];
Name expectedDn = new DistinguishedName("cn=john doe");
Name expectedDn = LdapUtils.newLdapName("cn=john doe");
ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor(ldapOperationsMock,
expectedDn, expectedActualItems, expectedCompensatingItems);

View File

@@ -18,9 +18,9 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.IncrementalAttributesMapper;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
import javax.naming.NamingException;
@@ -30,6 +30,7 @@ import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
@@ -76,7 +77,7 @@ public class ModifyAttributesOperationRecorderTest {
}
};
DistinguishedName expectedName = new DistinguishedName("cn=john doe");
LdapName expectedName = LdapUtils.newLdapName("cn=john doe");
when(attributesMapperMock.hasMore()).thenReturn(true, false);
when(attributesMapperMock.getAttributesForLookup())

View File

@@ -17,10 +17,11 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -36,9 +37,9 @@ public class RebindOperationExecutorTest {
@Test
public void testPerformOperation() {
DistinguishedName expectedOriginalDn = new DistinguishedName(
LdapName expectedOriginalDn = LdapUtils.newLdapName(
"cn=john doe");
DistinguishedName expectedTempDn = new DistinguishedName(
LdapName expectedTempDn = LdapUtils.newLdapName(
"cn=john doe_temp");
Object expectedObject = new Object();
BasicAttributes expectedAttributes = new BasicAttributes();
@@ -55,9 +56,9 @@ public class RebindOperationExecutorTest {
@Test
public void testCommit() {
DistinguishedName expectedOriginalDn = new DistinguishedName(
LdapName expectedOriginalDn = LdapUtils.newLdapName(
"cn=john doe");
DistinguishedName expectedTempDn = new DistinguishedName(
LdapName expectedTempDn = LdapUtils.newLdapName(
"cn=john doe_temp");
Object expectedObject = new Object();
BasicAttributes expectedAttributes = new BasicAttributes();
@@ -72,9 +73,9 @@ public class RebindOperationExecutorTest {
@Test
public void testRollback() {
DistinguishedName expectedOriginalDn = new DistinguishedName(
LdapName expectedOriginalDn = LdapUtils.newLdapName(
"cn=john doe");
DistinguishedName expectedTempDn = new DistinguishedName(
LdapName expectedTempDn = LdapUtils.newLdapName(
"cn=john doe_temp");
Object expectedObject = new Object();
BasicAttributes expectedAttributes = new BasicAttributes();

View File

@@ -17,11 +17,12 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -42,9 +43,9 @@ public class RebindOperationRecorderTest {
@Test
public void testRecordOperation() {
final DistinguishedName expectedDn = new DistinguishedName(
final LdapName expectedDn = LdapUtils.newLdapName(
"cn=john doe");
final DistinguishedName expectedTempDn = new DistinguishedName(
final LdapName expectedTempDn = LdapUtils.newLdapName(
"cn=john doe");
RebindOperationRecorder tested = new RebindOperationRecorder(
ldapOperationsMock, renamingStrategyMock);

View File

@@ -18,8 +18,10 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.ldap.LdapName;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -37,8 +39,8 @@ public class RenameOperationExecutorTest {
@Test
public void testPerformOperation() {
DistinguishedName expectedNewName = new DistinguishedName("ou=newOu");
DistinguishedName expectedOldName = new DistinguishedName("ou=someou");
LdapName expectedNewName = LdapUtils.newLdapName("ou=newOu");
LdapName expectedOldName = LdapUtils.newLdapName("ou=someou");
RenameOperationExecutor tested = new RenameOperationExecutor(
ldapOperationsMock, expectedOldName, expectedNewName);
@@ -50,8 +52,8 @@ public class RenameOperationExecutorTest {
@Test
public void testCommit() {
DistinguishedName expectedNewName = new DistinguishedName("ou=newOu");
DistinguishedName expectedOldName = new DistinguishedName("ou=someou");
LdapName expectedNewName = LdapUtils.newLdapName("ou=newOu");
LdapName expectedOldName = LdapUtils.newLdapName("ou=someou");
RenameOperationExecutor tested = new RenameOperationExecutor(
ldapOperationsMock, expectedOldName, expectedNewName);
@@ -64,8 +66,8 @@ public class RenameOperationExecutorTest {
@Test
public void testRollback() {
DistinguishedName expectedNewName = new DistinguishedName("ou=newOu");
DistinguishedName expectedOldName = new DistinguishedName("ou=someou");
LdapName expectedNewName = LdapUtils.newLdapName("ou=newOu");
LdapName expectedOldName = LdapUtils.newLdapName("ou=someou");
RenameOperationExecutor tested = new RenameOperationExecutor(
ldapOperationsMock, expectedOldName, expectedNewName);

View File

@@ -17,8 +17,10 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.ldap.LdapName;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -33,8 +35,8 @@ public class UnbindOperationExecutorTest {
@Test
public void testPerformOperation() {
DistinguishedName expectedOldName = new DistinguishedName("cn=oldDn");
DistinguishedName expectedTempName = new DistinguishedName("cn=newDn");
LdapName expectedOldName = LdapUtils.newLdapName("cn=oldDn");
LdapName expectedTempName = LdapUtils.newLdapName("cn=newDn");
UnbindOperationExecutor tested = new UnbindOperationExecutor(
ldapOperationsMock, expectedOldName, expectedTempName);
@@ -46,8 +48,8 @@ public class UnbindOperationExecutorTest {
@Test
public void testCommit() {
DistinguishedName expectedOldName = new DistinguishedName("cn=oldDn");
DistinguishedName expectedTempName = new DistinguishedName("cn=newDn");
LdapName expectedOldName = LdapUtils.newLdapName("cn=oldDn");
LdapName expectedTempName = LdapUtils.newLdapName("cn=newDn");
UnbindOperationExecutor tested = new UnbindOperationExecutor(
ldapOperationsMock, expectedOldName, expectedTempName);
@@ -58,8 +60,8 @@ public class UnbindOperationExecutorTest {
@Test
public void testRollback() {
DistinguishedName expectedOldName = new DistinguishedName("cn=oldDn");
DistinguishedName expectedTempName = new DistinguishedName("cn=newDn");
LdapName expectedOldName = LdapUtils.newLdapName("cn=oldDn");
LdapName expectedTempName = LdapUtils.newLdapName("cn=newDn");
UnbindOperationExecutor tested = new UnbindOperationExecutor(
ldapOperationsMock, expectedOldName, expectedTempName);

View File

@@ -17,10 +17,12 @@ package org.springframework.ldap.transaction.compensating;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -40,9 +42,9 @@ public class UnbindOperationRecorderTest {
@Test
public void testRecordOperation() {
final DistinguishedName expectedTempName = new DistinguishedName(
final LdapName expectedTempName = LdapUtils.newLdapName(
"cn=john doe_temp");
final DistinguishedName expectedDn = new DistinguishedName(
final LdapName expectedDn = LdapUtils.newLdapName(
"cn=john doe");
UnbindOperationRecorder tested = new UnbindOperationRecorder(
ldapOperationsMock, renamingStrategyMock);

View File

@@ -16,9 +16,10 @@
package org.springframework.ldap.transaction.compensating.support;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
@@ -27,7 +28,7 @@ public class DefaultTempEntryRenamingStrategyTest {
@Test
public void testGetTemporaryName() {
DistinguishedName expectedOriginalName = new DistinguishedName(
LdapName expectedOriginalName = LdapUtils.newLdapName(
"cn=john doe, ou=somecompany, c=SE");
DefaultTempEntryRenamingStrategy tested = new DefaultTempEntryRenamingStrategy();
@@ -39,12 +40,12 @@ public class DefaultTempEntryRenamingStrategyTest {
@Test
public void testGetTemporaryDN_MultivalueDN() {
DistinguishedName expectedOriginalName = new DistinguishedName(
LdapName expectedOriginalName = LdapUtils.newLdapName(
"cn=john doe+sn=doe, ou=somecompany, c=SE");
DefaultTempEntryRenamingStrategy tested = new DefaultTempEntryRenamingStrategy();
Name result = tested.getTemporaryName(expectedOriginalName);
assertEquals("cn=john doe_temp+sn=doe,ou=somecompany,c=SE", result
assertEquals("cn=john doe+sn=doe_temp,ou=somecompany,c=SE", result
.toString());
}

View File

@@ -16,19 +16,20 @@
package org.springframework.ldap.transaction.compensating.support;
import org.junit.Test;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
public class DifferentSubtreeTempEntryRenamingStrategyTest {
@Test
public void testGetTemporaryName() {
DistinguishedName originalName = new DistinguishedName(
LdapName originalName = LdapUtils.newLdapName(
"cn=john doe, ou=somecompany, c=SE");
DifferentSubtreeTempEntryRenamingStrategy tested = new DifferentSubtreeTempEntryRenamingStrategy(
new DistinguishedName("ou=tempEntries"));
LdapUtils.newLdapName("ou=tempEntries"));
int nextSequenceNo = tested.getNextSequenceNo();