3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
11 package org.opendaylight.controller.cluster.datastore;
13 import static org.mockito.Matchers.anyObject;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
25 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 public class TransactionChainProxyTest {
29 ActorContext actorContext = mock(ActorContext.class);
30 SchemaContext schemaContext = mock(SchemaContext.class);
34 doReturn(schemaContext).when(actorContext).getSchemaContext();
37 @SuppressWarnings("resource")
39 public void testNewReadOnlyTransaction() throws Exception {
41 DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadOnlyTransaction();
42 Assert.assertTrue(dst instanceof DOMStoreReadTransaction);
46 @SuppressWarnings("resource")
48 public void testNewReadWriteTransaction() throws Exception {
49 DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadWriteTransaction();
50 Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction);
54 @SuppressWarnings("resource")
56 public void testNewWriteOnlyTransaction() throws Exception {
57 DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newWriteOnlyTransaction();
58 Assert.assertTrue(dst instanceof DOMStoreWriteTransaction);
63 public void testClose() throws Exception {
64 ActorContext context = mock(ActorContext.class);
66 new TransactionChainProxy(context).close();
68 verify(context, times(1)).broadcast(anyObject());
72 public void testTransactionChainsHaveUniqueId(){
73 TransactionChainProxy one = new TransactionChainProxy(mock(ActorContext.class));
74 TransactionChainProxy two = new TransactionChainProxy(mock(ActorContext.class));
76 Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId());