Added range type to subject-feature-definition/parameter
[groupbasedpolicy.git] / renderers / opflex / src / test / java / org / opendaylight / groupbasedpolicy / renderer / opflex / lib / OpflexRpcServerTest.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.lib;
12
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
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;
32
33
34
35 /**
36  *
37  */
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";
43
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;
49
50     @Mock
51     private RpcServer mockServer;
52     @Mock
53     private OpflexConnectionService mockService;
54
55     @Override
56     public void addConnection(JsonRpcEndpoint endpoint) {
57     }
58
59     @Override
60     public void channelClosed(JsonRpcEndpoint endpoint) throws Exception {
61     }
62
63     @Before
64     public void setUp() throws Exception {
65         MockitoAnnotations.initMocks(this);
66         roles = new ArrayList<Role>();
67         roles.add(Role.POLICY_REPOSITORY);
68
69         testServer =
70                 new OpflexRpcServer(TEST_DOMAIN, TEST_IDENTITY, roles);
71         testServer.setRpcBroker(mockService);
72         testServer.setConnectionService(mockService);
73
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);
79     }
80
81
82     @Test
83     public void testStart() throws Exception {
84         testServer.start();
85         assertTrue(testServer.getRpcServer() != null);
86     }
87
88     @Test
89     public void testSameServer() throws Exception {
90         assertTrue(testServer.sameServer(ts1));
91         assertFalse(testServer.sameServer(ts2));
92         assertFalse(testServer.sameServer(ts3));
93     }
94
95 }