KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > test > SavantURLBuilderTest


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant.test;
8
9
10 import java.io.File JavaDoc;
11 import java.net.URL JavaDoc;
12
13 import junit.framework.TestCase;
14
15 import com.inversoft.savant.Artifact;
16 import com.inversoft.savant.SavantException;
17 import com.inversoft.savant.SavantURLBuilder;
18
19
20 /**
21  * <p>
22  * This class is the test case for the SavantURLBuilder.
23  * </p>
24  *
25  * @author Brian Pontarelli
26  */

27 public class SavantURLBuilderTest extends TestCase {
28
29     /**
30      * Constructs a new <code>SavantURLBuilderTest</code>.
31      */

32     public SavantURLBuilderTest(String JavaDoc name) {
33         super(name);
34     }
35
36
37     /**
38      * Tests that the building of the Savant URL works correctly.
39      */

40     public void testBuildURL() throws SavantException {
41         Artifact artifact = new Artifact();
42         artifact.setGroup("test-group");
43         artifact.setName("test-name");
44         artifact.setProjectname("test-project");
45         artifact.setType("jar");
46         artifact.setVersion("test-version");
47
48         SavantURLBuilder builder = new SavantURLBuilder();
49         URL JavaDoc url = builder.buildURL("http://domain", null, artifact);
50         assertEquals("http://domain/test-group/test-project/test-name-test-version.jar",
51             url.toString());
52     }
53
54     /**
55      * Tests that the building of the Savant URL works correctly with a mapping
56      * file.
57      */

58     public void testBuildURLMapping() throws SavantException {
59         Artifact artifact = new Artifact();
60         artifact.setGroup("my-group");
61         artifact.setName("test-name");
62         artifact.setProjectname("test-project");
63         artifact.setType("jar");
64         artifact.setVersion("test-version");
65
66         File JavaDoc file = new File JavaDoc("src/com/inversoft/savant/test/mapping.properties");
67         SavantURLBuilder builder = new SavantURLBuilder();
68         URL JavaDoc url = builder.buildURL("http://domain", file, artifact);
69         assertEquals("file://file_domain/my-group/test-project/test-name-test-version.jar",
70             url.toString());
71
72         artifact.setGroup("test-group");
73
74         url = builder.buildURL("http://domain", file, artifact);
75         assertEquals("http://domain/test-group/test-project/test-name-test-version.jar",
76             url.toString());
77     }
78
79     /**
80      * Tests that the building of the Savant MD5 URL works correctly.
81      */

82     public void testBuildMD5() throws SavantException {
83         Artifact artifact = new Artifact();
84         artifact.setGroup("test-group");
85         artifact.setName("test-name");
86         artifact.setProjectname("test-project");
87         artifact.setType("jar");
88         artifact.setVersion("test-version");
89
90         SavantURLBuilder builder = new SavantURLBuilder();
91         URL JavaDoc url = builder.buildMD5URL("http://domain", null, artifact);
92         assertEquals("http://domain/test-group/test-project/test-name-test-version.jar.md5",
93             url.toString());
94     }
95
96     /**
97      * Tests that the building of the Savant URL works correctly with a mapping
98      * file.
99      */

100     public void testBuildMD5Mapping() throws SavantException {
101         Artifact artifact = new Artifact();
102         artifact.setGroup("my-group");
103         artifact.setName("test-name");
104         artifact.setProjectname("test-project");
105         artifact.setType("jar");
106         artifact.setVersion("test-version");
107
108         File JavaDoc file = new File JavaDoc("src/com/inversoft/savant/test/mapping.properties");
109         SavantURLBuilder builder = new SavantURLBuilder();
110         URL JavaDoc url = builder.buildMD5URL("http://domain", file, artifact);
111         assertEquals("file://file_domain/my-group/test-project/test-name-test-version.jar.md5",
112             url.toString());
113
114         artifact.setGroup("test-group");
115
116         url = builder.buildMD5URL("http://domain", file, artifact);
117         assertEquals("http://domain/test-group/test-project/test-name-test-version.jar.md5",
118             url.toString());
119     }
120 }
Popular Tags