View Javadoc
1   package org.apache.maven.shared.jarsigner;
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.shared.utils.cli.javatool.JavaToolResult;
23  
24  import java.io.File;
25  
26  /**
27   * @author Olivier Lamy
28   */
29  public class SimpleJarSignTest
30      extends AbstractJarSignerTest
31  {
32      private JarSigner jarSigner;
33  
34      public void setUp()
35          throws Exception
36      {
37          super.setUp();
38  
39          jarSigner = (JarSigner) lookup( JarSigner.class.getName() );
40      }
41  
42      public void testSimpleSign()
43          throws Exception
44      {
45          File target = prepareTestJar( "simple.jar" );
46  
47          JarSignerSignRequest jarSignerRequest = new JarSignerSignRequest();
48          jarSignerRequest.setArchive( target );
49          jarSignerRequest.setKeystore( "src/test/keystore" );
50          jarSignerRequest.setVerbose( true );
51          jarSignerRequest.setAlias( "foo_alias" );
52          jarSignerRequest.setKeypass( "key-passwd" );
53          jarSignerRequest.setStorepass( "changeit" );
54          jarSignerRequest.setSignedjar( new File( "target/ssimple.jar" ) );
55  
56          JavaToolResult jarSignerResult = jarSigner.execute( jarSignerRequest );
57  
58          assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
59      }
60  
61      public void testSimpleSignAndVerify()
62          throws Exception
63      {
64          testSimpleSign();
65  
66          JarSignerVerifyRequest request = new JarSignerVerifyRequest();
67          request.setCerts( true );
68          request.setVerbose( true );
69          request.setArchive( new File( "target/ssimple.jar" ) );
70          request.setKeystore( "src/test/keystore" );
71          request.setAlias( "foo_alias" );
72          request.setStorepass( "changeit" );
73  
74          JavaToolResult jarSignerResult = jarSigner.execute( request );
75  
76          assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
77      }
78  }