1 23 24 package org.objectweb.fractal.julia.conform; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.Interface; 28 import org.objectweb.fractal.api.NoSuchInterfaceException; 29 import org.objectweb.fractal.api.control.ContentController; 30 import org.objectweb.fractal.api.factory.GenericFactory; 31 import org.objectweb.fractal.api.type.TypeFactory; 32 import org.objectweb.fractal.api.type.ComponentType; 33 import org.objectweb.fractal.api.type.InterfaceType; 34 35 import org.objectweb.fractal.julia.conform.components.C; 36 import org.objectweb.fractal.julia.conform.components.I; 37 38 import org.objectweb.fractal.util.Fractal; 39 40 import java.util.HashSet ; 41 import java.util.Arrays ; 42 43 public class TestCollection extends Test { 44 45 protected Component boot; 46 protected TypeFactory tf; 47 protected GenericFactory gf; 48 49 protected ComponentType t; 50 51 protected final static String serverI = "server/"+PKG+".I/false,false,false"; 52 protected final static String servers0I = "servers0/"+PKG+".I/false,false,true"; 53 protected final static String servers1I = "servers1/"+PKG+".I/false,false,true"; 54 protected final static String servers2I = "servers2/"+PKG+".I/true,false,true"; 55 protected final static String servers3I = "servers3/"+PKG+".I/true,false,true"; 56 protected final static String clientI = "client/"+PKG+".I/true,true,false"; 57 protected final static String clients0I = "clients0/"+PKG+".I/true,true,true"; 58 protected final static String clients1I = "clients1/"+PKG+".I/true,true,true"; 59 protected final static String clients2I = "clients2/"+PKG+".I/false,true,true"; 60 protected final static String clients3I = "clients3/"+PKG+".I/false,true,true"; 61 62 66 public TestCollection (final String name) { 67 super(name); 68 } 69 70 protected void setUp () throws Exception { 71 boot = Fractal.getBootstrapComponent(); 72 tf = Fractal.getTypeFactory(boot); 73 gf = Fractal.getGenericFactory(boot); 74 t = tf.createFcType(new InterfaceType[] { 75 tf.createFcItfType("server", I.class.getName(), false, false, false), 76 tf.createFcItfType("servers", I.class.getName(), false, false, true), 77 tf.createFcItfType("client", I.class.getName(), true, true, false), 78 tf.createFcItfType("clients", I.class.getName(), true, true, true) 79 }); 80 } 81 82 86 public void testPrimitiveWithCollection () throws Exception { 87 Component c = gf.newFcInstance(t, "primitive", C.class.getName()); 88 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 89 COMP, BC, LC, SC, NC, serverI, clientI 90 }))); 91 } 92 93 public void testCompositeWithCollection () throws Exception { 94 Component c = gf.newFcInstance(t, "composite", null); 95 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 96 COMP, BC, CC, LC, SC, NC, serverI, clientI 97 }))); 98 } 99 100 public void testPrimitiveTemplateWithCollection () throws Exception { 101 Component c = gf.newFcInstance( 102 t, "primitiveTemplate", new Object [] { "primitive", C.class.getName() }); 103 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 104 COMP, BC, F, SC, NC, serverI, clientI 105 }))); 106 c = Fractal.getFactory(c).newFcInstance(); 107 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 108 COMP, BC, LC, SC, NC, serverI, clientI 109 }))); 110 } 111 112 public void testCompositeTemplateWithCollection () throws Exception { 113 Component c = gf.newFcInstance( 114 t, "compositeTemplate", new Object [] { "composite", null }); 115 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 116 COMP, BC, CC, F, SC, NC, serverI, clientI 117 }))); 118 c = Fractal.getFactory(c).newFcInstance(); 119 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 120 COMP, BC, CC, LC, SC, NC, serverI, clientI 121 }))); 122 } 123 124 128 public void testPrimitiveGetFcInterface () throws Exception { 129 Component c = gf.newFcInstance(t, "primitive", C.class.getName()); 130 Fractal.getLifeCycleController(c).startFc(); 131 Interface i; 132 i = (Interface)c.getFcInterface("servers0"); 133 assertEquals("Bad interface", servers0I, getItf(i, false)); 134 checkInterface((I)i); 135 i = (Interface)c.getFcInterface("servers1"); 136 assertEquals("Bad interface", servers1I, getItf(i, false)); 137 checkInterface((I)i); 138 i = (Interface)c.getFcInterface("clients0"); 139 assertEquals("Bad interface", clients0I, getItf(i, false)); 140 i = (Interface)c.getFcInterface("clients1"); 141 assertEquals("Bad interface", clients1I, getItf(i, false)); 142 } 143 144 public void testCompositeGetFcInterface () throws Exception { 145 Component c = gf.newFcInstance(t, "composite", null); 146 Interface i; 147 i = (Interface)c.getFcInterface("servers0"); 148 assertEquals("Bad interface", servers0I, getItf(i, false)); 149 i = (Interface)c.getFcInterface("servers1"); 150 assertEquals("Bad interface", servers1I, getItf(i, false)); 151 i = (Interface)c.getFcInterface("clients0"); 152 assertEquals("Bad interface", clients0I, getItf(i, false)); 153 i = (Interface)c.getFcInterface("clients1"); 154 assertEquals("Bad interface", clients1I, getItf(i, false)); 155 156 ContentController cc = Fractal.getContentController(c); 157 i = (Interface)cc.getFcInternalInterface("servers2"); 158 assertEquals("Bad interface", servers2I, getItf(i, false)); 159 i = (Interface)cc.getFcInternalInterface("servers3"); 160 assertEquals("Bad interface", servers3I, getItf(i, false)); 161 i = (Interface)cc.getFcInternalInterface("clients2"); 162 assertEquals("Bad interface", clients2I, getItf(i, false)); 163 i = (Interface)cc.getFcInternalInterface("clients3"); 164 assertEquals("Bad interface", clients3I, getItf(i, false)); 165 } 166 167 public void testPrimitiveTemplateGetFcInterface () throws Exception { 168 Component c = gf.newFcInstance( 169 t, "primitiveTemplate", new Object [] { "primitive", C.class.getName() }); 170 Interface i; 171 i = (Interface)c.getFcInterface("servers0"); 172 assertEquals("Bad interface", servers0I, getItf(i, false)); 173 i = (Interface)c.getFcInterface("servers1"); 174 assertEquals("Bad interface", servers1I, getItf(i, false)); 175 i = (Interface)c.getFcInterface("clients0"); 176 assertEquals("Bad interface", clients0I, getItf(i, false)); 177 i = (Interface)c.getFcInterface("clients1"); 178 assertEquals("Bad interface", clients1I, getItf(i, false)); 179 180 c = Fractal.getFactory(c).newFcInstance(); 181 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 182 COMP, BC, LC, SC, NC, serverI, clientI 183 }))); 184 } 185 186 public void testCompositeTemplateGetFcInterface () throws Exception { 187 Component c = gf.newFcInstance( 188 t, "compositeTemplate", new Object [] { "composite", null }); 189 Interface i; 190 i = (Interface)c.getFcInterface("servers0"); 191 assertEquals("Bad interface", servers0I, getItf(i, false)); 192 i = (Interface)c.getFcInterface("servers1"); 193 assertEquals("Bad interface", servers1I, getItf(i, false)); 194 i = (Interface)c.getFcInterface("clients0"); 195 assertEquals("Bad interface", clients0I, getItf(i, false)); 196 i = (Interface)c.getFcInterface("clients1"); 197 assertEquals("Bad interface", clients1I, getItf(i, false)); 198 199 ContentController cc = Fractal.getContentController(c); 200 i = (Interface)cc.getFcInternalInterface("servers2"); 201 assertEquals("Bad interface", servers2I, getItf(i, false)); 202 i = (Interface)cc.getFcInternalInterface("servers3"); 203 assertEquals("Bad interface", servers3I, getItf(i, false)); 204 i = (Interface)cc.getFcInternalInterface("clients2"); 205 assertEquals("Bad interface", clients2I, getItf(i, false)); 206 i = (Interface)cc.getFcInternalInterface("clients3"); 207 assertEquals("Bad interface", clients3I, getItf(i, false)); 208 209 c = Fractal.getFactory(c).newFcInstance(); 210 checkComponent(c, new HashSet (Arrays.asList(new Object [] { 211 COMP, BC, CC, LC, SC, NC, serverI, clientI 212 }))); 213 } 214 215 219 public void testPrimitiveNoSuchCollectionItf () throws Exception { 220 Component c = gf.newFcInstance(t, "primitive", C.class.getName()); 221 try { 222 c.getFcInterface("server0"); 223 fail(); 224 } catch (NoSuchInterfaceException e) { 225 } 226 try { 227 c.getFcInterface("client0"); 228 fail(); 229 } catch (NoSuchInterfaceException e) { 230 } 231 } 232 233 public void testCompositeNoSuchCollectionItf () throws Exception { 234 Component c = gf.newFcInstance(t, "composite", null); 235 try { 236 c.getFcInterface("server0"); 237 fail(); 238 } catch (NoSuchInterfaceException e) { 239 } 240 try { 241 c.getFcInterface("client0"); 242 fail(); 243 } catch (NoSuchInterfaceException e) { 244 } 245 } 246 247 public void testPrimitiveTemplateNoSuchCollectionItf () throws Exception { 248 Component c = gf.newFcInstance( 249 t, "primitiveTemplate", new Object [] { "primitive", C.class.getName() }); 250 try { 251 c.getFcInterface("server0"); 252 fail(); 253 } catch (NoSuchInterfaceException e) { 254 } 255 try { 256 c.getFcInterface("client0"); 257 fail(); 258 } catch (NoSuchInterfaceException e) { 259 } 260 } 261 262 public void testCompositeTemplateNoSuchCollectionItf () throws Exception { 263 Component c = gf.newFcInstance( 264 t, "compositeTemplate", new Object [] { "composite", null }); 265 try { 266 c.getFcInterface("server0"); 267 fail(); 268 } catch (NoSuchInterfaceException e) { 269 } 270 try { 271 c.getFcInterface("client0"); 272 fail(); 273 } catch (NoSuchInterfaceException e) { 274 } 275 } 276 } 277 | Popular Tags |