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.FileUtils;
24  import org.apache.maven.it.util.ResourceExtractor;
25  
26  import java.io.File;
27  import java.util.Properties;
28  
29  /**
30   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4745">MNG-4745</a>.
31   * 
32   * @author Benjamin Bentmann
33   */
34  public class MavenITmng4745PluginVersionUpdateTest
35      extends AbstractMavenIntegrationTestCase
36  {
37  
38      public MavenITmng4745PluginVersionUpdateTest()
39      {
40          super( "[2.0.3,3.0-alpha-1),[3.0-beta-2,)" );
41      }
42  
43      /**
44       * Verify that the update policy of a (plugin) repository affects the check for newer plugin versions.
45       */
46      public void testitRepoPolicyAlways()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4745" );
50  
51          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
52          verifier.setAutoclean( false );
53          verifier.setForkJvm( true );
54          verifier.deleteArtifacts( "org.apache.maven.its.mng4745" );
55          verifier.getCliOptions().add( "-s" );
56          verifier.getCliOptions().add( "settings.xml" );
57          Properties filterProps = verifier.newDefaultFilterProperties();
58          filterProps.setProperty( "@updates@", "always" );
59          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
60  
61          writeMetadata( testDir, "1.0", "20100729123455" );
62          verifier.setLogFileName( "log-1a.txt" );
63          verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
64  
65          writeMetadata( testDir, "1.1", "20100730123456" );
66          verifier.setLogFileName( "log-1b.txt" );
67          verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
68  
69          verifier.verifyErrorFreeLog();
70          verifier.resetStreams();
71  
72          Properties props = verifier.loadProperties( "target/plugin.properties" );
73          assertEquals( "1.1", props.get( "plugin.version" ) );
74      }
75  
76      /**
77       * Verify that the update policy of a (plugin) repository affects the check for newer plugin versions.
78       */
79      public void testitRepoPolicyNever()
80          throws Exception
81      {
82          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4745" );
83  
84          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
85          verifier.setAutoclean( false );
86          verifier.setForkJvm( true );
87          verifier.deleteArtifacts( "org.apache.maven.its.mng4745" );
88          verifier.getCliOptions().add( "-s" );
89          verifier.getCliOptions().add( "settings.xml" );
90          Properties filterProps = verifier.newDefaultFilterProperties();
91          filterProps.setProperty( "@updates@", "never" );
92          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
93  
94          writeMetadata( testDir, "1.0", "20100729123455" );
95          verifier.setLogFileName( "log-2a.txt" );
96          verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
97  
98          writeMetadata( testDir, "1.1", "20100730123456" );
99          verifier.setLogFileName( "log-2b.txt" );
100         verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
101 
102         verifier.verifyErrorFreeLog();
103         verifier.resetStreams();
104 
105         Properties props = verifier.loadProperties( "target/plugin.properties" );
106         assertEquals( "1.0", props.get( "plugin.version" ) );
107     }
108 
109     /**
110      * Verify that the CLI's force update flag affects the check for newer plugin versions.
111      */
112     public void testitForceUpdate()
113         throws Exception
114     {
115         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4745" );
116 
117         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
118         verifier.setAutoclean( false );
119         verifier.setForkJvm( true );
120         verifier.deleteArtifacts( "org.apache.maven.its.mng4745" );
121         verifier.getCliOptions().add( "-U" );
122         verifier.getCliOptions().add( "-s" );
123         verifier.getCliOptions().add( "settings.xml" );
124         Properties filterProps = verifier.newDefaultFilterProperties();
125         filterProps.setProperty( "@updates@", "never" );
126         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
127 
128         writeMetadata( testDir, "1.0", "20100729123455" );
129         verifier.setLogFileName( "log-3a.txt" );
130         verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
131 
132         writeMetadata( testDir, "1.1", "20100730123456" );
133         verifier.setLogFileName( "log-3b.txt" );
134         verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
135 
136         verifier.verifyErrorFreeLog();
137         verifier.resetStreams();
138 
139         Properties props = verifier.loadProperties( "target/plugin.properties" );
140         assertEquals( "1.1", props.get( "plugin.version" ) );
141     }
142 
143     private static void writeMetadata( File testdir, String version, String timestamp )
144         throws Exception
145     {
146         StringBuffer content = new StringBuffer( 1024 );
147         content.append( "<?xml version=\"1.0\"?>\n" );
148         content.append( "<metadata>\n" );
149         content.append( "  <groupId>org.apache.maven.its.mng4745</groupId>\n" );
150         content.append( "  <artifactId>maven-it-plugin</artifactId>\n" );
151         content.append( "  <versioning>\n" );
152         content.append( "    <latest>" + version + "</latest>\n" );
153         content.append( "    <release>" + version + "</release>\n" );
154         content.append( "    <versions>\n" );
155         content.append( "      <version>1.0</version>\n" );
156         content.append( "    </versions>\n" );
157         content.append( "    <lastUpdated>" + timestamp + "</lastUpdated>\n" );
158         content.append( "  </versioning>\n" );
159         content.append( "</metadata>\n" );
160 
161         File metadata = new File( testdir, "repo/org/apache/maven/its/mng4745/maven-it-plugin/maven-metadata.xml" );
162         metadata.getParentFile().mkdirs();
163         FileUtils.fileWrite( metadata.getAbsolutePath(), "UTF-8", content.toString() );
164     }
165 
166 }