1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.schema;
21
22
23 import org.apache.directory.server.constants.MetaSchemaConstants;
24 import org.apache.directory.server.core.DirectoryService;
25 import org.apache.directory.server.core.integ.CiRunner;
26 import static org.apache.directory.server.core.integ.IntegrationUtils.*;
27 import org.apache.directory.shared.ldap.name.LdapDN;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.fail;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32
33 import javax.naming.NamingException;
34 import javax.naming.directory.Attribute;
35 import javax.naming.directory.Attributes;
36 import javax.naming.directory.BasicAttribute;
37 import javax.naming.directory.BasicAttributes;
38
39
40 @RunWith ( CiRunner.class )
41 public class ObjectClassCreateIT
42 {
43 private String testOID = "1.3.6.1.4.1.18060.0.4.0.3.1.555555.5555.5555555";
44
45
46 public static DirectoryService service;
47
48
49
50
51
52
53
54
55
56 private LdapDN getObjectClassContainer( String schemaName ) throws NamingException
57 {
58 return new LdapDN( "ou=objectClasses,cn=" + schemaName );
59 }
60
61
62
63
64
65 @Test
66 public void testCreateObjectClassWithInvalidNameAttribute() throws Exception
67 {
68 Attributes attributes = new BasicAttributes();
69 Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
70
71 objectClassAttribute.add( "top" );
72 objectClassAttribute.add( "metaTop" );
73 objectClassAttribute.add( "metaObjectClass" );
74
75 attributes.put( objectClassAttribute );
76
77 attributes.put( "m-oid", "testOID" );
78
79
80 attributes.put( "m-name", "http://example.com/users/accounts/L0" );
81
82 LdapDN dn = getObjectClassContainer( "apachemeta" );
83 dn.add( MetaSchemaConstants.M_OID_AT + "=" + testOID );
84
85 try
86 {
87 getSchemaContext( service ).createSubcontext( dn, attributes );
88 fail();
89 }
90 catch ( NamingException ne )
91 {
92 assertTrue( true );
93 }
94 }
95
96
97
98
99 @Test
100 public void testCreateObjectClassWithNoObjectClass() throws Exception
101 {
102 Attributes attributes = new BasicAttributes();
103 Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
104
105 objectClassAttribute.add( "top" );
106 objectClassAttribute.add( "metaTop" );
107 objectClassAttribute.add( "metaObjectClass" );
108
109
110
111
112 attributes.put( "m-oid", "testOID" );
113
114
115 attributes.put( "m-name", "no-objectClasses" );
116
117 LdapDN dn = getObjectClassContainer( "apachemeta" );
118 dn.add( MetaSchemaConstants.M_OID_AT + "=" + testOID );
119
120 try
121 {
122 getSchemaContext( service ).createSubcontext( dn, attributes );
123 fail();
124 }
125 catch ( NamingException ne )
126 {
127 assertTrue( true );
128 }
129 }
130 }