Merge "Initial implementation of the ClusteredDataStore"
[controller.git] / opendaylight / md-sal / clustered-data-store / implementation / src / test / java / org / opendaylight / controller / datastore / internal / ActivatorTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.datastore.internal;
11
12 import org.apache.felix.dm.Component;
13 import org.apache.felix.dm.ServiceDependency;
14
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
18
19 import static junit.framework.Assert.assertNotNull;
20 import static org.junit.Assert.assertEquals;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23
24 public class ActivatorTest {
25
26         private static  ServiceDependency serviceDependency;
27         
28         @BeforeClass 
29         public static void initialize(){
30                 serviceDependency = mock(ServiceDependency.class);
31         }
32         
33         private class ActivatorTestImpl extends Activator{
34                  protected ServiceDependency createServiceDependency() {
35                         return ActivatorTest.serviceDependency;
36                     }
37         }
38         
39     @Test
40     public void construct(){
41         assertNotNull(new Activator());
42     }
43     
44     @Test
45     public void construct_OnInvokeOfGlobalImpl_ShouldReturnNotNullObject(){
46         Activator activator = new Activator();
47         
48         assertNotNull(activator.getGlobalImplementations());
49         assertEquals(ClusteredDataStoreManager.class,activator.getGlobalImplementations()[0]);
50     }
51     
52     @Test
53     public void construct_OnInvokeOfConfigGlobalInstance_ShouldNotThrowAnyExceptions(){
54         Activator activator = new ActivatorTestImpl();
55         
56         Component c = mock(Component.class);
57         Object clusterDataStoreMgr = ClusteredDataStoreManager.class;
58         
59         when(serviceDependency.setService(IClusterGlobalServices.class)).thenReturn(serviceDependency);
60         when(serviceDependency.setCallbacks("setClusterGlobalServices",
61                     "unsetClusterGlobalServices")).thenReturn(serviceDependency);
62         when(serviceDependency.setRequired(true)).thenReturn(serviceDependency);
63         
64         
65         activator.configureGlobalInstance(c, clusterDataStoreMgr);
66         
67         
68     }
69     
70 }