1 package org.apache.maven.it;
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.it.util.ResourceExtractor;
23 import org.eclipse.jetty.server.Handler;
24 import org.eclipse.jetty.server.NetworkConnector;
25 import org.eclipse.jetty.server.Request;
26 import org.eclipse.jetty.server.Server;
27 import org.eclipse.jetty.server.handler.AbstractHandler;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.io.File;
32 import java.io.IOException;
33 import java.io.PrintWriter;
34 import java.util.List;
35 import java.util.Properties;
36
37
38
39
40
41
42
43 public class MavenITmng4360WebDavSupportTest
44 extends AbstractMavenIntegrationTestCase
45 {
46
47 public MavenITmng4360WebDavSupportTest()
48 {
49 super( "[2.1.0-M1,)" );
50 }
51
52
53
54
55
56
57
58 public void testitJackrabbitBasedImpl()
59 throws Exception
60 {
61 test( "jackrabbit" );
62 }
63
64
65
66
67
68
69
70 public void testitSlideBasedImpl()
71 throws Exception
72 {
73 test( "slide" );
74 }
75
76 private void test( String project )
77 throws Exception
78 {
79 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4360" );
80
81 testDir = new File( testDir, project );
82
83 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
84
85 Handler repoHandler = new AbstractHandler()
86 {
87 @Override
88 public void handle( String target, Request baseRequest, HttpServletRequest request,
89 HttpServletResponse response )
90 throws IOException
91 {
92 System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
93
94 PrintWriter writer = response.getWriter();
95
96 response.setStatus( HttpServletResponse.SC_OK );
97
98 if ( request.getRequestURI().endsWith( ".pom" ) )
99 {
100 writer.println( "<project>" );
101 writer.println( " <modelVersion>4.0.0</modelVersion>" );
102 writer.println( " <groupId>org.apache.maven.its.mng4360</groupId>" );
103 writer.println( " <artifactId>dep</artifactId>" );
104 writer.println( " <version>0.1</version>" );
105 writer.println( "</project>" );
106 }
107 else if ( request.getRequestURI().endsWith( ".jar" ) )
108 {
109 writer.println( "empty" );
110 }
111 else if ( request.getRequestURI().endsWith( ".md5" ) || request.getRequestURI().endsWith( ".sha1" ) )
112 {
113 response.setStatus( HttpServletResponse.SC_NOT_FOUND );
114 }
115
116 ( (Request) request ).setHandled( true );
117 }
118 };
119
120 Server server = new Server( 0 );
121 server.setHandler( repoHandler );
122
123 try
124 {
125 server.start();
126 if ( server.isFailed() )
127 {
128 fail( "Couldn't bind the server socket to a free port!" );
129 }
130 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
131 System.out.println( "Bound server socket to the port " + port );
132 verifier.setAutoclean( false );
133 verifier.deleteArtifacts( "org.apache.maven.its.mng4360" );
134 verifier.deleteDirectory( "target" );
135 Properties filterProps = verifier.newDefaultFilterProperties();
136 filterProps.setProperty( "@port@", Integer.toString( port ) );
137 verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", filterProps );
138 verifier.addCliOption( "--settings" );
139 verifier.addCliOption( "settings.xml" );
140 verifier.executeGoal( "validate" );
141 verifier.verifyErrorFreeLog();
142 verifier.resetStreams();
143 }
144 finally
145 {
146 server.stop();
147 server.join();
148 }
149
150 List<String> cp = verifier.loadLines( "target/classpath.txt", "UTF-8" );
151 assertTrue( cp.toString(), cp.contains( "dep-0.1.jar" ) );
152 }
153 }