01: /**
02: *
03: * Copyright 2004 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.ws.scout.registry.infomodel;
17:
18: import java.util.ArrayList;
19: import java.util.Collection;
20: import java.util.HashSet;
21:
22: import javax.xml.registry.JAXRException;
23: import javax.xml.registry.infomodel.Slot;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * @version $Rev$ $Date$
29: */
30: public class SlotTest extends TestCase {
31: private Slot slot;
32:
33: public void testEmptySlot() throws JAXRException {
34: slot = new SlotImpl();
35: assertNull(slot.getName());
36: assertNull(slot.getSlotType());
37: assertNotNull(slot.getValues()); // values may be empty but not null
38: assertTrue(slot.getValues().isEmpty());
39: }
40:
41: public void testName() throws JAXRException {
42: slot.setName("Test Name");
43: assertEquals("Test Name", slot.getName());
44: }
45:
46: public void testType() throws JAXRException {
47: slot.setSlotType("Test Type");
48: assertEquals("Test Type", slot.getSlotType());
49: }
50:
51: public void testValues() throws JAXRException {
52: // check duplicate values are removed
53: Collection<String> values = new ArrayList<String>();
54: values.add("Value 1");
55: values.add("Value 2");
56: values.add("Value 2");
57: slot.setValues(values);
58:
59: values = new HashSet<String>();
60: values.add("Value 1");
61: values.add("Value 2");
62: assertEquals(values, slot.getValues());
63: }
64:
65: public void testNullValues() throws JAXRException {
66: try {
67: slot.setValues(null);
68: fail("Expected IllegalArgumentException");
69: } catch (IllegalArgumentException e) {
70: // ok
71: }
72: }
73:
74: public void testEquals() throws JAXRException {
75: Slot slot1 = new SlotImpl();
76: Slot slot2 = new SlotImpl();
77: assertTrue(slot1.equals(slot2));
78: slot1.setName("test");
79: assertFalse(slot1.equals(slot2));
80: slot2.setName("test");
81: assertTrue(slot1.equals(slot2));
82: slot1.setName(null);
83: assertFalse(slot1.equals(slot2));
84: }
85:
86: protected void setUp() throws Exception {
87: super .setUp();
88: slot = new SlotImpl();
89: }
90: }
|