2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.mdsal.binding.dom.adapter.test;
11 import static org.junit.Assert.assertNotNull;
13 import java.util.Collections;
14 import javassist.ClassPool;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
17 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
18 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
19 import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
20 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
21 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
22 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
23 import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
24 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
25 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101.BooleanContainer;
26 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101.BooleanContainerBuilder;
27 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListBuilder;
28 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListIntBuilder;
29 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListIntKey;
30 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101._boolean.container.BooleanListKey;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
34 public class Bug5845booleanKeyTest extends AbstractDataBrokerTest {
37 public void testBug5845() throws Exception {
38 final BindingToNormalizedNodeCodec mappingService = new BindingToNormalizedNodeCodec(
39 GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), new BindingNormalizedNodeCodecRegistry(
40 StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
41 final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
42 moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BooleanContainer.class));
43 mappingService.onGlobalContextUpdated(moduleInfoBackedContext.tryToCreateSchemaContext().get());
45 final BooleanContainer booleanContainer = new BooleanContainerBuilder().setBooleanList(Collections
46 .singletonList(new BooleanListBuilder()
47 .withKey(new BooleanListKey(true, true))
48 .setBooleanLeaf1(true)
49 .setBooleanLeaf2(true)
53 final BooleanContainer booleanContainerInt = new BooleanContainerBuilder().setBooleanListInt(Collections
54 .singletonList(new BooleanListIntBuilder()
55 .withKey(new BooleanListIntKey((byte) 1))
56 .setBooleanLeafInt((byte) 1)
60 final BindingCodecTree codecContext = mappingService.getCodecFactory().getCodecContext();
61 final BindingCodecTreeNode<BooleanContainer> subtreeCodec = codecContext.getSubtreeCodec(
62 InstanceIdentifier.create(BooleanContainer.class));
63 final NormalizedNode<?, ?> serializedInt = subtreeCodec.serialize(booleanContainerInt);
64 assertNotNull(serializedInt);
65 final NormalizedNode<?, ?> serialized = subtreeCodec.serialize(booleanContainer);
66 assertNotNull(serialized);