KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > jndikit > rmi > test > AbstractRMIContextTestCase


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.spice.jndikit.rmi.test;
9
10 import javax.naming.Context JavaDoc;
11 import javax.naming.OperationNotSupportedException JavaDoc;
12 import javax.naming.NamingException JavaDoc;
13
14 import org.codehaus.spice.jndikit.rmi.RMIInitialContextFactory;
15 import org.codehaus.spice.jndikit.test.AbstractContextTestCase;
16 import junit.framework.AssertionFailedError;
17
18 /**
19  * Unit test for RMI context.
20  *
21  * @author Tim Anderson
22  * @version $Revision: 1.1 $
23  */

24 public abstract class AbstractRMIContextTestCase
25     extends AbstractContextTestCase
26 {
27
28     private final RMITestSetup _helper;
29
30     public AbstractRMIContextTestCase( RMIInitialContextFactory factory )
31     {
32         _helper = new RMITestSetup( factory );
33     }
34
35     public void testGetNameInNamespace() throws AssertionFailedError
36     {
37         try
38         {
39             Context JavaDoc sub1 = m_root.createSubcontext( "sub1");
40             Context JavaDoc sub2 = sub1.createSubcontext( "sub2");
41             Context JavaDoc sub3 = sub2.createSubcontext( "sub3");
42             Context JavaDoc sub4 = sub3.createSubcontext( "sub4");
43             assertEquals("sub1/sub2/sub3/sub4", sub4.getNameInNamespace());
44         }
45         catch( final NamingException JavaDoc ne )
46         {
47             throw new AssertionFailedError( ne.getMessage() );
48         }
49     }
50
51     /**
52      * Verifies that non-Serializable and non-Referenceable objects cannot be
53      * bound.
54      *
55      * @throws AssertionFailedError if the test fails
56      */

57     public void testInvalidBind() throws AssertionFailedError {
58         try
59         {
60             m_context.bind("invalid", new Object JavaDoc());
61             fail("Expected bind of non-Serializable, non-Referenceable object to throw NamingException");
62         } catch (final NamingException JavaDoc expected) {
63         }
64     }
65
66     protected void setUp() throws Exception JavaDoc
67     {
68         _helper.setUp();
69         super.setUp();
70     }
71
72     protected void tearDown() throws Exception JavaDoc
73     {
74         _helper.tearDown();
75         super.tearDown();
76     }
77
78     protected Context JavaDoc getRoot() throws Exception JavaDoc
79     {
80         return _helper.getRoot();
81     }
82
83 }
84
Popular Tags