You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Mark Derricutt <ma...@talios.com> on 2008/09/15 01:36:46 UTC

Loading custom schemas with AbstractServerTest under 1.5.4

'lo

With the recent changes to AbstractServerTest in 1.5.4, how does one
register custom schemas now?

Under 1.5.3 I was using:

        Set<AbstractBootstrapSchema> schemas =
configuration.getBootstrapSchemas();
        schemas.add(new Smx3Schema());
        configuration.setBootstrapSchemas(schemas);

where configuration came from the AbstractServerTest.  It looks like the
test harness has changed a bit.  I"m actually using TestNG to execute my
tests, rather than JUnit so hopefully theres still a way to handle this
easily.

Mark
He who started looking at ldap integration testing at the wrong time..

-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Kiran Ayyagari <ay...@gmail.com>.
hi Mark,

     After my own attempt to add a new schema it was observed that the 
registries are getting reset in the
     DefaultDirectoryService.initialize() (lines 1377-1380) as part of 
the DefaultDirectoryService.startup() call in
     AbstractServerTest.setUp().

     The schemas are getting loaded through a prebuilt partition 
'apacheds-schema-bootstrap' so the way I fixed
     this was by adding an entry in the pom.xml and built a local 
version of apacheds-schema-bootstrap partition.

     in my case it is like 
<bootstrapSchemaClass>org.apache.directory.server.schema.bootstrap.CustomSchema</bootstrapSchemaClass>

     Note that IMO this may not be certainly the best approach to solve 
the problem but hope this eliminates the
     need to import the schema manually.

HTH
Kiran Ayyagari

Mark Derricutt wrote:
> To be a bit more accurate - the exception I see when loading my LDIF 
> files is:
>
> entry.DefaultServerEntry - The attribute 'smxpartyid' cannot be stored
> javax.naming.NamingException: objectClass w/ OID 
> 1.3.6.1.4.1.28416.1.1.1.101 not registered!
>     at 
> org.apache.directory.server.schema.registries.DefaultObjectClassRegistry.lookup(DefaultObjectClassRegistry.java:114)
>     at 
> org.apache.directory.server.core.schema.SchemaInterceptor.alterObjectClasses(SchemaInterceptor.java:1069)
>     at 
> org.apache.directory.server.core.schema.SchemaInterceptor.check(SchemaInterceptor.java:1675)
>     at 
> org.apache.directory.server.core.schema.SchemaInterceptor.add(SchemaInterceptor.java:1819)
>     at 
> org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1189)
>     at 
> org.apache.directory.server.core.operational.OperationalAttributeInterceptor.add(OperationalAttributeInterceptor.java:191)
>
> I assume from this that the server is aware of my schema, as it 
> managed to deduce the OID to use.
>
> mark
>
> On Tue, Sep 23, 2008 at 12:29 PM, Mark Derricutt <mark@talios.com 
> <ma...@talios.com>> wrote:
>
>     As a further experiment, I copied the entire
>     DefaultDirectoryService class to my own code, and added my schema
>     to the
>     BootstrapSchemaLoader along with the other schema classes, then
>     reassigned the directoryService variable as:
>
>
>         public void configureDirectoryService() throws Exception {
>             directoryService = new SmxDirectoryService();
>             directoryService.setShutdownHookEnabled( false );
>             directoryService.setAllowAnonymousAccess( false );
>             ldapService.setDirectoryService( directoryService );
>
>     But this also didn't appear to work, hopefully someone who knows
>     the proper way of doing this can help out here?
>
>
>
>     On Mon, Sep 22, 2008 at 5:11 PM, Mark Derricutt <mark@talios.com
>     <ma...@talios.com>> wrote:
>
>
>         http://directory.apache.org/apacheds/1.5/using-apacheds-for-unit-tests.html
>
>         which currently says its out of date.  In the mean time I'll
>         continue hunting for a solution.
>
>         Mark
>
>
>         On Mon, Sep 15, 2008 at 12:19 PM, Alex Karasulu
>         <akarasulu@apache.org <ma...@apache.org>> wrote:
>
>             Just look at the code in the JUnit base classes that
>             enable a schema.  Push that code into your TestNG
>             harness.  It's rather simple.
>
>
>
>
>
>     -- 
>     "It is easier to optimize correct code than to correct optimized
>     code." -- Bill Harlan
>
>
>
>
> -- 
> "It is easier to optimize correct code than to correct optimized 
> code." -- Bill Harlan

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Mark Derricutt <ma...@talios.com>.
To be a bit more accurate - the exception I see when loading my LDIF files
is:

entry.DefaultServerEntry - The attribute 'smxpartyid' cannot be stored
javax.naming.NamingException: objectClass w/ OID 1.3.6.1.4.1.28416.1.1.1.101
not registered!
    at
org.apache.directory.server.schema.registries.DefaultObjectClassRegistry.lookup(DefaultObjectClassRegistry.java:114)
    at
org.apache.directory.server.core.schema.SchemaInterceptor.alterObjectClasses(SchemaInterceptor.java:1069)
    at
org.apache.directory.server.core.schema.SchemaInterceptor.check(SchemaInterceptor.java:1675)
    at
org.apache.directory.server.core.schema.SchemaInterceptor.add(SchemaInterceptor.java:1819)
    at
org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1189)
    at
