KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.test.notification;
2
3 import org.omg.CORBA.Any JavaDoc;
4 import org.omg.CORBA.LongSeqHelper JavaDoc;
5 import org.omg.CORBA.ORB JavaDoc;
6 import org.omg.CosNotification.EventHeader;
7 import org.omg.CosNotification.EventType;
8 import org.omg.CosNotification.FixedEventHeader;
9 import org.omg.CosNotification.Property;
10 import org.omg.CosNotification.StructuredEvent;
11 import org.omg.CosNotification.StructuredEventHelper;
12
13 /**
14  * @author Alphonse Bendt
15  */

16
17 public class NotificationTestUtils {
18
19     private final ORB JavaDoc orb_;
20     
21     public NotificationTestUtils(ORB JavaDoc orb) {
22         orb_ = orb;
23     }
24
25     public StructuredEvent getStructuredEvent() {
26         StructuredEvent _structuredEvent = getEmptyStructuredEvent();
27
28         _structuredEvent.header.fixed_header.event_name = "ALARM";
29         _structuredEvent.header.fixed_header.event_type.domain_name = "TESTING";
30         _structuredEvent.header.fixed_header.event_type.type_name = "TESTING";
31
32         _structuredEvent.remainder_of_body = getTestPersonAny();
33
34         return _structuredEvent;
35     }
36
37     public StructuredEvent getEmptyStructuredEvent() {
38         FixedEventHeader _fixedHeader = new FixedEventHeader();
39         _fixedHeader.event_name = "";
40         _fixedHeader.event_type = new EventType("", "");
41         EventHeader _header = new EventHeader(_fixedHeader, new Property[0]);
42
43         StructuredEvent _structuredEvent =
44             new StructuredEvent(_header, new Property[0], orb_.create_any());
45
46         return _structuredEvent;
47     }
48
49
50     public Any JavaDoc getStructuredEventAny() {
51         Any JavaDoc _structuredEventAny = orb_.create_any();
52
53         StructuredEventHelper.insert(_structuredEventAny, getStructuredEvent());
54
55         return _structuredEventAny;
56     }
57
58
59     public Person getTestPerson() {
60         // prepare test data
61
Person _p = new Person();
62         Address _a = new Address();
63
64         _p.first_name = "firstname";
65         _p.last_name = "lastname";
66         _p.age = 5;
67         _p.phone_numbers = new String JavaDoc[2];
68         _p.phone_numbers[0] = "12345678";
69         _p.phone_numbers[1] = "";
70         _p.nv = new NamedValue[2];
71         _p.nv[0] = new NamedValue();
72         _p.nv[1] = new NamedValue();
73         _p.person_profession = Profession.STUDENT;
74         _a.street = "Takustr.";
75         _a.number = 9;
76         _a.city = "Berlin";
77         _p.home_address = _a;
78         _p.aliases = new String JavaDoc[] {"Alias0", "Alias1", "Alias2"};
79         _p.numbers = new int[] {10, 20, 30, 40, 50};
80
81         return _p;
82     }
83
84     public Any JavaDoc getTestPersonAny() {
85         Any JavaDoc _testPerson;
86
87         _testPerson = orb_.create_any();
88         PersonHelper.insert(_testPerson, getTestPerson());
89
90         return _testPerson;
91     }
92
93     public Any JavaDoc getSizedTestData(int size) {
94         Any JavaDoc _testData = orb_.create_any();
95         int[] _payload = new int[size];
96         for (int x=0; x<size; ++x) {
97             _payload[x] = x;
98         }
99
100         LongSeqHelper.insert(_testData, _payload);
101
102         return _testData;
103     }
104
105     static StructuredEvent invalidStructuredEvent_;
106
107     public static StructuredEvent getInvalidStructuredEvent(ORB JavaDoc orb) {
108         if (invalidStructuredEvent_ == null) {
109             synchronized(NotificationTestUtils.class.getName()) {
110                 if (invalidStructuredEvent_ == null) {
111                     FixedEventHeader _fixedHeader = new FixedEventHeader();
112                     _fixedHeader.event_name = "";
113                     _fixedHeader.event_type = new EventType("","");
114                     EventHeader _header = new EventHeader(_fixedHeader, new Property[0]);
115
116                     invalidStructuredEvent_ =
117                         new StructuredEvent(_header, new Property[0], orb.create_any());
118                 }
119             }
120         }
121         return invalidStructuredEvent_;
122     }
123 }
124
Popular Tags