2 * Copyright (C) 2014 Cisco Systems, Inc.
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
8 * Authors : Thomas Bachman
11 package org.opendaylight.groupbasedpolicy.renderer.lib.jsonrpc;
13 import static io.netty.buffer.Unpooled.copiedBuffer;
14 import io.netty.channel.embedded.EmbeddedChannel;
15 import com.fasterxml.jackson.databind.JsonNode;
18 import io.netty.util.CharsetUtil;
19 import org.junit.Before;
20 import org.junit.Test;
21 import static org.mockito.Mockito.*;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class JsonRpcServiceBinderHandlerTest {
27 protected static final Logger logger = LoggerFactory.getLogger(JsonRpcEndpoint.class);
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}";
38 private JsonRpcEndpoint mockEndpoint;
39 private JsonRpcServiceBinderHandler binderHandler;
40 private JsonRpcDecoder decoder;
41 private EmbeddedChannel channel;
44 public void setUp() throws Exception {
46 mockEndpoint = mock(JsonRpcEndpoint.class);
47 decoder = new JsonRpcDecoder(1000);
48 binderHandler = new JsonRpcServiceBinderHandler(mockEndpoint);
49 channel = new EmbeddedChannel(decoder, binderHandler);
54 public void testRequest() throws Exception {
55 channel.writeInbound(copiedBuffer(testRequest, CharsetUtil.UTF_8));
57 verify(mockEndpoint).processRequest((JsonNode)anyObject());
61 public void testResponse() throws Exception {
62 channel.writeInbound(copiedBuffer(testResponse, CharsetUtil.UTF_8));
64 verify(mockEndpoint).processResult((JsonNode)anyObject());