Unit test for RequestSuccess.java and derived classes
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / ReadTransactionSuccessTest.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.Optional;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.controller.cluster.access.ABIVersion;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
18
19 public class ReadTransactionSuccessTest extends AbstractTransactionSuccessTest<ReadTransactionSuccess> {
20     private static final NormalizedNode<?, ?> NODE = Builders.containerBuilder().withNodeIdentifier(
21             YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build();
22
23     private static final ReadTransactionSuccess OBJECT = new ReadTransactionSuccess(
24             TRANSACTION_IDENTIFIER, 0, Optional.of(NODE));
25
26     @Override
27     protected ReadTransactionSuccess object() {
28         return OBJECT;
29     }
30
31     @Test
32     public void getDataTest() throws Exception {
33         final Optional<NormalizedNode<?, ?>> result = OBJECT.getData();
34         Assert.assertTrue(result.isPresent());
35         Assert.assertEquals(NODE.getValue(), result.get().getValue());
36     }
37
38     @Test
39     public void cloneAsVersionTest() throws Exception {
40         final ReadTransactionSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
41         Assert.assertEquals(OBJECT, clone);
42     }
43
44     @Override
45     protected void doAdditionalAssertions(Object deserialize) {
46         Assert.assertTrue(deserialize instanceof ReadTransactionSuccess);
47         Assert.assertEquals(OBJECT.getData(), ((ReadTransactionSuccess) deserialize).getData());
48     }
49 }