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.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
21 import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
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 extends AbstractActorTest{
29 ActorContext actorContext = null;
30 SchemaContext schemaContext = mock(SchemaContext.class);
34 actorContext = new MockActorContext(getSystem());
35 actorContext.setSchemaContext(schemaContext);
38 @SuppressWarnings("resource")
40 public void testNewReadOnlyTransaction() throws Exception {
42 DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadOnlyTransaction();
43 Assert.assertTrue(dst instanceof DOMStoreReadTransaction);
47 @SuppressWarnings("resource")
49 public void testNewReadWriteTransaction() throws Exception {
50 DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadWriteTransaction();
51 Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction);
55 @SuppressWarnings("resource")
57 public void testNewWriteOnlyTransaction() throws Exception {
58 DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newWriteOnlyTransaction();
59 Assert.assertTrue(dst instanceof DOMStoreWriteTransaction);
64 public void testClose() throws Exception {
65 ActorContext context = mock(ActorContext.class);
67 new TransactionChainProxy(context).close();
69 verify(context, times(1)).broadcast(anyObject());
73 public void testTransactionChainsHaveUniqueId(){
74 TransactionChainProxy one = new TransactionChainProxy(mock(ActorContext.class));
75 TransactionChainProxy two = new TransactionChainProxy(mock(ActorContext.class));
77 Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId());