001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.registry.infomodel;
017:
018: import java.util.Collection;
019: import java.util.HashSet;
020: import java.util.Set;
021:
022: import javax.xml.registry.JAXRException;
023: import javax.xml.registry.infomodel.ExtensibleObject;
024: import javax.xml.registry.infomodel.Slot;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * @version $Revision$ $Date$
030: */
031: public class ExtensibleObjectTest extends TestCase {
032: private ExtensibleObject eo;
033: private Slot slot;
034: private Slot slot2;
035:
036: public void testAddSlot() throws JAXRException {
037: eo.addSlot(slot2);
038: assertEquals(2, eo.getSlots().size());
039: assertTrue(eo.getSlots().contains(slot));
040: assertTrue(eo.getSlots().contains(slot2));
041: }
042:
043: public void testAddSlots() throws JAXRException {
044: Set<Slot> slots = new HashSet<Slot>();
045: slots.add(slot);
046: slots.add(slot2);
047: eo.addSlots(slots);
048: assertEquals(slots, new HashSet<Slot>(eo.getSlots()));
049: }
050:
051: public void testGetSlot() throws JAXRException {
052: assertEquals(slot, eo.getSlot("MockSlot"));
053: }
054:
055: public void testGetSlots() throws JAXRException {
056: Collection slots = eo.getSlots();
057: assertEquals(1, slots.size());
058: assertTrue(slots.contains(slot));
059: }
060:
061: public void testRemoveSlot() throws JAXRException {
062: eo.removeSlot("MockSlot");
063: assertTrue(eo.getSlots().isEmpty());
064: }
065:
066: public void testRemoveSlotWithOneRemaining() throws JAXRException {
067: eo.addSlot(slot2);
068: eo.removeSlot("MockSlot");
069: Collection slots = eo.getSlots();
070: assertEquals(1, slots.size());
071: assertFalse(slots.contains(slot));
072: assertTrue(slots.contains(slot2));
073: }
074:
075: public void testRemoveSlots() throws JAXRException {
076: MockSlot slot3 = new MockSlot("MockSlot3");
077: eo.addSlot(slot2);
078: eo.addSlot(slot3);
079: Collection<String> slotNames = new HashSet<String>();
080: slotNames.add(slot2.getName());
081: slotNames.add("MockSlot4");
082: eo.removeSlots(slotNames);
083: Collection<Slot> slots = eo.getSlots();
084: assertEquals(2, slots.size());
085: assertTrue(slots.contains(slot));
086: assertFalse(slots.contains(slot2));
087: assertTrue(slots.contains(slot3));
088: }
089:
090: public void setUp() throws Exception {
091: super .setUp();
092: eo = new TestObject();
093: slot = new MockSlot("MockSlot");
094: eo.addSlot(slot);
095: slot2 = new MockSlot("MockSlot2");
096: }
097:
098: private static class TestObject extends ExtensibleObjectImpl {
099: }
100:
101: private class MockSlot implements Slot {
102: private String name;
103:
104: public MockSlot(String name) {
105: this .name = name;
106: }
107:
108: public String getName() throws JAXRException {
109: return name;
110: }
111:
112: public String getSlotType() throws JAXRException {
113: return null;
114: }
115:
116: public Collection<String> getValues() throws JAXRException {
117: return null;
118: }
119:
120: public void setName(String name) throws JAXRException {
121: }
122:
123: public void setSlotType(String slotType) throws JAXRException {
124: }
125:
126: public void setValues(Collection values) throws JAXRException {
127: }
128: }
129: }
|