KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > AnyMessageTest


1 package org.jacorb.test.notification;
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.Test;
24
25 import org.jacorb.notification.AnyMessage;
26 import org.jacorb.notification.NoTranslationException;
27 import org.jacorb.notification.interfaces.Message;
28 import org.omg.CORBA.Any JavaDoc;
29 import org.omg.CosNotification.Property;
30 import org.omg.CosNotification.StructuredEvent;
31
32 /**
33  * @author Alphonse Bendt
34  * @version $Id: AnyMessageTest.java,v 1.4 2005/02/14 00:15:46 alphonse.bendt Exp $
35  */

36 public class AnyMessageTest extends NotificationTestCase
37 {
38     private AnyMessage objectUnderTest_;
39
40     public AnyMessageTest(String JavaDoc name, NotificationTestCaseSetup setup)
41     {
42         super(name, setup);
43     }
44
45     public void setUpTest() throws Exception JavaDoc
46     {
47         objectUnderTest_ = new AnyMessage();
48     }
49
50     public void testType()
51     {
52         assertEquals(Message.TYPE_ANY, objectUnderTest_.getType());
53     }
54     
55     public void testToAny()
56     {
57         Any JavaDoc any = toAny("my precious");
58         
59         objectUnderTest_.setAny(any);
60         
61         assertEquals(any, objectUnderTest_.toAny());
62     }
63     
64     public void testToStructuredEvent()
65     {
66         Any JavaDoc any = toAny("value");
67         
68         objectUnderTest_.setAny(any);
69         
70         StructuredEvent event = objectUnderTest_.toStructuredEvent();
71         
72         assertEquals(any, event.remainder_of_body);
73         assertEquals("%ANY", event.header.fixed_header.event_type.type_name);
74     }
75     
76     public void testToTypedEvent() throws Exception JavaDoc
77     {
78         Property[] _props = new Property[] { new Property("operation", toAny("operationName")),
79                 new Property("p1", toAny("param1")), new Property("p2", toAny(10)) };
80
81         objectUnderTest_.setAny(toAny(_props));
82
83         Property[] ps = objectUnderTest_.toTypedEvent();
84
85         assertEquals("operation", ps[0].name);
86         assertEquals("operationName", ps[0].value.extract_string());
87     }
88
89     public void testNoTranslationPossible_1() throws Exception JavaDoc
90     {
91         Property[] _props = new Property[] { new Property("p1", toAny("param1")),
92                 new Property("p2", toAny(10)) };
93
94         objectUnderTest_.setAny(toAny(_props));
95
96         try
97         {
98             objectUnderTest_.toTypedEvent();
99
100             fail();
101         } catch (NoTranslationException e)
102         {
103             // expected
104
}
105     }
106
107     public void testNoTranslationPossible_2() throws Exception JavaDoc
108     {
109         objectUnderTest_.setAny(toAny("operation"));
110
111         try
112         {
113             objectUnderTest_.toTypedEvent();
114
115             fail();
116         } catch (NoTranslationException e)
117         {
118             // expected
119
}
120     }
121
122     public static Test suite() throws Exception JavaDoc
123     {
124         return NotificationTestCase.suite(AnyMessageTest.class);
125     }
126 }
Popular Tags