mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
13.55.2013 64e790450f962f6a1cb696fbd1b3fa30bdef7b5e
Checkpoint commit for OPENDJ-1235 : Migrate configuration framework

* Fix bundle issue in unit tests for org.opends.server.admin package
** Move TestParentCfgDefn and TestChildCfgDefn properties and xml files to src/test/resources
so they are included in classpath

* Update pom.xml
** Generate core admin messages in src/main/resources directory
** Update generation of profiles messages

* Cleanup and minor refactoring in test classes and ConfigGuideGeneration class

2 files renamed
5 files modified
208 ■■■■■ changed files
opendj-admin/pom.xml 88 ●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java 65 ●●●● patch | view | raw | blame | history
opendj-admin/src/test/java/org/forgerock/opendj/config/ConfigurationMockTest.java 2 ●●●●● patch | view | raw | blame | history
opendj-admin/src/test/java/org/opends/server/admin/TestCfg.java 52 ●●●● patch | view | raw | blame | history
opendj-admin/src/test/java/org/opends/server/admin/ValidateConfigDefinitionsTest.java 1 ●●●● patch | view | raw | blame | history
opendj-admin/src/test/resources/org/opends/server/admin/TestChildConfiguration.xml patch | view | raw | blame | history
opendj-admin/src/test/resources/org/opends/server/admin/TestParentConfiguration.xml patch | view | raw | blame | history
opendj-admin/pom.xml
@@ -346,50 +346,6 @@
                    </parameter>
                  </parameters>
                </transformationSet>
                <!-- Generate LDAP profile for core administration components. -->
                <transformationSet>
                  <dir>${xmlDefinitionsDir}</dir>
                  <outputDir>${project.build.outputDirectory}/admin/profiles/ldap/${adminPackage}/meta</outputDir>
                  <stylesheet>${xslDir}/ldapMOProfile.xsl</stylesheet>
                  <excludes>
                    <exclude>Package.xml</exclude>
                  </excludes>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^([^/]+)Configuration\.xml$</pattern>
                      <replacement>$1CfgDefn.properties</replacement>
                    </fileMapper>
                  </fileMappers>
                  <parameters>
                    <parameter>
                      <name>base-dir</name>
                      <value>${xmlDefinitionsBaseDir}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
                <!-- Generate CLI profile for core administration components. -->
                <transformationSet>
                  <dir>${xmlDefinitionsDir}</dir>
                  <outputDir>${project.build.outputDirectory}/admin/profiles/cli/${adminPackage}/meta</outputDir>
                  <stylesheet>${xslDir}/cliMOProfile.xsl</stylesheet>
                  <excludes>
                    <exclude>Package.xml</exclude>
                  </excludes>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^([^/]+)Configuration\.xml$</pattern>
                      <replacement>$1CfgDefn.properties</replacement>
                    </fileMapper>
                  </fileMappers>
                  <parameters>
                    <parameter>
                      <name>base-dir</name>
                      <value>${xmlDefinitionsBaseDir}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
                <!-- Generate manifest file for core administration components. -->
                <transformationSet>
                  <dir>${xmlDefinitionsDir}</dir>
@@ -438,6 +394,50 @@
                    </parameter>
                  </parameters>
                </transformationSet>
                <!-- Generate LDAP profile for core administration components. -->
                <transformationSet>
                  <dir>${xmlDefinitionsDir}</dir>
                  <outputDir>${project.build.outputDirectory}/admin/profiles/ldap/${adminPackage}/meta</outputDir>
                  <stylesheet>${xslDir}/ldapMOProfile.xsl</stylesheet>
                  <excludes>
                    <exclude>Package.xml</exclude>
                  </excludes>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^([^/]+)Configuration\.xml$</pattern>
                      <replacement>$1CfgDefn.properties</replacement>
                    </fileMapper>
                  </fileMappers>
                  <parameters>
                    <parameter>
                      <name>base-dir</name>
                      <value>${xmlDefinitionsBaseDir}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
                <!-- Generate CLI profile for core administration components. -->
                <transformationSet>
                  <dir>${xmlDefinitionsDir}</dir>
                  <outputDir>${project.build.outputDirectory}/admin/profiles/cli/${adminPackage}/meta</outputDir>
                  <stylesheet>${xslDir}/cliMOProfile.xsl</stylesheet>
                  <excludes>
                    <exclude>Package.xml</exclude>
                  </excludes>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                     <pattern>^([^/]+)Configuration\.xml$</pattern>
                      <replacement>$1CfgDefn.properties</replacement>
                    </fileMapper>
                  </fileMappers>
                  <parameters>
                    <parameter>
                      <name>base-dir</name>
                      <value>${xmlDefinitionsBaseDir}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
              </transformationSets>
            </configuration>
          </execution>
