1 | package omq.ztest.farm; |
---|
2 | |
---|
3 | import static org.junit.Assert.assertEquals; |
---|
4 | |
---|
5 | import java.util.Properties; |
---|
6 | |
---|
7 | import omq.common.broker.Broker; |
---|
8 | import omq.common.util.ParameterQueue; |
---|
9 | |
---|
10 | import org.junit.BeforeClass; |
---|
11 | import org.junit.Test; |
---|
12 | |
---|
13 | public class FarmTest { |
---|
14 | private static FarmImpl farm; |
---|
15 | private static Farm remoteFarm; |
---|
16 | |
---|
17 | @BeforeClass |
---|
18 | public static void startServer() throws Exception { |
---|
19 | Properties env = new Properties(); |
---|
20 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
21 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
22 | |
---|
23 | // Get host info of rabbimq (where it is) |
---|
24 | env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); |
---|
25 | env.setProperty(ParameterQueue.SERVER_PORT, "5672"); |
---|
26 | |
---|
27 | // Get info about the queue & the exchange where the RemoteListener will |
---|
28 | // listen to. |
---|
29 | env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); |
---|
30 | env.setProperty(ParameterQueue.RPC_QUEUE, "rpc_queue"); |
---|
31 | env.setProperty(ParameterQueue.RPC_ROUTING_KEY, "rpc"); |
---|
32 | |
---|
33 | farm = new FarmImpl(); |
---|
34 | |
---|
35 | Broker.initBroker(env); |
---|
36 | Broker.bind(Farm.class.getSimpleName(), farm); |
---|
37 | } |
---|
38 | |
---|
39 | @BeforeClass |
---|
40 | public static void startClient() throws Exception { |
---|
41 | Properties env = new Properties(); |
---|
42 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
43 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
44 | |
---|
45 | // Set host info of rabbimq (where it is) |
---|
46 | env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); |
---|
47 | env.setProperty(ParameterQueue.SERVER_PORT, "5672"); |
---|
48 | |
---|
49 | // Set info about where the message will be sent |
---|
50 | env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); |
---|
51 | env.setProperty(ParameterQueue.RPC_ROUTING_KEY, "rpc"); |
---|
52 | |
---|
53 | // Set info about the queue & the exchange where the ResponseListener |
---|
54 | // will listen to. |
---|
55 | env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "reply_queue"); |
---|
56 | env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue"); |
---|
57 | |
---|
58 | Broker.initBroker(env); |
---|
59 | |
---|
60 | remoteFarm = (Farm) Broker.lookup(Farm.class.getSimpleName(), Farm.class); |
---|
61 | } |
---|
62 | |
---|
63 | @Test |
---|
64 | public void addCow() throws Exception { |
---|
65 | String name = "muu"; |
---|
66 | |
---|
67 | Cow cow = new Cow(); |
---|
68 | cow.setName(name); |
---|
69 | |
---|
70 | remoteFarm.setCow(cow); |
---|
71 | Thread.sleep(100); |
---|
72 | |
---|
73 | assertEquals(name, farm.getCow().getName()); |
---|
74 | } |
---|
75 | |
---|
76 | @Test |
---|
77 | public void getPig() throws Exception { |
---|
78 | String name = "oing"; |
---|
79 | |
---|
80 | Pig pig = new Pig(); |
---|
81 | pig.setName(name); |
---|
82 | |
---|
83 | remoteFarm.setPig(pig); |
---|
84 | Thread.sleep(100); |
---|
85 | |
---|
86 | pig = remoteFarm.getPig(); |
---|
87 | |
---|
88 | assertEquals(name, pig.getName()); |
---|
89 | } |
---|
90 | } |
---|