source: trunk/src/test/java/omq/test/calculator/ClientTest.java @ 51

Last change on this file since 51 was 51, checked in by stoda, 11 years ago
File size: 2.8 KB
Line 
1package omq.test.calculator;
2
3import static org.junit.Assert.assertEquals;
4
5import java.util.Arrays;
6import java.util.Collection;
7import java.util.Properties;
8
9import omq.common.broker.Broker;
10import omq.common.util.ParameterQueue;
11import omq.common.util.Serializer;
12
13import org.junit.After;
14import org.junit.Test;
15import org.junit.runner.RunWith;
16import org.junit.runners.Parameterized;
17import org.junit.runners.Parameterized.Parameters;
18
19@RunWith(value = Parameterized.class)
20public class ClientTest {
21
22        private static Calculator remoteCalc;
23        private static Calculator remoteCalc2;
24
25        public ClientTest(String type) throws Exception {
26                Properties env = new Properties();
27                env.setProperty(ParameterQueue.USER_NAME, "guest");
28                env.setProperty(ParameterQueue.USER_PASS, "guest");
29
30                // Set host info of rabbimq (where it is)
31                env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1");
32                env.setProperty(ParameterQueue.SERVER_PORT, "5672");
33                env.setProperty(ParameterQueue.DURABLE_QUEUES, "false");
34                env.setProperty(ParameterQueue.SERIALIZER_NAME, type);
35                env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false");
36
37                // Set info about where the message will be sent
38                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
39                // env.setProperty(ParameterQueue.DEBUGFILE, "c:\\middlewareDebug");
40
41                // Set info about the queue & the exchange where the ResponseListener
42                // will listen to.
43                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
44                env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue");
45
46                Broker.initBroker(env);
47                remoteCalc = (Calculator) Broker.lookup("calculator1", Calculator.class);
48                remoteCalc2 = (Calculator) Broker.lookup("calculator2", Calculator.class);
49        }
50
51        @Parameters
52        public static Collection<Object[]> data() {
53                Object[][] data = new Object[][] { { Serializer.java }, { Serializer.gson }, { Serializer.kryo } };
54                return Arrays.asList(data);
55        }
56
57        @After
58        public void stop() throws Exception {
59                Broker.stopBroker();
60        }
61
62        @Test
63        public void add() throws Exception {
64                int x = 10;
65                int y = 20;
66
67                int sync = remoteCalc.add(x, y);
68                int sum = x + y;
69
70                assertEquals(sum, sync);
71        }
72
73        @Test
74        public void add2() throws Exception {
75                int x = 10;
76                int y = 20;
77
78                int sync = remoteCalc2.add(x, y);
79                int sum = x + y;
80
81                assertEquals(sum, sync);
82        }
83
84        @Test
85        public void mult() throws Exception {
86                int x = 5;
87                int y = 15;
88
89                remoteCalc.mult(x, y);
90                Thread.sleep(200);
91        }
92
93        @Test
94        public void notifyEvent() throws Exception {
95                ZeroListener zL = new ZeroListener("zero-event");
96
97                remoteCalc.addListener(zL);
98
99                remoteCalc.asyncDivideByZero();
100
101                Thread.sleep(200);
102        }
103
104        @Test
105        public void sendMessage() throws Exception {
106                Message m = new Message(2334, "Hello objectmq");
107                remoteCalc.sendMessage(m);
108        }
109
110        @Test(expected = ArithmeticException.class)
111        public void divideByZero() {
112                remoteCalc.divideByZero();
113        }
114}
Note: See TracBrowser for help on using the repository browser.