| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Test SchemaBuilder. |
| | | */ |
| | | /** Test SchemaBuilder. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class SchemaBuilderTestCase extends AbstractSchemaTestCase { |
| | | |
| | |
| | | * attribute types regardless of the order in which they were added. |
| | | */ |
| | | @Test |
| | | public void testAttributeTypeDependenciesChildThenParent() { |
| | | public void attributeTypeDependenciesChildThenParent() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | | .addAttributeType("( childtype-oid NAME 'childtype' SUP parenttype )", |
| | |
| | | * attribute types regardless of the order in which they were added. |
| | | */ |
| | | @Test |
| | | public void testAttributeTypeDependenciesParentThenChild() { |
| | | public void attributeTypeDependenciesParentThenChild() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | | .addAttributeType( |
| | |
| | | "1.3.6.1.4.1.1466.115.121.1.15"); |
| | | } |
| | | |
| | | /** |
| | | * Tests that attribute types must have a syntax or a superior. |
| | | */ |
| | | /** Tests that attribute types must have a syntax or a superior. */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public void testAttributeTypeNoSuperiorNoSyntax() { |
| | | public void attributeTypeNoSuperiorNoSyntax() { |
| | | new SchemaBuilder(Schema.getCoreSchema()).addAttributeType( |
| | | "( parenttype-oid NAME 'parenttype' )", false); |
| | | } |
| | |
| | | * attribute types regardless of the order. |
| | | */ |
| | | @Test |
| | | public void testAttributeTypeSuperiorFailureChildThenParent() { |
| | | public void attributeTypeSuperiorFailureChildThenParent() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).addAttributeType( |
| | | "( childtype-oid NAME 'childtype' SUP parenttype )", false) |
| | |
| | | * attribute types regardless of the order. |
| | | */ |
| | | @Test |
| | | public void testAttributeTypeSuperiorFailureParentThenChild() { |
| | | public void attributeTypeSuperiorFailureParentThenChild() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).addAttributeType( |
| | | "( parenttype-oid NAME 'parenttype' SUP xxx )", false).addAttributeType( |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Test for OPENDJ-156: Errors when parsing collective attribute |
| | | * definitions. |
| | | */ |
| | | /** Test for OPENDJ-156: Errors when parsing collective attribute definitions. */ |
| | | @Test |
| | | public void testCollectiveAttribute() { |
| | | public void collectiveAttribute() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).addAttributeType( |
| | | "( 2.5.4.11.1 NAME 'c-ou' " |
| | |
| | | * another and take advantage of copy on write. |
| | | */ |
| | | @Test |
| | | public void testCopyOnWriteNoChanges() { |
| | | public void copyOnWriteNoChanges() { |
| | | final Schema baseSchema = Schema.getCoreSchema(); |
| | | final Schema schema = new SchemaBuilder(baseSchema).toSchema(); |
| | | |
| | | assertThat(schema).isSameAs(baseSchema); |
| | | } |
| | | |
| | | /** |
| | | * Tests that it is possible to create a schema which is based on another. |
| | | */ |
| | | /** Tests that it is possible to create a schema which is based on another. */ |
| | | @Test |
| | | public void testCopyOnWriteWithChanges() { |
| | | public void copyOnWriteWithChanges() { |
| | | final Schema baseSchema = Schema.getCoreSchema(); |
| | | final Schema schema = |
| | | new SchemaBuilder(baseSchema).addAttributeType( |
| | |
| | | .isEqualTo(baseSchema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS)); |
| | | } |
| | | |
| | | /** |
| | | * Tests that it is possible to create an empty schema. |
| | | */ |
| | | /** Tests that it is possible to create an empty schema. */ |
| | | @Test |
| | | public void testCreateEmptySchema() { |
| | | public void createEmptySchema() { |
| | | final Schema schema = new SchemaBuilder().toSchema(); |
| | | assertThat(schema.getAttributeTypes()).isEmpty(); |
| | | assertThat(schema.getObjectClasses()).isEmpty(); |
| | |
| | | // Could go on... |
| | | } |
| | | |
| | | /** |
| | | * Tests that multiple consecutive invocations of toSchema return the exact |
| | | * same schema. |
| | | */ |
| | | /** Tests that multiple consecutive invocations of toSchema return the exact same schema. */ |
| | | @Test |
| | | public void testMultipleToSchema1() { |
| | | public void multipleToSchema1() { |
| | | final Schema baseSchema = Schema.getCoreSchema(); |
| | | final SchemaBuilder builder = new SchemaBuilder(baseSchema); |
| | | final Schema schema1 = builder.toSchema(); |
| | |
| | | assertThat(schema1).isSameAs(schema2); |
| | | } |
| | | |
| | | /** |
| | | * Tests that multiple consecutive invocations of toSchema return the exact |
| | | * same schema. |
| | | */ |
| | | /** Tests that multiple consecutive invocations of toSchema return the exact same schema. */ |
| | | @Test |
| | | public void testMultipleToSchema2() { |
| | | public void multipleToSchema2() { |
| | | final SchemaBuilder builder = |
| | | new SchemaBuilder().addAttributeType( |
| | | "( testtype-oid NAME 'testtype' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", |
| | |
| | | * object classes regardless of the order in which they were added. |
| | | */ |
| | | @Test |
| | | public void testObjectClassDependenciesChildThenParent() { |
| | | public void objectClassDependenciesChildThenParent() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).addObjectClass( |
| | | "( childtype-oid NAME 'childtype' SUP parenttype STRUCTURAL MUST sn )", |
| | |
| | | * object classes regardless of the order in which they were added. |
| | | */ |
| | | @Test |
| | | public void testObjectClassDependenciesParentThenChild() { |
| | | public void objectClassDependenciesParentThenChild() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | | .addObjectClass( |
| | |
| | | * object classes regardless of the order. |
| | | */ |
| | | @Test |
| | | public void testObjectClassSuperiorFailureChildThenParent() { |
| | | public void objectClassSuperiorFailureChildThenParent() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).addObjectClass( |
| | | "( childtype-oid NAME 'childtype' SUP parenttype STRUCTURAL MUST sn )", |
| | |
| | | * object classes regardless of the order. |
| | | */ |
| | | @Test |
| | | public void testObjectClassSuperiorFailureParentThenChild() { |
| | | public void objectClassSuperiorFailureParentThenChild() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | | .addObjectClass( |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests that a schema builder can be re-used after toSchema has been |
| | | * called. |
| | | */ |
| | | /** Tests that a schema builder can be re-used after toSchema has been called. */ |
| | | @Test |
| | | public void testReuseSchemaBuilder() { |
| | | public void reuseSchemaBuilder() { |
| | | final SchemaBuilder builder = new SchemaBuilder(); |
| | | final Schema schema1 = |
| | | builder.addAttributeType( |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | | public final void testSchemaBuilderDoesntAllowNullEntry() throws Exception { |
| | | public final void schemaBuilderDoesntAllowNullEntry() throws Exception { |
| | | new SchemaBuilder((Entry) null); |
| | | } |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryWithCoreSchema() throws Exception { |
| | | public final void schemaBuilderWithEntryWithCoreSchema() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderWithEntryWithoutCoreSchema() throws Exception { |
| | | public final void schemaBuilderWithEntryWithoutCoreSchema() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAttributeWithoutSpace() throws Exception { |
| | | public final void schemaBuilderAttributeWithoutSpace() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAttributeExtensionWithoutSpace() throws Exception { |
| | | public final void schemaBuilderAttributeExtensionWithoutSpace() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddLdapSyntax() throws Exception { |
| | | public final void schemaBuilderWithEntryAddLdapSyntax() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMalformedLdapSyntax() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMalformedLdapSyntax() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMatchingRuleUse() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMatchingRuleUse() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMalformedMatchingRuleUse() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMalformedMatchingRuleUse() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMatchingRule() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMatchingRule() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMalformedMatchingRule() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMalformedMatchingRule() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddDITContentRule() throws Exception { |
| | | public final void schemaBuilderWithEntryAddDITContentRule() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMalformedDITContentRule() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMalformedDITContentRule() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddObjectClass() throws Exception { |
| | | public final void schemaBuilderWithEntryAddObjectClass() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderWithEntryAddMalformedObjectClass() throws Exception { |
| | | public final void schemaBuilderWithEntryAddMalformedObjectClass() throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | | "dn: cn=schema", |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAddAttributeWithEntryContainingDescriptionWithCoreSchema() |
| | | public final void schemaBuilderAddAttributeWithEntryContainingDescriptionWithCoreSchema() |
| | | throws Exception { |
| | | // @formatter:off |
| | | final String[] strEntry = { |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAddAttributeContainingDescriptionWithCoreSchema() |
| | | public final void schemaBuilderAddAttributeContainingDescriptionWithCoreSchema() |
| | | throws Exception { |
| | | |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | // Adding the new schema containing the customclass |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public final void testSchemaBuilderAddAttributeDoesntAllowWrongUsage() throws Exception { |
| | | |
| | | public final void schemaBuilderAddAttributeDoesntAllowWrongUsage() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | // Adding the new schema containing the customclass |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | | public final void testSchemaBuilderAddAttributeTypeDoesntAllowNull() throws Exception { |
| | | public final void schemaBuilderAddAttributeTypeDoesntAllowNull() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | // Adding the new schema containing the customclass |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public final void testSchemaBuilderAddAttributeTypeDoesntAllowEmptyString() throws Exception { |
| | | |
| | | public final void schemaBuilderAddAttributeTypeDoesntAllowEmptyString() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | // Adding the new schema containing the customclass |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | | + "' SUP top AUXILIARY MAY myCustomAttribute )", false); |
| | | scBuild.addAttributeType(" ", false); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public final void testSchemaBuilderAddAttributeDoesntAllowLeftParenthesisMising() |
| | | public final void schemaBuilderAddAttributeDoesntAllowLeftParenthesisMising() |
| | | throws Exception { |
| | | |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getDefaultSchema()); |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | | + "' SUP top AUXILIARY MAY myCustomAttribute )", false); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public final void testSchemaBuilderAddAttributeDoesntAllowRightParenthesisMising() |
| | | public final void schemaBuilderAddAttributeDoesntAllowRightParenthesisMising() |
| | | throws Exception { |
| | | |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getDefaultSchema()); |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | | + "' SUP top AUXILIARY MAY myCustomAttribute )", false); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderCompareAddAttributeTypesSucceed() throws Exception { |
| | | |
| | | public final void schemaBuilderCompareAddAttributeTypesSucceed() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getDefaultSchema()); |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | | + "' SUP top AUXILIARY MAY myCustomAttribute )", false); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public final void testSchemaBuilderAddObjectClassDoesntAllowMalformedObjectClass() |
| | | public final void schemaBuilderAddObjectClassDoesntAllowMalformedObjectClass() |
| | | throws Exception { |
| | | |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | // Left parenthesis is missing underneath |
| | | scBuild.addObjectClass(" temporary-fake-oc-id NAME 'myCustomObjClass" |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = LocalizedIllegalArgumentException.class) |
| | | public final void testSchemaBuilderAddObjectClassDoesntAllowMalformedObjectClassIllegalToken() |
| | | public final void schemaBuilderAddObjectClassDoesntAllowMalformedObjectClassIllegalToken() |
| | | throws Exception { |
| | | |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | // Wrong object class definition (AUXI) |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | |
| | | false); |
| | | } |
| | | |
| | | /** |
| | | * Rewrite an existing object class. |
| | | */ |
| | | /** Rewrite an existing object class. */ |
| | | @Test |
| | | public final void testSchemaBuilderAddObjectClass() throws Exception { |
| | | public final void schemaBuilderAddObjectClass() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(getDefaultSchema()); |
| | | scBuild.buildObjectClass("2.5.6.14") |
| | | .names("device") |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = ConflictingSchemaElementException.class) |
| | | public final void testSchemaBuilderDoesntAllowConflictingAttributesOverwriteFalse() |
| | | public final void schemaBuilderDoesntAllowConflictingAttributesOverwriteFalse() |
| | | throws Exception { |
| | | |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | |
| | | scBuild.addAttributeType( |
| | |
| | | } |
| | | |
| | | @Test |
| | | public final void testSchemaBuilderWithAttributeUsageDifferentFromSuperior() { |
| | | public final void schemaBuilderWithAttributeUsageDifferentFromSuperior() { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | |
| | | // directoryOperation can't inherit from userApplications |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAllowsConflictingAttributesOverwriteTrue() throws Exception { |
| | | public final void schemaBuilderAllowsConflictingAttributesOverwriteTrue() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | |
| | | //@formatter:off |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = ConflictingSchemaElementException.class) |
| | | public final void testSchemaBuilderDoesntAllowConflictingDITOverwriteFalse() throws Exception { |
| | | public final void schemaBuilderDoesntAllowConflictingDITOverwriteFalse() throws Exception { |
| | | //@formatter:off |
| | | new SchemaBuilder(Schema.getDefaultSchema()) |
| | | .addObjectClass( |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAllowsConflictingDITStructureRuleOverwriteTrue() |
| | | public final void schemaBuilderAllowsConflictingDITStructureRuleOverwriteTrue() |
| | | throws Exception { |
| | | // @formatter:off |
| | | final Schema schema = |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAddDITContentRuleBuilder() throws Exception { |
| | | public final void schemaBuilderAddDITContentRuleBuilder() throws Exception { |
| | | // @formatter:off |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = ConflictingSchemaElementException.class) |
| | | public final void testSchemaBuilderDoesntAllowConflictingDITContentRuleOverwriteFalse() |
| | | public final void schemaBuilderDoesntAllowConflictingDITContentRuleOverwriteFalse() |
| | | throws Exception { |
| | | // @formatter:off |
| | | new SchemaBuilder(Schema.getDefaultSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAllowsConflictingDITContentRuleOverwriteTrue() |
| | | public final void schemaBuilderAllowsConflictingDITContentRuleOverwriteTrue() |
| | | throws Exception { |
| | | // @formatter:off |
| | | final Schema schema = new SchemaBuilder(Schema.getDefaultSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = ConflictingSchemaElementException.class) |
| | | public final void testSchemaBuilderDoesntAllowConflictingMatchingRuleOverwriteFalse() |
| | | public final void schemaBuilderDoesntAllowConflictingMatchingRuleOverwriteFalse() |
| | | throws Exception { |
| | | // @formatter:off |
| | | new SchemaBuilder(Schema.getDefaultSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAllowsConflictingMatchingRuleOverwriteTrue() |
| | | public final void schemaBuilderAllowsConflictingMatchingRuleOverwriteTrue() |
| | | throws Exception { |
| | | // @formatter:off |
| | | final Schema schema = |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = ConflictingSchemaElementException.class) |
| | | public final void testSchemaBuilderDoesntAllowConflictingMatchingRuleUseOverwriteFalse() |
| | | public final void schemaBuilderDoesntAllowConflictingMatchingRuleUseOverwriteFalse() |
| | | throws Exception { |
| | | // @formatter:off |
| | | new SchemaBuilder(Schema.getDefaultSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAllowsConflictingMatchingRuleUseOverwriteTrue() |
| | | public final void schemaBuilderAllowsConflictingMatchingRuleUseOverwriteTrue() |
| | | throws Exception { |
| | | // @formatter:off |
| | | final Schema schema = |
| | |
| | | + " X-ORIGIN 'RFC 4512' )"); |
| | | } |
| | | assertThat(schema.getWarnings()).isEmpty(); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = ConflictingSchemaElementException.class) |
| | | public final void testSchemaBuilderDoesntAllowConflictingNameFormOverwriteFalse() |
| | | public final void schemaBuilderDoesntAllowConflictingNameFormOverwriteFalse() |
| | | throws Exception { |
| | | // @formatter:off |
| | | new SchemaBuilder(Schema.getDefaultSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAllowsConflictingNameFormOverwriteTrue() throws Exception { |
| | | public final void schemaBuilderAllowsConflictingNameFormOverwriteTrue() throws Exception { |
| | | // @formatter:off |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getDefaultSchema()) |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveAttributeType() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveAttributeType() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getDefaultSchema()); |
| | | scBuild.addObjectClass("( temporary-fake-oc-id NAME 'myCustomObjClass" |
| | | + "' SUP top AUXILIARY MAY myCustomAttribute )", false); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantAttributeType() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantAttributeType() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeAttributeType("wrongName"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantSyntax() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantSyntax() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeSyntax("1.3.6.1.4.1.14aa"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveSyntax() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveSyntax() throws Exception { |
| | | assertThat(Schema.getCoreSchema().getSyntax("1.3.6.1.4.1.1466.115.121.1.15")).isNotNull(); |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getDefaultSchema()); |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveDitContentRule() throws Exception { |
| | | public final void schemaBuilderRemoveDitContentRule() throws Exception { |
| | | // @formatter:off |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | scBuild.addObjectClass("( 2.16.840.1.113730.3.2.2 NAME 'myCustomObjClass" |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantDitContentRule() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantDitContentRule() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeDITContentRule("badDITContentRule"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveDitStructureRule() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveDitStructureRule() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | scBuild.addObjectClass( |
| | | "( testditstructureruleconstraintssupoc-oid " |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantDitStructureRule() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantDitStructureRule() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeDITStructureRule(999014); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveMatchingRule() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveMatchingRule() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | scBuild.addMatchingRule( |
| | | // Matching rules from RFC 2252 |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantMatchingRule() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantMatchingRule() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeMatchingRule("bitStringMatchZ"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveMatchingRuleUSe() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveMatchingRuleUSe() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | scBuild.addMatchingRuleUse( |
| | | "( 2.5.13.16 NAME 'bitStringMatch' APPLIES ( givenName $ surname ) )", false); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantMatchingRuleUse() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantMatchingRuleUse() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeMatchingRuleUse("bitStringMatchZ"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveNameForm() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveNameForm() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | scBuild.addNameForm("( testviolatessinglevaluednameform-oid " |
| | | + "NAME 'testViolatesSingleValuedNameForm' " |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantNameForm() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantNameForm() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeNameForm("bitStringMatchZ"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = UnknownSchemaElementException.class) |
| | | public final void testSchemaBuilderRemoveObjectClass() throws Exception { |
| | | |
| | | public final void schemaBuilderRemoveObjectClass() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(); |
| | | scBuild.addObjectClass("( 2.5.6.6 NAME 'person' SUP top STRUCTURAL MUST ( sn $ cn )" |
| | | + " MAY ( userPassword $ telephoneNumber $ seeAlso $ description )" |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderRemoveInexistantObjectClass() throws Exception { |
| | | public final void schemaBuilderRemoveInexistantObjectClass() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | boolean isRemoved = scBuild.removeObjectClass("bitStringMatchZ"); |
| | | assertThat(isRemoved).isFalse(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | | public final void testSchemaBuilderAddSchemaForEntryDoesntAllowNull() throws Exception { |
| | | |
| | | public final void schemaBuilderAddSchemaForEntryDoesntAllowNull() throws Exception { |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | scBuild.addSchemaForEntry(null, null, false); |
| | | } |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test(expectedExceptions = EntryNotFoundException.class) |
| | | public final void testSchemaBuilderAddSchemaForEntryDoesntContainSubschemaMockConnection() |
| | | public final void schemaBuilderAddSchemaForEntryDoesntContainSubschemaMockConnection() |
| | | throws Exception { |
| | | Connection connection = mock(Connection.class); |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | |
| | | |
| | | scBuild.addSchemaForEntry(connection, |
| | | DN.valueOf("uid=scarter,ou=People,dc=example,dc=com"), false); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAddSchemaForEntryMockConnection() throws Exception { |
| | | public final void schemaBuilderAddSchemaForEntryMockConnection() throws Exception { |
| | | Connection connection = mock(Connection.class); |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Test |
| | | public final void testSchemaBuilderAddSchemaForEntryAsyncMockConnection() throws Exception { |
| | | public final void schemaBuilderAddSchemaForEntryAsyncMockConnection() throws Exception { |
| | | Connection connection = mock(Connection.class); |
| | | final SchemaBuilder scBuild = new SchemaBuilder(Schema.getCoreSchema()); |
| | | |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testDefaultSyntax() { |
| | | public void defaultSyntax() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).toSchema().asNonStrictSchema(); |
| | | assertThat(schema.getDefaultSyntax()).isEqualTo(CoreSchema.getOctetStringSyntax()); |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testOverrideDefaultSyntax() { |
| | | public void overrideDefaultSyntax() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | | .setOption(DEFAULT_SYNTAX_OID, getDirectoryStringSyntax().getOID()) |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testDefaultMatchingRule() { |
| | | public void defaultMatchingRule() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()).toSchema().asNonStrictSchema(); |
| | | assertThat(schema.getDefaultMatchingRule()).isEqualTo( |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testOverrideMatchingRule() { |
| | | public void overrideMatchingRule() { |
| | | final Schema schema = |
| | | new SchemaBuilder(Schema.getCoreSchema()) |
| | | .setOption(DEFAULT_MATCHING_RULE_OID, getCaseIgnoreMatchingRule().getOID()) |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testDefaultSyntaxDefinedInSchema() { |
| | | public void defaultSyntaxDefinedInSchema() { |
| | | // The next line was triggering a NPE with OPENDJ-1252. |
| | | final Schema schema = |
| | | new SchemaBuilder().addSyntax("( 9.9.9 DESC 'Test Syntax' )", false).addSyntax( |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testDefaultMatchingRuleDefinedInSchema() throws DecodeException { |
| | | public void defaultMatchingRuleDefinedInSchema() throws DecodeException { |
| | | final Schema schema = |
| | | new SchemaBuilder().addSyntax(CoreSchema.getOctetStringSyntax().toString(), false) |
| | | .addMatchingRule( |
| | |
| | | schema.getMatchingRule("9.9.9").normalizeAttributeValue(ByteString.valueOfUtf8("test"))) |
| | | .isEqualTo(ByteString.valueOfUtf8("test")); |
| | | } |
| | | |
| | | } |