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.opflex.jsonrpc;
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;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.fasterxml.jackson.databind.JsonNode;
27 public class JsonRpcServiceBinderHandlerTest {
28 protected static final Logger logger = LoggerFactory.getLogger(JsonRpcEndpoint.class);
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}";
39 private JsonRpcEndpoint mockEndpoint;
40 private JsonRpcServiceBinderHandler binderHandler;
41 private JsonRpcDecoder decoder;
42 private EmbeddedChannel channel;
45 public void setUp() throws Exception {
47 mockEndpoint = mock(JsonRpcEndpoint.class);
48 decoder = new JsonRpcDecoder(1000);
49 binderHandler = new JsonRpcServiceBinderHandler(mockEndpoint);
50 channel = new EmbeddedChannel(decoder, binderHandler);
55 public void testRequest() throws Exception {
56 channel.writeInbound(copiedBuffer(testRequest, CharsetUtil.UTF_8));
58 verify(mockEndpoint).processRequest((JsonNode)anyObject());
62 public void testResponse() throws Exception {
63 channel.writeInbound(copiedBuffer(testResponse, CharsetUtil.UTF_8));
65 verify(mockEndpoint).processResult((JsonNode)anyObject());