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.Server;
26  import org.eclipse.jetty.server.handler.DefaultHandler;
27  import org.eclipse.jetty.server.handler.HandlerList;
28  import org.eclipse.jetty.server.handler.ResourceHandler;
29  
30  import java.io.File;
31  import java.io.IOException;
32  import java.net.InetAddress;
33  import java.util.Properties;
34  
35  public class MavenIT0146InstallerSnapshotNaming
36      extends AbstractMavenIntegrationTestCase
37  {
38      private Server server;
39  
40      private int port;
41  
42      private final File testDir;
43  
44      public MavenIT0146InstallerSnapshotNaming()
45          throws IOException
46      {
47          super( "(2.0.2,)" );
48          testDir = ResourceExtractor.simpleExtractResources( getClass(), "/it0146" );
49      }
50  
51      @Override
52      protected void setUp()
53          throws Exception
54      {
55          ResourceHandler resourceHandler = new ResourceHandler();
56          resourceHandler.setResourceBase( new File( testDir, "repo" ).getAbsolutePath() );
57          HandlerList handlers = new HandlerList();
58          handlers.setHandlers( new Handler[]{ resourceHandler, new DefaultHandler() } );
59  
60          server = new Server( 0 );
61          server.setHandler( handlers );
62          server.start();
63          if ( server.isFailed() )
64          {
65              fail( "Couldn't bind the server socket to a free port!" );
66          }
67          port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
68          System.out.println( "Bound server socket to the port " + port );
69      }
70  
71  
72      @Override
73      protected void tearDown()
74          throws Exception
75      {
76          if ( server != null )
77          {
78              server.stop();
79              server.join();
80          }
81      }
82  
83      public void testitRemoteDownloadTimestampedName()
84          throws Exception
85      {
86          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
87  
88          Properties properties = verifier.newDefaultFilterProperties();
89          properties.setProperty( "@host@", InetAddress.getLoopbackAddress().getCanonicalHostName() );
90          properties.setProperty( "@port@", Integer.toString( port ) );
91  
92          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", properties );
93  
94          verifier.addCliOption( "--settings" );
95          verifier.addCliOption( "settings.xml" );
96  
97          verifier.deleteArtifacts( "org.apache.maven.its.it0146" );
98  
99          verifier.addCliOption( "-X" );
100 
101         verifier.deleteDirectory( "target" );
102 
103         verifier.executeGoal( "validate" );
104         verifier.verifyErrorFreeLog();
105         verifier.resetStreams();
106 
107         verifier.assertFilePresent( "target/appassembler/repo/dep-0.1-20110726.105319-1.jar" );
108     }
109 
110 
111     public void testitNonTimestampedNameWithInstalledSNAPSHOT()
112         throws Exception
113     {
114         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
115         verifier.deleteArtifacts( "org.apache.maven.its.it0146" );
116         verifier.addCliOption( "-f" );
117         verifier.addCliOption( "project/pom.xml" );
118         verifier.deleteDirectory( "project/target" );
119         verifier.setLogFileName( "log2.txt" );
120 
121         verifier.executeGoal( "install" );
122         verifier.verifyErrorFreeLog();
123         verifier.resetStreams();
124 
125         verifier = newVerifier( testDir.getAbsolutePath() );
126 
127         Properties properties = verifier.newDefaultFilterProperties();
128         properties.setProperty( "@host@", InetAddress.getLoopbackAddress().getCanonicalHostName() );
129         properties.setProperty( "@port@", Integer.toString( port ) );
130 
131         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", properties );
132 
133         verifier.addCliOption( "--settings" );
134         verifier.addCliOption( "settings.xml" );
135         verifier.setLogFileName( "log3.txt" );
136 
137 
138         verifier.addCliOption( "-X" );
139 
140         verifier.deleteDirectory( "target" );
141 
142         verifier.executeGoal( "validate" );
143         verifier.verifyErrorFreeLog();
144         verifier.resetStreams();
145 
146         verifier.assertFilePresent( "target/appassembler/repo/dep-0.1-SNAPSHOT.jar" );
147     }
148 }