1 package org.jacorb.test.notification; 2 3 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 ; 29 import org.omg.CosNotification.Property; 30 import org.omg.CosNotification.StructuredEvent; 31 32 36 public class AnyMessageTest extends NotificationTestCase 37 { 38 private AnyMessage objectUnderTest_; 39 40 public AnyMessageTest(String name, NotificationTestCaseSetup setup) 41 { 42 super(name, setup); 43 } 44 45 public void setUpTest() throws Exception 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 any = toAny("my precious"); 58 59 objectUnderTest_.setAny(any); 60 61 assertEquals(any, objectUnderTest_.toAny()); 62 } 63 64 public void testToStructuredEvent() 65 { 66 Any 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 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 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 } 105 } 106 107 public void testNoTranslationPossible_2() throws Exception 108 { 109 objectUnderTest_.setAny(toAny("operation")); 110 111 try 112 { 113 objectUnderTest_.toTypedEvent(); 114 115 fail(); 116 } catch (NoTranslationException e) 117 { 118 } 120 } 121 122 public static Test suite() throws Exception 123 { 124 return NotificationTestCase.suite(AnyMessageTest.class); 125 } 126 } | Popular Tags |