Java源码示例:org.springframework.ldap.test.LdapTestUtils
示例1
protected static void loadData() throws Exception
{
// Bind to the directory
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://127.0.0.1:10389");
contextSource.setUserDn("uid=admin,ou=system");
contextSource.setPassword("secret");
contextSource.setPooled(false);
//contextSource.setDirObjectFactory(null);
contextSource.afterPropertiesSet();
// Create the Sprint LDAP template
LdapTemplate template = new LdapTemplate(contextSource);
// Clear out any old data - and load the test data
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("dc=example,dc=com"));
LdapTestUtils.loadLdif(contextSource, new ClassPathResource("data.ldif"));
}
示例2
@BeforeClass
public static void startLDAPServer() throws Exception {
LdapTestUtils.startApacheDirectoryServer(PORT, baseName.toString(), "test", PRINCIPAL, CREDENTIALS, null);
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://127.0.0.1:" + PORT);
contextSource.setUserDn("");
contextSource.setPassword("");
contextSource.setPooled(false);
contextSource.afterPropertiesSet();
// Create the Sprint LDAP template
LdapTemplate template = new LdapTemplate(contextSource);
// Clear out any old data - and load the test data
LdapTestUtils.cleanAndSetup(template.getContextSource(), baseName, new ClassPathResource("ldap/testdata.ldif"));
System.out.println("____________Started LDAP_________");
}
示例3
@BeforeClass
public static void setUpClass() throws Exception
{
// Start an LDAP server and import test data
// LdapTestUtils.startEmbeddedServer(10389, "", "test");
// LdapTestUtils.startEmbeddedServer(10389, "dc=example,dc=com", "test");
LdapTestUtils.startEmbeddedServer(10389, "dc=com", "test");
loadData();
}
示例4
@BeforeClass
public static void setUpClass() throws Exception {
// Added because the close down of Apache DS on Linux does
// not seem to free up its port.
port=GetFreePort.getFreePort();
commonFlags=new String[] {
"--url", "ldap://127.0.0.1:"+port,
"--username", "",
"--password", "",
"--error"};
// Start an in process LDAP server
LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test");
}
示例5
@BeforeClass
public static void setUpClass() throws Exception {
// Added because the close down of Apache DS on Linux does
// not seem to free up its port.
port=GetFreePort.getFreePort();
// Start an in process LDAP server
LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test");
}
示例6
@Before
public void setUp() throws Exception {
// Create some basic converters and a converter manager
converterManager = new ConverterManagerImpl();
Converter ptc = new FromStringConverter();
converterManager.addConverter(String.class, "", Byte.class, ptc);
converterManager.addConverter(String.class, "", Short.class, ptc);
converterManager.addConverter(String.class, "", Integer.class, ptc);
converterManager.addConverter(String.class, "", Long.class, ptc);
converterManager.addConverter(String.class, "", Double.class, ptc);
converterManager.addConverter(String.class, "", Float.class, ptc);
converterManager.addConverter(String.class, "", Boolean.class, ptc);
Converter tsc = new ToStringConverter();
converterManager.addConverter(Byte.class, "", String.class, tsc);
converterManager.addConverter(Short.class, "", String.class, tsc);
converterManager.addConverter(Integer.class, "", String.class, tsc);
converterManager.addConverter(Long.class, "", String.class, tsc);
converterManager.addConverter(Double.class, "", String.class, tsc);
converterManager.addConverter(Float.class, "", String.class, tsc);
converterManager.addConverter(Boolean.class, "", String.class, tsc);
// Bind to the directory
contextSource = new LdapContextSource();
contextSource.setUrl("ldap://127.0.0.1:" + port);
contextSource.setUserDn("");
contextSource.setPassword("");
contextSource.setPooled(false);
contextSource.afterPropertiesSet();
// Clear out any old data - and load the test data
LdapTestUtils.cleanAndSetup(contextSource, baseName, new ClassPathResource("testdata.ldif"));
}
示例7
@After
public void tearDown() throws Exception {
LdapTestUtils.shutdownEmbeddedServer();
contextSource=null;
converterManager=null;
}
示例8
@BeforeClass
public static void setUpClass() throws Exception {
// Added because the close down of Apache DS on Linux does
// not seem to free up its port.
port=GetFreePort.getFreePort();
// Start an LDAP server and import test data
LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test");
}
示例9
public void setUp(String url, String username, String password) throws Exception {
// Create some basic converters and a converter manager
converterManager = new ConverterManagerImpl();
Converter ptc = new FromStringConverter();
converterManager.addConverter(String.class, "", Byte.class, ptc);
converterManager.addConverter(String.class, "", Short.class, ptc);
converterManager.addConverter(String.class, "", Integer.class, ptc);
converterManager.addConverter(String.class, "", Long.class, ptc);
converterManager.addConverter(String.class, "", Double.class, ptc);
converterManager.addConverter(String.class, "", Float.class, ptc);
converterManager.addConverter(String.class, "", Boolean.class, ptc);
Converter tsc = new ToStringConverter();
converterManager.addConverter(Byte.class, "", String.class, tsc);
converterManager.addConverter(Short.class, "", String.class, tsc);
converterManager.addConverter(Integer.class, "", String.class, tsc);
converterManager.addConverter(Long.class, "", String.class, tsc);
converterManager.addConverter(Double.class, "", String.class, tsc);
converterManager.addConverter(Float.class, "", String.class, tsc);
converterManager.addConverter(Boolean.class, "", String.class, tsc);
// Bind to the directory
contextSource = getContextSource(url, username, password);
// Clear out any old data - and load the test data
LdapTestUtils.cleanAndSetup(contextSource, baseName, new ClassPathResource("testdata.ldif"));
// Create our OdmManager
Set<Class<?>> managedClasses=new HashSet<Class<?>>();
managedClasses.add(Person.class);
managedClasses.add(PlainPerson.class);
managedClasses.add(OrganizationalUnit.class);
odmManager = new OdmManagerImpl(converterManager, contextSource, managedClasses);
}
示例10
@After
public void tearDown() throws Exception {
LdapTestUtils.clearSubContexts(contextSource, baseName);
odmManager=null;
contextSource=null;
converterManager=null;
}
示例11
/**
* This method depends on a DirObjectFactory (
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
@Test
public void verifyThatInvalidConnectionIsAutomaticallyPurged() throws Exception {
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,ou=Sweden");
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
// Shutdown server and kill all existing connections
LdapTestUtils.shutdownEmbeddedServer();
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
try {
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
fail("Exception expected");
} catch (Exception expected) {
// This should fail because the target connection was closed
assertThat(true).isTrue();
}
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
// But this should be OK, because the dirty connection should have been automatically purged.
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
}
示例12
@Before
public void prepareTestedData() throws IOException, NamingException {
LdapTestUtils.cleanAndSetup(
contextSource,
LdapUtils.newLdapName("ou=People"),
new ClassPathResource("/setup_data.ldif"));
}
示例13
@Before
public void prepareTestedInstance() throws Exception {
LdapTestUtils.cleanAndSetup(
contextSource,
LdapUtils.newLdapName("ou=People"),
new ClassPathResource("/setup_data.ldif"));
}
示例14
@Before
public void prepareTestedInstance() throws Exception {
LdapTestUtils.cleanAndSetup(
contextSource,
LdapUtils.newLdapName("ou=People"),
new ClassPathResource("/setup_data.ldif"));
attributesMapper = new AttributeCheckAttributesMapper();
contextMapper = new AttributeCheckContextMapper();
}
示例15
@AfterClass
public static void tearDownClass() throws Exception
{
LdapTestUtils.shutdownEmbeddedServer();
}
示例16
@AfterClass
public static void shutdownLDAP() throws Exception {
LdapTestUtils.destroyApacheDirectoryServer(PRINCIPAL, CREDENTIALS);
System.out.println("____________Shutdown LDAP_________");
}
示例17
@AfterClass
public static void tearDownClass() throws Exception {
LdapTestUtils.shutdownEmbeddedServer();
}
示例18
@AfterClass
public static void tearDownClass() throws Exception {
// Stop the in process LDAP server
LdapTestUtils.shutdownEmbeddedServer();
}
示例19
@AfterClass
public static void tearDownClass() throws Exception {
LdapTestUtils.shutdownEmbeddedServer();
}
示例20
@After
public void cleanup() throws Exception {
LdapTestUtils.shutdownEmbeddedServer();
}
示例21
@After
public void cleanup() throws NamingException {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("ou=People"));
}
示例22
@After
public void cleanup() throws Exception {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("ou=People"));
}
示例23
@After
public void cleanup() throws Exception {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("ou=People"));
attributesMapper = null;
contextMapper = null;
}