Fix various warnings from json-rpc
[groupbasedpolicy.git] / groupbasedpolicy / src / test / java / org / opendaylight / groupbasedpolicy / renderer / lib / 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.lib.jsonrpc;
12
13 import static io.netty.buffer.Unpooled.copiedBuffer;
14 import io.netty.channel.embedded.EmbeddedChannel;
15 import com.fasterxml.jackson.databind.JsonNode;
16
17
18 import io.netty.util.CharsetUtil;
19 import org.junit.Before;
20 import org.junit.Test;
21 import static org.mockito.Mockito.*;
22
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class JsonRpcServiceBinderHandlerTest {
27     protected static final Logger logger = LoggerFactory.getLogger(JsonRpcEndpoint.class);
28
29     // Used for testing incoming JSONRPC request messages
30     static final String testRequest = 
31             "{ \"id\":\"2da9e3d7-0bbe-4099-b343-12783777452f\"," +
32             "\"method\":  \"test_foo\",\"params\":null}";
33     // Used for testing incoming JSONRPC response messages
34     static final String testResponse = 
35             "{ \"id\":\"2da9e3d7-0bbe-4099-b343-12783777452f\"," +
36             "\"result\":\"foobar\",\"error\":null}";
37     
38     private JsonRpcEndpoint mockEndpoint;
39     private JsonRpcServiceBinderHandler binderHandler;
40     private JsonRpcDecoder decoder;
41     private EmbeddedChannel channel;
42     
43     @Before
44     public void setUp() throws Exception {
45         
46         mockEndpoint = mock(JsonRpcEndpoint.class);
47         decoder = new JsonRpcDecoder(1000);
48         binderHandler = new JsonRpcServiceBinderHandler(mockEndpoint);
49         channel = new EmbeddedChannel(decoder, binderHandler);
50     }
51
52
53     @Test
54     public void testRequest() throws Exception {
55         channel.writeInbound(copiedBuffer(testRequest, CharsetUtil.UTF_8));
56         channel.finish();
57         verify(mockEndpoint).processRequest((JsonNode)anyObject());
58     }
59
60     //@Test
61     public void testResponse() throws Exception {
62         channel.writeInbound(copiedBuffer(testResponse, CharsetUtil.UTF_8));
63         channel.finish();
64         verify(mockEndpoint).processResult((JsonNode)anyObject());
65
66     }
67
68