8b41fede8a7232aa966d58981de139950fe5cedb
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / DispatchersTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.utils;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.anyString;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import akka.dispatch.MessageDispatcher;
17 import org.junit.Test;
18
19 public class DispatchersTest {
20
21     @Test
22     public void testGetDefaultDispatcherPath() {
23         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
24         doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
25         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
26
27         for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
28             assertEquals(Dispatchers.DEFAULT_DISPATCHER_PATH,
29                     dispatchers.getDispatcherPath(type));
30         }
31
32     }
33
34     @Test
35     public void testGetDefaultDispatcher() {
36         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
37         MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
38         doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
39         doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
40         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
41
42         for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
43             assertEquals(mockGlobalDispatcher,
44                     dispatchers.getDispatcher(type));
45         }
46
47     }
48
49     @Test
50     public void testGetDispatcherPath() {
51         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
52         doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
53         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
54
55         assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
56                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
57
58         assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
59                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
60
61         assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
62                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
63
64         assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
65                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
66
67     }
68
69     @Test
70     public void testGetDispatcher() {
71         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
72         MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
73         doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
74         doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
75         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
76
77         assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
78                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
79
80         assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
81                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
82
83         assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
84                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
85
86         assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
87                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
88
89     }
90 }