Do not flood logs with modifications
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / ModifyTransactionRequestTest.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.opendaylight.controller.cluster.access.commands.TransactionModification.TYPE_WRITE;
11
12 import com.google.common.base.MoreObjects;
13 import com.google.common.collect.Lists;
14 import java.util.List;
15 import java.util.Optional;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.access.ABIVersion;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
23
24 public class ModifyTransactionRequestTest extends AbstractTransactionRequestTest<ModifyTransactionRequest> {
25     private static final NormalizedNode<?, ?> NODE = Builders.containerBuilder().withNodeIdentifier(
26             YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build();
27
28     private static final List<TransactionModification> MODIFICATIONS = Lists.newArrayList(
29             new TransactionWrite(YangInstanceIdentifier.EMPTY, NODE));
30
31     private static final PersistenceProtocol PROTOCOL = PersistenceProtocol.ABORT;
32
33     private static final ModifyTransactionRequest OBJECT = new ModifyTransactionRequest(
34             TRANSACTION_IDENTIFIER, 0, ACTOR_REF, MODIFICATIONS, PROTOCOL);
35
36     @Override
37     protected ModifyTransactionRequest object() {
38         return OBJECT;
39     }
40
41     @Test
42     public void getPersistenceProtocolTest() throws Exception {
43         final Optional<PersistenceProtocol> result = OBJECT.getPersistenceProtocol();
44         Assert.assertTrue(result.isPresent());
45         Assert.assertEquals(PROTOCOL, result.get());
46     }
47
48     @Test
49     public void getModificationsTest() throws Exception {
50         final List<TransactionModification> result = OBJECT.getModifications();
51         Assert.assertNotNull(result);
52         Assert.assertEquals(MODIFICATIONS, result);
53     }
54
55     @Test
56     public void addToStringAttributesTest() {
57         final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
58         Assert.assertTrue(result.toString().contains("modifications=1"));
59         Assert.assertTrue(result.toString().contains("protocol=" + PROTOCOL));
60     }
61
62     @Test
63     public void cloneAsVersionTest() throws Exception {
64         final ModifyTransactionRequest clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
65         Assert.assertEquals(OBJECT, clone);
66     }
67
68     @Override
69     protected void doAdditionalAssertions(final Object deserialize) {
70         Assert.assertTrue(deserialize instanceof ModifyTransactionRequest);
71         final ModifyTransactionRequest casted = (ModifyTransactionRequest) deserialize;
72
73         Assert.assertEquals(OBJECT.getReplyTo(), casted.getReplyTo());
74         Assert.assertEquals(OBJECT.getPersistenceProtocol(), casted.getPersistenceProtocol());
75
76         Assert.assertNotNull(casted.getModifications());
77         Assert.assertEquals(1, casted.getModifications().size());
78         final TransactionModification modification = casted.getModifications().get(0);
79         Assert.assertEquals(YangInstanceIdentifier.EMPTY, modification.getPath());
80         Assert.assertEquals(TYPE_WRITE, modification.getType());
81     }
82 }

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