2 * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.manager.impl.osgi;
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;
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;
31 public class BlankTransactionServiceTrackerTest {
33 private BlankTransactionServiceTracker.BlankTransaction blankTx;
34 private BlankTransactionServiceTracker tracker;
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());
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();
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();
59 tracker.addingService(getMockServiceReference());
60 verify(blankTx, times(10)).hit();
64 public void testConflictingException() throws Exception {
66 tracker = new BlankTransactionServiceTracker(blankTx, maxAttempts, MoreExecutors.newDirectExecutorService());
68 final ConflictingVersionException ex = new ConflictingVersionException();
69 doThrow(ex).when(blankTx).hit();
71 tracker.addingService(getMockServiceReference());
72 verify(blankTx, times(maxAttempts)).hit();
75 private static ServiceReference<ModuleFactory> getMockServiceReference() {
76 return mock(ServiceReference.class);