1   /*
2    * Copyright 2008 Hippo
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    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" 
12   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  package nl.hippo.client.webdav;
17  
18  import java.io.File;
19  import java.io.FileInputStream;
20  import java.io.FileOutputStream;
21  import java.io.InputStream;
22  
23  import junit.framework.TestCase;
24  
25  public class WebDavConfigTest extends TestCase {
26    
27    private File configFileBefore;
28    private File configFileAfter;
29    
30    public void setUp() throws Exception {   
31      configFileBefore = File.createTempFile("before", ".properties");
32      configFileBefore.deleteOnExit();
33      configFileAfter = File.createTempFile("after", ".properties");
34      configFileAfter.deleteOnExit();
35    }
36    
37    public void test() throws Exception {
38      
39      // Load default configuration
40    	InputStream is =  WebDavConfigTest.class.getResourceAsStream("resources/webdav.properties");
41      WebdavConfig before = new WebdavConfig(is);
42    	
43      // Write configuration to a temporary file
44      before.save(new FileOutputStream(configFileBefore));
45      
46      // Alter the configuration using WebdavConfigFactory 
47      WebdavConfigFactory factory = new WebdavConfigFactory(before);
48      factory.setHost("aap");
49      factory.setUsername("noot");
50      factory.setPort(123);
51      
52      // Write the altered configuration to a temporary file
53      WebdavConfig after = new WebdavConfig(factory);
54      after.save(new FileOutputStream(configFileAfter));
55      
56      // Read the altered configuration in a new WebdavConfig object
57      InputStream stream = new FileInputStream(configFileAfter);
58      WebdavConfig verify = new WebdavConfig(stream);
59      stream.close();
60      
61      // Verify that the alteration has been successful.
62      assertEquals(verify.getHost(), "aap");
63      assertEquals(verify.getPort(), 123);
64      assertEquals(verify.getUsername(), "noot");
65      assertEquals(verify.getPassword(), "password");
66      assertEquals(verify.getRealm(), "default realm");
67    }
68    
69  }