Unit tests for AbstractLocalTransactionRequest derived classes
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / CommitLocalTransactionRequestTest.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 akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.testkit.TestProbe;
13 import com.google.common.base.MoreObjects;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
19 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
20 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.MemberName;
22 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
24
25 public class CommitLocalTransactionRequestTest extends AbstractTransactionRequestTest<CommitLocalTransactionRequest> {
26
27     private static final FrontendIdentifier FRONTEND = FrontendIdentifier.create(
28             MemberName.forName("test"), FrontendType.forName("one"));
29     private static final ClientIdentifier CLIENT = ClientIdentifier.create(FRONTEND, 0);
30     private static final LocalHistoryIdentifier HISTORY = new LocalHistoryIdentifier(CLIENT, 0);
31     private static final TransactionIdentifier TRANSACTION = new TransactionIdentifier(HISTORY, 0);
32
33     private static final ActorSystem SYSTEM = ActorSystem.create("test");
34     private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
35
36     private static final DataTreeModification MODIFICATION = Mockito.mock(DataTreeModification.class);
37     private static final boolean COORDINATED = Boolean.TRUE;
38
39     private static final CommitLocalTransactionRequest OBJECT = new CommitLocalTransactionRequest(
40             TRANSACTION, 0, ACTOR_REF, MODIFICATION, COORDINATED);
41
42     @Override
43     CommitLocalTransactionRequest object() {
44         return OBJECT;
45     }
46
47     @Test
48     public void getModificationTest() {
49         Assert.assertEquals(MODIFICATION, OBJECT.getModification());
50     }
51
52     @Test
53     public void isCoordinatedTest() {
54         Assert.assertEquals(COORDINATED, OBJECT.isCoordinated());
55     }
56
57     @Test
58     public void addToStringAttributesTest() {
59         final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
60         Assert.assertTrue(result.toString().contains("coordinated=" + COORDINATED));
61     }
62 }