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.util.ArrayList;
28  import java.util.Collections;
29  import java.util.List;
30  import java.util.Properties;
31  
32  import javax.servlet.ServletException;
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  
36  import org.mortbay.jetty.Server;
37  import org.mortbay.jetty.handler.AbstractHandler;
38  import org.mortbay.jetty.handler.DefaultHandler;
39  import org.mortbay.jetty.handler.HandlerList;
40  
41  /**
42   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4772">MNG-4772</a>.
43   * 
44   * @author Benjamin Bentmann
45   */
46  public class MavenITmng4772PluginVersionResolutionDoesntTouchDisabledRepoTest
47      extends AbstractMavenIntegrationTestCase
48  {
49  
50      public MavenITmng4772PluginVersionResolutionDoesntTouchDisabledRepoTest()
51      {
52          super( "[2.0.3,3.0-alpha-1),[3.0-beta-3,)" );
53      }
54  
55      /**
56       * Verify that repositories which have both releases and snapshots disabled aren't touched when looking for
57       * the latest plugin version.
58       */
59      public void testit()
60          throws Exception
61      {
62          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4772" );
63  
64          final List requestedUris = Collections.synchronizedList( new ArrayList() );
65  
66          AbstractHandler logHandler = new AbstractHandler()
67          {
68              public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
69                  throws IOException, ServletException
70              {
71                  requestedUris.add( request.getRequestURI() );
72              }
73          };
74  
75          HandlerList handlerList = new HandlerList();
76          handlerList.addHandler( logHandler );
77          handlerList.addHandler( new DefaultHandler() );
78  
79          Server server = new Server( 0 );
80          server.setHandler( handlerList );
81          server.start();
82  
83          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
84          try
85          {
86              verifier.setAutoclean( false );
87              verifier.deleteDirectory( "target" );
88              Properties filterProps = verifier.newDefaultFilterProperties();
89              filterProps.setProperty( "@port@", Integer.toString( server.getConnectors()[0].getLocalPort() ) );
90              verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
91              verifier.getCliOptions().add( "-U" );
92              verifier.getCliOptions().add( "-s" );
93              verifier.getCliOptions().add( "settings.xml" );
94              verifier.executeGoal( "org.apache.maven.its.mng4772:maven-it-plugin:touch" );
95              verifier.verifyErrorFreeLog();
96              fail( "Build should have failed to resolve version for unknown plugin" );
97          }
98          catch ( VerificationException e )
99          {
100             assertTrue( true );
101         }
102         finally
103         {
104             verifier.resetStreams();
105             server.stop();
106         }
107 
108         assertTrue( requestedUris.toString(), requestedUris.isEmpty() );
109     }
110 
111 }