1 19 package org.enhydra.zeus.binding; 20 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 29 import org.enhydra.zeus.AbstractBindingTest; 30 import org.enhydra.zeus.Binding; 31 32 45 public abstract class AbstractContainerTest extends AbstractBindingTest { 46 47 55 protected abstract Container createContainer(); 56 57 64 public AbstractContainerTest(String name) { 65 super(name); 66 } 67 68 77 public static Test suite() { 78 return new TestSuite(AbstractContainerTest.class); 79 } 80 81 89 public Binding createBinding() { 90 91 return createContainer(); 93 } 94 95 100 public void testAddProperty() { 101 Container container = createContainer(); 102 Property property = new AtomicProperty("xmlName", "xmlType"); 103 container.addProperty(property); 104 105 109 List properties = container.getProperties(); 110 boolean hasProperty = false; 111 for (Iterator i = properties.iterator(); i.hasNext(); ) { 112 Property p = (Property)i.next(); 113 if (p.getXMLName().equals(property.getXMLName())) { 114 hasProperty = true; 115 break; 116 } 117 } 118 assertTrue(hasProperty); 119 } 120 121 126 public void testRemoveProperty() { 127 Container container = createContainer(); 128 Property property = new AtomicProperty("xmlName", "xmlType"); 129 property.setJavaName("javaName"); 130 container.addProperty(property); 131 container.removeProperty(property.getJavaName()); 132 133 137 List properties = container.getProperties(); 138 139 boolean removedProperty = true; 140 for (Iterator i = properties.iterator(); i.hasNext(); ) { 141 Property p = (Property)i.next(); 142 if (p.getXMLName().equals(property.getXMLName())) { 143 removedProperty = false; 144 break; 145 } 146 } 147 assertTrue(removedProperty); 148 } 149 150 155 public void testGetProperties() { 156 Container container = createContainer(); 157 Property property1 = new AtomicProperty("xmlName1", "xmlType1"); 158 Property property2 = new AtomicProperty("xmlName2", "xmlType2"); 159 container.addProperty(property1); 160 container.addProperty(property2); 161 162 List properties = container.getProperties(); 163 boolean hasProperty1 = false; 164 boolean hasProperty2 = false; 165 for (Iterator i = properties.iterator(); i.hasNext(); ) { 166 Property p = (Property)i.next(); 167 if (p.getXMLName().equals(property1.getXMLName())) { 168 hasProperty1 = true; 169 } else if (p.getXMLName().equals(property2.getXMLName())) { 170 hasProperty2 = true; 171 } 172 } 173 assertTrue(hasProperty1 && hasProperty2); 174 } 175 176 179 public void testSetProperties() { 180 Container container = createContainer(); 181 Property property1 = new AtomicProperty("xmlName1", "xmlType1"); 182 Property property2 = new AtomicProperty("xmlName2", "xmlType2"); 183 List properties = new LinkedList (); 184 properties.add(property1); 185 properties.add(property2); 186 container.setProperties(properties); 187 188 List containerProperties = container.getProperties(); 189 boolean hasProperty1 = false; 190 boolean hasProperty2 = false; 191 boolean hasOtherProperties = false; 192 for (Iterator i = containerProperties.iterator(); i.hasNext(); ) { 193 Property property = (Property)i.next(); 194 if (property.getXMLName().equals(property1.getXMLName())) { 195 hasProperty1 = true; 196 } else if (property.getXMLName().equals(property2.getXMLName())) { 197 hasProperty2 = true; 198 } else { 199 hasOtherProperties = true; 200 } 201 } 202 assertTrue(hasProperty1 && hasProperty2 && !hasOtherProperties); 203 } 204 205 208 public void testClearProperties() { 209 Container container = createContainer(); 210 Property property1 = new AtomicProperty("xmlName1", "xmlType1"); 211 Property property2 = new AtomicProperty("xmlName2", "xmlType2"); 212 container.addProperty(property1); 213 container.addProperty(property2); 214 container.clearProperties(); 215 216 List properties = container.getProperties(); 217 assertTrue(properties.size() == 0); 218 } 219 } 220 | Popular Tags |