OLD | NEW |
1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 @Test | 128 @Test |
129 public void testUserEquals() { | 129 public void testUserEquals() { |
130 Principal p1 = new UserPrincipal("id"); | 130 Principal p1 = new UserPrincipal("id"); |
131 assertFalse(p1.equals(null)); | 131 assertFalse(p1.equals(null)); |
132 Principal p2 = new UserPrincipal("id"); | 132 Principal p2 = new UserPrincipal("id"); |
133 assertEquals(p1, p2); | 133 assertEquals(p1, p2); |
134 Principal p3 = new UserPrincipal("id", "N"); | 134 Principal p3 = new UserPrincipal("id", "N"); |
135 assertFalse(p1.equals(p3)); | 135 assertFalse(p1.equals(p3)); |
136 assertFalse(p2.equals(p3)); | 136 assertFalse(p2.equals(p3)); |
| 137 |
| 138 Principal p4 = new UserPrincipal("user@domain.local", "Default"); |
| 139 Principal p5 = new UserPrincipal("domain.local\\user", "Default"); |
| 140 Principal p6 = new UserPrincipal("domain.local/user", "Default"); |
| 141 |
| 142 Principal g1 = new GroupPrincipal("domain.local/user", "Default"); |
| 143 |
| 144 assertEquals(p4, p5); |
| 145 assertEquals(p4, p6); |
| 146 assertFalse(p6.equals(g1)); |
137 } | 147 } |
138 | 148 |
139 @Test | 149 @Test |
140 public void testGroupEquals() { | 150 public void testGroupEquals() { |
141 Principal p1 = new GroupPrincipal("id"); | 151 Principal p1 = new GroupPrincipal("id"); |
142 assertFalse(p1.equals(null)); | 152 assertFalse(p1.equals(null)); |
143 Principal p2 = new GroupPrincipal("id"); | 153 Principal p2 = new GroupPrincipal("id"); |
144 assertEquals(p1, p2); | 154 assertEquals(p1, p2); |
145 Principal p3 = new GroupPrincipal("id", "N"); | 155 Principal p3 = new GroupPrincipal("id", "N"); |
146 assertFalse(p1.equals(p3)); | 156 assertFalse(p1.equals(p3)); |
147 assertFalse(p2.equals(p3)); | 157 assertFalse(p2.equals(p3)); |
148 } | 158 } |
149 | 159 |
150 @Test | 160 @Test |
151 public void testUserAndGroupNotEqual() { | 161 public void testUserAndGroupNotEqual() { |
152 Principal u = new UserPrincipal("id"); | 162 Principal u = new UserPrincipal("id"); |
153 Principal g = new GroupPrincipal("id"); | 163 Principal g = new GroupPrincipal("id"); |
154 assertFalse(u.equals(g)); | 164 assertFalse(u.equals(g)); |
155 } | 165 } |
156 | 166 |
157 @Test | 167 @Test |
158 public void testUserHashCode() { | 168 public void testUserHashCode() { |
159 Principal p1 = new UserPrincipal("id"); | 169 Principal p1 = new UserPrincipal("id"); |
160 Principal p2 = new UserPrincipal("id"); | 170 Principal p2 = new UserPrincipal("id"); |
161 assertEquals(p1.hashCode(), p2.hashCode()); | 171 assertEquals(p1.hashCode(), p2.hashCode()); |
162 Set<Principal> p = new HashSet<Principal>(); | 172 Set<Principal> p = new HashSet<Principal>(); |
163 p.add(p1); | 173 p.add(p1); |
164 p.add(p2); | 174 p.add(p2); |
165 assertEquals(1, p.size()); | 175 assertEquals(1, p.size()); |
166 } | 176 } |
167 | 177 |
168 @Test | 178 @Test |
169 public void testGroupHashCode() { | 179 public void testGroupHashCode() { |
170 Principal p1 = new GroupPrincipal("id"); | 180 Principal p1 = new GroupPrincipal("id"); |
171 Principal p2 = new GroupPrincipal("id"); | 181 Principal p2 = new GroupPrincipal("id"); |
172 assertEquals(p1.hashCode(), p2.hashCode()); | 182 assertEquals(p1.hashCode(), p2.hashCode()); |
173 Set<Principal> p = new HashSet<Principal>(); | 183 Set<Principal> p = new HashSet<Principal>(); |
174 p.add(p1); | 184 p.add(p1); |
175 p.add(p2); | 185 p.add(p2); |
176 assertEquals(1, p.size()); | 186 assertEquals(1, p.size()); |
177 } | 187 } |
178 | 188 |
179 @Test | 189 @Test |
180 public void testToString() { | 190 public void testToString() { |
181 Principal u = new UserPrincipal("1d"); | 191 Principal u = new UserPrincipal("1d"); |
182 String s = "" + u; | 192 String s = "" + u; |
183 assertTrue(s.contains("User")); | 193 assertTrue(s.contains("User")); |
184 assertTrue(s.contains("1d")); | 194 assertTrue(s.contains("1d")); |
185 assertTrue(s.contains("Default")); | 195 assertTrue(s.contains("Default")); |
186 } | 196 } |
187 | 197 |
188 @Test | 198 @Test |
189 public void testComparator() { | 199 public void testComparator() { |
190 List<Principal> sorted = Collections.unmodifiableList(Arrays.asList( | 200 List<Principal> sorted = Collections.unmodifiableList(Arrays.asList( |
191 new UserPrincipal("Garbie", "Newbies"), | 201 new UserPrincipal("Garbie", "Newbies"), |
192 new GroupPrincipal("Dragons", "Newbies"), | 202 new GroupPrincipal("Dragons", "Newbies"), |
193 new UserPrincipal("Honeysuckle", "Oldies"), | 203 new UserPrincipal("Honeysuckle", "Oldies"), |
194 new UserPrincipal("Honeysuckle", "Oldies"), | 204 new UserPrincipal("Honeysuckle", "Oldies"), |
195 new UserPrincipal("Honeysuckle", "Oldies"), | 205 new UserPrincipal("Honeysuckle", "Oldies"), |
196 new UserPrincipal("Morning Glory", "Oldies"), | 206 new UserPrincipal("Morning Glory", "Oldies"), |
197 new UserPrincipal("Rosedust", "Oldies"), | 207 new UserPrincipal("Rosedust", "Oldies"), |
198 new GroupPrincipal("Flutter Ponies", "Oldies") | 208 new GroupPrincipal("Flutter Ponies", "Oldies") |
199 )); | 209 )); |
200 int ntrials = 10; | 210 int ntrials = 10; |
201 for (int i = 0; i < ntrials; i++) { | 211 for (int i = 0; i < ntrials; i++) { |
202 List<Principal> dup = new ArrayList<Principal>(sorted); | 212 List<Principal> dup = new ArrayList<Principal>(sorted); |
203 Collections.shuffle(dup); | 213 Collections.shuffle(dup); |
204 Collections.sort(dup); | 214 Collections.sort(dup); |
205 assertEquals(sorted, dup); | 215 assertEquals(sorted, dup); |
206 } | 216 } |
207 } | 217 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 assertEquals(new ParsedPrincipal(false, "z", "b", DomainFormat.DNS, "c"), | 341 assertEquals(new ParsedPrincipal(false, "z", "b", DomainFormat.DNS, "c"), |
332 p.plainName("z")); | 342 p.plainName("z")); |
333 assertEquals(new ParsedPrincipal(false, "a", "z", DomainFormat.DNS, "c"), | 343 assertEquals(new ParsedPrincipal(false, "a", "z", DomainFormat.DNS, "c"), |
334 p.domain("z")); | 344 p.domain("z")); |
335 assertEquals(new ParsedPrincipal(false, "a", "b", DomainFormat.NONE, "c"), | 345 assertEquals(new ParsedPrincipal(false, "a", "b", DomainFormat.NONE, "c"), |
336 p.domainFormat(DomainFormat.NONE)); | 346 p.domainFormat(DomainFormat.NONE)); |
337 assertEquals(new ParsedPrincipal(false, "a", "b", DomainFormat.DNS, "z"), | 347 assertEquals(new ParsedPrincipal(false, "a", "b", DomainFormat.DNS, "z"), |
338 p.namespace("z")); | 348 p.namespace("z")); |
339 } | 349 } |
340 } | 350 } |
OLD | NEW |