| 1 | package omq.ztest.calculator; |
|---|
| 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 ClientTest { |
|---|
| 14 | private static Calculator remoteCalc; |
|---|
| 15 | private static Calculator remoteCalc2; |
|---|
| 16 | |
|---|
| 17 | @BeforeClass |
|---|
| 18 | public static void startClient() throws Exception { |
|---|
| 19 | Properties env = new Properties(); |
|---|
| 20 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
|---|
| 21 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
|---|
| 22 | |
|---|
| 23 | // Set 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 | // env.setProperty(ParameterQueue.SERIALIZERNAME, |
|---|
| 27 | // "omq.common.util.Serializers.KryoImp"); |
|---|
| 28 | env.setProperty(ParameterQueue.SERIALIZERNAME, "omq.common.util.Serializers.GsonImp"); |
|---|
| 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.divideByZero(); |
|---|
| 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 | } |
|---|