001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: import java.util.*;
036:
037: import junit.framework.*;
038:
039: public class TestGraphSummarizerWithFiltering extends TestCase {
040: private RegularExpressionSelectionCriteria scopeCriteria;
041: private RegularExpressionSelectionCriteria filterCriteria;
042: private NodeFactory factory;
043:
044: private Node a_A_a;
045: private Node b;
046: private Node b_B_b;
047: private Node c_C_c;
048:
049: private List<String> includeScope;
050: private List<String> includeFilter;
051: private List<String> excludeFilter;
052:
053: private GraphCopier copier;
054:
055: protected void setUp() throws Exception {
056: scopeCriteria = new RegularExpressionSelectionCriteria("//");
057: filterCriteria = new RegularExpressionSelectionCriteria("//");
058: factory = new NodeFactory();
059:
060: a_A_a = factory.createFeature("a.A.a");
061: b = factory.createPackage("b");
062: b_B_b = factory.createFeature("b.B.b");
063: c_C_c = factory.createFeature("c.C.c");
064:
065: includeScope = new LinkedList<String>();
066: includeScope.add("/^a/");
067:
068: includeFilter = new LinkedList<String>();
069: includeFilter.add("/^b/");
070:
071: excludeFilter = new LinkedList<String>();
072: excludeFilter.add("/^c/");
073:
074: copier = new GraphSummarizer(scopeCriteria, filterCriteria);
075: }
076:
077: public void testIncludeFilterF2FtoP2P() {
078: a_A_a.addDependency(b_B_b);
079: a_A_a.addDependency(c_C_c);
080:
081: scopeCriteria.setMatchingClasses(false);
082: scopeCriteria.setMatchingFeatures(false);
083: filterCriteria.setMatchingClasses(false);
084: filterCriteria.setMatchingFeatures(false);
085: filterCriteria.setGlobalIncludes(includeFilter);
086:
087: copier.traverseNodes(factory.getPackages().values());
088:
089: assertTrue(copier.getScopeFactory().createPackage("a")
090: .getInboundDependencies().isEmpty());
091: assertEquals(copier.getScopeFactory().createPackage("a")
092: .getOutboundDependencies().toString(), 1, copier
093: .getScopeFactory().createPackage("a")
094: .getOutboundDependencies().size());
095: assertTrue(copier.getScopeFactory().createPackage("a")
096: .getOutboundDependencies().contains(b));
097: }
098:
099: public void testExcludeFilterF2FtoP2P() {
100: a_A_a.addDependency(b_B_b);
101: a_A_a.addDependency(c_C_c);
102:
103: scopeCriteria.setMatchingClasses(false);
104: scopeCriteria.setMatchingFeatures(false);
105: scopeCriteria.setGlobalIncludes(includeScope);
106: filterCriteria.setMatchingClasses(false);
107: filterCriteria.setMatchingFeatures(false);
108: filterCriteria.setGlobalExcludes(excludeFilter);
109:
110: assertTrue(!filterCriteria.matchesFeatureName(c_C_c.getName()));
111:
112: copier.traverseNodes(factory.getPackages().values());
113:
114: assertTrue(copier.getScopeFactory().createPackage("a")
115: .getInboundDependencies().isEmpty());
116: assertEquals(copier.getScopeFactory().createPackage("a")
117: .getOutboundDependencies().toString(), 1, copier
118: .getScopeFactory().createPackage("a")
119: .getOutboundDependencies().size());
120: assertTrue(copier.getScopeFactory().createPackage("a")
121: .getOutboundDependencies().contains(b));
122: }
123: }
|