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.jndi;
21
22
23 import org.apache.directory.server.core.DirectoryService;
24 import org.apache.directory.server.core.integ.CiRunner;
25 import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
26 import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
27 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
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.directory.Attribute;
34 import javax.naming.directory.Attributes;
35 import javax.naming.directory.BasicAttribute;
36 import javax.naming.directory.BasicAttributes;
37 import javax.naming.ldap.LdapContext;
38
39
40
41
42
43
44
45
46 @RunWith ( CiRunner.class )
47 public class AddIT
48 {
49 public static DirectoryService service;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 @Test
106 public void testAddAttributesNotInObjectClasses() throws Exception
107 {
108 LdapContext sysRoot = getSystemContext( service );
109
110 Attributes attrs = new BasicAttributes( true );
111 Attribute oc = new BasicAttribute( "ObjectClass", "top" );
112 Attribute cn = new BasicAttribute( "cn", "kevin Spacey" );
113 Attribute dc = new BasicAttribute( "dc", "ke" );
114 attrs.put( oc );
115 attrs.put( cn );
116 attrs.put( dc);
117
118 String base = "uid=kevin";
119
120
121 try
122 {
123 sysRoot.createSubcontext( base, attrs );
124 fail( "Should not reach this state" );
125 }
126 catch ( LdapSchemaViolationException e )
127 {
128 assertTrue( true );
129 }
130 }
131
132
133
134
135
136
137
138 @Test
139 public void testAddAttributesBadSyntax() throws Exception
140 {
141 LdapContext sysRoot = getSystemContext( service );
142
143 Attributes attrs = new BasicAttributes( true );
144 Attribute oc = new BasicAttribute( "ObjectClass", "top" );
145 oc.add( "person" );
146 Attribute cn = new BasicAttribute( "cn", "kevin Spacey" );
147 Attribute sn = new BasicAttribute( "sn", "ke" );
148 Attribute telephone = new BasicAttribute( "telephoneNumber", "0123456abc" );
149 attrs.put( oc );
150 attrs.put( cn );
151 attrs.put( sn );
152 attrs.put( telephone );
153
154 String base = "sn=kevin";
155
156
157 try
158 {
159 sysRoot.createSubcontext( base, attrs );
160 fail( "Should not reach this state" );
161 }
162 catch ( LdapInvalidAttributeValueException e )
163 {
164 assertTrue( true );
165 }
166 }
167 }