Remove unused exceptions
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / ModifyTransactionRequestBuilderTest.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.access.commands;
9
10 import static org.junit.Assert.assertEquals;
11
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.actor.Props;
15 import akka.testkit.TestActors;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
20 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
22 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
23 import org.opendaylight.controller.cluster.access.concepts.MemberName;
24 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
29
30 public class ModifyTransactionRequestBuilderTest {
31
32     private final MemberName memberName = MemberName.forName("member-1");
33     private final FrontendType frontendType = FrontendType.forName("test");
34     private final FrontendIdentifier frontendId = FrontendIdentifier.create(memberName, frontendType);
35     private final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
36     private final TransactionIdentifier transactionIdentifier =
37             new TransactionIdentifier(new LocalHistoryIdentifier(clientId, 0L), 0L);
38     private final ActorRef actorRef = ActorSystem.create("test").actorOf(Props.create(TestActors.EchoActor.class));
39     private final NormalizedNode<?, ?> node = Builders.containerBuilder().withNodeIdentifier(
40             YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build();
41     private final TransactionModification transactionModification =
42             new TransactionWrite(YangInstanceIdentifier.EMPTY, node);
43     private final ModifyTransactionRequestBuilder modifyTransactionRequestBuilder =
44             new ModifyTransactionRequestBuilder(transactionIdentifier, actorRef);
45
46     @Before
47     public void setUp() {
48         modifyTransactionRequestBuilder.setSequence(0L);
49         modifyTransactionRequestBuilder.addModification(transactionModification);
50         assertEquals(1, modifyTransactionRequestBuilder.size());
51     }
52
53     @Test
54     public void testGetIdentifier() {
55         final TransactionIdentifier identifier = modifyTransactionRequestBuilder.getIdentifier();
56         Assert.assertEquals(transactionIdentifier, identifier);
57     }
58
59     @Test
60     public void testBuildReady() {
61         modifyTransactionRequestBuilder.setReady();
62         final ModifyTransactionRequest modifyTransactionRequest = modifyTransactionRequestBuilder.build();
63         Assert.assertEquals(PersistenceProtocol.READY, modifyTransactionRequest.getPersistenceProtocol().get());
64         Assert.assertEquals(transactionModification, modifyTransactionRequest.getModifications().get(0));
65     }
66
67     @Test
68     public void testBuildAbort() {
69         modifyTransactionRequestBuilder.setAbort();
70         final ModifyTransactionRequest modifyTransactionRequest = modifyTransactionRequestBuilder.build();
71         Assert.assertEquals(PersistenceProtocol.ABORT, modifyTransactionRequest.getPersistenceProtocol().get());
72         Assert.assertTrue(modifyTransactionRequest.getModifications().isEmpty());
73     }
74
75     @Test
76     public void testBuildCommitTrue() {
77         modifyTransactionRequestBuilder.setCommit(true);
78         final ModifyTransactionRequest modifyTransactionRequest = modifyTransactionRequestBuilder.build();
79         Assert.assertEquals(PersistenceProtocol.THREE_PHASE, modifyTransactionRequest.getPersistenceProtocol().get());
80     }
81
82     @Test
83     public void testBuildCommitFalse() {
84         modifyTransactionRequestBuilder.setCommit(false);
85         final ModifyTransactionRequest modifyTransactionRequest = modifyTransactionRequestBuilder.build();
86         Assert.assertEquals(PersistenceProtocol.SIMPLE, modifyTransactionRequest.getPersistenceProtocol().get());
87     }
88
89 }

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