Add lazily-instantiated lists
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / AbstractBindingCodecTest.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies s.r.o. 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.assertEquals;
11
12 import java.util.Map.Entry;
13 import org.junit.AfterClass;
14 import org.junit.Before;
15 import org.junit.BeforeClass;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20
21 public abstract class AbstractBindingCodecTest extends AbstractBindingRuntimeTest {
22     protected BindingCodecContext codecContext;
23
24     @BeforeClass
25     public static void beforeClass() {
26         AbstractBindingRuntimeTest.beforeClass();
27     }
28
29     @AfterClass
30     public static void afterClass() {
31         AbstractBindingRuntimeTest.afterClass();
32     }
33
34     @Before
35     public void before() {
36         this.codecContext = new BindingCodecContext(getRuntimeContext());
37     }
38
39     @SuppressWarnings("unchecked")
40     protected <T extends DataObject> T thereAndBackAgain(final InstanceIdentifier<T> path, final T data) {
41         final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> there = codecContext.toNormalizedNode(path, data);
42         final Entry<InstanceIdentifier<?>, DataObject> backAgain = codecContext.fromNormalizedNode(there.getKey(),
43             there.getValue());
44         assertEquals(path, backAgain.getKey());
45         return (T) backAgain.getValue();
46     }
47 }