2 * Copyright (c) 2018 Pantheon Technologies 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.mdsal.binding.dom.codec.impl;
10 import static org.junit.Assert.assertEquals;
12 import org.junit.AfterClass;
13 import org.junit.Before;
14 import org.junit.BeforeClass;
15 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer.NodeResult;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 public abstract class AbstractBindingCodecTest extends AbstractBindingRuntimeTest {
20 protected BindingCodecContext codecContext;
23 public static void beforeClass() {
24 AbstractBindingRuntimeTest.beforeClass();
28 public static void afterClass() {
29 AbstractBindingRuntimeTest.afterClass();
33 public void before() {
34 codecContext = new BindingCodecContext(getRuntimeContext());
37 @SuppressWarnings("unchecked")
38 protected <T extends DataObject> T thereAndBackAgain(final InstanceIdentifier<T> path, final T data) {
39 final var there = (NodeResult) codecContext.toNormalizedNode(path, data);
40 final var backAgain = codecContext.fromNormalizedNode(there.path(), there.node());
41 assertEquals(path, backAgain.getKey());
42 return (T) backAgain.getValue();