KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > TestGraphCopierWithFiltering


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependency;
34
35 import java.io.*;
36 import java.util.*;
37
38 import junit.framework.*;
39
40 public class TestGraphCopierWithFiltering extends TestCase {
41     private RegularExpressionSelectionCriteria scopeCriteria;
42     private RegularExpressionSelectionCriteria filterCriteria;
43     private NodeFactory factory;
44     
45     private Node a;
46     private Node a_A;
47     private Node a_A_a;
48     
49     private Node b;
50     private Node b_B;
51     private Node b_B_b;
52     
53     private Node c;
54     private Node c_C;
55     private Node c_C_c;
56
57     private List includeFilter;
58     private List excludeFilter;
59
60     private GraphCopier copier;
61
62     protected void setUp() throws Exception JavaDoc {
63         scopeCriteria = new RegularExpressionSelectionCriteria();
64         filterCriteria = new RegularExpressionSelectionCriteria();
65         factory = new NodeFactory();
66
67         a = factory.createPackage("a");
68         a_A = factory.createClass("a.A");
69         a_A_a = factory.createFeature("a.A.a");
70         
71         b = factory.createPackage("b");
72         b_B = factory.createClass("b.B");
73         b_B_b = factory.createFeature("b.B.b");
74         
75         c = factory.createPackage("c");
76         c_C = factory.createClass("c.C");
77         c_C_c = factory.createFeature("c.C.c");
78         
79         includeFilter = new LinkedList();
80         includeFilter.add("/^b/");
81         
82         excludeFilter = new LinkedList();
83         excludeFilter.add("/^c/");
84
85         copier = new GraphCopier(new SelectiveTraversalStrategy(scopeCriteria, filterCriteria));
86     }
87
88     public void testIncludeFilterF2FtoP2P() {
89         a_A_a.addDependency(b_B_b);
90         a_A_a.addDependency(c_C_c);
91         
92         scopeCriteria.setMatchingClasses(false);
93         scopeCriteria.setMatchingFeatures(false);
94         filterCriteria.setMatchingClasses(false);
95         filterCriteria.setMatchingFeatures(false);
96         filterCriteria.setGlobalIncludes(includeFilter);
97         
98         copier.traverseNodes(factory.getPackages().values());
99
100         assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty());
101         assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().isEmpty());
102     }
103
104     public void testExcludeFilterF2FtoP2P() {
105         a_A_a.addDependency(b_B_b);
106         a_A_a.addDependency(c_C_c);
107         
108         scopeCriteria.setMatchingClasses(false);
109         scopeCriteria.setMatchingFeatures(false);
110         filterCriteria.setMatchingClasses(false);
111         filterCriteria.setMatchingFeatures(false);
112         filterCriteria.setGlobalExcludes(excludeFilter);
113         
114         copier.traverseNodes(factory.getPackages().values());
115
116         assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty());
117         assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().isEmpty());
118     }
119 }
120
Popular Tags