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.lib;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
16 import java.util.ArrayList;
17 import java.util.List;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.groupbasedpolicy.jsonrpc.ConnectionService;
24 import org.opendaylight.groupbasedpolicy.jsonrpc.JsonRpcEndpoint;
25 import org.opendaylight.groupbasedpolicy.jsonrpc.RpcServer;
26 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.OpflexConnectionService;
27 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.OpflexRpcServer;
28 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.Role;
29 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.OpflexMessageTest;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
38 public class OpflexRpcServerTest implements ConnectionService {
39 protected static final Logger logger = LoggerFactory.getLogger(OpflexMessageTest.class);
40 private static final String TEST_IDENTITY = "localhost:6671";
41 private static final String TEST_IDENTITY2 = "localhost:6672";
42 private static final String TEST_DOMAIN = "default";
44 private OpflexRpcServer testServer = null;
45 private OpflexRpcServer ts1 = null;
46 private OpflexRpcServer ts2 = null;
47 private OpflexRpcServer ts3 = null;
48 private List<Role> roles = null;
51 private RpcServer mockServer;
53 private OpflexConnectionService mockService;
56 public void addConnection(JsonRpcEndpoint endpoint) {
60 public void channelClosed(JsonRpcEndpoint endpoint) throws Exception {
64 public void setUp() throws Exception {
65 MockitoAnnotations.initMocks(this);
66 roles = new ArrayList<Role>();
67 roles.add(Role.POLICY_REPOSITORY);
70 new OpflexRpcServer(TEST_DOMAIN, TEST_IDENTITY, roles);
71 testServer.setRpcBroker(mockService);
72 testServer.setConnectionService(mockService);
74 ts1 = new OpflexRpcServer(TEST_DOMAIN, TEST_IDENTITY, roles);
75 ts2 = new OpflexRpcServer(TEST_DOMAIN, TEST_IDENTITY2, roles);
76 roles = new ArrayList<Role>();
77 roles.add(Role.POLICY_ELEMENT);
78 ts3 = new OpflexRpcServer(TEST_DOMAIN, TEST_IDENTITY2, roles);
83 public void testStart() throws Exception {
85 assertTrue(testServer.getRpcServer() != null);
89 public void testSameServer() throws Exception {
90 assertTrue(testServer.sameServer(ts1));
91 assertFalse(testServer.sameServer(ts2));
92 assertFalse(testServer.sameServer(ts3));