KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > permissions > impl > acegi > FilteringResultSetTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.security.permissions.impl.acegi;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.ListIterator JavaDoc;
21
22 import junit.framework.TestCase;
23
24 import org.alfresco.model.ContentModel;
25 import org.alfresco.repo.search.results.ChildAssocRefResultSet;
26 import org.alfresco.service.cmr.repository.ChildAssociationRef;
27 import org.alfresco.service.cmr.repository.NodeRef;
28 import org.alfresco.service.cmr.repository.StoreRef;
29 import org.alfresco.service.cmr.search.ResultSet;
30 import org.alfresco.service.cmr.search.ResultSetRow;
31 import org.alfresco.service.namespace.QName;
32
33 public class FilteringResultSetTest extends TestCase
34 {
35
36     
37     
38     public FilteringResultSetTest()
39     {
40         super();
41     }
42
43     public FilteringResultSetTest(String JavaDoc arg0)
44     {
45         super(arg0);
46     }
47
48     public void test()
49     {
50         StoreRef storeRef = new StoreRef("protocol", "test");
51         NodeRef root = new NodeRef(storeRef, "n0");
52         NodeRef n1 = new NodeRef(storeRef, "n1");
53         NodeRef n2 = new NodeRef(storeRef, "n2");
54         NodeRef n3 = new NodeRef(storeRef, "n3");
55         NodeRef n4 = new NodeRef(storeRef, "n4");
56         NodeRef n5 = new NodeRef(storeRef, "n5");
57         
58         ArrayList JavaDoc<ChildAssociationRef> cars = new ArrayList JavaDoc<ChildAssociationRef>();
59         ChildAssociationRef car0 = new ChildAssociationRef(null, null, null, root);
60         ChildAssociationRef car1 = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, root, QName.createQName("{test}n2"), n1);
61         ChildAssociationRef car2 = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, n1, QName.createQName("{test}n3"), n2);
62         ChildAssociationRef car3 = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, n2, QName.createQName("{test}n4"), n3);
63         ChildAssociationRef car4 = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, n3, QName.createQName("{test}n5"), n4);
64         ChildAssociationRef car5 = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, n4, QName.createQName("{test}n6"), n5);
65         cars.add(car0);
66         cars.add(car1);
67         cars.add(car2);
68         cars.add(car3);
69         cars.add(car4);
70         cars.add(car5);
71         
72         ResultSet in = new ChildAssocRefResultSet(null, cars, null);
73         
74         FilteringResultSet filtering = new FilteringResultSet(in);
75         
76         assertEquals(0, filtering.length());
77         for(int i = 0; i < 6; i++)
78         {
79            filtering.setIncluded(i, true);
80            assertEquals(1, filtering.length());
81            assertEquals("n"+i, filtering.getNodeRef(0).getId());
82            filtering.setIncluded(i, false);
83            assertEquals(0, filtering.length());
84         }
85         
86         for(int i = 0; i < 6; i++)
87         {
88             filtering.setIncluded(i, true);
89             assertEquals(i+1, filtering.length());
90             assertEquals("n"+i, filtering.getNodeRef(i).getId());
91         }
92         
93         int count = 0;
94         for(ResultSetRow row : filtering)
95         {
96             assertNotNull(row);
97             assertTrue(count < 6);
98             count++;
99         }
100         
101         ResultSetRow last = null;
102         for(ListIterator JavaDoc<ResultSetRow> it = filtering.iterator(); it.hasNext(); /**/)
103         {
104             ResultSetRow row = it.next();
105             if(last != null)
106             {
107                 assertTrue(it.hasPrevious());
108                 ResultSetRow previous = it.previous();
109                 assertEquals(last.getIndex(), previous.getIndex());
110                 row = it.next();
111                 
112             }
113             else
114             {
115                 assertFalse(it.hasPrevious());
116             }
117             last = row;
118          
119         }
120     }
121     
122 }
123
Popular Tags