KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > adl > conform > TestSharing


1 /***
2  * Fractal ADL Parser
3  * Copyright (C) 2002-2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.adl.conform;
25
26 import java.util.HashSet JavaDoc;
27 import java.util.Set JavaDoc;
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 JavaDoc 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 JavaDoc()).size());
53     assertEquals(1, getComponents(d, "b", new HashSet JavaDoc()).size());
54     assertEquals(1, getComponents(d, "c", new HashSet JavaDoc()).size());
55     assertEquals(1, getComponents(d, "d", new HashSet JavaDoc()).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 JavaDoc()).size());
61     assertEquals(1, getComponents(d, "b", new HashSet JavaDoc()).size());
62     assertEquals(1, getComponents(d, "c", new HashSet JavaDoc()).size());
63     assertEquals(1, getComponents(d, "d", new HashSet JavaDoc()).size());
64     assertEquals(1, getComponents(d, "e", new HashSet JavaDoc()).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 JavaDoc()).size());
70     assertEquals(1, getComponents(d, "b", new HashSet JavaDoc()).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 JavaDoc()).size());
76     assertEquals(1, getComponents(d, "b", new HashSet JavaDoc()).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 JavaDoc()).size());
82     assertEquals(1, getComponents(d, "b", new HashSet JavaDoc()).size());
83   }
84
85   private Set JavaDoc getComponents (final ComponentContainer c, final String JavaDoc n, final Set JavaDoc 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