View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4360">MNG-4360</a>.
39   *
40   * @author Benjamin Bentmann
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       * Verify that WebDAV works in principle. This test is not actually concerned about proper transfers but more
54       * that the Jackrabbit based wagon can be properly loaded and doesn't die due to some class realm issue.
55       *
56       * @throws Exception in case of failure
57       */
58      public void testitJackrabbitBasedImpl()
59          throws Exception
60      {
61          test( "jackrabbit" );
62      }
63  
64      /**
65       * Verify that WebDAV works in principle. This test is not actually concerned about proper transfers but more
66       * that the Slide based wagon can be properly loaded and doesn't die due to some class realm issue.
67       *
68       * @throws Exception in case of failure
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 }