Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / osgi / BlankTransactionServiceTrackerTest.java
1 /*
2  * Copyright (c) 2014, 2017 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.config.manager.impl.osgi;
10
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.doThrow;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16
17 import com.google.common.util.concurrent.MoreExecutors;
18 import java.util.Collections;
19 import javax.management.ObjectName;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.opendaylight.controller.config.api.ConflictingVersionException;
25 import org.opendaylight.controller.config.api.ModuleIdentifier;
26 import org.opendaylight.controller.config.api.ValidationException;
27 import org.opendaylight.controller.config.api.jmx.CommitStatus;
28 import org.opendaylight.controller.config.spi.ModuleFactory;
29 import org.osgi.framework.ServiceReference;
30
31 public class BlankTransactionServiceTrackerTest {
32     @Mock
33     private BlankTransactionServiceTracker.BlankTransaction blankTx;
34     private BlankTransactionServiceTracker tracker;
35
36     @Before
37     public void setUp() throws Exception {
38         MockitoAnnotations.initMocks(this);
39         doReturn(new CommitStatus(Collections.<ObjectName>emptyList(), Collections.<ObjectName>emptyList(),
40                 Collections.<ObjectName>emptyList())).when(blankTx).hit();
41         tracker = new BlankTransactionServiceTracker(blankTx, 10, MoreExecutors.newDirectExecutorService());
42     }
43
44     @Test
45     public void testBlankTransaction() throws Exception {
46         tracker.addingService(getMockServiceReference());
47         tracker.modifiedService(getMockServiceReference(), null);
48         tracker.removedService(getMockServiceReference(), null);
49         verify(blankTx, times(3)).hit();
50     }
51
52     @Test
53     public void testValidationException() throws Exception {
54         IllegalArgumentException argumentException = new IllegalArgumentException();
55         ValidationException validationException = ValidationException
56                 .createForSingleException(new ModuleIdentifier("m", "i"), argumentException);
57         doThrow(validationException).when(blankTx).hit();
58
59         tracker.addingService(getMockServiceReference());
60         verify(blankTx, times(10)).hit();
61     }
62
63     @Test
64     public void testConflictingException() throws Exception {
65         int maxAttempts = 2;
66         tracker = new BlankTransactionServiceTracker(blankTx, maxAttempts, MoreExecutors.newDirectExecutorService());
67
68         final ConflictingVersionException ex = new ConflictingVersionException();
69         doThrow(ex).when(blankTx).hit();
70
71         tracker.addingService(getMockServiceReference());
72         verify(blankTx, times(maxAttempts)).hit();
73     }
74
75     private static ServiceReference<ModuleFactory> getMockServiceReference() {
76         return mock(ServiceReference.class);
77     }
78 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.