View Javadoc
1   package org.apache.maven.plugins.repository.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 static org.apache.maven.plugins.repository.it.support.IntegrationTestUtils.getTestDir;
23  import static org.apache.maven.plugins.repository.testutil.Assertions.assertZipContents;
24  import static junit.framework.Assert.fail;
25  
26  import org.apache.maven.it.VerificationException;
27  import org.apache.maven.it.Verifier;
28  import org.apache.maven.plugins.repository.it.support.IntegrationTestUtils;
29  import org.apache.maven.plugins.repository.testutil.Assertions;
30  import org.junit.Test;
31  
32  import java.io.File;
33  import java.io.IOException;
34  import java.net.URISyntaxException;
35  import java.util.HashSet;
36  import java.util.List;
37  import java.util.Set;
38  
39  public class BundleCreateIT
40  {
41      
42      @SuppressWarnings( "unchecked" )
43      @Test
44      public void createWithSCMInfoProvided()
45          throws IOException, URISyntaxException, VerificationException
46      {
47          File dir = getTestDir( "bundle-create" );
48          
49          Verifier verifier = new Verifier( dir.getAbsolutePath() );
50          
51          verifier.getCliOptions().add( "--settings ../settings.xml" );
52          
53          String prefix = IntegrationTestUtils.getCliPluginPrefix();
54          
55          verifier.executeGoal( prefix + "bundle-create" );
56          verifier.verifyErrorFreeLog();
57          verifier.resetStreams();
58          
59          File bundleSource = new File( dir, "target/test-1.0-bundle.jar" );
60          
61          Set<String> requiredEntries = new HashSet<String>();
62          requiredEntries.add( "pom.xml" );
63          requiredEntries.add( "test-1.0.jar" );
64          requiredEntries.add( "test-1.0-sources.jar" );
65          
66          assertZipContents( requiredEntries, Assertions.EMPTY_ENTRY_NAMES, bundleSource );
67      }
68  
69      @SuppressWarnings( "unchecked" )
70      @Test
71      public void createWithSCMInfoMissing()
72          throws IOException, URISyntaxException, VerificationException
73      {
74          File dir = getTestDir( "bundle-create-no-scm" );
75          
76          Verifier verifier = new Verifier( dir.getAbsolutePath() );
77          
78          List<String> cliOptions = verifier.getCliOptions();
79          cliOptions.add( "--settings ../settings.xml" );
80          
81          String prefix = IntegrationTestUtils.getCliPluginPrefix();
82          
83          try
84          {
85              verifier.executeGoal( prefix + "bundle-create" );
86              verifier.verifyErrorFreeLog();
87              
88              fail( "No SCM Section provided, build should fail." );
89          }
90          catch( VerificationException e )
91          {
92              // expected, since POM doesn't supply a SCM section.
93          }
94          finally
95          {
96              verifier.resetStreams();
97          }
98      }
99      
100     @SuppressWarnings( "unchecked" )
101     @Test
102     public void createFromAlternativePom()
103         throws Exception
104     {
105         File dir = getTestDir( "bundle-create-alt-pom" );
106         
107         Verifier verifier = new Verifier( dir.getAbsolutePath() );
108         
109         verifier.getCliOptions().add( "-f alternative-pom.xml --settings ../settings.xml" );
110         
111         String prefix = IntegrationTestUtils.getCliPluginPrefix();
112         
113         verifier.executeGoal( prefix + "bundle-create" );
114         verifier.verifyErrorFreeLog();
115         verifier.resetStreams();
116         
117         File bundleSource = new File( dir, "target/test-1.0-bundle.jar" );
118         
119         Set<String> requiredEntries = new HashSet<String>();
120         requiredEntries.add( "pom.xml" );
121         requiredEntries.add( "test-1.0.jar" );
122         requiredEntries.add( "test-1.0-sources.jar" );
123         
124         assertZipContents( requiredEntries, Assertions.EMPTY_ENTRY_NAMES, bundleSource );
125     }
126 
127 }