source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 2.5 KB
Line 
1/*
2 * Copyright 2003-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18/*
19 * Created on Feb 19, 2003
20 */
21package org.apache.tools.ant.taskdefs;
22
23import java.io.IOException;
24
25import org.apache.tools.ant.util.JavaEnvUtils;
26
27import junit.framework.TestCase;
28
29/**
30 */
31public class ProcessDestroyerTest extends TestCase {
32
33 /**
34 * Constructor for ProcessDestroyerTest.
35 * @param arg0
36 */
37 public ProcessDestroyerTest(String arg0) {
38 super(arg0);
39 }
40
41 public void testProcessDestroyer(){
42 if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)
43 || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
44 return;
45 }
46
47 try {
48 ProcessDestroyer processDestroyer = new ProcessDestroyer();
49 Process process =
50 Runtime.getRuntime().exec(
51 "java -cp "
52 + System.getProperty("java.class.path")
53 + " "
54 + getClass().getName());
55
56 assertFalse("Not registered as shutdown hook",
57 processDestroyer.isAddedAsShutdownHook());
58
59 processDestroyer.add(process);
60
61 assertTrue("Registered as shutdown hook",
62 processDestroyer.isAddedAsShutdownHook());
63 try {
64 process.destroy();
65 } finally {
66 processDestroyer.remove(process);
67 }
68
69 assertFalse("Not registered as shutdown hook",
70 processDestroyer.isAddedAsShutdownHook());
71 } catch (IOException e) {
72 e.printStackTrace();
73 }
74 }
75
76 public static void main(String[] args){
77 new ProcessDestroyerTest("testProcessDestroyer").testProcessDestroyer();
78 try{
79 Thread.sleep(60000);
80 }catch(InterruptedException ie){
81 ie.printStackTrace();
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.