You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Juergen Weber <we...@gmail.com> on 2008/11/17 11:44:56 UTC

Re: Loading custom schemas with AbstractServerTest under 1.5.4

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.


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
>>
>>
>