source: trunk/src/test/java/omq/test/calculator/CalculatorTest.java @ 73

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

All the references of event removed

File size: 3.4 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.BeforeClass;
15import org.junit.Test;
16import org.junit.runner.RunWith;
17import org.junit.runners.Parameterized;
18import org.junit.runners.Parameterized.Parameters;
19
20@RunWith(value = Parameterized.class)
21public class CalculatorTest {
22
23        private static Broker broker;
24        private static Calculator remoteCalc;
25        private static Calculator remoteCalc2;
26
27        public CalculatorTest(String type) throws Exception {
28                Properties env = new Properties();
29                env.setProperty(ParameterQueue.USER_NAME, "guest");
30                env.setProperty(ParameterQueue.USER_PASS, "guest");
31
32                // Set host info of rabbimq (where it is)
33                env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1");
34                env.setProperty(ParameterQueue.SERVER_PORT, "5672");
35                env.setProperty(ParameterQueue.DURABLE_QUEUES, "false");
36                env.setProperty(ParameterQueue.SERIALIZER_NAME, type);
37                env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false");
38
39                // Set info about where the message will be sent
40                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
41
42                // Set info about the queue & the exchange where the ResponseListener
43                // will listen to.
44                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
45
46                broker = new Broker(env);
47                remoteCalc = broker.lookup("calculator1", Calculator.class);
48                remoteCalc2 = 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        @BeforeClass
58        public static void server() throws Exception {
59                Properties env = new Properties();
60                env.setProperty(ParameterQueue.USER_NAME, "guest");
61                env.setProperty(ParameterQueue.USER_PASS, "guest");
62
63                // Get host info of rabbimq (where it is)
64                env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1");
65                env.setProperty(ParameterQueue.SERVER_PORT, "5672");
66                env.setProperty(ParameterQueue.DURABLE_QUEUES, "false");
67                env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false");
68
69                // Set info about where the message will be sent
70                env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange");
71                env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000");
72
73                CalculatorImpl calc = new CalculatorImpl();
74                CalculatorImpl calc2 = new CalculatorImpl();
75
76                Broker broker = new Broker(env);
77                broker.bind("calculator1", calc);
78                broker.bind("calculator2", calc2);
79
80                System.out.println("Server started");
81        }
82
83        @After
84        public void stop() throws Exception {
85                broker.stopBroker();
86        }
87
88        @Test
89        public void add() throws Exception {
90                int x = 10;
91                int y = 20;
92
93                int sync = remoteCalc.add(x, y);
94                int sum = x + y;
95
96                assertEquals(sum, sync);
97        }
98
99        @Test
100        public void add2() throws Exception {
101                int x = 10;
102                int y = 20;
103
104                int sync = remoteCalc2.add(x, y);
105                int sum = x + y;
106
107                assertEquals(sum, sync);
108        }
109
110        @Test
111        public void mult() throws Exception {
112                int x = 5;
113                int y = 15;
114
115                remoteCalc.mult(x, y);
116                Thread.sleep(200);
117        }
118
119        @Test
120        public void sendMessage() throws Exception {
121                Message m = new Message(2334, "Hello objectmq");
122                remoteCalc.sendMessage(m);
123        }
124
125        @Test(expected = ArithmeticException.class)
126        public void divideByZero() {
127                remoteCalc.divideByZero();
128        }
129}
Note: See TracBrowser for help on using the repository browser.