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:
19: /*
20: * Created on Feb 19, 2003
21: */
22: package org.apache.tools.ant.taskdefs;
23:
24: import java.io.IOException;
25:
26: import org.apache.tools.ant.util.JavaEnvUtils;
27:
28: import junit.framework.TestCase;
29:
30: /**
31: */
32: public class ProcessDestroyerTest extends TestCase {
33:
34: /**
35: * Constructor for ProcessDestroyerTest.
36: * @param arg0
37: */
38: public ProcessDestroyerTest(String arg0) {
39: super (arg0);
40: }
41:
42: public void testProcessDestroyer() {
43: if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
44: return;
45: }
46:
47: try {
48: ProcessDestroyer processDestroyer = new ProcessDestroyer();
49: Process process = Runtime.getRuntime().exec(
50: "java -cp " + System.getProperty("java.class.path")
51: + " " + getClass().getName());
52:
53: assertFalse("Not registered as shutdown hook",
54: processDestroyer.isAddedAsShutdownHook());
55:
56: processDestroyer.add(process);
57:
58: assertTrue("Registered as shutdown hook", processDestroyer
59: .isAddedAsShutdownHook());
60: try {
61: process.destroy();
62: } finally {
63: processDestroyer.remove(process);
64: }
65:
66: assertFalse("Not registered as shutdown hook",
67: processDestroyer.isAddedAsShutdownHook());
68: } catch (IOException e) {
69: e.printStackTrace();
70: }
71: }
72:
73: public static void main(String[] args) {
74: new ProcessDestroyerTest("testProcessDestroyer")
75: .testProcessDestroyer();
76: try {
77: Thread.sleep(60000);
78: } catch (InterruptedException ie) {
79: ie.printStackTrace();
80: }
81: }
82: }
|