2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
10 import static org.mockito.Mockito.when;
11 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertOperationThrowsException;
13 import akka.testkit.TestProbe;
14 import com.google.common.base.VerifyException;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
18 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
19 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder;
20 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
23 public class LocalReadOnlyProxyTransactionTest extends LocalProxyTransactionTest<LocalReadOnlyProxyTransaction> {
25 private DataTreeSnapshot snapshot;
28 protected LocalReadOnlyProxyTransaction createTransaction(final ProxyHistory parent,
29 final TransactionIdentifier id,
30 final DataTreeSnapshot snapshot) {
31 when(snapshot.readNode(PATH_1)).thenReturn(com.google.common.base.Optional.of(DATA_1));
32 when(snapshot.readNode(PATH_3)).thenReturn(com.google.common.base.Optional.absent());
33 this.snapshot = snapshot;
34 return new LocalReadOnlyProxyTransaction(parent, id, this.snapshot);
38 public void testIsSnapshotOnly() {
39 Assert.assertTrue(transaction.isSnapshotOnly());
43 public void testReadOnlyView() {
44 Assert.assertEquals(snapshot, transaction.readOnlyView());
48 @Test(expected = UnsupportedOperationException.class)
49 public void testDirectCommit() throws Exception {
50 transaction.directCommit();
54 @Test(expected = UnsupportedOperationException.class)
55 public void testCanCommit() throws Exception {
56 transaction.canCommit(new VotingFuture<>(new Object(), 1));
60 @Test(expected = UnsupportedOperationException.class)
61 public void testPreCommit() throws Exception {
62 transaction.preCommit(new VotingFuture<>(new Object(), 1));
66 @Test(expected = UnsupportedOperationException.class)
67 public void testDoCommit() throws Exception {
68 transaction.doCommit(new VotingFuture<>(new Object(), 1));
72 @Test(expected = UnsupportedOperationException.class)
73 public void testDelete() {
74 transaction.delete(PATH_1);
78 @Test(expected = UnsupportedOperationException.class)
79 public void testMerge() {
80 transaction.merge(PATH_1, DATA_1);
84 @Test(expected = UnsupportedOperationException.class)
85 public void testWrite() {
86 transaction.write(PATH_1, DATA_1);
89 @Test(expected = UnsupportedOperationException.class)
90 public void testDoDelete() {
91 transaction.doDelete(PATH_1);
94 @Test(expected = UnsupportedOperationException.class)
95 public void testDoMerge() {
96 transaction.doMerge(PATH_1, DATA_1);
99 @Test(expected = UnsupportedOperationException.class)
100 public void testDoWrite() {
101 transaction.doWrite(PATH_1, DATA_1);
104 @Test(expected = UnsupportedOperationException.class)
105 public void testCommitRequest() {
106 transaction.commitRequest(true);
110 public void testApplyModifyTransactionRequest() throws Exception {
111 final TestProbe probe = createProbe();
112 final ModifyTransactionRequestBuilder builder =
113 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
114 builder.setSequence(0);
116 final ModifyTransactionRequest request = builder.build();
117 transaction.applyModifyTransactionRequest(request, createCallbackMock());
118 getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
122 public void testApplyModifyTransactionRequestNotAbort() throws Exception {
123 final TestProbe probe = createProbe();
124 final ModifyTransactionRequestBuilder builder =
125 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
126 builder.setSequence(0);
128 final ModifyTransactionRequest request = builder.build();
129 assertOperationThrowsException(() -> transaction.applyModifyTransactionRequest(request, createCallbackMock()),
130 VerifyException.class);