KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > bugs > bug384 > TestCase


1 package org.jacorb.test.bugs.bug384;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import junit.framework.*;
24
25 import org.omg.CORBA.*;
26 import org.jacorb.test.common.*;
27 import org.omg.PortableServer.*;
28
29
30 /**
31  * Tests that the _is_a() operation on object references gives correct
32  * results for both local and non-local objects.
33  *
34  * @author Gerald Brose
35  * @version $Id: TestCase.java,v 1.4 2003/10/30 10:03:13 nick.cross Exp $
36  */

37
38 public class TestCase
39     extends ClientServerTestCase
40 {
41     private org.omg.CORBA.Object JavaDoc testObject;
42     private org.omg.CORBA.Object JavaDoc localTestObject;
43     private POA poa;
44     private org.omg.CORBA.ORB JavaDoc orb;
45
46     public TestCase( String JavaDoc name, ClientServerSetup setup )
47     {
48         super( name, setup );
49     }
50
51     public void setUp()
52     {
53         testObject = setup.getServerObject();
54         orb = org.omg.CORBA.ORB.init( new String JavaDoc[0], null);
55     try
56     {
57         poa = POAHelper.narrow( orb.resolve_initial_references("RootPOA"));
58
59         poa.the_POAManager().activate();
60
61         localTestObject =
62                 poa.servant_to_reference( new TestObjectImpl());
63         }
64         catch( Exception JavaDoc e )
65         {
66             e.printStackTrace();
67         }
68     }
69
70
71     public static Test suite()
72     {
73         TestSuite suite = new TestSuite( "bug 384 wrong is_a results" );
74
75         try
76         {
77             ClientServerSetup setup =
78                 new ClientServerSetup( suite,
79                                        "org.jacorb.test.bugs.bug384.TestObjectImpl" );
80
81             suite.addTest( new TestCase( "testNonLocalIsA", setup ));
82             suite.addTest( new TestCase( "testLocalIsA", setup ));
83             suite.addTest( new TestCase( "testMarshall", setup ));
84
85             return setup;
86         }
87         catch( Exception JavaDoc e )
88         {
89             e.printStackTrace();
90         }
91         return null;
92     }
93
94     public void testNonLocalIsA()
95     {
96         assertTrue( "Is_a incorrectly returns false for non-local object",
97                      testObject._is_a( "IDL:org/jacorb/test/bugs/bug384/TestObject:1.0") );
98
99         assertFalse( "Is_a incorrectly returns true for non-local object",
100                     testObject._is_a( "IDL:omg.org/CosNaming/NamingContext:1.0" ));
101     }
102
103     public void testLocalIsA()
104     {
105         assertTrue( "Is_a incorrectly returns false for non-local object",
106                      localTestObject._is_a( "IDL:org/jacorb/test/bugs/bug384/TestObject:1.0") );
107
108         assertFalse( "Is_a incorrectly returns true for non-local object",
109                     localTestObject._is_a( "IDL:omg.org/CosNaming/NamingContext:1.0" ));
110     }
111
112     public void testMarshall()
113     {
114         TestObject serverObj = TestObjectHelper.narrow( testObject );
115         try
116         {
117             A[] result = serverObj.testMarshall();
118         }
119         catch (Exception JavaDoc e)
120         {
121             fail( "Caught an exception " + e );
122         }
123     }
124
125
126     public void tearDown() throws Exception JavaDoc
127     {
128         super.tearDown();
129         orb.shutdown( true );
130     }
131
132
133     public static void main( String JavaDoc[] args )
134     {
135         junit.textui.TestRunner.run( TestCase.class );
136     }
137
138 }
139
Popular Tags