1 23 24 package org.objectweb.fractal.adl.conform; 25 26 import java.util.HashSet ; 27 import java.util.Set ; 28 29 import org.objectweb.fractal.adl.ADLException; 30 import org.objectweb.fractal.adl.Loader; 31 import org.objectweb.fractal.adl.components.Component; 32 import org.objectweb.fractal.adl.components.ComponentContainer; 33 import org.objectweb.fractal.adl.components.ComponentLoader; 34 import org.objectweb.fractal.adl.xml.XMLLoader; 35 36 public class TestSharing extends Test { 37 38 public Loader l; 39 40 public TestSharing (final String name) { 41 super(name); 42 } 43 44 protected void setUp () { 45 ComponentLoader compLoader = new ComponentLoader(); 46 compLoader.clientLoader = new XMLLoader(false); 47 l = compLoader; 48 } 49 50 public void test1 () throws ADLException { 51 ComponentContainer d = (ComponentContainer)l.load("SHARING1", null); 52 assertEquals(1, getComponents(d, "a", new HashSet ()).size()); 53 assertEquals(1, getComponents(d, "b", new HashSet ()).size()); 54 assertEquals(1, getComponents(d, "c", new HashSet ()).size()); 55 assertEquals(1, getComponents(d, "d", new HashSet ()).size()); 56 } 57 58 public void test2 () throws ADLException { 59 ComponentContainer d = (ComponentContainer)l.load("SHARING2", null); 60 assertEquals(1, getComponents(d, "a", new HashSet ()).size()); 61 assertEquals(1, getComponents(d, "b", new HashSet ()).size()); 62 assertEquals(1, getComponents(d, "c", new HashSet ()).size()); 63 assertEquals(1, getComponents(d, "d", new HashSet ()).size()); 64 assertEquals(1, getComponents(d, "e", new HashSet ()).size()); 65 } 66 67 public void test3 () throws ADLException { 68 ComponentContainer d = (ComponentContainer)l.load("SHARING4", null); 69 assertEquals(1, getComponents(d, "a", new HashSet ()).size()); 70 assertEquals(1, getComponents(d, "b", new HashSet ()).size()); 71 } 72 73 public void test4 () throws ADLException { 74 ComponentContainer d = (ComponentContainer)l.load("SHARING5", null); 75 assertEquals(1, getComponents(d, "a", new HashSet ()).size()); 76 assertEquals(1, getComponents(d, "b", new HashSet ()).size()); 77 } 78 79 public void test5 () throws ADLException { 80 ComponentContainer d = (ComponentContainer)l.load("SHARING6", null); 81 assertEquals(1, getComponents(d, "a", new HashSet ()).size()); 82 assertEquals(1, getComponents(d, "b", new HashSet ()).size()); 83 } 84 85 private Set getComponents (final ComponentContainer c, final String n, final Set r) { 86 if (c instanceof Component && ((Component)c).getName().equals(n)) { 87 r.add(c); 88 } 89 Component[] comps = c.getComponents(); 90 for (int i = 0; i < comps.length; ++i) { 91 getComponents(comps[i], n, r); 92 } 93 return r; 94 } 95 } 96 | Popular Tags |