1 package org.apache.maven.scm.provider.accurev;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepositoryMatcher.isRepo;
23 import static org.hamcrest.Matchers.is;
24 import static org.junit.Assert.assertThat;
25
26 import org.apache.maven.scm.repository.ScmRepositoryException;
27 import org.junit.Test;
28
29 public class AccurevScmProviderTest
30 {
31
32 @Test
33 public void testMakeProviderScmRepository()
34 throws Exception
35 {
36
37
38 assertAccurevRepo( "", null, null );
39 assertAccurevRepo( "aStream:/project/dir", "aStream", "project/dir" );
40 assertAccurevRepo( "/project/dir", null, "project/dir" );
41 assertAccurevRepo( "my_QA_Stream", "my_QA_Stream", null );
42
43 }
44
45 private static void assertAccurevRepo( String url, String expStream, String expPath )
46 throws ScmRepositoryException
47 {
48 AccuRevScmProvider provider = new AccuRevScmProvider();
49
50 AccuRevScmProviderRepository repository =
51 (AccuRevScmProviderRepository) provider.makeProviderScmRepository( url, ':' );
52
53 assertThat( repository, isRepo( null, null, null, AccuRev.DEFAULT_PORT, expStream, expPath ) );
54
55 }
56
57 @Test
58 public void testMakeProviderWithBothKindsOfDirectorySeparators()
59 throws ScmRepositoryException
60 {
61 assertThat( getRepo( "aStream:\\project\\dir" ), isRepo( null, null, null, 5050, "aStream", "project\\dir" ) );
62 }
63
64 @Test
65 public void testProviderWithHostPort()
66 throws Exception
67 {
68
69 assertThat( getRepo( "@myHost:aStream:/project/dir" ), isRepo( null, null, "myHost", AccuRev.DEFAULT_PORT,
70 "aStream", "project/dir" ) );
71 assertThat( getRepo( "@myHost:5051:/project/dir" ), isRepo( null, null, "myHost", 5051, null, "project/dir" ) );
72 }
73
74 @Test
75 public void testBlankAsUsedInTckTests()
76 throws ScmRepositoryException
77 {
78 assertThat( getRepo( ":aDepotStream" ), isRepo( null, null, null, 5050, "aDepotStream", null ) );
79 }
80
81 @Test
82 public void testProviderWithUserPass()
83 throws Exception
84 {
85 assertThat( getRepo( "aUser/theirPassword:/project/dir" ), isRepo( "aUser", "theirPassword", null,
86 AccuRev.DEFAULT_PORT, null, "project/dir" ) );
87
88 assertThat( getRepo( "aUser/theirPassword@theHost:5051:aStream:/project/dir" ), isRepo( "aUser",
89 "theirPassword",
90 "theHost", 5051,
91 "aStream",
92 "project/dir" ) );
93
94 assertThat( getRepo( "aUser@theHost:5050:aStream" ), isRepo( "aUser", null, "theHost", 5050, "aStream", null ) );
95
96 assertThat( getRepo( "aUser/" ), isRepo( "aUser", null, null, 5050, null, null ) );
97 }
98
99 @Test
100 public void testProviderWithProperties()
101 throws Exception
102 {
103 AccuRevScmProviderRepository repo =
104 getRepo( "aUser/theirPassword@theHost:5051:aStream:?tagFormat='depot_%s'&accurevExe=/opt/accurev/bin/accurev:/project/dir" );
105
106 assertThat( repo, isRepo( "aUser", "theirPassword", "theHost", 5051, "aStream", "project/dir" ) );
107 assertThat( repo.getAccuRev().getExecutable(), is( "/opt/accurev/bin/accurev" ) );
108 assertThat( repo.getTagFormat(), is( "depot_%s" ) );
109 }
110
111 @Test
112 public void testProviderWithSystemProperties()
113 throws Exception
114 {
115 String tagFormatProperty = AccuRevScmProvider.SYSTEM_PROPERTY_PREFIX + AccuRevScmProvider.TAG_FORMAT_PROPERTY;
116 System.setProperty( tagFormatProperty, "depot_%s" );
117 String exeProperty = AccuRevScmProvider.SYSTEM_PROPERTY_PREFIX + AccuRevScmProvider.ACCUREV_EXECUTABLE_PROPERTY;
118 System.setProperty( exeProperty, "/expect/overide" );
119
120 AccuRevScmProviderRepository repo =
121 getRepo( "aUser/theirPassword@theHost:5051:aStream:?accurevExe=/opt/accurev/bin/accurev:/project/dir" );
122
123 assertThat( repo, isRepo( "aUser", "theirPassword", "theHost", 5051, "aStream", "project/dir" ) );
124 assertThat( repo.getAccuRev().getExecutable(), is( "/opt/accurev/bin/accurev" ) );
125 assertThat( repo.getTagFormat(), is( "depot_%s" ) );
126
127 System.clearProperty( tagFormatProperty );
128 System.clearProperty( exeProperty );
129 }
130
131 private static AccuRevScmProviderRepository getRepo( String url )
132 throws ScmRepositoryException
133 {
134 AccuRevScmProviderRepository repo =
135 (AccuRevScmProviderRepository) new AccuRevScmProvider().makeProviderScmRepository( url, ':' );
136 return repo;
137 }
138
139 @Test
140 public void testGetSCMType()
141 {
142
143 assertThat( ( new AccuRevScmProvider() ).getScmType(), is( "accurev" ) );
144 }
145 }