Fix leafref-to-enum encoding
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / test / BinaryKeyTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.binding.dom.codec.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12
13 import java.util.Optional;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.odl.test.binary.key.rev160101.BinaryList;
16 import org.opendaylight.yang.gen.v1.odl.test.binary.key.rev160101.BinaryListBuilder;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19
20 public class BinaryKeyTest extends AbstractBindingCodecTest {
21     private final InstanceIdentifier<BinaryList> instanceIdentifier = InstanceIdentifier.create(BinaryList.class);
22
23     @Test
24     public void binaryKeyTest() {
25         final byte[] binaryKey1 = {1, 1, 1};
26         final byte[] binaryKey2 = {1};
27         final BinaryList binaryList1 = new BinaryListBuilder()
28                 .setBinaryItem("first")
29                 .setBinaryKey(binaryKey1)
30                 .build();
31         final BinaryList binaryList2 = new BinaryListBuilder()
32                 .setBinaryItem("second")
33                 .setBinaryKey(binaryKey2)
34                 .build();
35         final BinaryList processedBinaryList1 = process(binaryList1);
36         final BinaryList processedBinaryList2 = process(binaryList2);
37
38         assertEquals(binaryList1, processedBinaryList1);
39         assertEquals(binaryList1, binaryList1);
40         assertEquals(processedBinaryList1, processedBinaryList1);
41
42         assertNotEquals(binaryList1, processedBinaryList2);
43         assertNotEquals(binaryList1, binaryList2);
44         assertNotEquals(processedBinaryList1, processedBinaryList2);
45     }
46
47     private BinaryList process(final BinaryList binaryList) {
48         final NormalizedNode<?, ?> domTreeEntry = registry.toNormalizedNode(instanceIdentifier, binaryList).getValue();
49         return registry.deserializeFunction(instanceIdentifier).apply(Optional.of(domTreeEntry)).get();
50     }
51 }