692c661e4fcebde74bed86c6ca004050780bd206
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / ModifyTransactionRequestEmptyTest.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 com.google.common.base.MoreObjects;
11 import com.google.common.collect.Lists;
12 import java.util.List;
13 import java.util.Optional;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17
18 public class ModifyTransactionRequestEmptyTest extends AbstractTransactionRequestTest<ModifyTransactionRequest> {
19     private static final PersistenceProtocol PROTOCOL = PersistenceProtocol.ABORT;
20
21     private static final ModifyTransactionRequest OBJECT = new ModifyTransactionRequest(
22             TRANSACTION_IDENTIFIER, 0, ACTOR_REF, Lists.newArrayList(), PROTOCOL);
23
24     @Override
25     protected ModifyTransactionRequest object() {
26         return OBJECT;
27     }
28
29     @Test
30     public void getPersistenceProtocolTest() throws Exception {
31         final Optional<PersistenceProtocol> result = OBJECT.getPersistenceProtocol();
32         Assert.assertTrue(result.isPresent());
33         Assert.assertEquals(PROTOCOL, result.get());
34     }
35
36     @Test
37     public void getModificationsTest() throws Exception {
38         final List<TransactionModification> result = OBJECT.getModifications();
39         Assert.assertNotNull(result);
40         Assert.assertTrue(result.isEmpty());
41     }
42
43     @Test
44     public void addToStringAttributesTest() {
45         final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
46         Assert.assertTrue(result.toString().contains("operations=" + Lists.newArrayList()));
47         Assert.assertTrue(result.toString().contains("protocol=" + PROTOCOL));
48     }
49
50     @Test
51     public void cloneAsVersionTest() throws Exception {
52         final ModifyTransactionRequest clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
53         Assert.assertEquals(OBJECT, clone);
54     }
55
56     @Override
57     protected void doAdditionalAssertions(final Object deserialize) {
58         Assert.assertTrue(deserialize instanceof ModifyTransactionRequest);
59         final ModifyTransactionRequest casted = (ModifyTransactionRequest) deserialize;
60
61         Assert.assertEquals(OBJECT.getReplyTo(), casted.getReplyTo());
62         Assert.assertEquals(OBJECT.getModifications(), casted.getModifications());
63         Assert.assertEquals(OBJECT.getPersistenceProtocol(), casted.getPersistenceProtocol());
64     }
65 }

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