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.restconf.common.util;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
20 * Unit tests for {@link RestconfSchemaUtil}.
22 public class RestconfSchemaUtilTest {
25 public void findInCollectionTest() {
26 final SchemaNode origSchNode = mockSchemaNode("key");
27 final SchemaNode actualSch = findSchemaNodeInCollection("key", origSchNode);
28 Assert.assertEquals(origSchNode, actualSch);
31 @Test(expected = RuntimeException.class)
32 public void findInCollectionFailedTest() {
33 final SchemaNode origSchNode = mockSchemaNode("key");
34 findSchemaNodeInCollection("bad_key", origSchNode);
37 private static SchemaNode findSchemaNodeInCollection(final String key, final SchemaNode... origSchNode) {
38 final List<SchemaNode> collection = new ArrayList<>();
39 for (final SchemaNode element : origSchNode) {
40 collection.add(element);
42 return RestconfSchemaUtil.findSchemaNodeInCollection(collection, key);
45 private static SchemaNode mockSchemaNode(final String origKey) {
46 final SchemaNode mockSchNode = Mockito.mock(SchemaNode.class);
47 Mockito.when(mockSchNode.getQName())
48 .thenReturn(QName.create("ns", "2016-10-10", origKey));