1 17 package org.apache.geronimo.system.configuration; 18 19 import java.io.File ; 20 import java.util.Collections ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.geronimo.kernel.Jsr77Naming; 25 import org.apache.geronimo.kernel.config.ConfigurationData; 26 import org.apache.geronimo.kernel.repository.Artifact; 27 import org.apache.geronimo.kernel.repository.Environment; 28 29 32 public class InPlaceConfigurationUtilTest extends TestCase { 33 private static final File basedir = new File (System.getProperty("basedir", System.getProperty("user.dir"))); 34 35 private static final File baseConfigDir = new File (basedir, "target/config"); 36 private static final File configDir = new File (baseConfigDir, "config"); 37 private static final File inPlaceConfig = new File (baseConfigDir, "inPlaceConfig"); 38 39 private InPlaceConfigurationUtil inPlaceConfUtil; 40 41 public void testWriteReadInPlaceLocation() throws Exception { 42 ConfigurationData configurationData = new ConfigurationData(null, 43 null, 44 Collections.EMPTY_LIST, 45 Collections.EMPTY_MAP, 46 new Environment(new Artifact("groupId", "artifactId", "version", "type")), 47 configDir, 48 inPlaceConfig, 49 new Jsr77Naming()); 50 51 inPlaceConfUtil.writeInPlaceLocation(configurationData, configDir); 52 53 File actualInPlaceConfig = inPlaceConfUtil.readInPlaceLocation(configDir); 54 assertEquals(inPlaceConfig, actualInPlaceConfig); 55 } 56 57 public void testAttemptReadNotExistingInPlaceLocation() throws Exception { 58 File actualInPlaceConfig = inPlaceConfUtil.readInPlaceLocation(configDir); 59 assertNull(actualInPlaceConfig); 60 } 61 62 public void testIsInPlaceConfiguration() throws Exception { 63 assertFalse(inPlaceConfUtil.isInPlaceConfiguration(configDir)); 64 65 ConfigurationData configurationData = new ConfigurationData(null, 66 null, 67 Collections.EMPTY_LIST, 68 Collections.EMPTY_MAP, 69 new Environment(new Artifact("groupId", "artifactId", "version", "type")), 70 configDir, 71 inPlaceConfig, 72 new Jsr77Naming()); 73 74 inPlaceConfUtil.writeInPlaceLocation(configurationData, configDir); 75 assertTrue(inPlaceConfUtil.isInPlaceConfiguration(configDir)); 76 } 77 78 protected void setUp() throws Exception { 79 configDir.mkdirs(); 80 inPlaceConfig.mkdirs(); 81 82 inPlaceConfUtil = new InPlaceConfigurationUtil(); 83 } 84 85 protected void tearDown() throws Exception { 86 recursiveDelete(baseConfigDir); 87 } 88 89 private final void recursiveDelete(File dir) { 90 File [] nestedFiles = dir.listFiles(); 91 if (null != nestedFiles) { 92 for (int i = 0; i < nestedFiles.length; i++) { 93 recursiveDelete(nestedFiles[i]); 94 } 95 } 96 dir.delete(); 97 } 98 } 99 | Popular Tags |