Feature uses features-parent as parent
[groupbasedpolicy.git] / renderers / opflex / src / test / java / org / opendaylight / groupbasedpolicy / renderer / opflex / jsonrpc / JsonRpcServiceBinderHandlerTest.java
1 /*
2  * Copyright (C) 2014 Cisco Systems, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  *  Authors : Thomas Bachman
9  */
10
11 package org.opendaylight.groupbasedpolicy.renderer.opflex.jsonrpc;
12
13 import static io.netty.buffer.Unpooled.copiedBuffer;
14 import static org.mockito.Matchers.anyObject;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.verify;
17 import io.netty.channel.embedded.EmbeddedChannel;
18 import io.netty.util.CharsetUtil;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import com.fasterxml.jackson.databind.JsonNode;
26
27 public class JsonRpcServiceBinderHandlerTest {
28     protected static final Logger logger = LoggerFactory.getLogger(JsonRpcEndpoint.class);
29
30     // Used for testing incoming JSONRPC request messages
31     static final String testRequest =
32             "{ \"id\":\"2da9e3d7-0bbe-4099-b343-12783777452f\"," +
33             "\"method\":  \"test_foo\",\"params\":null}";
34     // Used for testing incoming JSONRPC response messages
35     static final String testResponse =
36             "{ \"id\":\"2da9e3d7-0bbe-4099-b343-12783777452f\"," +
37             "\"result\":\"foobar\",\"error\":null}";
38
39     private JsonRpcEndpoint mockEndpoint;
40     private JsonRpcServiceBinderHandler binderHandler;
41     private JsonRpcDecoder decoder;
42     private EmbeddedChannel channel;
43
44     @Before
45     public void setUp() throws Exception {
46
47         mockEndpoint = mock(JsonRpcEndpoint.class);
48         decoder = new JsonRpcDecoder(1000);
49         binderHandler = new JsonRpcServiceBinderHandler(mockEndpoint);
50         channel = new EmbeddedChannel(decoder, binderHandler);
51     }
52
53
54     @Test
55     public void testRequest() throws Exception {
56         channel.writeInbound(copiedBuffer(testRequest, CharsetUtil.UTF_8));
57         channel.finish();
58         verify(mockEndpoint).processRequest((JsonNode)anyObject());
59     }
60
61     @Test
62     public void testResponse() throws Exception {
63         channel.writeInbound(copiedBuffer(testResponse, CharsetUtil.UTF_8));
64         channel.finish();
65         verify(mockEndpoint).processResult((JsonNode)anyObject());
66
67     }
68
69 }