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.type.InterfaceType; 30 import org.objectweb.fractal.api.control.ContentController; 31 32 import org.objectweb.fractal.julia.conform.components.I; 33 34 import org.objectweb.fractal.util.Fractal; 35 36 import junit.framework.TestCase; 37 38 import java.util.Set ; 39 import java.util.Iterator ; 40 import java.util.HashSet ; 41 42 public class Test extends TestCase { 43 44 protected final static String COMP = "component/org.objectweb.fractal.api.Component/false,false,false"; 45 protected final static String BC = "binding-controller/org.objectweb.fractal.api.control.BindingController/false,false,false"; 46 protected final static String LC = "lifecycle-controller/org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator/false,false,false"; 47 protected final static String CC = "content-controller/org.objectweb.fractal.api.control.ContentController/false,false,false"; 48 protected final static String SC = "super-controller/org.objectweb.fractal.julia.control.content.SuperControllerNotifier/false,false,false"; 49 protected final static String NC = "name-controller/org.objectweb.fractal.api.control.NameController/false,false,false"; 50 protected final static String F = "factory/org.objectweb.fractal.julia.factory.Template/false,false,false"; 51 52 protected final static String PKG = "org.objectweb.fractal.julia.conform.components"; 53 54 public Test (final String name) { 55 super(name); 56 } 57 58 protected void checkInterface (I i) { 59 i.m(true); 60 i.m((byte)1); 61 i.m((char)1); 62 i.m((short)1); 63 i.m((int)1); 64 i.m((long)1); 65 i.m((float)1); 66 i.m((double)1); 67 i.m("1"); 68 i.m(new String [] { "1" }); 69 70 assertEquals(true, i.n(true, null)); 71 assertEquals((byte)1, i.n((byte)1, null)); 72 assertEquals((char)1, i.n((char)1, (double)0)); 73 assertEquals((short)1, i.n((short)1, (float)0)); 74 assertEquals((int)1, i.n((int)1, (long)0)); 75 assertEquals((long)1, i.n((long)1, (int)0)); 76 assertEquals((float)1, i.n((float)1, (short)0), 0); 77 assertEquals((double)1, i.n((double)1, (char)0), 0); 78 assertEquals("1", i.n("1", (byte)0)); 79 } 80 81 protected void checkComponent (Component c, Set itfs) throws Exception { 82 Set extItfs = getExternalItfs(c); 83 assertEquals("Wrong external interface list", itfs, extItfs); 84 Iterator i = itfs.iterator(); 85 while (i.hasNext()) { 86 String itf = (String )i.next(); 87 String compItf = null; 88 try { 89 compItf = getItf((Interface)c.getFcInterface(getItfName(itf)), false); 90 } catch (NoSuchInterfaceException e) { 91 fail("Missing external interface: " + itf); 92 } 93 assertEquals("Wrong external interface", itf, compItf); 94 } 95 96 ContentController cc; 97 try { 98 cc = Fractal.getContentController(c); 99 } catch (NoSuchInterfaceException e) { 100 return; 101 } 102 103 itfs = new HashSet (itfs); 104 i = itfs.iterator(); 105 while (i.hasNext()) { 106 String itf = (String )i.next(); 107 if (itf.startsWith("component/") || itf.indexOf("-controller/") != -1) { 108 i.remove(); 109 } 110 } 111 112 Set intItfs = getInternalItfs(cc); 113 assertEquals("Wrong internal interface list", itfs, intItfs); 114 i = itfs.iterator(); 115 while (i.hasNext()) { 116 String itf = (String )i.next(); 117 String compItf = null; 118 try { 119 compItf = getItf((Interface)cc.getFcInternalInterface(getItfName(itf)), true); 120 } catch (NoSuchInterfaceException e) { 121 fail("Missing internal interface: " + itf); 122 } 123 assertEquals("Wrong internal interface", itf, compItf); 124 } 125 } 126 127 private Set getExternalItfs (Component c) { 128 HashSet result = new HashSet (); 129 Object [] extItfs = c.getFcInterfaces(); 130 for (int i = 0; i < extItfs.length; ++i) { 131 String itf = getItf((Interface)extItfs[i], false); 132 if (!result.add(itf)) { 133 fail("Duplicated interface: " + itf); 134 } 135 } 136 return result; 137 } 138 139 private Set getInternalItfs (ContentController cc) { 140 HashSet result = new HashSet (); 141 Object [] extItfs = cc.getFcInternalInterfaces(); 142 for (int i = 0; i < extItfs.length; ++i) { 143 String itf = getItf((Interface)extItfs[i], true); 144 if (!result.add(itf)) { 145 fail("Duplicated interface: " + itf); 146 } 147 } 148 return result; 149 } 150 151 protected static String getItf (Interface itf, boolean internal) { 152 InterfaceType itfType = (InterfaceType)itf.getFcItfType(); 153 return getItf( 154 itf.getFcItfName(), 155 itfType.getFcItfSignature(), 156 itfType.isFcClientItf() ^ internal, 157 itfType.isFcOptionalItf(), 158 itfType.isFcCollectionItf()); 159 } 160 161 private static String getItf ( 162 String name, 163 String signature, 164 boolean isClient, 165 boolean isOptional, 166 boolean isCollection) 167 { 168 return name+'/'+signature+'/'+isClient+','+isOptional+','+isCollection; 169 } 170 171 private static String getItfName (String itf) { 172 return itf.substring(0, itf.indexOf('/')); 173 } 174 } 175 | Popular Tags |