This project has retired. For details please refer to its Attic page.
ApplicationConfigurationTest xref
View Javadoc
1   /*
2    * Copyright 2001-2009 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    *      http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.apache.juddi.config;
16  
17  import java.net.MalformedURLException;
18  import java.net.URI;
19  import java.net.URISyntaxException;
20  
21  import org.apache.commons.configuration.ConfigurationException;
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  /**
26   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
27   */
28  public class ApplicationConfigurationTest 
29  {
30  	@Test
31  	public void readPropertyFromFile() throws ConfigurationException
32  	{
33  		try {
34  			long refreshDelay = AppConfig.getConfiguration().getLong(Property.JUDDI_CONFIGURATION_RELOAD_DELAY);
35  			System.out.println("refreshDelay=" + refreshDelay);
36  			Assert.assertEquals(2000l, refreshDelay);
37  		} catch (Exception e) {
38  			e.printStackTrace();
39  			Assert.fail();
40  		}
41  	}
42  	
43  	@Test
44  	public void readNonExistingProperty() throws ConfigurationException
45  	{
46  		long defaultValue = 3000l;
47  		try {
48  			long nonexisting = AppConfig.getConfiguration().getLong("nonexisting.property",defaultValue);
49  			System.out.println("nonexisting=" + nonexisting);
50  			Assert.assertEquals(3000l, nonexisting);
51  		} catch (Exception e) {
52  			e.printStackTrace();
53  			Assert.fail();
54  		}
55  	}
56  	
57  	@Test
58  	public void testURLFormats() throws MalformedURLException, URISyntaxException {
59  		
60  		URI file = new URI("file:/tmp/");
61  		String path = file.getSchemeSpecificPart();
62  		Assert.assertEquals("/tmp/", path);
63  		
64  		URI fileInJar = new URI("jar:file:/tmp/my.jar!/");
65  		String path1 = fileInJar.getSchemeSpecificPart();
66  		Assert.assertEquals("file:/tmp/my.jar!/", path1);
67  				
68  		URI fileInZip = new URI("zip:D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!");
69  		String path2 = fileInZip.getSchemeSpecificPart();
70  		Assert.assertEquals("D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!", path2);
71  		
72  		URI fileInVfszip = new URI("vfsfile:/tmp/SOA%20Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml");
73  		String path3 = fileInVfszip.getSchemeSpecificPart();
74  		Assert.assertEquals("/tmp/SOA Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml", path3);
75  		
76  	}
77  	
78  }