857b279abcf051a41c52671f22210e954b6de5fa
[bgpcep.git] / programming / impl / src / test / java / org / opendaylight / bgpcep / programming / impl / AbstractProgrammingTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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 package org.opendaylight.bgpcep.programming.impl;
9
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doAnswer;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14
15 import org.junit.Before;
16 import org.mockito.Mock;
17 import org.opendaylight.mdsal.binding.api.RpcProviderService;
18 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
22 import org.opendaylight.yangtools.concepts.Registration;
23
24 abstract class AbstractProgrammingTest extends AbstractConcurrentDataBrokerTest {
25     @Mock
26     RpcProviderService rpcRegistry;
27     @Mock
28     ClusterSingletonServiceProvider cssp;
29     @Mock
30     ClusterSingletonServiceRegistration singletonServiceRegistration;
31     @Mock
32     private Registration registration;
33     ClusterSingletonService singletonService;
34
35     AbstractProgrammingTest() {
36         super(true);
37     }
38
39     @Before
40     public void setUp() throws Exception {
41         doAnswer(invocationOnMock -> {
42             this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
43             return this.singletonServiceRegistration;
44         }).when(this.cssp).registerClusterSingletonService(any(ClusterSingletonService.class));
45         doAnswer(invocationOnMock -> {
46             this.singletonService.closeServiceInstance().get();
47             return null;
48         }).when(this.singletonServiceRegistration).close();
49
50         doReturn(this.registration).when(this.rpcRegistry).registerRpcImplementations(any());
51
52         doNothing().when(this.registration).close();
53     }
54 }