2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.yangtools.yang.data.impl.codec;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
20 void testBooleanStringUnion() {
21 final var module = YangParserTestUtils.parseYang("""
32 }""").findModule("yt1097").orElseThrow();
33 final var foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")).orElseThrow();
34 assertInstanceOf(LeafSchemaNode.class, foo);
36 final var codec = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType());
37 assertInstanceOf(UnionStringCodec.class, codec);
39 assertDecoded(codec, Boolean.TRUE, "true");
40 assertDecoded(codec, Boolean.FALSE, "false");
41 assertDecoded(codec, "True");
42 assertDecoded(codec, "TRUE");
43 assertDecoded(codec, "False");
44 assertDecoded(codec, "FALSE");
47 private static void assertDecoded(final TypeDefinitionAwareCodec<?, ?> codec, final String input) {
48 assertDecoded(codec, input, input);
51 private static void assertDecoded(final TypeDefinitionAwareCodec<?, ?> codec, final Object expected,
53 assertEquals(expected, assertInstanceOf(expected.getClass(), codec.deserialize(input)));