1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ws.scout.registry.infomodel;
18
19 import java.util.Collection;
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import javax.xml.registry.JAXRException;
24 import javax.xml.registry.infomodel.ExtensibleObject;
25 import javax.xml.registry.infomodel.Slot;
26
27 import junit.framework.TestCase;
28
29
30
31
32 public class ExtensibleObjectTest extends TestCase {
33 private ExtensibleObject eo;
34 private Slot slot;
35 private Slot slot2;
36
37 public void testAddSlot() throws JAXRException {
38 eo.addSlot(slot2);
39 assertEquals(2, eo.getSlots().size());
40 assertTrue(eo.getSlots().contains(slot));
41 assertTrue(eo.getSlots().contains(slot2));
42 }
43
44 public void testAddSlots() throws JAXRException {
45 Set<Slot> slots = new HashSet<Slot>();
46 slots.add(slot);
47 slots.add(slot2);
48 eo.addSlots(slots);
49 assertEquals(slots, new HashSet<Slot>(eo.getSlots()));
50 }
51
52 public void testGetSlot() throws JAXRException {
53 assertEquals(slot, eo.getSlot("MockSlot"));
54 }
55
56 public void testGetSlots() throws JAXRException {
57 Collection slots = eo.getSlots();
58 assertEquals(1, slots.size());
59 assertTrue(slots.contains(slot));
60 }
61
62 public void testRemoveSlot() throws JAXRException {
63 eo.removeSlot("MockSlot");
64 assertTrue(eo.getSlots().isEmpty());
65 }
66
67 public void testRemoveSlotWithOneRemaining() throws JAXRException {
68 eo.addSlot(slot2);
69 eo.removeSlot("MockSlot");
70 Collection slots = eo.getSlots();
71 assertEquals(1, slots.size());
72 assertFalse(slots.contains(slot));
73 assertTrue(slots.contains(slot2));
74 }
75
76 public void testRemoveSlots() throws JAXRException {
77 MockSlot slot3 = new MockSlot("MockSlot3");
78 eo.addSlot(slot2);
79 eo.addSlot(slot3);
80 Collection<String> slotNames = new HashSet<String>();
81 slotNames.add(slot2.getName());
82 slotNames.add("MockSlot4");
83 eo.removeSlots(slotNames);
84 Collection<Slot> slots = eo.getSlots();
85 assertEquals(2, slots.size());
86 assertTrue(slots.contains(slot));
87 assertFalse(slots.contains(slot2));
88 assertTrue(slots.contains(slot3));
89 }
90
91 public void setUp() throws Exception {
92 super.setUp();
93 eo = new TestObject();
94 slot = new MockSlot("MockSlot");
95 eo.addSlot(slot);
96 slot2 = new MockSlot("MockSlot2");
97 }
98
99 private static class TestObject extends ExtensibleObjectImpl {
100 }
101
102 private class MockSlot implements Slot {
103 private String name;
104
105 public MockSlot(String name) {
106 this.name = name;
107 }
108
109 public String getName() throws JAXRException {
110 return name;
111 }
112
113 public String getSlotType() throws JAXRException {
114 return null;
115 }
116
117 public Collection<String> getValues() throws JAXRException {
118 return null;
119 }
120
121 public void setName(String name) throws JAXRException {
122 }
123
124 public void setSlotType(String slotType) throws JAXRException {
125 }
126
127 public void setValues(Collection values) throws JAXRException {
128 }
129 }
130 }