KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > configuration > InPlaceConfigurationUtilTest


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

17 package org.apache.geronimo.system.configuration;
18
19 import java.io.File JavaDoc;
20 import java.util.Collections JavaDoc;
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 /**
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class InPlaceConfigurationUtilTest extends TestCase {
33     private static final File JavaDoc basedir = new File JavaDoc(System.getProperty("basedir", System.getProperty("user.dir")));
34
35     private static final File JavaDoc baseConfigDir = new File JavaDoc(basedir, "target/config");
36     private static final File JavaDoc configDir = new File JavaDoc(baseConfigDir, "config");
37     private static final File JavaDoc inPlaceConfig = new File JavaDoc(baseConfigDir, "inPlaceConfig");
38
39     private InPlaceConfigurationUtil inPlaceConfUtil;
40
41     public void testWriteReadInPlaceLocation() throws Exception JavaDoc {
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 JavaDoc actualInPlaceConfig = inPlaceConfUtil.readInPlaceLocation(configDir);
54         assertEquals(inPlaceConfig, actualInPlaceConfig);
55     }
56
57     public void testAttemptReadNotExistingInPlaceLocation() throws Exception JavaDoc {
58         File JavaDoc actualInPlaceConfig = inPlaceConfUtil.readInPlaceLocation(configDir);
59         assertNull(actualInPlaceConfig);
60     }
61
62     public void testIsInPlaceConfiguration() throws Exception JavaDoc {
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 JavaDoc {
79         configDir.mkdirs();
80         inPlaceConfig.mkdirs();
81         
82         inPlaceConfUtil = new InPlaceConfigurationUtil();
83     }
84     
85     protected void tearDown() throws Exception JavaDoc {
86         recursiveDelete(baseConfigDir);
87     }
88     
89     private final void recursiveDelete(File JavaDoc dir) {
90         File JavaDoc[] 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