View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2005, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  
22  package org.dbunit.util.search;
23  
24  import java.util.SortedSet;
25  
26  /**
27   * @author Felipe Leme (dbunit@felipeal.net)
28   * @version $Revision$
29   * @since Aug 25, 2005
30   */
31  
32  public class ExcludeNodesSearchCallbackTest extends AbstractSearchTestCase {
33  
34    private ISearchCallback callback;
35  
36    protected ISearchCallback getCallback() {
37      return this.callback;    
38    }
39    
40    protected void setDenied( Object[] deniedNodes ) {
41      this.callback =  new AbstractExcludeNodesSearchCallback( deniedNodes ) {
42        
43        public SortedSet getEdges(Object fromNode) throws SearchException {
44          return getEdgesFromNode(fromNode);
45        }
46      };
47      
48    }
49      
50    public void testSingleNode() throws Exception {
51      setInput(new String[] { A });
52      setDenied( new String[] { A } );
53      doIt();
54    }
55  
56    public void testSingleEdgeDeniedA() throws Exception {
57      setInput(new String[] { A });
58      addEdges(A, new String[] { B });
59      setDenied( new String[] { A } );
60      doIt();
61    }
62  
63    public void testSingleEdgeDeniedB() throws Exception {
64      setInput(new String[] { A });
65      addEdges(A, new String[] { B });
66      setDenied( new String[] { B } );
67      setOutput(new String[] { A });
68      doIt();
69    }
70    
71    public void testSingleEdgeMultipleInputDeniedB() throws Exception {
72      setInput(new String[] { A, B });
73      addEdges(A, new String[] { B });
74      setDenied( new String[] { B } );
75      setOutput(new String[] { A });
76      doIt();
77    }
78    
79    public void testSingleEdgeMultipleInputDeniedA() throws Exception {
80      setInput(new String[] { A, B });
81      addEdges(A, new String[] { B });
82      setDenied( new String[] { A } );
83      setOutput(new String[] { B });
84      doIt();
85    }
86  
87    public void testDisconnected() throws Exception {
88      setInput(new String[] { A, C });
89      addEdges(A, new String[] { B });
90      setDenied( new String[] { B, A } );
91      setOutput(new String[] { C });
92      doIt();
93    }
94  
95    public void testDisconnectedAllowedC() throws Exception {
96      setInput(new String[] { A, C });
97      addEdges(A, new String[] { B });
98      setDenied( new String[] { C } );
99      setOutput(new String[] { B, A });
100     doIt();
101   }
102   
103 
104 }