01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.services.persondir.support.merger;
07:
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: /**
12: * Testcase for the NoncollidingAttributeAdder.
13: * @author andrew.petro@yale.edu
14: * @version $Revision: 35128 $ $Date: 2004-12-13 16:27:49 -0700 (Mon, 13 Dec 2004) $
15: */
16: public class NoncollidingAttributeAdderTest extends
17: AttributeMergerAbstractTest {
18:
19: private NoncollidingAttributeAdder adder = new NoncollidingAttributeAdder();
20:
21: /**
22: * Test identity of adding an empty map.
23: */
24: public void testAddEmpty() {
25: Map someAttributes = new HashMap();
26: someAttributes.put("attName", "attValue");
27: someAttributes.put("attName2", "attValue2");
28:
29: Map expected = new HashMap();
30: expected.putAll(someAttributes);
31:
32: Map result = this .adder.mergeAttributes(someAttributes,
33: new HashMap());
34:
35: assertEquals(expected, result);
36: }
37:
38: /**
39: * Test a simple case of adding one map of attributes to another, with
40: * no collisions.
41: */
42: public void testAddNoncolliding() {
43: Map someAttributes = new HashMap();
44: someAttributes.put("attName", "attValue");
45: someAttributes.put("attName2", "attValue2");
46:
47: Map otherAttributes = new HashMap();
48: otherAttributes.put("attName3", "attValue3");
49: otherAttributes.put("attName4", "attValue4");
50:
51: Map expected = new HashMap();
52: expected.putAll(someAttributes);
53: expected.putAll(otherAttributes);
54:
55: Map result = this .adder.mergeAttributes(someAttributes,
56: otherAttributes);
57: assertEquals(expected, result);
58: }
59:
60: /**
61: * Test that colliding attributes are not added.
62: */
63: public void testColliding() {
64: Map someAttributes = new HashMap();
65: someAttributes.put("attName", "attValue");
66: someAttributes.put("attName2", "attValue2");
67:
68: Map otherAttributes = new HashMap();
69: otherAttributes.put("attName", "attValue3");
70: otherAttributes.put("attName4", "attValue4");
71:
72: Map expected = new HashMap();
73: expected.putAll(someAttributes);
74: expected.put("attName4", "attValue4");
75:
76: Map result = this .adder.mergeAttributes(someAttributes,
77: otherAttributes);
78: assertEquals(expected, result);
79: }
80:
81: /* (non-Javadoc)
82: * @see org.jasig.portal.services.persondir.support.merger.AttributeMergerAbstractTest#getAttributeMerger()
83: */
84: protected IAttributeMerger getAttributeMerger() {
85: return new NoncollidingAttributeAdder();
86: }
87:
88: }
|