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 java.io.File;
23  import java.util.Properties;
24  
25  import org.apache.maven.it.util.ResourceExtractor;
26  import org.apache.maven.shared.utils.Os;
27  
28  import static org.hamcrest.CoreMatchers.anyOf;
29  import static org.hamcrest.CoreMatchers.endsWith;
30  import static org.junit.Assert.assertThat;
31  
32  /**
33   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-6386">MNG-6386</a>.
34   */
35  public class MavenITmng6386BaseUriPropertyTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng6386BaseUriPropertyTest()
40      {
41          super( "[3.5.4,)" );
42      }
43  
44      public void testitMNG6386()
45          throws Exception
46      {
47          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6386" ).getCanonicalFile();
48  
49          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
50          verifier.setAutoclean( false );
51          verifier.deleteDirectory( "target" );
52          verifier.setLogFileName( "log-basic.txt" );
53          verifier.executeGoal( "validate" );
54          verifier.verifyErrorFreeLog();
55          verifier.resetStreams();
56  
57          Properties props = verifier.loadProperties( "target/profile.properties" );
58          String pomProperty = props.getProperty( "project.properties.pomProperty" );
59          // set via project
60          assertEquals( testDir.toPath().toUri().toASCIIString(), pomProperty );
61          // check that baseUri begins with file:///
62          assertTrue( pomProperty.startsWith( "file:///" ) );
63      }
64  
65       public void testitMNG6386UnicodeChars()
66          throws Exception
67      {
68          String fileEncoding = System.getProperty( "file.encoding" );
69          /*
70           * Unfortunately, AbstractMavenIntegrationTestCase still uses JUnit 3.8 which does not have
71           * Assume, so we cannot make assumptions and skip the test on non-compatible systems.
72           */
73          if ( Os.isFamily( Os.FAMILY_WINDOWS ) ||
74               "UTF-8".equalsIgnoreCase( fileEncoding ) || "UTF8".equalsIgnoreCase( fileEncoding ) )
75          {
76              File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6386-это по-русский" ).getCanonicalFile();
77  
78              Verifier verifier = newVerifier( testDir.getAbsolutePath() );
79              verifier.setAutoclean( false );
80              verifier.deleteDirectory( "target" );
81              verifier.setLogFileName( "log-basic.txt" );
82              verifier.executeGoal( "validate" );
83              verifier.verifyErrorFreeLog();
84              verifier.resetStreams();
85  
86              Properties props = verifier.loadProperties( "target/profile.properties" );
87              String pomProperty = props.getProperty( "project.properties.pomProperty" );
88              // set via project
89              assertEquals( testDir.toPath().toUri().toASCIIString(), pomProperty );
90              // check that baseUri begins with file:///
91              assertTrue( pomProperty.startsWith( "file:///" ) );
92              // check that baseUri ends with "это по-русский/", but properly URI-encoded
93              // We need to make sure that either form NFC or NFD is accepted since HFS+ and APFS might use them
94              assertThat( pomProperty, anyOf( endsWith( "%D1%8D%D1%82%D0%BE%20%D0%BF%D0%BE-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9/" ),
95                                              endsWith( "%D1%8D%D1%82%D0%BE%20%D0%BF%D0%BE-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B8%CC%86/" ) ) );
96          }
97          else
98          {
99              System.out.println();
100             System.out.println( "[WARNING] Skipping MNG-6386 Unicode Chars Test on incompatible encoding: " + fileEncoding );
101             System.out.println();
102         }
103     }
104 
105 }