source: trunk/src/test/java/exceptionTest/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.3 KB
Line 
1package exceptionTest;
2
3import static org.junit.Assert.assertEquals;
4
5import java.lang.reflect.UndeclaredThrowableException;
6import java.util.Properties;
7
8import omq.common.broker.Broker;
9import omq.common.util.ParameterQueue;
10import omq.common.util.Serializer;
11
12import org.junit.BeforeClass;
13import org.junit.Test;
14
15public class ClientTest {
16        private static ClientInterface client;
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.kryo);
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
34                // Set info about the queue & the exchange where the ResponseListener
35                // will listen to.
36                env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue");
37                env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue");
38
39                Broker.initBroker(env);
40                client = (ClientInterface) Broker.lookup("server", ClientInterface.class);
41        }
42
43        @Test
44        public void addWheels() throws Exception {
45                int wheels = 4;
46                client.addWheels(wheels);
47                Thread.sleep(200);
48                int result = client.getWheels();
49
50                assertEquals(wheels, result);
51        }
52
53        @Test
54        public void addHp() throws Exception {
55                int hp = 200;
56                client.addHp(hp);
57                Thread.sleep(200);
58                int result = client.getHp();
59
60                assertEquals(hp, result);
61        }
62
63        @Test
64        public void addTrailer() throws Exception {
65                Trailer t = new Trailer(1200);
66                client.addTrailer(t);
67                Thread.sleep(200);
68        }
69
70        @Test(expected = UndeclaredThrowableException.class)
71        // This exception will be caused by java.lang.NoSuchMethodException
72        public void getTrailer() throws Exception {
73                client.getTrailer();
74        }
75
76        @Test
77        public void setPrice() throws Exception {
78                double price = 4999.99;
79                client.setPrice(price);
80                Thread.sleep(200);
81        }
82
83        @Test(expected = ClassCastException.class)
84        public void getPrice() throws Exception {
85                client.getPrice();
86        }
87}
Note: See TracBrowser for help on using the repository browser.