1 17 18 19 20 package org.apache.lenya.ac.file; 21 22 import java.io.File ; 23 import java.io.IOException ; 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 ; 34 35 public class FileGroupTest extends AccessControlTest { 36 37 41 public FileGroupTest(String arg0) { 42 super(arg0); 43 } 44 45 50 public static void main(String [] args) { 51 PublicationHelper.extractPublicationArguments(args); 52 junit.textui.TestRunner.run(FileGroupTest.class); 53 } 54 55 63 final public void testFileGroup() 64 throws AccessControlException, ConfigurationException, SAXException , IOException { 65 66 FileGroup group = getGroup(); 67 group.save(); 68 69 File groupFile = new File (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 GROUP_ID = "testGroup"; 88 89 94 protected FileGroup getGroup() { 95 File configurationDirectory = getAccreditablesDirectory(); 96 System.out.println("Configuration directory: " + configurationDirectory); 97 FileGroup group = new FileGroup(configurationDirectory, GROUP_ID); 98 return group; 99 } 100 101 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 |