1 23 24 package org.objectweb.fractal.julia.conform; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.factory.GenericFactory; 28 import org.objectweb.fractal.api.factory.InstantiationException; 29 import org.objectweb.fractal.api.type.TypeFactory; 30 import org.objectweb.fractal.api.type.InterfaceType; 31 import org.objectweb.fractal.api.type.ComponentType; 32 33 import org.objectweb.fractal.julia.conform.components.C; 34 import org.objectweb.fractal.julia.conform.components.I; 35 import org.objectweb.fractal.julia.conform.components.W; 36 import org.objectweb.fractal.julia.conform.components.X; 37 import org.objectweb.fractal.julia.conform.components.Y; 38 import org.objectweb.fractal.julia.conform.components.Z; 39 import org.objectweb.fractal.julia.conform.components.CAttributes; 40 41 import org.objectweb.fractal.util.Fractal; 42 43 import java.util.HashSet ; 44 import java.util.Arrays ; 45 46 public class TestGenericFactory extends Test { 47 48 protected Component boot; 49 protected TypeFactory tf; 50 protected GenericFactory gf; 51 52 protected ComponentType t, u; 53 54 protected final static String AC = "attribute-controller/"+PKG+".CAttributes/false,false,false"; 55 protected final static String sI = "server/"+PKG+".I/false,false,false"; 56 protected final static String cI = "client/"+PKG+".I/true,false,false"; 57 58 62 public TestGenericFactory (final String name) { 63 super(name); 64 } 65 66 protected void setUp () throws Exception { 67 boot = Fractal.getBootstrapComponent(); 68 tf = Fractal.getTypeFactory(boot); 69 gf = Fractal.getGenericFactory(boot); 70 t = tf.createFcType(new InterfaceType[] { 71 tf.createFcItfType("server", I.class.getName(), false, false, false), 72 tf.createFcItfType("client", I.class.getName(), true, false, false) 73 }); 74 u = tf.createFcType(new InterfaceType[] { 75 tf.createFcItfType("attribute-controller", CAttributes.class.getName(), false, false, false), 76 tf.createFcItfType("server", I.class.getName(), false, false, false), 77 tf.createFcItfType("client", I.class.getName(), true, false, false) 78 }); 79 } 80 81 85 public void testFPrimitive () throws Exception { 86 Component c = gf.newFcInstance(t, "flatPrimitive", C.class.getName()); 87 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 88 COMP, BC, LC, NC, sI, cI 89 }))); 90 } 91 92 public void testFParametricPrimitive () throws Exception { 93 Component c = gf.newFcInstance(u, "flatParametricPrimitive", C.class.getName()); 94 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 95 COMP, BC, LC, AC, NC, sI, cI 96 }))); 97 } 98 99 public void testPrimitive () throws Exception { 100 Component c = gf.newFcInstance(t, "primitive", C.class.getName()); 101 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 102 COMP, BC, LC, SC, NC, sI, cI 103 }))); 104 } 105 106 public void testParametricPrimitive () throws Exception { 107 Component c = gf.newFcInstance(u, "parametricPrimitive", C.class.getName()); 108 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 109 COMP, BC, LC, SC, AC, NC, sI, cI 110 }))); 111 } 112 113 public void testComposite () throws Exception { 114 Component c = gf.newFcInstance(t, "composite", null); 115 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 116 COMP, BC, CC, LC, SC, NC, sI, cI 117 }))); 118 } 119 120 public void testParametricComposite () throws Exception { 121 Component c = gf.newFcInstance(u, "parametricComposite", C.class.getName()); 122 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 123 COMP, BC, CC, LC, SC, AC, NC, sI, cI 124 }))); 125 } 126 127 131 public void testFPrimitiveTemplate () throws Exception { 132 Component c = gf.newFcInstance( 133 t, "flatPrimitiveTemplate", new Object [] { "flatPrimitive", C.class.getName() }); 134 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 135 COMP, BC, F, NC, sI, cI 136 }))); 137 c = Fractal.getFactory(c).newFcInstance(); 138 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 139 COMP, BC, LC, NC, sI, cI 140 }))); 141 } 142 143 public void testFParametricPrimitiveTemplate () throws Exception { 144 Component c = gf.newFcInstance( 145 u, "flatParametricPrimitiveTemplate", new Object [] { "flatParametricPrimitive", C.class.getName() }); 146 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 147 COMP, BC, F, AC, NC, sI, cI 148 }))); 149 c = Fractal.getFactory(c).newFcInstance(); 150 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 151 COMP, BC, LC, AC, NC, sI, cI 152 }))); 153 } 154 155 public void testPrimitiveTemplate () throws Exception { 156 Component c = gf.newFcInstance( 157 t, "primitiveTemplate", new Object [] { "primitive", C.class.getName() }); 158 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 159 COMP, BC, F, SC, NC, sI, cI 160 }))); 161 c = Fractal.getFactory(c).newFcInstance(); 162 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 163 COMP, BC, LC, SC, NC, sI, cI 164 }))); 165 } 166 167 public void testParametricPrimitiveTemplate () throws Exception { 168 Component c = gf.newFcInstance( 169 u, "parametricPrimitiveTemplate", new Object [] { "parametricPrimitive", C.class.getName() }); 170 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 171 COMP, BC, F, SC, AC, NC, sI, cI 172 }))); 173 c = Fractal.getFactory(c).newFcInstance(); 174 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 175 COMP, BC, LC, SC, AC, NC, sI, cI 176 }))); 177 } 178 179 public void testCompositeTemplate () throws Exception { 180 Component c = gf.newFcInstance( 181 t, "compositeTemplate", new Object [] { "composite", null }); 182 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 183 COMP, BC, CC, F, SC, NC, sI, cI 184 }))); 185 c = Fractal.getFactory(c).newFcInstance(); 186 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 187 COMP, BC, CC, LC, SC, NC, sI, cI 188 }))); 189 } 190 191 public void testParametricCompositeTemplate () throws Exception { 192 Component c = gf.newFcInstance( 193 u, "parametricCompositeTemplate", new Object [] { "parametricComposite", C.class.getName() }); 194 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 195 COMP, BC, CC, F, SC, AC, NC, sI, cI 196 }))); 197 c = Fractal.getFactory(c).newFcInstance(); 198 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 199 COMP, BC, CC, LC, SC, AC, NC, sI, cI 200 }))); 201 } 202 203 207 public void testUnknownControllerDescriptor () throws Exception { 208 try { 209 gf.newFcInstance(t, "unknownDescriptor", C.class.getName()); 211 fail(); 212 } catch (InstantiationException e) { 213 } 214 } 215 216 public void testBadControllerDescriptor1 () throws Exception { 217 try { 218 gf.newFcInstance(t, "badPrimitive", C.class.getName()); 220 fail(); 221 } catch (InstantiationException e) { 222 } 223 } 224 225 public void testBadControllerDescriptor2 () throws Exception { 226 try { 227 gf.newFcInstance(u, "badParametricPrimitive", C.class.getName()); 229 fail(); 230 } catch (InstantiationException e) { 231 } 232 } 233 234 public void testContentClassNotFound () throws Exception { 235 try { 236 gf.newFcInstance(t, "primitive", "UnknownClass"); 238 fail(); 239 } catch (InstantiationException e) { 240 } 241 } 242 243 public void testContentClassAbstract () throws Exception { 244 try { 245 gf.newFcInstance(t, "primitive", W.class.getName()); 247 fail(); 248 } catch (InstantiationException e) { 249 } 250 } 251 252 public void testContentClassNoDefaultConstructor () throws Exception { 253 try { 254 gf.newFcInstance(t, "primitive", X.class.getName()); 256 fail(); 257 } catch (InstantiationException e) { 258 } 259 } 260 261 public void testContentClassControlInterfaceMissing () throws Exception { 262 try { 263 gf.newFcInstance(t, "primitive", Y.class.getName()); 265 fail(); 266 } catch (InstantiationException e) { 267 } 268 } 269 270 public void testContentClassInterfaceMissing () throws Exception { 271 try { 272 gf.newFcInstance(t, "primitive", Z.class.getName()); 274 fail(); 275 } catch (InstantiationException e) { 276 } 277 } 278 279 public void testTemplateContentClassNotFound () throws Exception { 280 try { 281 gf.newFcInstance( 283 t, "primitiveTemplate", new Object [] { "primitive", "UnknownClass" }); 284 fail(); 285 } catch (InstantiationException e) { 286 } 287 } 288 289 public void testTemplateContentClassAbstract () throws Exception { 290 try { 291 gf.newFcInstance( 293 t, "primitiveTemplate", new Object [] { "primitive", W.class.getName() }); 294 fail(); 295 } catch (InstantiationException e) { 296 } 297 } 298 299 public void testTemplateContentClassNoDefaultConstructor () throws Exception { 300 try { 301 gf.newFcInstance( 303 t, "primitiveTemplate", new Object [] { "primitive", X.class.getName() }); 304 fail(); 305 } catch (InstantiationException e) { 306 } 307 } 308 309 public void testTemplateContentClassControlInterfaceMissing () throws Exception { 310 try { 311 gf.newFcInstance( 313 t, "primitiveTemplate", new Object [] { "primitive", Y.class.getName() }); 314 fail(); 315 } catch (InstantiationException e) { 316 } 317 } 318 319 public void testTemplateContentClassInterfaceMissing () throws Exception { 320 try { 321 gf.newFcInstance( 323 t, "primitiveTemplate", new Object [] { "primitive", Z.class.getName() }); 324 fail(); 325 } catch (InstantiationException e) { 326 } 327 } 328 } 329 | Popular Tags |