KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestGraphSummarizerWithFiltering 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 includeScope;
58     private List includeFilter;
59     private List excludeFilter;
60
61     private GraphCopier copier;
62
63     protected void setUp() throws Exception JavaDoc {
64         scopeCriteria = new RegularExpressionSelectionCriteria();
65         filterCriteria = new RegularExpressionSelectionCriteria();
66         factory = new NodeFactory();
67
68         a = factory.createPackage("a");
69         a_A = factory.createClass("a.A");
70         a_A_a = factory.createFeature("a.A.a");
71         
72         b = factory.createPackage("b");
73         b_B = factory.createClass("b.B");
74         b_B_b = factory.createFeature("b.B.b");
75         
76         c = factory.createPackage("c");
77         c_C = factory.createClass("c.C");
78         c_C_c = factory.createFeature("c.C.c");
79         
80         includeScope = new LinkedList();
81         includeScope.add("/^a/");
82         
83         includeFilter = new LinkedList();
84         includeFilter.add("/^b/");
85         
86         excludeFilter = new LinkedList();
87         excludeFilter.add("/^c/");
88
89         copier = new GraphSummarizer(scopeCriteria, filterCriteria);
90     }
91
92     public void testIncludeFilterF2FtoP2P() {
93         a_A_a.addDependency(b_B_b);
94         a_A_a.addDependency(c_C_c);
95         
96         scopeCriteria.setMatchingClasses(false);
97         scopeCriteria.setMatchingFeatures(false);
98         filterCriteria.setMatchingClasses(false);
99         filterCriteria.setMatchingFeatures(false);
100         filterCriteria.setGlobalIncludes(includeFilter);
101         
102         copier.traverseNodes(factory.getPackages().values());
103
104         assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty());
105         assertEquals(copier.getScopeFactory().createPackage("a").getOutboundDependencies().toString(),
106                      1,
107                      copier.getScopeFactory().createPackage("a").getOutboundDependencies().size());
108         assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().contains(b));
109     }
110
111     public void testExcludeFilterF2FtoP2P() {
112         a_A_a.addDependency(b_B_b);
113         a_A_a.addDependency(c_C_c);
114         
115         scopeCriteria.setMatchingClasses(false);
116         scopeCriteria.setMatchingFeatures(false);
117         scopeCriteria.setGlobalIncludes(includeScope);
118         filterCriteria.setMatchingClasses(false);
119         filterCriteria.setMatchingFeatures(false);
120         filterCriteria.setGlobalExcludes(excludeFilter);
121
122         assertTrue(!filterCriteria.matchesFeatureName(c_C_c.getName()));
123         
124         copier.traverseNodes(factory.getPackages().values());
125
126         assertTrue(copier.getScopeFactory().createPackage("a").getInboundDependencies().isEmpty());
127         assertEquals(copier.getScopeFactory().createPackage("a").getOutboundDependencies().toString(),
128                      1,
129                      copier.getScopeFactory().createPackage("a").getOutboundDependencies().size());
130         assertTrue(copier.getScopeFactory().createPackage("a").getOutboundDependencies().contains(b));
131     }
132 }
133
Popular Tags