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