Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
18   71   5   3.6
0   42   0.28   5
5     1  
1    
 
  UrlUtilityTest       Line # 30 18 5 100% 1.0
 
  (4)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.base.io;
17   
18    import java.io.File;
19    import java.net.URI;
20    import java.net.URL;
21   
22    import org.qedeq.base.test.QedeqTestCase;
23    import org.qedeq.base.test.WebServer;
24   
25    /**
26    * Test {@link org.qedeq.kernel.utility.IoUtility}.
27    *
28    * @author Michael Meyling
29    */
 
30    public class UrlUtilityTest extends QedeqTestCase {
31   
32   
 
33  1 toggle public void testToUrl() throws Exception {
34  1 final URL url = UrlUtility.toUrl(new File("."));
35  1 final URI uri = new URI(url.toString());
36  1 assertEquals(new File(".").getCanonicalPath(),
37    new File(uri).getCanonicalPath());
38    }
39   
 
40  1 toggle public void testToFile() throws Exception {
41  1 final File start = new File("empty path");
42  1 assertEquals(UrlUtility.transformURLPathToFilePath(UrlUtility.toUrl(start)).getCanonicalPath(),
43    start.getCanonicalPath());
44    }
45   
 
46  1 toggle public void testEasyUrl() throws Exception {
47  1 final String url1 = "http://www.qedeq.org/sample.html#poke";
48  1 assertEquals(url1, UrlUtility.easyUrl(url1));
49  1 final String file = "/user/home/qedeq/sample1.qedeq";
50  1 assertEquals(new File(file.replace('/', File.separatorChar)).getCanonicalPath(),
51    UrlUtility.easyUrl("file://" + file));
52    }
53   
 
54  1 toggle public void testSaveUrlToFile() throws Exception {
55  1 final File original = new File(getOutdir(), "testSaveUrlToFile1.txt");
56  1 IoUtility.saveFile(original, "we don't need another hero");
57  1 final File save = new File(getOutdir(), "testSaveUrlToFile2.txt");
58  1 final WebServer server = new WebServer(8082, getOutdir(), 5000, true);
59  1 server.start();
60  1 UrlUtility.saveUrlToFile("http://localhost:8082/" + original.getName(), save, null, null, null, 0, 0,
61    new LoadingListener() {
 
62  2 toggle public void loadingCompletenessChanged(double completeness) {
63  2 System.out.println(completeness);
64    }
65    }
66    );
67  1 assertTrue(IoUtility.compareFilesBinary(original, save));
68  1 server.stop();
69    }
70   
71    }