You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Jonathan Carlson <jo...@code42.com> on 2011/09/16 20:49:18 UTC

ApplyLdifs

I'm hoping there is an easy answer to this...

When I specify @ApplyLdifs on the test class it *always* tells me that the dn exists already, even if it is the first time I've run it.

@ApplyLdifs({
"dn: cn=jon4,ou=system\n" +
"objectClass: person\n" +
"cn: jon4\n" +
"sn: Carlson\n"
})
@RunWith(FrameworkRunner.class)
@CreateLdapServer(
allowAnonymousAccess = true,
transports = { @CreateTransport(protocol = "LDAP") })

org.apache.directory.shared.ldap.exception.LdapEntryAlreadyExistsException: ERR_250 cn=jon4,ou=system already exists!

Yet, when I move the @ApplyLdifs to a method, the method doesn't get run by jUnit.

I'm using the Apache DS version 1.5.7 libraries...

Thanks!

jon carlson   |  codefortytwo software
1 Main St SE, #400     |   Minneapolis, MN 55414
Office: 612.333.4242  |   web: www.code42.com<http://www.code42.com/>


Re: ApplyLdifs

Posted by Stefan Seelmann <se...@apache.org>.
See inline

On Sat, Sep 17, 2011 at 12:57 AM, Jonathan Carlson <jo...@code42.com> wrote:
> Thanks so much Stefan for taking the time to make that example.  I just didn't notice the formatting change in the example code I was looking at.
>
> Is there an example of creating a small hierarchy?  I've tried something like this but got an error saying there was no partition for dc=example,dc=com

You need to create a partition for "dc=example,dc=com" first. You can
do that in the @CreateDS annotation. Here is an example:
http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java

> @ApplyLdifs({
> "dn: dc=example,dc=com",
> "objectClass: dcObject",
> "dn: ou=users,dc=example,dc=com",
> "objectClass: organizationalUnit",
> "ou: users\n",
> "dn: cn=jon,ou=users,dc=example,dc=com",
> "objectClass: person",
> "cn: jon",
> "sn: Carlson"
> })
>
> Also, is there an example of doing a lookup on a directory created this way using an InitialContext?  The LDAP client framework that I am testing uses this method of lookup so it needs to support it.
>
> // Create a environment container
> Hashtable<Object, Object> env = new Hashtable<Object, Object>();
> env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
> env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
> env.put(Context.SECURITY_CREDENTIALS, "secret");
> env.put(Context.SECURITY_AUTHENTICATION, "simple");
> env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
> InitialContext initialContext = new InitialContext(env);
> DirContext appRoot = (DirContext) initialContext.lookup("");
> SearchControls controls = new SearchControls();
> controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
> controls.setTimeLimit(30000);
> NamingEnumeration<SearchResult> results = appRoot.search("", "(cn=jon)", controls);

Yes, that is possible. But be aware that the port you use is variable.
I found an example that shows how to obtain the port here:
http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/server-integ/src/test/java/org/apache/directory/server/ssl/LdapsIT.java

You can find more examples within the tests:
http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/test-framework
http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/server-integ

Kind Regards,
Stefan

Re: ApplyLdifs

Posted by Jonathan Carlson <jo...@code42.com>.
Thanks so much Stefan for taking the time to make that example.  I just didn't notice the formatting change in the example code I was looking at.

Is there an example of creating a small hierarchy?  I've tried something like this but got an error saying there was no partition for dc=example,dc=com

@ApplyLdifs({
"dn: dc=example,dc=com",
"objectClass: dcObject",
"dn: ou=users,dc=example,dc=com",
"objectClass: organizationalUnit",
"ou: users\n",
"dn: cn=jon,ou=users,dc=example,dc=com",
"objectClass: person",
"cn: jon",
"sn: Carlson"
})

Also, is there an example of doing a lookup on a directory created this way using an InitialContext?  The LDAP client framework that I am testing uses this method of lookup so it needs to support it.

// Create a environment container
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
InitialContext initialContext = new InitialContext(env);
DirContext appRoot = (DirContext) initialContext.lookup("");
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setTimeLimit(30000);
NamingEnumeration<SearchResult> results = appRoot.search("", "(cn=jon)", controls);



Thanks so much for your help.  Have a great weekend.

- Jon


On Sep 16, 2011, at 5:07 PM, Stefan Seelmann wrote:

Please try to concat the LDIF with commas like this:

@ApplyLdifs(
   {
       "dn: cn=jon4,ou=system",
       "objectClass: person",
       "cn: jon4",
       "sn: Carlson"
})

Here is a full working example: https://gist.github.com/2dbfa4eb8d0120a3e297

Kind Regards,
Stefan


On Fri, Sep 16, 2011 at 8:49 PM, Jonathan Carlson <jo...@code42.com>> wrote:
I'm hoping there is an easy answer to this...

When I specify @ApplyLdifs on the test class it *always* tells me that the dn exists already, even if it is the first time I've run it.

@ApplyLdifs({
"dn: cn=jon4,ou=system\n" +
"objectClass: person\n" +
"cn: jon4\n" +
"sn: Carlson\n"
})
@RunWith(FrameworkRunner.class)
@CreateLdapServer(
allowAnonymousAccess = true,
transports = { @CreateTransport(protocol = "LDAP") })

org.apache.directory.shared.ldap.exception.LdapEntryAlreadyExistsException: ERR_250 cn=jon4,ou=system already exists!

Yet, when I move the @ApplyLdifs to a method, the method doesn't get run by jUnit.

I'm using the Apache DS version 1.5.7 libraries...

Thanks!

jon carlson   |  codefortytwo software
1 Main St SE, #400     |   Minneapolis, MN 55414
Office: 612.333.4242  |   web: www.code42.com<http://www.code42.com/>





Re: ApplyLdifs

Posted by Stefan Seelmann <se...@apache.org>.
Please try to concat the LDIF with commas like this:

@ApplyLdifs(
    {
        "dn: cn=jon4,ou=system",
        "objectClass: person",
        "cn: jon4",
        "sn: Carlson"
})

Here is a full working example: https://gist.github.com/2dbfa4eb8d0120a3e297

Kind Regards,
Stefan


On Fri, Sep 16, 2011 at 8:49 PM, Jonathan Carlson <jo...@code42.com> wrote:
> I'm hoping there is an easy answer to this...
>
> When I specify @ApplyLdifs on the test class it *always* tells me that the dn exists already, even if it is the first time I've run it.
>
> @ApplyLdifs({
> "dn: cn=jon4,ou=system\n" +
> "objectClass: person\n" +
> "cn: jon4\n" +
> "sn: Carlson\n"
> })
> @RunWith(FrameworkRunner.class)
> @CreateLdapServer(
> allowAnonymousAccess = true,
> transports = { @CreateTransport(protocol = "LDAP") })
>
> org.apache.directory.shared.ldap.exception.LdapEntryAlreadyExistsException: ERR_250 cn=jon4,ou=system already exists!
>
> Yet, when I move the @ApplyLdifs to a method, the method doesn't get run by jUnit.
>
> I'm using the Apache DS version 1.5.7 libraries...
>
> Thanks!
>
> jon carlson   |  codefortytwo software
> 1 Main St SE, #400     |   Minneapolis, MN 55414
> Office: 612.333.4242  |   web: www.code42.com<http://www.code42.com/>
>
>