01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.tools.ant.taskdefs.optional;
19:
20: import org.apache.tools.ant.BuildException;
21: import org.apache.tools.ant.taskdefs.Execute;
22: import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
23: import org.apache.tools.ant.types.Commandline;
24: import junit.framework.TestCase;
25:
26: public class RpmTest extends TestCase {
27:
28: public void testShouldThrowExceptionWhenRpmFails() throws Exception {
29: Rpm rpm = new MyRpm();
30: rpm.setProject(new org.apache.tools.ant.Project());
31: rpm.setFailOnError(true);
32: // execute
33: try {
34: rpm.execute();
35: fail("should have thrown a build exception");
36: } catch (BuildException ex) {
37: assertTrue(ex.getMessage().indexOf(
38: "' failed with exit code 2") != -1);
39: }
40: }
41:
42: public void testShouldNotThrowExceptionWhenRpmFails()
43: throws Exception {
44: Rpm rpm = new MyRpm();
45: rpm.execute();
46: }
47:
48: // override some of the code so we can test the handling of the
49: // return code only.
50: public static class MyRpm extends Rpm {
51: protected Execute getExecute(Commandline toExecute,
52: ExecuteStreamHandler streamhandler) {
53: return new Execute() {
54: public int execute() {
55: // 2 is != 0 and even, so it is considered
56: // failure on any platform currently supported
57: // by Execute#isFailure.
58: return 2;
59: }
60: };
61: }
62:
63: public void log(String msg, int msgLevel) {
64: }
65: }
66:
67: }
|