001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /* $Id: FileGroupTest.java 485769 2006-12-11 17:41:23Z andreas $ */
020:
021: package org.apache.lenya.ac.file;
022:
023: import java.io.File;
024: import java.io.IOException;
025:
026: import org.apache.avalon.framework.configuration.Configuration;
027: import org.apache.avalon.framework.configuration.ConfigurationException;
028: import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
029: import org.apache.lenya.ac.AccessControlException;
030: import org.apache.lenya.ac.Group;
031: import org.apache.lenya.ac.Groupable;
032: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
033: import org.xml.sax.SAXException;
034:
035: /**
036: * Test for file-based groups
037: */
038: public class FileGroupTest extends AbstractAccessControlTest {
039:
040: /**
041: * <code>GROUP_ID</code> The group id
042: */
043: public static final String GROUP_ID = "testGroup";
044:
045: /**
046: * Runs the test
047: *
048: * @throws AccessControlException if an AC error occurs
049: * @throws ConfigurationException if an error with the configuration occurs
050: * @throws SAXException if a parsing error occurs
051: * @throws IOException if an IO error occurs
052: */
053: final public void testFileGroup() throws AccessControlException,
054: ConfigurationException, SAXException, IOException {
055:
056: FileGroup group = getGroup();
057: group.save();
058:
059: File groupFile = new File(getAccreditablesDirectory(), GROUP_ID
060: + FileGroupManager.SUFFIX);
061: assertNotNull(groupFile);
062: assertTrue(groupFile.exists());
063:
064: Configuration config = null;
065: config = new DefaultConfigurationBuilder()
066: .buildFromFile(groupFile);
067: assertNotNull(config);
068:
069: FileGroup newGroup = null;
070: newGroup = new FileGroup(getAccreditableManager()
071: .getGroupManager(), getLogger());
072: newGroup.setConfigurationDirectory(getAccreditablesDirectory());
073: newGroup.configure(config);
074: assertNotNull(newGroup);
075:
076: assertTrue(newGroup.getId().equals(GROUP_ID));
077:
078: }
079:
080: /**
081: * Test getGroup
082: *
083: * @return a <code>FileGroup</code>
084: * @throws AccessControlException
085: */
086: protected FileGroup getGroup() throws AccessControlException {
087: File configurationDirectory = getAccreditablesDirectory();
088: getLogger().info(
089: "Configuration directory: " + configurationDirectory);
090: FileGroup group = new FileGroup(getAccreditableManager()
091: .getGroupManager(), getLogger(), GROUP_ID);
092: return group;
093: }
094:
095: /**
096: * Tests the removeAllMembers() method.
097: * @throws AccessControlException
098: */
099: public void testRemoveAllMembers() throws AccessControlException {
100: Group group = getGroup();
101: Groupable members[] = group.getMembers();
102: group.removeAllMembers();
103: for (int i = 0; i < members.length; i++) {
104: assertFalse(group.contains(members[i]));
105: }
106: }
107:
108: }
|