org.apache.directory.server.core.operational.OperationalAttributeInterceptor.add(OperationalAttributeInterceptor.java:191)

I assume from this that the server is aware of my schema, as it managed to
deduce the OID to use.

mark

On Tue, Sep 23, 2008 at 12:29 PM, Mark Derricutt <ma...@talios.com> wrote:

> As a further experiment, I copied the entire DefaultDirectoryService class
> to my own code, and added my schema to the
> BootstrapSchemaLoader along with the other schema classes, then reassigned
> the directoryService variable as:
>
>     public void configureDirectoryService() throws Exception {
>         directoryService = new SmxDirectoryService();
>         directoryService.setShutdownHookEnabled( false );
>         directoryService.setAllowAnonymousAccess( false );
>         ldapService.setDirectoryService( directoryService );
>
> But this also didn't appear to work, hopefully someone who knows the proper
> way of doing this can help out here?
>
>
> On Mon, Sep 22, 2008 at 5:11 PM, Mark Derricutt <ma...@talios.com> wrote:
>
>>
>>
>> http://directory.apache.org/apacheds/1.5/using-apacheds-for-unit-tests.html
>>
>> which currently says its out of date.  In the mean time I'll continue
>> hunting for a solution.
>>
>> Mark
>>
>> On Mon, Sep 15, 2008 at 12:19 PM, Alex Karasulu <ak...@apache.org>wrote:
>>
>>> Just look at the code in the JUnit base classes that enable a schema.
>>> Push that code into your TestNG harness.  It's rather simple.
>>>
>>>
>>
>
>
> --
> "It is easier to optimize correct code than to correct optimized code." --
> Bill Harlan
>



-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Mark Derricutt <ma...@talios.com>.
As a further experiment, I copied the entire DefaultDirectoryService class
to my own code, and added my schema to the
BootstrapSchemaLoader along with the other schema classes, then reassigned
the directoryService variable as:

    public void configureDirectoryService() throws Exception {
        directoryService = new SmxDirectoryService();
        directoryService.setShutdownHookEnabled( false );
        directoryService.setAllowAnonymousAccess( false );
        ldapService.setDirectoryService( directoryService );

But this also didn't appear to work, hopefully someone who knows the proper
way of doing this can help out here?


On Mon, Sep 22, 2008 at 5:11 PM, Mark Derricutt <ma...@talios.com> wrote:

>
> http://directory.apache.org/apacheds/1.5/using-apacheds-for-unit-tests.html
>
> which currently says its out of date.  In the mean time I'll continue
> hunting for a solution.
>
> Mark
>
> On Mon, Sep 15, 2008 at 12:19 PM, Alex Karasulu <ak...@apache.org>wrote:
>
>> Just look at the code in the JUnit base classes that enable a schema.
>> Push that code into your TestNG harness.  It's rather simple.
>>
>>
>


-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Mark Derricutt <ma...@talios.com>.
Simple for those who know where to look - but I can't seem to find any tests
which enable a custom schema anywhere in the apacheds tree.  I can find a
few tests that construct a new BootstrapSchemaLoader and add Schema
instances to it for testing,  but I don't see a way to inject that into a
running service except through addToLoadedSet().

After a bit of hunting I started looking at:

    public void configureDirectoryService() throws Exception {
        directoryService.getRegistries().addToLoadedSet(new Smx3Schema());

with no luck, neither did:

    public void configureLdapServer() {

directoryService.getSchemaService().getRegistries().addToLoadedSet(new
Smx3Schema());

neither triggered any exceptions of errors, but neither do I see the schema
being reported when querying ldap or inserting objects using the schema.

If someone who knows what/how to do this - could they update the wiki page
at:

http://directory.apache.org/apacheds/1.5/using-apacheds-for-unit-tests.html

which currently says its out of date.  In the mean time I'll continue
hunting for a solution.

Mark

On Mon, Sep 15, 2008 at 12:19 PM, Alex Karasulu <ak...@apache.org>wrote:

> Just look at the code in the JUnit base classes that enable a schema.  Push
> that code into your TestNG harness.  It's rather simple.
>
>

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Alex Karasulu <ak...@apache.org>.
Just look at the code in the JUnit base classes that enable a schema.  Push
that code into your TestNG harness.  It's rather simple.

Alex

On Sun, Sep 14, 2008 at 8:15 PM, Mark Derricutt <ma...@talios.com> wrote:

> Replying to my own post - whilst I thought I was running this against 1.5.3
> it seems I wasn't, at least for the tests which appeared to be using 1.0.2
> or something.
>
> I see that schema objects are configured in the constructor of
> DefaultDirectoryService which isn't accessable, and I also see that ApacheDS
> has moved to JUnit 4.4 for its current integration tests - which puts me in
> a pickle.
>
> All I'm actually after is a way to embed/launch ApacheDS with a custom
> schema, for our app to talk to during its integration testing phase.  As
> we're using TestNG I'd like to do something thats not JUnit if possible,
> maybe some form of maven plugin which starts a server using a custom schema?
>
> Any one have any ideas or suggestions?
>
>
> On Mon, Sep 15, 2008 at 11:36 AM, Mark Derricutt <ma...@talios.com> wrote:
>
>> 'lo
>>
>> With the recent changes to AbstractServerTest in 1.5.4, how does one
>> register custom schemas now?
>>
>> Under 1.5.3 I was using:
>>
>>         Set<AbstractBootstrapSchema> schemas =
>> configuration.getBootstrapSchemas();
>>         schemas.add(new Smx3Schema());
>>         configuration.setBootstrapSchemas(schemas);
>>
>> where configuration came from the AbstractServerTest.  It looks like the
>> test harness has changed a bit.  I"m actually using TestNG to execute my
>> tests, rather than JUnit so hopefully theres still a way to handle this
>> easily.
>>
>> Mark
>> He who started looking at ldap integration testing at the wrong time..
>>
>> --
>> "It is easier to optimize correct code than to correct optimized code." --
>> Bill Harlan
>>
>
>
>
> --
> "It is easier to optimize correct code than to correct optimized code." --
> Bill Harlan
>

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Mark Derricutt <ma...@talios.com>.
Replying to my own post - whilst I thought I was running this against 1.5.3
it seems I wasn't, at least for the tests which appeared to be using 1.0.2
or something.

I see that schema objects are configured in the constructor of
DefaultDirectoryService which isn't accessable, and I also see that ApacheDS
has moved to JUnit 4.4 for its current integration tests - which puts me in
a pickle.

All I'm actually after is a way to embed/launch ApacheDS with a custom
schema, for our app to talk to during its integration testing phase.  As
we're using TestNG I'd like to do something thats not JUnit if possible,
maybe some form of maven plugin which starts a server using a custom schema?

Any one have any ideas or suggestions?


On Mon, Sep 15, 2008 at 11:36 AM, Mark Derricutt <ma...@talios.com> wrote:

> 'lo
>
> With the recent changes to AbstractServerTest in 1.5.4, how does one
> register custom schemas now?
>
> Under 1.5.3 I was using:
>
>         Set<AbstractBootstrapSchema> schemas =
> configuration.getBootstrapSchemas();
>         schemas.add(new Smx3Schema());
>         configuration.setBootstrapSchemas(schemas);
>
> where configuration came from the AbstractServerTest.  It looks like the
> test harness has changed a bit.  I"m actually using TestNG to execute my
> tests, rather than JUnit so hopefully theres still a way to handle this
> easily.
>
> Mark
> He who started looking at ldap integration testing at the wrong time..
>
> --
> "It is easier to optimize correct code than to correct optimized code." --
> Bill Harlan
>



-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Denis Robert <dr...@bfm.bm>.
Here's my take on this. I subclassed DefaultDirectoryService, then overrode
startup(). In startup, I first call super.startup() to ensure that the
directory is properly initialized, then I populate the schema directly,
using the underlying API.

Doing this is a little involved, but it works quite well. The first step is
to create a dummy ServerEntry containing the proper attributes for the
schema object you want to create, e.g.:

ServerEntry entry = new DefaultServerEntry(service.getRegistries());
		entry.add(typeRegistry.lookup("m-oid"), oid);
		entry.add(typeRegistry.lookup("m-name"), name);
		entry.add(typeRegistry.lookup("m-description"), desc);
		entry.add(typeRegistry.lookup("m-equality"), equality);
		entry.add(typeRegistry.lookup("m-syntax"), syntax);
		entry.add(typeRegistry.lookup("m-singleValue"),
String.valueOf(singleValue));

(the attributes in the entry can be looked up in the existing schema entries
in the ou=schema partition).

Then you use the SchemaEntityFactory to create a schema object from the
directory entry (this is how ApacheDS populates the schema internally from
schema entried in the ou=schema partition). For an attribute type:

factory.getAttributeType(entry, service.getRegistries(),
				schemaName);

for an objectclass:

factory.getObjectClass(entry, service.getRegistries(),
				schemaName);

Once you have the schemaEntity object, you need to register it with the
correct registry:

e.g., for an attributetype:

service.getRegistries().getAttributeTypeRegistry().register(myattributetype);

for an objectclasss:

service.getRegistries().getObjectClassRegistry().register(myobjectclass);

et voilà, your schema is registered. Hope it helps.

(Of course, you could put the entities in an Ldif file, and use the
LdifReader() to build the ServerEntries instead of creating them in code as
above).




Emmanuel Lecharny-3 wrote:
> 
> Mark Derricutt wrote:
>> For our own tests we opted for #2, however, it'd be great if someone
>> extracted the "export to LDIF" code from Studio so that it could be
>> called
>> to convert a schema to LdifReader.  That'd be a good compromise I think.
>>   
> If you mean, convert from schema format to LDIF format, the code already 
> exists in the independent subproject shared-converted (in shared). There 
> are plenty of tests which can be used to create a working tool.
> 
> A good idea would be to create a command line toold to provide such a 
> conversion, something which should be drafted in a couple of hours, IMO. 
> (and if someone provide it, we will be very pleased to integrate it in 
> the project !)
> 
> -- 
> --
> cordialement, regards,
> Emmanuel Lécharny
> www.iktek.com
> directory.apache.org
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Loading-custom-schemas-with-AbstractServerTest-under-1.5.4-tp19485510p22566076.html
Sent from the Apache Directory Project mailing list archive at Nabble.com.


Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Emmanuel Lecharny <el...@gmail.com>.
Mark Derricutt wrote:
> For our own tests we opted for #2, however, it'd be great if someone
> extracted the "export to LDIF" code from Studio so that it could be called
> to convert a schema to LdifReader.  That'd be a good compromise I think.
>   
If you mean, convert from schema format to LDIF format, the code already 
exists in the independent subproject shared-converted (in shared). There 
are plenty of tests which can be used to create a working tool.

A good idea would be to create a command line toold to provide such a 
conversion, something which should be drafted in a couple of hours, IMO. 
(and if someone provide it, we will be very pleased to integrate it in 
the project !)

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org



Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Mark Derricutt <ma...@talios.com>.
For our own tests we opted for #2, however, it'd be great if someone
extracted the "export to LDIF" code from Studio so that it could be called
to convert a schema to LdifReader.  That'd be a good compromise I think.

On Tue, Nov 18, 2008 at 1:46 AM, Kiran Ayyagari <ay...@gmail.com>wrote:

> hi Juergen,
>
>   AFAIK its not possible to add a custom schema on the fly to the server
> using
>   directory service. To add a custom schema
>
>   1) One need to build schema-bootstrap (with the custom schema file) and
> then
>      bootstrap-partition (to include the custom schema in the server
> statically)
>
>   2) Export schema as LDIF and add those entries to the running instance of
> directory server
>
>   However there is a workaround to include the schema dynamically through
>   AbstractServerTest using the technique 2 as mentioned below
>
>    @Override
>    protected void configureDirectoryService() throws Exception
>    {
>       // usual configuration directory service you do
>
>        // instantiate the reader
>        LdifReader reader = new LdifReader();
>
>        // parse the schema file present in LDIF format
>        List<LdifEntry> entries = reader.parseLdifFile(
> "src/test/resources/custom-schema.ldif" );
>
>        // let the directory service inject them during startup
>        directoryService.setTestEntries( entries );
>    }
>
>    You may wish to cache the parsed LDIF entries for performance reasons
>
> HTH
>
> Kiran Ayyagari
>
>
> Juergen Weber wrote:
>
>> Hi,
>>
>> any updates to this? Anybody got a working sample using DS 1.5.4,
>> AbstractServerTest and custom schemas?
>>
>> Thx,
>> Juergen
>>
>>
>> Mark Derricutt wrote:
>>
>>> 'lo
>>>
>>> With the recent changes to AbstractServerTest in 1.5.4, how does one
>>> register custom schemas now?
>>>
>>> Under 1.5.3 I was using:
>>>
>>>        Set<AbstractBootstrapSchema> schemas =
>>> configuration.getBootstrapSchemas();
>>>        schemas.add(new Smx3Schema());
>>>        configuration.setBootstrapSchemas(schemas);
>>>
>>> where configuration came from the AbstractServerTest.  It looks like the
>>> test harness has changed a bit.  I"m actually using TestNG to execute my
>>> tests, rather than JUnit so hopefully theres still a way to handle this
>>> easily.
>>>
>>> Mark
>>> He who started looking at ldap integration testing at the wrong time..
>>>
>>> --
>>> "It is easier to optimize correct code than to correct optimized code."
>>> --
>>> Bill Harlan
>>>
>>>
>>>
>>


-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Kiran Ayyagari <ay...@gmail.com>.
hi Juergen,

    AFAIK its not possible to add a custom schema on the fly to the server using
    directory service. To add a custom schema

    1) One need to build schema-bootstrap (with the custom schema file) and then
       bootstrap-partition (to include the custom schema in the server statically)

    2) Export schema as LDIF and add those entries to the running instance of directory server

    However there is a workaround to include the schema dynamically through
    AbstractServerTest using the technique 2 as mentioned below

     @Override
     protected void configureDirectoryService() throws Exception
     {
        // usual configuration directory service you do

         // instantiate the reader
         LdifReader reader = new LdifReader();

         // parse the schema file present in LDIF format
         List<LdifEntry> entries = reader.parseLdifFile( "src/test/resources/custom-schema.ldif" );

         // let the directory service inject them during startup
         directoryService.setTestEntries( entries );
     }

     You may wish to cache the parsed LDIF entries for performance reasons

