KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > registry > mergedctx > ReusedSubcontextTest


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 package org.netbeans.api.registry.mergedctx;
20
21 import org.netbeans.api.registry.Context;
22 import org.netbeans.api.registry.ContextException;
23 import org.netbeans.api.registry.SubcontextTest;
24 import org.openide.filesystems.FileObject;
25
26 public class ReusedSubcontextTest extends SubcontextTest{
27     private Context rootCtx;
28     protected Context getRootContext() {
29         if (rootCtx == null)
30             rootCtx = SetUpUtils.getSimpleContext(super.getRootContext());
31         return rootCtx;
32     }
33
34     protected void setUp() throws Exception JavaDoc {
35         super.setUp();
36         getRootContext();
37     }
38
39     protected FileObject findResource(String JavaDoc resource) {
40         return SetUpUtils.findSimpleResource(resource);
41     }
42
43     protected FileObject getFileObject() {
44         return SetUpUtils.getSimpleRoot();
45     }
46
47     protected FileObject getRoot() {
48         return SetUpUtils.getSimpleRoot();
49     }
50
51     public ReusedSubcontextTest(String JavaDoc name) {
52         super(name);
53     }
54
55     public void testFlipFlap () throws ContextException {
56         Context ctx = getRootContext().createSubcontext("test");;
57         final String JavaDoc subCtxName = "subCtx";
58
59         Object JavaDoc tmpObj;
60
61         tmpObj = ctx.createSubcontext(subCtxName);
62         assertEquals("Unexpected: different instances",tmpObj, ctx.getSubcontext(subCtxName));
63
64         ctx.destroySubcontext(subCtxName);
65         tmpObj = ctx.createSubcontext(subCtxName);
66         assertEquals("Unexpected: different instances",tmpObj, ctx.getSubcontext(subCtxName));
67
68         ctx.destroySubcontext(subCtxName);
69         tmpObj = ctx.createSubcontext(subCtxName);
70         assertEquals("Unexpected: different instances",tmpObj, ctx.getSubcontext(subCtxName));
71     }
72
73     public void testDestroyContext () throws Exception JavaDoc {
74         String JavaDoc subCtxName = "subct12345";
75         Context subctx = getRootContext().createSubcontext (subCtxName);
76         Context parent = subctx.getParentContext();
77         parent.destroySubcontext (subCtxName);
78         assertTrue("Parent Context found", parent.getSubcontext(subCtxName) == null);
79     }
80
81 }
82
Popular Tags