1 package org.apache.continuum.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 public class ContinuumBuildAgentDavResourceLocatorTest
25 extends TestCase
26 {
27 private ContinuumBuildAgentDavLocatorFactory factory;
28
29 private ContinuumBuildAgentDavResourceLocator locator;
30
31 @Override
32 protected void setUp()
33 throws Exception
34 {
35 super.setUp();
36 factory = new ContinuumBuildAgentDavLocatorFactory();
37 }
38
39 public void testAvoidDoubleSlashInHref()
40 throws Exception
41 {
42 String prefix = "http://myhost/";
43 String href = "/workingcopy/1/";
44 locator = getLocator( prefix, href );
45
46 assertEquals( 1, locator.getProjectId() );
47 assertEquals( "", locator.getWorkspaceName() );
48 assertEquals( "", locator.getWorkspacePath() );
49 assertEquals( "http://myhost/", locator.getPrefix() );
50 assertEquals( "http://myhost/workingcopy/1/", locator.getHref( false ) );
51 assertEquals( "http://myhost/workingcopy/1/", locator.getHref( true ) );
52 assertEquals( "/workingcopy/1", locator.getResourcePath() );
53 assertEquals( "/workingcopy/1", locator.getRepositoryPath() );
54 }
55
56 public void testLocatorWithPrefixHref()
57 throws Exception
58 {
59 String prefix = "http://myhost/";
60 String href = "/workingcopy/1";
61 locator = getLocator( prefix, href );
62
63 assertEquals( 1, locator.getProjectId() );
64 assertEquals( "", locator.getWorkspaceName() );
65 assertEquals( "", locator.getWorkspacePath() );
66 assertEquals( "http://myhost/", locator.getPrefix() );
67 assertEquals( "http://myhost/workingcopy/1", locator.getHref( false ) );
68 assertEquals( "http://myhost/workingcopy/1/", locator.getHref( true ) );
69 assertEquals( "/workingcopy/1", locator.getResourcePath() );
70 assertEquals( "/workingcopy/1", locator.getRepositoryPath() );
71 }
72
73 public void testLocatorWithHrefThatContainsPrefix()
74 throws Exception
75 {
76 String prefix = "http://myhost/";
77 String href = "http://myhost/workingcopy/1";
78 locator = getLocator( prefix, href );
79
80 assertEquals( 1, locator.getProjectId() );
81 assertEquals( "", locator.getWorkspaceName() );
82 assertEquals( "", locator.getWorkspacePath() );
83 assertEquals( "http://myhost/", locator.getPrefix() );
84 assertEquals( "http://myhost/workingcopy/1", locator.getHref( false ) );
85 assertEquals( "http://myhost/workingcopy/1/", locator.getHref( true ) );
86 assertEquals( "/workingcopy/1", locator.getResourcePath() );
87 assertEquals( "/workingcopy/1", locator.getRepositoryPath() );
88 }
89
90 public void testLocatorWithRootHref()
91 throws Exception
92 {
93 String prefix = "http://myhost/";
94 String href = "/";
95 locator = getLocator( prefix, href );
96
97 assertEquals( 0, locator.getProjectId() );
98 assertEquals( "", locator.getWorkspaceName() );
99 assertEquals( "", locator.getWorkspacePath() );
100 assertEquals( "http://myhost/", locator.getPrefix() );
101 assertEquals( "http://myhost/", locator.getHref( false ) );
102 assertEquals( "http://myhost/", locator.getHref( true ) );
103 assertEquals( "/", locator.getResourcePath() );
104 assertEquals( "/", locator.getRepositoryPath() );
105 }
106
107 private ContinuumBuildAgentDavResourceLocator getLocator( String prefix, String href )
108 {
109 return (ContinuumBuildAgentDavResourceLocator) factory.createResourceLocator( prefix, href );
110 }
111 }