1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/test/com/sun/xml/registry/ebxml/infomodel/ExtensibleObjectImplTest.java,v 1.3 2003/07/30 09:45:33 doballve Exp $ 3 * 4 * ==================================================================== 5 * 6 * This code is subject to the freebxml License, Version 1.1 7 * 8 * Copyright (c) 2003 freebxml.org. All rights reserved. 9 * 10 * ==================================================================== 11 */ 12 package com.sun.xml.registry.ebxml.infomodel; 13 14 import com.sun.xml.registry.ebxml.*; 15 import com.sun.xml.registry.ebxml.ApelonJAXRTestSetup; 16 import com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl; 17 import javax.xml.registry.*; 18 import javax.xml.registry.infomodel.*; 19 import java.util.*; 20 import com.sun.xml.registry.ebxml.util.I18nUtil; 21 import javax.xml.registry.JAXRException; 22 import junit.framework.*; 23 import junit.textui.TestRunner; 24 import org.oasis.ebxml.registry.bindings.rim.RegistryObjectType; 25 import org.oasis.ebxml.registry.bindings.rim.SlotType1; 26 27 /*** 28 * jUnit Test for ExtensibleObjectImpl. 29 * 30 * @author Diego Ballve / Republica Corp. 31 */ 32 public class ExtensibleObjectImplTest extends TestCase { 33 34 static ApelonJAXRTestSetup setup = null; 35 36 private final String slotName1 = "mySlotName1"; 37 private final String slotName2 = "mySlotName2"; 38 private final String slotName3 = "mySlotName3"; 39 private static Slot slot1 = null; 40 private static Slot slot2 = null; 41 private static Slot slot3 = null; 42 private static ExtensibleObjectImplImpl extObj = null; 43 44 public ExtensibleObjectImplTest(java.lang.String testName) { 45 super(testName); 46 } 47 48 public static void main(java.lang.String[] args) { 49 try { 50 TestRunner.run(suite()); 51 } catch (Throwable t) { 52 System.out.println("Throwable: " + t.getClass().getName() 53 + " Message: " + t.getMessage()); 54 t.printStackTrace(); 55 } 56 } 57 58 public static Test suite() throws Exception { 59 TestSuite suite = new TestSuite(ExtensibleObjectImplTest.class); 60 setup = new ApelonJAXRTestSetup(suite); 61 return setup; 62 } 63 64 protected void setUp() throws Exception { 65 super.setUp(); 66 Collection values = new ArrayList(); 67 values.add("value"); 68 slot1 = setup.getLCM().createSlot(slotName1, values, "type"); 69 slot2 = setup.getLCM().createSlot(slotName2, values, "type"); 70 slot3 = setup.getLCM().createSlot(slotName3, values, "type"); 71 extObj = new ExtensibleObjectImplImpl((LifeCycleManagerImpl)setup.getLCM()); 72 } 73 74 /*** Test of addSlot method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 75 public void testAddSlot() throws Exception { 76 System.out.println("testAddSlot"); 77 Slot slot; 78 79 extObj.addSlot(slot1); 80 slot = extObj.getSlot(slot1.getName()); 81 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot1); 82 83 extObj.addSlot(slot2); 84 slot = extObj.getSlot(slot2.getName()); 85 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot2); 86 slot = extObj.getSlot(slot1.getName()); 87 assertEquals("Previously inserted test slot missing.", slot, slot1); 88 89 try { 90 extObj.addSlot(slot1); 91 fail("Exception should have been thrown: Duplicate Slot name"); 92 } catch (JAXRException e) { 93 System.out.println("Attempt to add Slot with duplicate name catched with message: " + e.getMessage()); 94 } 95 } 96 97 /*** Test of getSlot method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 98 public void testGetSlot() throws Exception { 99 System.out.println("testGetSlot"); 100 Slot slot; 101 102 extObj.addSlot(slot1); 103 slot = extObj.getSlot(slot1.getName()); 104 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot1); 105 } 106 107 /*** Test of removeSlot method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 108 public void testRemoveSlot() throws Exception { 109 System.out.println("testRemoveSlot"); 110 Slot slot; 111 112 extObj.addSlot(slot1); 113 slot = extObj.getSlot(slot1.getName()); 114 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot1); 115 116 extObj.removeSlot(slot1.getName()); 117 slot = extObj.getSlot(slot1.getName()); 118 assertNull("getSlot should be null for Slot: " + slot1.getName(), slot); 119 120 extObj.addSlot(slot1); 121 slot = extObj.getSlot(slot1.getName()); 122 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot1); 123 extObj.addSlot(slot2); 124 slot = extObj.getSlot(slot2.getName()); 125 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot2); 126 127 extObj.removeSlot(slot1.getName()); 128 slot = extObj.getSlot(slot1.getName()); 129 assertNull("getSlot should be null for Slot: " + slot1.getName(), slot); 130 extObj.removeSlot(slot2.getName()); 131 slot = extObj.getSlot(slot1.getName()); 132 assertNull("getSlot should be null for Slot: " + slot1.getName(), slot); 133 extObj.removeSlot(slot1.getName()); 134 slot = extObj.getSlot(slot1.getName()); 135 assertNull("getSlot should be null for Slot: " + slot1.getName(), slot); 136 137 extObj.removeSlot("anotherName"); 138 } 139 140 /*** Test of addSlots method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 141 public void testAddSlots() throws Exception { 142 System.out.println("testAddSlots"); 143 Slot slot; 144 Collection slots; 145 146 slots = new ArrayList(); 147 slots.add(slot1); 148 slots.add(slot2); 149 150 extObj.addSlots(slots); 151 slot = extObj.getSlot(slot1.getName()); 152 assertEquals("Failed to retrive inserted Slot: " + slot1.getName(), slot, slot1); 153 slot = extObj.getSlot(slot2.getName()); 154 assertEquals("Failed to retrive inserted Slot: " + slot2.getName(), slot, slot2); 155 slot = extObj.getSlot(slot3.getName()); 156 assertNull("getSlot should be null for Slot: " + slot3.getName(), slot); 157 158 159 try { 160 slots = new ArrayList(); 161 slots.add(slot1); 162 slots.add(slot2); 163 slots.add(slot3); 164 extObj.addSlots(slots); 165 fail("Exception should have been thrown: Duplicate Slot names"); 166 } catch (JAXRException e) { 167 System.out.println("Attempt to add Slot with duplicate name catched with message: " + e.getMessage()); 168 slot = extObj.getSlot(slot3.getName()); 169 assertNull("getSlot should be null for Slot: " + slot3.getName(), slot); 170 } 171 172 try { 173 slots = new ArrayList(); 174 slots.add(slot3); 175 slots.add(slot3); 176 extObj.addSlots(slots); 177 fail("Exception should have been thrown: Duplicate Slot names"); 178 } catch (JAXRException e) { 179 System.out.println("Attempt to add Slot with duplicate name catched with message: " + e.getMessage()); 180 slot = extObj.getSlot(slot3.getName()); 181 assertNull("Duplicate Slot names not catched. getSlot should be null for Slot: " + slot3.getName(), slot); 182 } 183 184 slots = new ArrayList(); 185 slots.add(slot3); 186 extObj.addSlots(slots); 187 slot = extObj.getSlot(slot1.getName()); 188 assertEquals("Failed to retrive inserted Slot: " + slot1.getName(), slot, slot1); 189 slot = extObj.getSlot(slot2.getName()); 190 assertEquals("Failed to retrive inserted Slot: " + slot2.getName(), slot, slot2); 191 slot = extObj.getSlot(slot3.getName()); 192 assertEquals("getSlot should be nuul for Slot: " + slot3.getName(), slot, slot3); 193 } 194 195 /*** Test of getSlots method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 196 public void testGetSlots() throws Exception { 197 System.out.println("testGetSlots"); 198 Slot slot; 199 Collection slots, slots2; 200 201 slots2 = extObj.getSlots(); 202 assertTrue("Slots should have been initially empty.", slots2.isEmpty()); 203 204 slots = new ArrayList(); 205 slots.add(slot1); 206 slots.add(slot2); 207 slots.add(slot3); 208 209 extObj.addSlots(slots); 210 slot = extObj.getSlot(slot1.getName()); 211 assertEquals("Failed to retrive inserted Slot: " + slot1.getName(), slot, slot1); 212 slot = extObj.getSlot(slot2.getName()); 213 assertEquals("Failed to retrive inserted Slot: " + slot2.getName(), slot, slot2); 214 slot = extObj.getSlot(slot3.getName()); 215 assertEquals("Failed to retrive inserted Slot: " + slot3.getName(), slot, slot3); 216 217 slots2 = extObj.getSlots(); 218 assertTrue("Slots' Collection instances must be different.", slots != slots2); 219 assertEquals("Returned slots' Collection has different size.", slots.size(), slots2.size()); 220 Iterator it = slots.iterator(); 221 while (it.hasNext()) { 222 slot = (Slot)it.next(); 223 assertTrue("Missing inserted Slot in ComposedObjects: " + slot.getName(), slots2.contains(slot)); 224 } 225 } 226 227 /*** Test of removeSlots method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 228 public void testRemoveSlots() throws Exception { 229 System.out.println("testRemoveSlots"); 230 Slot slot; 231 Collection slotNames; 232 233 extObj.addSlot(slot1); 234 slot = extObj.getSlot(slot1.getName()); 235 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot1); 236 extObj.addSlot(slot2); 237 slot = extObj.getSlot(slot2.getName()); 238 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot2); 239 extObj.addSlot(slot3); 240 slot = extObj.getSlot(slot3.getName()); 241 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot3); 242 243 slotNames = new ArrayList(); 244 slotNames.add(slot1.getName()); 245 slotNames.add(slot2.getName()); 246 slotNames.add("anotherName"); 247 extObj.removeSlots(slotNames); 248 slot = extObj.getSlot(slot1.getName()); 249 assertNull("getSlot should be null for Slot: " + slot1.getName(), slot); 250 slot = extObj.getSlot(slot2.getName()); 251 assertNull("getSlot should be null for Slot: " + slot2.getName(), slot); 252 slot = extObj.getSlot(slot3.getName()); 253 assertEquals("Retrieved Slot is not the same as inserted.", slot, slot3); 254 } 255 256 /*** Test of getComposedObjects method, of class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. */ 257 public void testGetComposedObjects() throws Exception { 258 System.out.println("testGetComposedObjects"); 259 Slot slot; 260 Collection slots, compObjs; 261 262 compObjs= extObj.getSlots(); 263 assertTrue("Composed Objects should have been initially empty.", compObjs.isEmpty()); 264 265 slots = new ArrayList(); 266 slots.add(slot1); 267 slots.add(slot2); 268 slots.add(slot3); 269 270 extObj.addSlots(slots); 271 slot = extObj.getSlot(slot1.getName()); 272 assertEquals("Failed to retrive inserted Slot: " + slot1.getName(), slot, slot1); 273 slot = extObj.getSlot(slot2.getName()); 274 assertEquals("Failed to retrive inserted Slot: " + slot2.getName(), slot, slot2); 275 slot = extObj.getSlot(slot3.getName()); 276 assertEquals("Failed to retrive inserted Slot: " + slot3.getName(), slot, slot3); 277 278 compObjs = extObj.getSlots(); 279 assertEquals("ComposedObjects should contain the same objects as inserted Slots' Collection. Different size.", slots.size(), compObjs.size()); 280 Iterator it = slots.iterator(); 281 while (it.hasNext()) { 282 slot = (Slot)it.next(); 283 assertTrue("Missing inserted Slot in ComposedObjects: " + slot.getName(), compObjs.contains(slot)); 284 } 285 } 286 287 /*** Test of slot being owned by only 1 ExtensibleObjectImpl. */ 288 public void testOneParentPerSlot() throws Exception { 289 ExtensibleObject extObj2 = new ExtensibleObjectImplImpl((LifeCycleManagerImpl)setup.getLCM()); 290 extObj.addSlot(slot1); 291 try { 292 extObj2.addSlot(slot1); 293 fail("Exception should have been thrown: Multiple parents per Slot"); 294 } catch (InvalidRequestException e) { 295 System.out.println("Attempt to add Slot to 2nd parent catched with message: " + e.getMessage()); 296 } 297 extObj.removeSlot(slot1.getName()); 298 try { 299 extObj2.addSlot(slot1); 300 } catch (JAXRException e) { 301 fail("Slot should have no parent after being removed."); 302 } 303 } 304 305 306 /*** Generated implementation of abstract class com.sun.xml.registry.ebxml.infomodel.ExtensibleObjectImpl. Please fill dummy bodies of generated methods. */ 307 private class ExtensibleObjectImplImpl extends ExtensibleObjectImpl { 308 309 ExtensibleObjectImplImpl(LifeCycleManagerImpl lcm) { 310 super(lcm); 311 } 312 313 ExtensibleObjectImplImpl(LifeCycleManagerImpl lcm, RegistryObjectType ebObject) throws JAXRException { 314 super(lcm, ebObject); 315 } 316 317 } 318 319 public void tearDown() { 320 System.out.println(); 321 } 322 323 324 }

This page was automatically generated by Maven