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.Verifier;
23  import org.apache.maven.it.util.ResourceExtractor;
24  
25  import java.io.File;
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import java.util.List;
29  import java.util.Properties;
30  
31  import javax.servlet.ServletException;
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  import org.mortbay.jetty.Handler;
36  import org.mortbay.jetty.Request;
37  import org.mortbay.jetty.Server;
38  import org.mortbay.jetty.handler.AbstractHandler;
39  
40  /**
41   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4360">MNG-4360</a>.
42   * 
43   * @author Benjamin Bentmann
44   * @version $Id: MavenITmng4360WebDavSupportTest.java 981712 2010-08-03 00:36:19Z bentmann $
45   */
46  public class MavenITmng4360WebDavSupportTest
47      extends AbstractMavenIntegrationTestCase
48  {
49  
50      public MavenITmng4360WebDavSupportTest()
51      {
52          super( "[2.1.0-M1,)" );
53      }
54  
55      /**
56       * Verify that WebDAV works in principle. This test is not actually concerned about proper transfers but more 
57       * that the Jackrabbit based wagon can be properly loaded and doesn't die due to some class realm issue.
58       */
59      public void testitJackrabbitBasedImpl()
60          throws Exception
61      {
62          test( "jackrabbit" );
63      }
64  
65      /**
66       * Verify that WebDAV works in principle. This test is not actually concerned about proper transfers but more 
67       * that the Slide based wagon can be properly loaded and doesn't die due to some class realm issue.
68       */
69      public void testitSlideBasedImpl()
70          throws Exception
71      {
72          test( "slide" );
73      }
74  
75      private void test( String project )
76          throws Exception
77      {
78          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4360" );
79  
80          testDir = new File( testDir, project );
81  
82          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
83  
84          Handler repoHandler = new AbstractHandler()
85          {
86              public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
87                  throws IOException, ServletException
88              {
89                  System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
90  
91                  PrintWriter writer = response.getWriter();
92  
93                  response.setStatus( HttpServletResponse.SC_OK );
94  
95                  if ( request.getRequestURI().endsWith( ".pom" ) )
96                  {
97                      writer.println( "<project>" );
98                      writer.println( "  <modelVersion>4.0.0</modelVersion>" );
99                      writer.println( "  <groupId>org.apache.maven.its.mng4360</groupId>" );
100                     writer.println( "  <artifactId>dep</artifactId>" );
101                     writer.println( "  <version>0.1</version>" );
102                     writer.println( "</project>" );
103                 }
104                 else if ( request.getRequestURI().endsWith( ".jar" ) )
105                 {
106                     writer.println( "empty" );
107                 }
108                 else if ( request.getRequestURI().endsWith( ".md5" ) || request.getRequestURI().endsWith( ".sha1" ) )
109                 {
110                     response.setStatus( HttpServletResponse.SC_NOT_FOUND );
111                 }
112 
113                 ( (Request) request ).setHandled( true );
114             }
115         };
116 
117         Server server = new Server( 0 );
118         server.setHandler( repoHandler );
119         server.start();
120 
121         try
122         {
123             int port = server.getConnectors()[0].getLocalPort();
124 
125             verifier.setAutoclean( false );
126             verifier.deleteArtifacts( "org.apache.maven.its.mng4360" );
127             verifier.deleteDirectory( "target" );
128             Properties filterProps = verifier.newDefaultFilterProperties();
129             filterProps.setProperty( "@port@", Integer.toString( port ) );
130             verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", filterProps );
131             verifier.getCliOptions().add( "--settings" );
132             verifier.getCliOptions().add( "settings.xml" );
133             verifier.executeGoal( "validate" );
134             verifier.verifyErrorFreeLog();
135             verifier.resetStreams();
136         }
137         finally
138         {
139             server.stop();
140         }
141 
142         List cp = verifier.loadLines( "target/classpath.txt", "UTF-8" );
143         assertTrue( cp.toString(), cp.contains( "dep-0.1.jar" ) );
144     }
145 
146 }