1 package org.apache.maven.wagon.providers.scm;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.manager.plexus.DefaultScmManager;
23 import org.apache.maven.scm.provider.ScmProvider;
24 import org.apache.maven.wagon.FileTestUtils;
25 import org.apache.maven.wagon.ResourceDoesNotExistException;
26 import org.apache.maven.wagon.TransferFailedException;
27 import org.apache.maven.wagon.Wagon;
28 import org.apache.maven.wagon.WagonConstants;
29 import org.apache.maven.wagon.WagonTestCase;
30 import org.apache.maven.wagon.authorization.AuthorizationException;
31 import org.apache.maven.wagon.repository.Repository;
32 import org.apache.maven.wagon.resource.Resource;
33 import org.codehaus.plexus.util.FileUtils;
34
35 import java.io.File;
36 import java.io.IOException;
37 import java.util.List;
38
39
40
41
42
43
44
45 public abstract class AbstractScmWagonTest
46 extends WagonTestCase
47 {
48
49 @Override
50 public void testWagonPutDirectory() throws Exception
51 {
52 super.testWagonPutDirectory();
53
54
55
56 super.testWagonPutDirectory();
57 }
58
59 private ScmWagon wagon;
60
61 private String providerClassName;
62
63 protected void setUp()
64 throws Exception
65 {
66 super.setUp();
67
68 FileUtils.deleteDirectory( getCheckoutDirectory() );
69
70 if ( wagon == null )
71 {
72 wagon = (ScmWagon) super.getWagon();
73
74 DefaultScmManager scmManager = (DefaultScmManager) wagon.getScmManager();
75
76 if ( getScmProvider() != null )
77 {
78 scmManager.setScmProvider( getScmId(), getScmProvider() );
79
80 providerClassName = getScmProvider().getClass().getName();
81 }
82 else
83 {
84 providerClassName = scmManager.getProviderByType( getScmId() ).getClass().getName();
85 }
86
87 wagon.setCheckoutDirectory( getCheckoutDirectory() );
88 }
89 }
90
91
92
93
94
95
96
97
98 protected ScmProvider getScmProvider()
99 {
100 return null;
101 }
102
103 protected Wagon getWagon()
104 throws Exception
105 {
106 return wagon;
107 }
108
109 private File getCheckoutDirectory()
110 {
111 return new File( FileTestUtils.getTestOutputDir(), "/checkout-" + providerClassName );
112 }
113
114 protected int getExpectedContentLengthOnGet( int expectedSize )
115 {
116 return WagonConstants.UNKNOWN_LENGTH;
117 }
118
119 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
120 {
121 return 0;
122 }
123
124
125
126
127
128
129 protected abstract String getScmId();
130
131 protected String getProtocol()
132 {
133 return "scm";
134 }
135
136 protected void createDirectory( Wagon wagon, String resourceToCreate, String dirName )
137 throws Exception
138 {
139 super.createDirectory( wagon, resourceToCreate, dirName );
140 FileUtils.deleteDirectory( getCheckoutDirectory() );
141 }
142
143 protected void assertResourcesAreInRemoteSide( Wagon wagon, List<String> resourceNames )
144 throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException
145 {
146 FileUtils.deleteDirectory( getCheckoutDirectory() );
147 super.assertResourcesAreInRemoteSide( wagon, resourceNames );
148 }
149 }