Java Code Examples for org.springframework.ldap.test.LdapTestUtils#cleanAndSetup()

The following examples show how to use org.springframework.ldap.test.LdapTestUtils#cleanAndSetup() . 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 File: LDAPIdentityServiceImplTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@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 2
Source File: TestSchemaToJava.java    From spring-ldap with 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 3
Source File: TestLdap.java    From spring-ldap with 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 4
Source File: LdapTemplatePooledITest.java    From spring-ldap with 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 5
Source File: PagedSearchITest.java    From spring-ldap with 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 6
Source File: DigestMd5AuthenticationITest.java    From spring-ldap with 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 7
Source File: LdapTemplateSearchResultITest.java    From spring-ldap with 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();
}