Fix NoSuchMethodError in Eclipse IDE by removing M2E lifecycle mapping
[mdsal.git] / singleton-service / mdsal-singleton-dom-impl / src / test / java / org / opendaylight / mdsal / singleton / common / spi / ClusterSingletonServiceRegistrationDelegatorTest.java
1 /*
2  * Copyright (c) 2016 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.mdsal.singleton.common.spi;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.verify;
15 import com.google.common.util.concurrent.Futures;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
22 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
23
24 /**
25  * Testing {@link ClusterSingletonServiceRegistrationDelegator}
26  */
27 public class ClusterSingletonServiceRegistrationDelegatorTest {
28
29     private static final String SERVICE_IDENTIFIER_NAME = "TestServiceIdent";
30     private static final ServiceGroupIdentifier SERVICE_IDENTIFIER = ServiceGroupIdentifier
31             .create(SERVICE_IDENTIFIER_NAME);
32
33     @Mock
34     private ClusterSingletonServiceGroup<?, ?, ?> mockClusterSingletonServiceGroup;
35     @Mock
36     private ClusterSingletonService mockClusterSingletonService;
37
38     private ClusterSingletonServiceRegistrationDelegator delegator;
39
40     /**
41      * Initialization functionality for every Tests in this suite
42      *
43      * @throws Exception - unexpected setup exception
44      */
45     @Before
46     public void setup() throws Exception {
47         MockitoAnnotations.initMocks(this);
48
49         doNothing().when(mockClusterSingletonServiceGroup)
50                 .unregisterService(any(ClusterSingletonServiceRegistrationDelegator.class));
51         doReturn(SERVICE_IDENTIFIER).when(mockClusterSingletonService).getIdentifier();
52         doNothing().when(mockClusterSingletonService).instantiateServiceInstance();
53         doReturn(Futures.immediateFuture(null)).when(mockClusterSingletonService).closeServiceInstance();
54         delegator = new ClusterSingletonServiceRegistrationDelegator(mockClusterSingletonService,
55                 mockClusterSingletonServiceGroup);
56     }
57
58     /**
59      * Test create input with {@link ClusterSingletonService} as null
60      */
61     @Test(expected = NullPointerException.class)
62     public void testSetupNullService() {
63         delegator = new ClusterSingletonServiceRegistrationDelegator(null, mockClusterSingletonServiceGroup);
64     }
65
66     /**
67      * Test create input with {@link ClusterSingletonServiceGroupImpl} as null
68      */
69     @Test(expected = NullPointerException.class)
70     public void testSetupNullGroup() {
71         delegator = new ClusterSingletonServiceRegistrationDelegator(mockClusterSingletonService, null);
72     }
73
74     /**
75      * Test a method delegation {@link ClusterSingletonService#instantiateServiceInstance()}
76      */
77     @Test
78     public void testInstatiateServiceDelegMethod() {
79         delegator.instantiateServiceInstance();
80         verify(mockClusterSingletonService).instantiateServiceInstance();
81     }
82
83     /**
84      * Test a method delegation {@link ClusterSingletonService#instantiateServiceInstance()}
85      */
86     @Test
87     public void testCloseServiceDelegMethod() {
88         delegator.closeServiceInstance();
89         verify(mockClusterSingletonService).closeServiceInstance();
90     }
91
92     /**
93      * Test a method delegation {@link ClusterSingletonService#getIdentifier()}
94      */
95     @Test
96     public void testGetServiceIdentifierDelegMethod() {
97         final String serviceIdentifier = delegator.getServiceGroupIdentifier();
98         Assert.assertEquals(SERVICE_IDENTIFIER_NAME, serviceIdentifier);
99         verify(mockClusterSingletonService).getIdentifier();
100     }
101
102     /**
103      * Test a close method delegation to {@link ClusterSingletonServiceGroupImpl#unregisterService(ClusterSingletonService)}
104      *
105      * @throws Exception is from AutoclosableInterface
106      */
107     @Test
108     public void testCloseMethod() throws Exception {
109         delegator.close();
110         verify(mockClusterSingletonServiceGroup).unregisterService(delegator);
111     }
112 }