Move mdsal-binding-dom-codec tests
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / Bug5845booleanKeyTest.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.impl;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import java.util.Collections;
13 import org.junit.Test;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
15 import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
16 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101.BooleanContainer;
17 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101.BooleanContainerBuilder;
18 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListBuilder;
19 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListIntBuilder;
20 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListIntKey;
21 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24
25 public class Bug5845booleanKeyTest extends AbstractBindingCodecTest {
26     @Test
27     public void testBug5845() throws Exception {
28         final BooleanListKey blk = new BooleanListKey(true, true);
29         final BooleanContainer booleanContainer = new BooleanContainerBuilder()
30                 .setBooleanList(Collections.singletonMap(blk, new BooleanListBuilder()
31                     .withKey(blk)
32                     .setBooleanLeaf1(true)
33                     .setBooleanLeaf2(true)
34                     .build()))
35                 .build();
36
37         final BooleanListIntKey blik = new BooleanListIntKey((byte) 1);
38         final BooleanContainer booleanContainerInt = new BooleanContainerBuilder()
39                 .setBooleanListInt(Collections.singletonMap(blik, new BooleanListIntBuilder()
40                         .withKey(blik)
41                         .setBooleanLeafInt((byte) 1)
42                         .build()))
43                 .build();
44
45         final BindingCodecTree codecContext = registry.getCodecContext();
46         final BindingDataObjectCodecTreeNode<BooleanContainer> subtreeCodec = codecContext.getSubtreeCodec(
47                 InstanceIdentifier.create(BooleanContainer.class));
48         final NormalizedNode<?, ?> serializedInt = subtreeCodec.serialize(booleanContainerInt);
49         assertNotNull(serializedInt);
50         final NormalizedNode<?, ?> serialized = subtreeCodec.serialize(booleanContainer);
51         assertNotNull(serialized);
52     }
53 }