Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / actors / dds / LocalReadOnlyProxyTransactionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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 package org.opendaylight.controller.cluster.databroker.actors.dds;
9
10 import static org.mockito.Mockito.when;
11 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertOperationThrowsException;
12
13 import akka.testkit.TestProbe;
14 import com.google.common.base.Ticker;
15 import com.google.common.base.VerifyException;
16 import java.util.Optional;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
20 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
21 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder;
22 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
24
25 public class LocalReadOnlyProxyTransactionTest extends LocalProxyTransactionTest<LocalReadOnlyProxyTransaction> {
26
27     private DataTreeSnapshot snapshot;
28
29     @Override
30     @SuppressWarnings("checkstyle:hiddenField")
31     protected LocalReadOnlyProxyTransaction createTransaction(final ProxyHistory parent,
32                                                               final TransactionIdentifier id,
33                                                               final DataTreeSnapshot snapshot) {
34         when(snapshot.readNode(PATH_1)).thenReturn(Optional.of(DATA_1));
35         when(snapshot.readNode(PATH_3)).thenReturn(Optional.empty());
36         this.snapshot = snapshot;
37         return new LocalReadOnlyProxyTransaction(parent, id, this.snapshot);
38     }
39
40     @Test
41     public void testIsSnapshotOnly() {
42         Assert.assertTrue(transaction.isSnapshotOnly());
43     }
44
45     @Test
46     public void testReadOnlyView() {
47         Assert.assertEquals(snapshot, transaction.readOnlyView());
48     }
49
50     @Override
51     @Test(expected = UnsupportedOperationException.class)
52     public void testDirectCommit() throws Exception {
53         transaction.directCommit();
54     }
55
56     @Override
57     @Test(expected = UnsupportedOperationException.class)
58     public void testCanCommit() throws Exception {
59         transaction.canCommit(new VotingFuture<>(new Object(), 1));
60     }
61
62     @Override
63     @Test(expected = UnsupportedOperationException.class)
64     public void testPreCommit() throws Exception {
65         transaction.preCommit(new VotingFuture<>(new Object(), 1));
66     }
67
68     @Override
69     @Test(expected = UnsupportedOperationException.class)
70     public void testDoCommit() throws Exception {
71         transaction.doCommit(new VotingFuture<>(new Object(), 1));
72     }
73
74     @Override
75     @Test(expected = UnsupportedOperationException.class)
76     public void testDelete() {
77         transaction.delete(PATH_1);
78     }
79
80     @Override
81     @Test(expected = UnsupportedOperationException.class)
82     public void testMerge() {
83         transaction.merge(PATH_1, DATA_1);
84     }
85
86     @Override
87     @Test(expected = UnsupportedOperationException.class)
88     public void testWrite() {
89         transaction.write(PATH_1, DATA_1);
90     }
91
92     @Test(expected = UnsupportedOperationException.class)
93     public void testDoDelete() {
94         transaction.doDelete(PATH_1);
95     }
96
97     @Test(expected = UnsupportedOperationException.class)
98     public void testDoMerge() {
99         transaction.doMerge(PATH_1, DATA_1);
100     }
101
102     @Test(expected = UnsupportedOperationException.class)
103     public void testDoWrite() {
104         transaction.doWrite(PATH_1, DATA_1);
105     }
106
107     @Test(expected = UnsupportedOperationException.class)
108     public void testCommitRequest() {
109         transaction.commitRequest(true);
110     }
111
112     @Test
113     public void testApplyModifyTransactionRequest() throws Exception {
114         final TestProbe probe = createProbe();
115         final ModifyTransactionRequestBuilder builder =
116                 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
117         builder.setSequence(0);
118         builder.setAbort();
119         final ModifyTransactionRequest request = builder.build();
120         transaction.replayModifyTransactionRequest(request, createCallbackMock(), Ticker.systemTicker().read());
121         getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
122     }
123
124     @Test
125     public void testApplyModifyTransactionRequestNotAbort() throws Exception {
126         final TestProbe probe = createProbe();
127         final ModifyTransactionRequestBuilder builder =
128                 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
129         builder.setSequence(0);
130         builder.setReady();
131         final ModifyTransactionRequest request = builder.build();
132         assertOperationThrowsException(() -> transaction.replayModifyTransactionRequest(request, createCallbackMock(),
133             Ticker.systemTicker().read()), VerifyException.class);
134     }
135 }

©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.