KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > file > FileGroupTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: FileGroupTest.java 42739 2004-03-20 11:46:20Z gregor $ */
19
20 package org.apache.lenya.ac.file;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
28 import org.apache.lenya.ac.AccessControlException;
29 import org.apache.lenya.ac.Group;
30 import org.apache.lenya.ac.Groupable;
31 import org.apache.lenya.ac.impl.AccessControlTest;
32 import org.apache.lenya.cms.PublicationHelper;
33 import org.xml.sax.SAXException JavaDoc;
34
35 public class FileGroupTest extends AccessControlTest {
36
37     /**
38      * Constructor for FileGroupTest.
39      * @param arg0 command line args
40      */

41     public FileGroupTest(String JavaDoc arg0) {
42         super(arg0);
43     }
44
45     /**
46      * DOCUMENT ME!
47      *
48      * @param args DOCUMENT ME!
49      */

50     public static void main(String JavaDoc[] args) {
51         PublicationHelper.extractPublicationArguments(args);
52         junit.textui.TestRunner.run(FileGroupTest.class);
53     }
54
55     /**
56      * DOCUMENT ME!
57      *
58      * @throws AccessControlException DOCUMENT ME!
59      * @throws ConfigurationException DOCUMENT ME!
60      * @throws SAXException DOCUMENT ME!
61      * @throws IOException DOCUMENT ME!
62      */

63     final public void testFileGroup()
64         throws AccessControlException, ConfigurationException, SAXException JavaDoc, IOException JavaDoc {
65
66         FileGroup group = getGroup();
67         group.save();
68
69         File JavaDoc groupFile = new File JavaDoc(getAccreditablesDirectory(), GROUP_ID + FileGroupManager.SUFFIX);
70         assertNotNull(groupFile);
71         assertTrue(groupFile.exists());
72
73         Configuration config = null;
74         config = new DefaultConfigurationBuilder().buildFromFile(groupFile);
75         assertNotNull(config);
76
77         FileGroup newGroup = null;
78         newGroup = new FileGroup();
79         newGroup.setConfigurationDirectory(getAccreditablesDirectory());
80         newGroup.configure(config);
81         assertNotNull(newGroup);
82
83         assertTrue(newGroup.getId().equals(GROUP_ID));
84
85     }
86
87     public static final String JavaDoc GROUP_ID = "testGroup";
88
89     /**
90      * Test getGroup
91      *
92      * @return a <code>FileGroup</code>
93      */

94     protected FileGroup getGroup() {
95         File JavaDoc configurationDirectory = getAccreditablesDirectory();
96         System.out.println("Configuration directory: " + configurationDirectory);
97         FileGroup group = new FileGroup(configurationDirectory, GROUP_ID);
98         return group;
99     }
100
101     /**
102      * Tests the removeAllMembers() method.
103      */

104     public void testRemoveAllMembers() {
105         Group group = getGroup();
106         Groupable members[] = group.getMembers();
107         group.removeAllMembers();
108         for (int i = 0; i < members.length; i++) {
109             assertFalse(group.contains(members[i]));
110         }
111     }
112
113 }
114
Popular Tags