1 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 { 35 super.setUp(); 36 getRootContext(); 37 } 38 39 protected FileObject findResource(String 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 name) { 52 super(name); 53 } 54 55 public void testFlipFlap () throws ContextException { 56 Context ctx = getRootContext().createSubcontext("test");; 57 final String subCtxName = "subCtx"; 58 59 Object 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 { 74 String 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 |