1 23 24 package org.objectweb.fractal.julia.conform; 25 26 import org.objectweb.fractal.api.type.InterfaceType; 27 import org.objectweb.fractal.api.type.TypeFactory; 28 import org.objectweb.fractal.api.type.ComponentType; 29 import org.objectweb.fractal.api.Component; 30 import org.objectweb.fractal.api.control.ContentController; 31 import org.objectweb.fractal.api.control.IllegalContentException; 32 import org.objectweb.fractal.api.factory.GenericFactory; 33 34 import org.objectweb.fractal.julia.conform.components.I; 35 import org.objectweb.fractal.julia.conform.components.C; 36 37 import org.objectweb.fractal.util.Fractal; 38 39 import java.util.Arrays ; 40 41 public class TestContentController extends Test { 42 43 protected Component boot; 44 protected TypeFactory tf; 45 protected GenericFactory gf; 46 47 protected ComponentType t; 48 protected Component c, d, e; 49 50 54 public TestContentController (final String name) { 55 super(name); 56 } 57 58 protected void setUp () throws Exception { 59 boot = Fractal.getBootstrapComponent(); 60 tf = Fractal.getTypeFactory(boot); 61 gf = Fractal.getGenericFactory(boot); 62 t = tf.createFcType(new InterfaceType[] { 63 tf.createFcItfType("server", I.class.getName(), false, false, false), 64 tf.createFcItfType("client", I.class.getName(), true, true, false) 65 }); 66 setUpComponents(); 67 } 68 69 protected void setUpComponents () throws Exception { 70 c = gf.newFcInstance(t, "composite", null); 71 d = gf.newFcInstance(t, "composite", null); 72 e = gf.newFcInstance(t, "primitive", C.class.getName()); 73 } 74 75 79 public void testAddAndRemove () throws Exception { 80 ContentController cc = Fractal.getContentController(c); 81 cc.addFcSubComponent(e); 82 assertTrue(Arrays.asList(cc.getFcSubComponents()).contains(e)); 83 cc.removeFcSubComponent(e); 84 assertTrue(!Arrays.asList(cc.getFcSubComponents()).contains(e)); 85 } 86 87 91 public void testAlreadySubComponent () throws Exception { 92 ContentController cc = Fractal.getContentController(c); 93 cc.addFcSubComponent(e); 94 try { 95 cc.addFcSubComponent(e); 96 fail(); 97 } catch (IllegalContentException e) { 98 } 99 } 100 101 public void testWouldCreateCycle1 () throws Exception { 102 ContentController cc = Fractal.getContentController(c); 103 try { 104 cc.addFcSubComponent(c); 105 fail(); 106 } catch (IllegalContentException e) { 107 } 108 } 109 110 public void testWouldCreateCycle2 () throws Exception { 111 ContentController cc = Fractal.getContentController(c); 112 ContentController cd = Fractal.getContentController(d); 113 cc.addFcSubComponent(d); 114 try { 115 cd.addFcSubComponent(c); 116 fail(); 117 } catch (IllegalContentException e) { 118 } 119 } 120 121 125 public void testNotASubComponent () throws Exception { 126 ContentController cc = Fractal.getContentController(c); 127 try { 128 cc.removeFcSubComponent(d); 129 fail(); 130 } catch (IllegalContentException e) { 131 } 132 } 133 134 public void testWouldCreateNonLocalExportBinding () throws Exception { 135 ContentController cc = Fractal.getContentController(c); 136 cc.addFcSubComponent(e); 137 Fractal.getBindingController(c).bindFc("server", e.getFcInterface("server")); 138 try { 139 cc.removeFcSubComponent(e); 140 fail(); 141 } catch (IllegalContentException e) { 142 } 143 } 144 145 public void testWouldCreateNonLocalImportBinding () throws Exception { 146 ContentController cc = Fractal.getContentController(c); 147 cc.addFcSubComponent(e); 148 Fractal.getBindingController(e).bindFc("client", cc.getFcInternalInterface("client")); 149 try { 150 cc.removeFcSubComponent(e); 151 fail(); 152 } catch (IllegalContentException e) { 153 } 154 } 155 156 public void testWouldCreateNonLocalNormalBinding () throws Exception { 157 ContentController cc = Fractal.getContentController(c); 158 cc.addFcSubComponent(d); 159 cc.addFcSubComponent(e); 160 Fractal.getBindingController(d).bindFc("client", e.getFcInterface("server")); 161 try { 162 cc.removeFcSubComponent(e); 163 fail(); 164 } catch (IllegalContentException e) { 165 } 166 } 167 168 170 public static class Template extends TestContentController { 171 172 public Template (String name) { 173 super(name); 174 } 175 176 protected void setUpComponents () throws Exception { 177 c = gf.newFcInstance(t, "compositeTemplate", new Object [] { "composite", null }); 178 d = gf.newFcInstance(t, "compositeTemplate", new Object [] { "composite", null }); 179 e = gf.newFcInstance(t, "primitiveTemplate", new Object [] { "primitive", C.class.getName() }); 180 } 181 182 public void testInstanceContent () throws Exception { 183 Component r = gf.newFcInstance(t, "compositeTemplate", new Object [] { "composite", null }); 184 Fractal.getContentController(r).addFcSubComponent(c); 185 Fractal.getContentController(r).addFcSubComponent(d); 186 Fractal.getContentController(c).addFcSubComponent(e); 187 Fractal.getContentController(d).addFcSubComponent(e); 188 189 Component root = Fractal.getFactory(r).newFcInstance(); 190 Component[] comps = Fractal.getContentController(root).getFcSubComponents(); 191 assertEquals(2, comps.length); 192 Component[] cComps = Fractal.getContentController(comps[0]).getFcSubComponents(); 193 Component[] dComps = Fractal.getContentController(comps[1]).getFcSubComponents(); 194 assertEquals(1, cComps.length); 195 assertEquals(1, dComps.length); 196 assertEquals(cComps[0], dComps[0]); 197 } 198 } 199 } 200 | Popular Tags |