Java Code Examples for org.springframework.ldap.test.LdapTestUtils

The following examples show how to use org.springframework.ldap.test.LdapTestUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: geofence   Source File: BaseDAOTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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"));
}
 
Example 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_________");
}
 
Example 3
Source Project: geofence   Source File: BaseDAOTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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();
    }
 
Example 4
Source Project: spring-ldap   Source File: TestSchemaViewer.java    License: Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 5
Source Project: spring-ldap   Source File: TestSchemaToJava.java    License: Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 6
Source Project: spring-ldap   Source File: TestSchemaToJava.java    License: Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 7
Source Project: spring-ldap   Source File: TestSchemaToJava.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    LdapTestUtils.shutdownEmbeddedServer();

    contextSource=null;
    converterManager=null;
}
 
Example 8
Source Project: spring-ldap   Source File: TestLdap.java    License: Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 9
Source Project: spring-ldap   Source File: TestLdap.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 10
Source Project: spring-ldap   Source File: TestLdap.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    LdapTestUtils.clearSubContexts(contextSource, baseName);

    odmManager=null;
    contextSource=null;
    converterManager=null;
}
 
Example 11
Source Project: spring-ldap   Source File: LdapTemplatePooledITest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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");
   }
 
Example 12
Source Project: spring-ldap   Source File: PagedSearchITest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void prepareTestedData() throws IOException, NamingException {
    LdapTestUtils.cleanAndSetup(
            contextSource,
            LdapUtils.newLdapName("ou=People"),
            new ClassPathResource("/setup_data.ldif"));
}
 
Example 13
Source Project: spring-ldap   Source File: DigestMd5AuthenticationITest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void prepareTestedInstance() throws Exception {
    LdapTestUtils.cleanAndSetup(
            contextSource,
            LdapUtils.newLdapName("ou=People"),
            new ClassPathResource("/setup_data.ldif"));
}
 
Example 14
Source Project: spring-ldap   Source File: LdapTemplateSearchResultITest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void prepareTestedInstance() throws Exception {
       LdapTestUtils.cleanAndSetup(
               contextSource,
               LdapUtils.newLdapName("ou=People"),
               new ClassPathResource("/setup_data.ldif"));

	attributesMapper = new AttributeCheckAttributesMapper();
	contextMapper = new AttributeCheckContextMapper();
}
 
Example 15
Source Project: geofence   Source File: BaseDAOTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception
{
    LdapTestUtils.shutdownEmbeddedServer();
}
 
Example 16
@AfterClass
public static void shutdownLDAP() throws Exception {
    LdapTestUtils.destroyApacheDirectoryServer(PRINCIPAL, CREDENTIALS);
     System.out.println("____________Shutdown LDAP_________");
}
 
Example 17
Source Project: spring-ldap   Source File: TestSchemaViewer.java    License: Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception {
    LdapTestUtils.shutdownEmbeddedServer();
}
 
Example 18
Source Project: spring-ldap   Source File: TestSchemaToJava.java    License: Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception {
    // Stop the in process LDAP server
    LdapTestUtils.shutdownEmbeddedServer();
}
 
Example 19
Source Project: spring-ldap   Source File: TestLdap.java    License: Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception {
    LdapTestUtils.shutdownEmbeddedServer();
}
 
Example 20
Source Project: spring-ldap   Source File: LdapTemplatePooledITest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() throws Exception {
    LdapTestUtils.shutdownEmbeddedServer();
}
 
Example 21
Source Project: spring-ldap   Source File: PagedSearchITest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() throws NamingException {
    LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("ou=People"));
}
 
Example 22
Source Project: spring-ldap   Source File: DigestMd5AuthenticationITest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() throws Exception {
    LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("ou=People"));
}
 
Example 23
Source Project: spring-ldap   Source File: LdapTemplateSearchResultITest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() throws Exception {
       LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("ou=People"));
	attributesMapper = null;
	contextMapper = null;
}