001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildFileTest;
022: import org.apache.tools.ant.util.JavaEnvUtils;
023:
024: /**
025: * Testcase for the Signjar task
026: *
027: */
028: public class SignJarTest extends BuildFileTest {
029:
030: public static final String EXPANDED_MANIFEST = "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF";
031:
032: public SignJarTest(String name) {
033: super (name);
034: }
035:
036: public void setUp() {
037: configureProject("src/etc/testcases/taskdefs/signjar.xml");
038: }
039:
040: public void tearDown() {
041: executeTarget("clean");
042: }
043:
044: /**
045: * check for being offline
046: * @return true iff the system property "offline" is "true"
047: */
048: private boolean isOffline() {
049: return Boolean.getBoolean("offline");
050: }
051:
052: public void testBasicSigning() {
053: executeTarget("basic");
054: }
055:
056: public void testSigFile() {
057: executeTarget("sigfile");
058: }
059:
060: public void testMaxMemory() {
061: executeTarget("maxmemory");
062: }
063:
064: public void testURLKeystoreFile() {
065: executeTarget("urlKeystoreFile");
066: }
067:
068: public void testURLKeystoreHTTP() {
069: if (!isOffline()) {
070: executeTarget("urlKeystoreHTTP");
071: }
072: }
073:
074: public void testPreserveLastModified() {
075: executeTarget("preserveLastModified");
076: }
077:
078: public void testFileset() {
079: executeTarget("testFileset");
080: }
081:
082: public void testFilesetAndJar() {
083: executeTarget("testFilesetAndJar");
084: }
085:
086: public void testFilesetAndSignedJar() {
087: expectBuildExceptionContaining("testFilesetAndSignedJar",
088: "incompatible attributes",
089: SignJar.ERROR_SIGNEDJAR_AND_PATHS);
090: }
091:
092: public void testPath() {
093: executeTarget("testPath");
094: }
095:
096: public void testPathAndJar() {
097: executeTarget("testPathAndJar");
098: }
099:
100: public void testPathAndSignedJar() {
101: expectBuildExceptionContaining("testPathAndSignedJar",
102: "incompatible attributes",
103: SignJar.ERROR_SIGNEDJAR_AND_PATHS);
104: }
105:
106: public void testSignedJar() {
107: executeTarget("testSignedJar");
108: }
109:
110: public void testDestDir() {
111: executeTarget("testDestDir");
112: }
113:
114: public void testDestDirAndSignedJar() {
115: expectBuildExceptionContaining("testFilesetAndSignedJar",
116: "incompatible attributes",
117: SignJar.ERROR_SIGNEDJAR_AND_PATHS);
118: }
119:
120: public void testDestDirAndSignedJar2() {
121: expectBuildExceptionContaining("testPathAndSignedJar",
122: "incompatible attributes",
123: SignJar.ERROR_SIGNEDJAR_AND_PATHS);
124: }
125:
126: public void testDestDirFileset() {
127: executeTarget("testDestDirFileset");
128: }
129:
130: public void testMapperFileset() {
131: executeTarget("testMapperFileset");
132: }
133:
134: public void testDestDirPath() {
135: executeTarget("testDestDirPath");
136: }
137:
138: public void testMapperPath() {
139: executeTarget("testMapperPath");
140: }
141:
142: public void testMapperNoDest() {
143: expectBuildExceptionContaining("testMapperNoDest",
144: "two mappers", SignJar.ERROR_MAPPER_WITHOUT_DEST);
145: }
146:
147: public void testTwoMappers() {
148: expectBuildExceptionContaining("testTwoMappers", "two mappers",
149: SignJar.ERROR_TOO_MANY_MAPPERS);
150: }
151:
152: public void testNoAlias() {
153: expectBuildExceptionContaining("testNoAlias", "no alias",
154: SignJar.ERROR_NO_ALIAS);
155: }
156:
157: public void testNoFiles() {
158: expectBuildExceptionContaining("testNoFiles", "no files",
159: SignJar.ERROR_NO_SOURCE);
160: }
161:
162: public void testNoStorePass() {
163: expectBuildExceptionContaining("testNoStorePass",
164: "no password", SignJar.ERROR_NO_STOREPASS);
165: }
166:
167: public void testTsaLocalhost() {
168: //only test on java1.5+
169: if (JavaEnvUtils.getJavaVersionNumber() >= 15) {
170: expectBuildException("testTsaLocalhost",
171: "no TSA at localhost:0");
172: assertLogContaining("java.net.ConnectException");
173: }
174: }
175:
176: public void testSysProperty() {
177: executeTarget("testSysProperty");
178: }
179:
180: public void testVerifyJar() {
181: executeTarget("testVerifyJar");
182: }
183:
184: public void testVerifyNoArgs() {
185: expectBuildExceptionContaining("testVerifyNoArgs", "no args",
186: AbstractJarSignerTask.ERROR_NO_SOURCE);
187: }
188:
189: public void testVerifyJarUnsigned() {
190: expectBuildExceptionContaining("testVerifyJarUnsigned",
191: "unsigned JAR file", VerifyJar.ERROR_NO_VERIFY);
192: }
193:
194: public void NotestVerifyJarNotInKeystore() {
195: expectBuildExceptionContaining("testVerifyJarNotInKeystore",
196: "signature not in keystore", VerifyJar.ERROR_NO_VERIFY);
197: }
198:
199: public void testVerifyFileset() {
200: executeTarget("testVerifyFileset");
201: }
202:
203: public void testVerifyPath() {
204: executeTarget("testVerifyPath");
205: }
206:
207: }
|