HTH

Kiran Ayyagari

Juergen Weber wrote:
> Hi,
> 
> any updates to this? Anybody got a working sample using DS 1.5.4,
> AbstractServerTest and custom schemas?
> 
> Thx,
> Juergen
> 
> 
> Mark Derricutt wrote:
>> 'lo
>>
>> With the recent changes to AbstractServerTest in 1.5.4, how does one
>> register custom schemas now?
>>
>> Under 1.5.3 I was using:
>>
>>         Set<AbstractBootstrapSchema> schemas =
>> configuration.getBootstrapSchemas();
>>         schemas.add(new Smx3Schema());
>>         configuration.setBootstrapSchemas(schemas);
>>
>> where configuration came from the AbstractServerTest.  It looks like the
>> test harness has changed a bit.  I"m actually using TestNG to execute my
>> tests, rather than JUnit so hopefully theres still a way to handle this
>> easily.
>>
>> Mark
>> He who started looking at ldap integration testing at the wrong time..
>>
>> -- 
>> "It is easier to optimize correct code than to correct optimized code." --
>> Bill Harlan
>>
>>
> 

Re: Loading custom schemas with AbstractServerTest under 1.5.4

Posted by Juergen Weber <we...@gmail.com>.
Hi,

any updates to this? Anybody got a working sample using DS 1.5.4,
AbstractServerTest and custom schemas?

Thx,
Juergen


Mark Derricutt wrote:
> 
> 'lo
> 
> With the recent changes to AbstractServerTest in 1.5.4, how does one
> register custom schemas now?
> 
> Under 1.5.3 I was using:
> 
>         Set<AbstractBootstrapSchema> schemas =
> configuration.getBootstrapSchemas();
>         schemas.add(new Smx3Schema());
>         configuration.setBootstrapSchemas(schemas);
> 
> where configuration came from the AbstractServerTest.  It looks like the
> test harness has changed a bit.  I"m actually using TestNG to execute my
> tests, rather than JUnit so hopefully theres still a way to handle this
> easily.
> 
> Mark
> He who started looking at ldap integration testing at the wrong time..
> 
> -- 
> "It is easier to optimize correct code than to correct optimized code." --
> Bill Harlan
> 
> 

-- 
View this message in context: http://www.nabble.com/Loading-custom-schemas-with-AbstractServerTest-under-1.5.4-tp19485510p20537225.html
Sent from the Apache Directory Project mailing list archive at Nabble.com.