opendj-admin/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java
@@ -76,6 +76,7 @@
 * This class allow Configuration Guide documentation generation (html format).
 * It is based on the Admin Framework Introspection API
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class ConfigGuideGeneration {
    // Note : still to be done :
@@ -249,8 +250,9 @@
    /**
     * Generate the inheritance tree of all the managed objects.
     */
    @SuppressWarnings("unchecked")
    private void genManagedObjectInheritanceTree(TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>> list) {
    private void genManagedObjectInheritanceTree(
            TreeMap<String, TreeMap<String, AbstractManagedObjectDefinition>> list) {
        htmlHeader(DynamicConstants.PRODUCT_NAME + " " + "Configuration Reference - Inheritance View");
        tabMenu(INHERITANCE_TREE_FILE);
@@ -262,7 +264,8 @@
            // Get the list of the category
            TreeMap<String, AbstractManagedObjectDefinition> catList = list.get(catName);
            for (AbstractManagedObjectDefinition mo : catList.values()) {
                if ((relList.get(mo.getName()) != null) && (relList.get(mo.getName()).hasOption(RelationOption.HIDDEN))) {
                if ((relList.get(mo.getName()) != null)
                        && (relList.get(mo.getName()).hasOption(RelationOption.HIDDEN))) {
                    continue;
                }
                paragraph(getLink(mo.getUserFriendlyName().toString(), mo.getName() + ".html", MAIN_FRAME));
@@ -276,7 +279,6 @@
        generateFile(INHERITANCE_TREE_FILE);
    }
    @SuppressWarnings("unchecked")
    private void genMoInheritanceTree(TreeMap<String, AbstractManagedObjectDefinition> catList) {
        beginList();
@@ -325,7 +327,6 @@
        generateFile(RELATION_TREE_FILE);
    }
    @SuppressWarnings("unchecked")
    private void genMORelationTree(TreeMap<String, RelationDefinition> list) {
        for (RelationDefinition rel : list.values()) {
            AbstractManagedObjectDefinition childMo = rel.getChildDefinition();
@@ -337,7 +338,8 @@
            if (rel.hasOption(RelationOption.HIDDEN)) {
                continue;
            }
            String linkStr = getLink(childMo.getUserFriendlyName().toString(), childMo.getName() + ".html", MAIN_FRAME);
            String linkStr = getLink(childMo.getUserFriendlyName().toString(), childMo.getName() + ".html",
                    MAIN_FRAME);
            String fromStr = "";
            if (!parentMo.getName().equals("")) {
                fromStr = " (from "
@@ -374,7 +376,6 @@
    /**
     * Generate all the managed objects HTML pages.
     */
    @SuppressWarnings("unchecked")
    private void genAllManagedObject(TreeMap<String, AbstractManagedObjectDefinition> list) {
        for (AbstractManagedObjectDefinition mo : list.values()) {
@@ -415,7 +416,7 @@
            heading3("Direct Subcomponents");
            paragraph("The following " + mo.getUserFriendlyPluralName() + " are available in the server :");
            beginList();
            @SuppressWarnings("unchecked")
            TreeMap<String, AbstractManagedObjectDefinition> children = makeMOTreeMap(mo.getChildren());
            for (AbstractManagedObjectDefinition child : children.values()) {
                link(child.getUserFriendlyName().toString(), child.getName() + ".html");
@@ -460,7 +461,7 @@
        TreeMap<String, PropertyDefinition> basicProps = new TreeMap<String, PropertyDefinition>();
        TreeMap<String, PropertyDefinition> advancedProps = new TreeMap<String, PropertyDefinition>();
        // Properties actually defined in this managed object
        @SuppressWarnings("unchecked")
        Collection<PropertyDefinition> props = mo.getAllPropertyDefinitions();
        for (PropertyDefinition prop : props) {
            if (prop.hasOption(PropertyOption.ADVANCED)) {
@@ -503,7 +504,6 @@
    private TreeMap<String, PropertyDefinition> getPropertyList(AbstractManagedObjectDefinition mo) {
        @SuppressWarnings("unchecked")
        Collection<PropertyDefinition> props = mo.getAllPropertyDefinitions();
        return makePropTreeMap(props);
    }
@@ -516,14 +516,14 @@
    private void generateRelationsSection(AbstractManagedObjectDefinition mo) {
        // Composition relations
        @SuppressWarnings("unchecked")
        Collection<RelationDefinition> compRels = mo.getRelationDefinitions();
        @SuppressWarnings("unchecked")
        Collection<RelationDefinition> reverseCompRels = mo.getReverseRelationDefinitions();
        // Aggregation properties
        @SuppressWarnings("unchecked")
        Collection<AggregationPropertyDefinition> aggregProps = mo.getAggregationPropertyDefinitions();
        @SuppressWarnings("unchecked")
        Collection<AggregationPropertyDefinition> reverseAggregProps = mo.getReverseAggregationPropertyDefinitions();
        // Check if something to print in composition relations
@@ -558,7 +558,7 @@
        if (!reverseAggregProps.isEmpty()) {
            for (AggregationPropertyDefinition agg : reverseAggregProps) {
                AbstractManagedObjectDefinition fromMo = agg.getManagedObjectDefinition();
                @SuppressWarnings("unchecked")
                Collection<RelationDefinition> rels = fromMo.getAllReverseRelationDefinitions();
                for (RelationDefinition rel : rels) {
                    if (rel.hasOption(RelationOption.HIDDEN)) {
@@ -717,7 +717,8 @@
            String basicHtmlCell = "";
            if (basicPropName != null) {
                basicHtmlCell = "  <td>&darr;&nbsp;<a href=\"#" + basicPropName + "\">" + basicPropName + "</a></td>\n";
                basicHtmlCell = "  <td>&darr;&nbsp;<a href=\"#" + basicPropName + "\">" + basicPropName
                        + "</a></td>\n";
            } else if ((basicPropsArray.length == 0) && (ii == 0)) {
                basicHtmlCell = "  <td>&nbsp;None</td>\n";
            } else if (ii >= basicPropsArray.length) {
@@ -805,8 +806,8 @@
                moPointers.append(getAnchor(letter) + getHeading2(letter));
                lettersPointers += getLink(letter, "#" + letter) + " ";
            }
            moPointers.append("<p> " + getLink(mo.getUserFriendlyName().toString(), mo.getName() + ".html", MAIN_FRAME)
                    + "</p>\n");
            moPointers.append("<p> "
                    + getLink(mo.getUserFriendlyName().toString(), mo.getName() + ".html", MAIN_FRAME) + "</p>\n");
        }
        paragraph(lettersPointers);
        htmlBuff.append(moPointers);
@@ -903,13 +904,13 @@
    private void genMainTopPage() {
        htmlHeader(DynamicConstants.PRODUCT_NAME + " Configuration Reference - Main Top");
        htmlBuff.append("<div class=\"breadcrumb\"><span class=\"pageactions\">" + "<a href=\"" + OpenDJHome
                + "\" target=\"_parent\">" + "<span style=\"font-size: 12px;\">&laquo;&nbsp;&nbsp;</span>" + "Back to "
                + DynamicConstants.PRODUCT_NAME + " Home</a></span>&nbsp;&nbsp;</div>\n");
                + "\" target=\"_parent\">" + "<span style=\"font-size: 12px;\">&laquo;&nbsp;&nbsp;</span>"
                + "Back to " + DynamicConstants.PRODUCT_NAME + " Home</a></span>&nbsp;&nbsp;</div>\n");
        htmlBuff.append("<table class=\"titletable\" cellspacing=\"0\" " + "width=\"100%\">\n");
        htmlBuff.append("<tbody><tr>\n");
        htmlBuff.append("  <td><h2>" + DynamicConstants.PRODUCT_NAME + " Configuration Reference</h2></td>\n");
        htmlBuff.append("  <td valign=\"bottom\" width=\"10%\">" + "<a href=\"" + OpenDJHome + "\" target=\"_parent\">"
                + "<img src=\"opendj_logo_sm.png\" alt=\"OpenDJ Logo\" align=\"bottom\" "
        htmlBuff.append("  <td valign=\"bottom\" width=\"10%\">" + "<a href=\"" + OpenDJHome
                + "\" target=\"_parent\">" + "<img src=\"opendj_logo_sm.png\" alt=\"OpenDJ Logo\" align=\"bottom\" "
                + "border=\"0\" height=\"33\" width=\"114\"></a></td>\n");
        htmlBuff.append("</tr>\n");
        htmlBuff.append("</tbody></table>\n");
@@ -961,7 +962,6 @@
        return null;
    }
    @SuppressWarnings("unchecked")
    private String getSyntaxStr(PropertyDefinition prop) {
        // Create a visitor for performing syntax specific processing.
        PropertyDefinitionVisitor<String, Void> visitor = new PropertyDefinitionVisitor<String, Void>() {
@@ -979,8 +979,8 @@
                return "The DN of any "
                        + linkStr
                        + ". "
                        + ((prop.getSourceConstraintSynopsis() != null) ? prop.getSourceConstraintSynopsis().toString()
                                : "");
                        + ((prop.getSourceConstraintSynopsis() != null) ? prop.getSourceConstraintSynopsis()
                                .toString() : "");
            }
            @Override
@@ -1022,7 +1022,8 @@
                if (prop.getMaximumUnit() != null) {
                    durationStr += "Maximum unit is \"" + prop.getMaximumUnit().getLongName() + "\". ";
                }
                long lowerLimitStr = new Double(prop.getBaseUnit().fromMilliSeconds(prop.getLowerLimit())).longValue();
                long lowerLimitStr = new Double(prop.getBaseUnit().fromMilliSeconds(prop.getLowerLimit()))
                        .longValue();
                durationStr += "Lower limit is " + lowerLimitStr + " " + prop.getBaseUnit().getLongName() + ". ";
                if (prop.getUpperLimit() != null) {
                    long upperLimitStr = new Double(prop.getBaseUnit().fromMilliSeconds(prop.getUpperLimit()))
@@ -1109,7 +1110,6 @@
    }
    @SuppressWarnings("unchecked")
    private String getDefaultBehaviorString(PropertyDefinition prop) {
        DefaultBehaviorProvider defaultBehav = prop.getDefaultBehaviorProvider();
        String defValueStr = "";
@@ -1244,11 +1244,12 @@
                "<span><a " + (activeTab.equals(RELATION_TREE_FILE) ? "class=\"activetab\" " : "") + "href=\""
                + RELATION_TREE_FILE + "\"" + " title=\"Relational View of Components\">Structure</a></span> " +
                "<span><a " + (activeTab.equals(MO_LIST_FILE) ? "class=\"activetab\" " : "") + "href=\"" + MO_LIST_FILE
                + "\"" + " title=\"Alphabetical Index of Components\">Components</a></span> " +
                "<span><a " + (activeTab.equals(MO_LIST_FILE) ? "class=\"activetab\" " : "") + "href=\""
                + MO_LIST_FILE + "\"" + " title=\"Alphabetical Index of Components\">Components</a></span> " +
                "<span><a " + (activeTab.equals(PROPERTIES_INDEX_FILE) ? "class=\"activetab\" " : "") + "href=\""
                + PROPERTIES_INDEX_FILE + "\"" + " title=\"Alphabetical Index of Properties\" >Properties</a></span>" +
                + PROPERTIES_INDEX_FILE + "\"" + " title=\"Alphabetical Index of Properties\" >Properties</a></span>"
                +
                "</div>" + "\n");
    }
@@ -1406,8 +1407,8 @@
    private void generateFile(String fileName) {
        // Write the html buffer in a file
        try {
            PrintWriter file = new java.io.PrintWriter(
                    new java.io.FileWriter(generationDir + File.separator + fileName));
            PrintWriter file = new java.io.PrintWriter(new java.io.FileWriter(generationDir + File.separator
                    + fileName));
            file.write(htmlBuff.toString());
            file.close();
        } catch (Exception e) {
opendj-admin/src/test/java/org/forgerock/opendj/config/ConfigurationMockTest.java
@@ -34,6 +34,7 @@
import org.forgerock.opendj.admin.server.GoverningStructureRuleVirtualAttributeCfg;
import org.forgerock.opendj.admin.server.LDAPConnectionHandlerCfg;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.admin.AttributeTypePropertyDefinition;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -75,6 +76,7 @@
    @Test
    public void testPropertyWithAttributeTypeReturnValue() throws Exception {
        AttributeTypePropertyDefinition.setCheckSchema(false); // attribute type is not in default schema
        CollectiveAttributeSubentriesVirtualAttributeCfg mock =
                mockCfg(CollectiveAttributeSubentriesVirtualAttributeCfg.class);
        assertThat(mock.getAttributeType()).isEqualTo(
opendj-admin/src/test/java/org/opends/server/admin/TestCfg.java
@@ -62,10 +62,6 @@
                RootCfgDefn.getInstance(), "test-one-to-zero-or-one-parent", TestParentCfgDefn.getInstance());
        RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT = builder.getInstance();
    }
    //private static ObjectClass TEST_PARENT_OBJECTCLASS = null;
    //private static ObjectClass TEST_CHILD_OBJECTCLASS = null;
    /**
     * Registers test parent and child object class definitions and any required
     * resource bundles.
@@ -77,43 +73,8 @@
     *             If an unexpected error occurred.
     */
    public synchronized static void setUp() throws Exception {
//        SchemaBuilder schemaBuilder = new SchemaBuilder(Schema.getDefaultSchema());
//        if (TEST_PARENT_OBJECTCLASS == null || TEST_CHILD_OBJECTCLASS == null) {
//            String def1 = "( 1.3.6.1.4.1.26027.1.2.4455114401 " + "NAME 'ds-cfg-test-parent-dummy' "
//                    + "SUP top STRUCTURAL " + "MUST ( cn $ ds-cfg-java-class $ "
//                    + "ds-cfg-enabled $ ds-cfg-attribute-type ) " + "MAY ( ds-cfg-base-dn $ ds-cfg-group-dn $ "
//                    + "ds-cfg-filter $ ds-cfg-conflict-behavior ) " + "X-ORIGIN 'OpenDS Directory Server' )";
//            schemaBuilder.addObjectClass(def1, false);
//
//            String def2 = "( 1.3.6.1.4.1.26027.1.2.4455114402 " + "NAME 'ds-cfg-test-child-dummy' "
//                    + "SUP top STRUCTURAL " + "MUST ( cn $ ds-cfg-java-class $ "
//                    + "ds-cfg-enabled $ ds-cfg-attribute-type ) " + "MAY ( ds-cfg-base-dn $ ds-cfg-group-dn $ "
//                    + "ds-cfg-filter $ ds-cfg-conflict-behavior $" + "ds-cfg-rotation-policy) "
//                    + "X-ORIGIN 'OpenDS Directory Server' )";
//            schemaBuilder.addObjectClass(def2, false);
//            Schema schema = schemaBuilder.toSchema();
//            TEST_PARENT_OBJECTCLASS = schema.getObjectClass("ds-cfg-test-parent-dummy");
//            TEST_CHILD_OBJECTCLASS = schema.getObjectClass("ds-cfg-test-child-dummy");
//        }
        {
            // Register the test parent resource bundle.
            TestParentCfgDefn def = TestParentCfgDefn.getInstance();
            def.initialize();
            String baseName = def.getClass().getName();
            ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName);
            ManagedObjectDefinitionI18NResource.getInstance().setResourceBundle(def, resourceBundle);
        }
        {
            // Register the test child resource bundle.
            TestChildCfgDefn def = TestChildCfgDefn.getInstance();
            def.initialize();
            String baseName = def.getClass().getName();
            ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName);
            ManagedObjectDefinitionI18NResource.getInstance().setResourceBundle(def, resourceBundle);
        }
        initializeAndRegisterBundle(TestParentCfgDefn.getInstance());
        initializeAndRegisterBundle(TestChildCfgDefn.getInstance());
        // Ensure that the relations are registered (do this after things
        // that can fail and leave tests in a bad state).
@@ -122,10 +83,17 @@
        LDAPProfile.getInstance().pushWrapper(new MockLDAPProfile());
    }
    private static void initializeAndRegisterBundle(ManagedObjectDefinition<?,?> definition) throws Exception {
        definition.initialize();
        String baseName = definition.getClass().getName();
        ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName);
        ManagedObjectDefinitionI18NResource.getInstance().setResourceBundle(definition, resourceBundle);
    }
    /**
     * Deregisters the test configurations from the administration framework.
     */
    public static void cleanup() {
    public synchronized static void cleanup() {
        LDAPProfile.getInstance().popWrapper();
        AbstractManagedObjectDefinition<?, ?> root = RootCfgDefn.getInstance();
opendj-admin/src/test/java/org/opends/server/admin/ValidateConfigDefinitionsTest.java
@@ -44,6 +44,7 @@
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@Test(singleThreaded = true)
public class ValidateConfigDefinitionsTest extends ConfigTestCase {
    private static final String EOL = System.getProperty("line.separator");
opendj-admin/src/test/resources/org/opends/server/admin/TestChildConfiguration.xml
opendj-admin/src/test/resources/org/opends/server/admin/TestParentConfiguration.xml