source: trunk/src/test/java/calculatorTest/ClientTest.java @ 44

Last change on this file since 44 was 44, checked in by stoda, 11 years ago

Objectmq converted to maven project

File size: 2.4 KB
Line 
1package calculatorTest;
2
3import static org.junit.Assert.assertEquals;
4
5import java.util.Properties;
6
7import omq.common.broker.Broker;
8import omq.common.util.ParameterQueue;
9import omq.common.util.Serializer;
10
11import org.junit.BeforeClass;
12import org.junit.Test;
13
14public class ClientTest {
15        private static Calculator remoteCalc;
16        private static Calculator remoteCalc2;
17
18        @BeforeClass
19        public static void startClient() throws Exception {
20                Properties env = new Properties();
21                env.setProperty(ParameterQueue.USER_NAME, "guest");
22                env.setProperty(ParameterQueue.USER_PASS, "guest");
23
24                // Set host info of rabbimq (where it is)
25                env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1");
26                env.setProperty(ParameterQueue.SERVER_PORT, "5672");
27                env.setProperty(ParameterQueue.DURABLE_QUEUES, "false");
28                env.setProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java);
29                env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false");
30
31                // Set info about where the message will be sent
32                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
33                // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug");
34
35                // Set info about the queue & the exchange where the ResponseListener
36                // will listen to.
37                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
38                env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue");
39
40                Broker.initBroker(env);
41                remoteCalc = (Calculator) Broker.lookup("calculator1", Calculator.class);
42                remoteCalc2 = (Calculator) Broker.lookup("calculator2", Calculator.class);
43        }
44
45        @Test
46        public void add() throws Exception {
47                int x = 10;
48                int y = 20;
49
50                int sync = remoteCalc.add(x, y);
51                int sum = x + y;
52
53                assertEquals(sum, sync);
54        }
55
56        @Test
57        public void add2() throws Exception {
58                int x = 10;
59                int y = 20;
60
61                int sync = remoteCalc2.add(x, y);
62                int sum = x + y;
63
64                assertEquals(sum, sync);
65        }
66
67        @Test
68        public void mult() throws Exception {
69                int x = 5;
70                int y = 15;
71
72                remoteCalc.mult(x, y);
73                Thread.sleep(200);
74        }
75
76        @Test
77        public void notifyEvent() throws Exception {
78                ZeroListener zL = new ZeroListener("zero-event");
79
80                remoteCalc.addListener(zL);
81
82                remoteCalc.asyncDivideByZero();
83
84                Thread.sleep(200);
85        }
86
87        @Test
88        public void sendMessage() throws Exception {
89                Message m = new Message(2334, "Hello objectmq");
90                remoteCalc.sendMessage(m);
91        }
92
93        @Test(expected = ArithmeticException.class)
94        public void divideByZero() {
95                remoteCalc.divideByZero();
96        }
97}
Note: See TracBrowser for help on using the repository browser.