KickJava   Java API By Example, From Geeks To Geeks.

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


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.TypedEventMessage;
26 import org.jacorb.test.notification.typed.CoffeeHelper;
27 import org.omg.CORBA.Any JavaDoc;
28 import org.omg.CosNotification.EventType;
29 import org.omg.CosNotification.EventTypeHelper;
30 import org.omg.CosNotification.Property;
31 import org.omg.CosNotification.PropertySeqHelper;
32 import org.omg.CosNotification.StructuredEvent;
33
34 /**
35  * @author Alphonse Bendt
36  * @version $Id: TypedEventMessageTest.java,v 1.6 2005/05/01 21:14:29 alphonse.bendt Exp $
37  */

38 public class TypedEventMessageTest extends NotificationTestCase
39 {
40     private static final Property[] EMPTY_PROPS = new Property[0];
41
42     private TypedEventMessage objectUnderTest_;
43
44     private static String JavaDoc DRINKING_COFFEE_ID = "::org::jacorb::test::notification::typed::Coffee::drinking_coffee";
45
46     public void setUpTest() throws Exception JavaDoc
47     {
48         objectUnderTest_ = new TypedEventMessage();
49     }
50
51     public TypedEventMessageTest(String JavaDoc name, NotificationTestCaseSetup setup)
52     {
53         super(name, setup);
54     }
55
56     public void testToProperty()
57     {
58         objectUnderTest_.setTypedEvent(CoffeeHelper.id(), "drinking_coffee", EMPTY_PROPS);
59
60         Property[] _props = objectUnderTest_.toTypedEvent();
61
62         assertEquals(1, _props.length);
63         assertEquals("event_type", _props[0].name);
64
65         EventType et = EventTypeHelper.extract(_props[0].value);
66         assertEquals(CoffeeHelper.id(), et.domain_name);
67         assertEquals("drinking_coffee", et.type_name);
68     }
69
70     public void testToAny()
71     {
72         objectUnderTest_.setTypedEvent(CoffeeHelper.id(), DRINKING_COFFEE_ID, EMPTY_PROPS);
73
74         Any JavaDoc _any = objectUnderTest_.toAny();
75
76         assertEquals(PropertySeqHelper.type(), _any.type());
77
78         Property[] _props = PropertySeqHelper.extract(_any);
79
80         assertEquals(1, _props.length);
81
82         assertEquals("operation", _props[0].name);
83
84         assertEquals(DRINKING_COFFEE_ID, _props[0].value.extract_string());
85     }
86
87     public void testToStructured()
88     {
89         objectUnderTest_.setTypedEvent(CoffeeHelper.id(), DRINKING_COFFEE_ID, EMPTY_PROPS);
90
91         StructuredEvent _structEvent = objectUnderTest_.toStructuredEvent();
92
93         assertEquals(1, _structEvent.filterable_data.length);
94
95         assertEquals("operation", _structEvent.filterable_data[0].name);
96
97         assertEquals(DRINKING_COFFEE_ID, _structEvent.filterable_data[0].value.extract_string());
98
99         assertEquals("%TYPED", _structEvent.header.fixed_header.event_type.type_name);
100     }
101
102     public static Test suite() throws Exception JavaDoc
103     {
104         return NotificationTestCase.suite(TypedEventMessageTest.class);
105     }
106 }
107
Popular Tags