This project has retired. For details please refer to its Attic page.
SlotTest xref
View Javadoc
1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     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   */
17  package org.apache.ws.scout.registry.infomodel;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.HashSet;
22  
23  import javax.xml.registry.JAXRException;
24  import javax.xml.registry.infomodel.Slot;
25  
26  import junit.framework.TestCase;
27  
28  /**
29   * @version $Rev$ $Date$
30   */
31  public class SlotTest extends TestCase {
32      private Slot slot;
33  
34      public void testEmptySlot() throws JAXRException {
35          slot = new SlotImpl();
36          assertNull(slot.getName());
37          assertNull(slot.getSlotType());
38          assertNotNull(slot.getValues()); // values may be empty but not null
39          assertTrue(slot.getValues().isEmpty());
40      }
41  
42      public void testName() throws JAXRException {
43          slot.setName("Test Name");
44          assertEquals("Test Name", slot.getName());
45      }
46  
47      public void testType() throws JAXRException {
48          slot.setSlotType("Test Type");
49          assertEquals("Test Type", slot.getSlotType());
50      }
51  
52      public void testValues() throws JAXRException {
53          // check duplicate values are removed
54          Collection<String> values = new ArrayList<String>();
55          values.add("Value 1");
56          values.add("Value 2");
57          values.add("Value 2");
58          slot.setValues(values);
59  
60          values = new HashSet<String>();
61          values.add("Value 1");
62          values.add("Value 2");
63          assertEquals(values, slot.getValues());
64      }
65  
66      public void testNullValues() throws JAXRException {
67          try {
68              slot.setValues(null);
69              fail("Expected IllegalArgumentException");
70          } catch (IllegalArgumentException e) {
71              // ok
72          }
73      }
74  
75      public void testEquals() throws JAXRException {
76          Slot slot1 = new SlotImpl();
77          Slot slot2 = new SlotImpl();
78          assertTrue(slot1.equals(slot2));
79          slot1.setName("test");
80          assertFalse(slot1.equals(slot2));
81          slot2.setName("test");
82          assertTrue(slot1.equals(slot2));
83          slot1.setName(null);
84          assertFalse(slot1.equals(slot2));
85      }
86  
87      protected void setUp() throws Exception {
88          super.setUp();
89          slot = new SlotImpl();
90      }
91  }