KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > progress > aggregate > AggregateProgressHandleTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.progress.aggregate;
21
22 import junit.framework.TestCase;
23 import org.netbeans.progress.module.Controller;
24 import org.netbeans.progress.spi.ProgressUIWorker;
25 import org.netbeans.progress.spi.ProgressEvent;
26
27 /**
28  *
29  * @author mkleint
30  */

31 public class AggregateProgressHandleTest extends TestCase {
32
33     public AggregateProgressHandleTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     protected void setUp() throws Exception JavaDoc {
38         Controller.defaultInstance = new Controller(new ProgressUIWorker() {
39             public void processProgressEvent(ProgressEvent event) { }
40             public void processSelectedProgressEvent(ProgressEvent event) { }
41         });
42     }
43
44     public void testContributorShare() throws Exception JavaDoc {
45         ProgressContributor contrib1 = AggregateProgressFactory.createProgressContributor("1");
46         ProgressContributor contrib2 = AggregateProgressFactory.createProgressContributor("2");
47         AggregateProgressHandle handle = AggregateProgressFactory.createHandle("fact1", new ProgressContributor[] { contrib1, contrib2}, null, null);
48         assertEquals(AggregateProgressHandle.WORKUNITS /2, contrib1.getRemainingParentWorkUnits());
49         assertEquals(AggregateProgressHandle.WORKUNITS /2, contrib2.getRemainingParentWorkUnits());
50         
51         ProgressContributor contrib3 = AggregateProgressFactory.createProgressContributor("3");
52         handle.addContributor(contrib3);
53         assertEquals(AggregateProgressHandle.WORKUNITS /3, contrib1.getRemainingParentWorkUnits());
54         assertEquals(AggregateProgressHandle.WORKUNITS /3, contrib2.getRemainingParentWorkUnits());
55         // the +1 deal is there because of the rounding, the last one gest the remainder
56
assertEquals(AggregateProgressHandle.WORKUNITS /3 + 1, contrib3.getRemainingParentWorkUnits());
57     }
58     
59     public void testDynamicContributorShare() throws Exception JavaDoc {
60         ProgressContributor contrib1 = AggregateProgressFactory.createProgressContributor("1");
61         AggregateProgressHandle handle = AggregateProgressFactory.createHandle("fact1", new ProgressContributor[] { contrib1}, null, null);
62         assertEquals(AggregateProgressHandle.WORKUNITS, contrib1.getRemainingParentWorkUnits());
63     
64         handle.start();
65         contrib1.start(100);
66         contrib1.progress(50);
67         assertEquals(AggregateProgressHandle.WORKUNITS /2, contrib1.getRemainingParentWorkUnits());
68         assertEquals(AggregateProgressHandle.WORKUNITS /2, handle.getCurrentProgress());
69         
70         ProgressContributor contrib2 = AggregateProgressFactory.createProgressContributor("2");
71         handle.addContributor(contrib2);
72         assertEquals(AggregateProgressHandle.WORKUNITS /4, contrib2.getRemainingParentWorkUnits());
73         contrib1.finish();
74         assertEquals(AggregateProgressHandle.WORKUNITS /4 * 3, handle.getCurrentProgress());
75         
76         ProgressContributor contrib3 = AggregateProgressFactory.createProgressContributor("3");
77         handle.addContributor(contrib3);
78         assertEquals(AggregateProgressHandle.WORKUNITS /8, contrib2.getRemainingParentWorkUnits());
79         assertEquals(AggregateProgressHandle.WORKUNITS /8, contrib3.getRemainingParentWorkUnits());
80         contrib3.start(100);
81         contrib3.finish();
82         assertEquals((AggregateProgressHandle.WORKUNITS /4 * 3) + (AggregateProgressHandle.WORKUNITS /8),
83                      handle.getCurrentProgress());
84         
85         
86     }
87     
88 }
89
Popular Tags