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.Date;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 * Unit tests for {@link RestconfSchemaUtil}.
24 public class RestconfSchemaUtilTest {
27 public void findInCollectionTest() {
28 final SchemaNode origSchNode = mockSchemaNode("key");
29 final SchemaNode actualSch = findSchemaNodeInCollection("key", origSchNode);
30 Assert.assertEquals(origSchNode, actualSch);
33 @Test(expected = RuntimeException.class)
34 public void findInCollectionFailedTest() {
35 final SchemaNode origSchNode = mockSchemaNode("key");
36 findSchemaNodeInCollection("bad_key", origSchNode);
39 private static SchemaNode findSchemaNodeInCollection(final String key, final SchemaNode... origSchNode) {
40 final List<SchemaNode> collection = new ArrayList<>();
41 for (final SchemaNode element : origSchNode) {
42 collection.add(element);
44 return RestconfSchemaUtil.findSchemaNodeInCollection(collection, key);
47 private static SchemaNode mockSchemaNode(final String origKey) {
48 final SchemaNode mockSchNode = Mockito.mock(SchemaNode.class);
49 Mockito.when(mockSchNode.getQName())
50 .thenReturn(QName.create("ns", SimpleDateFormatUtil.getRevisionFormat().format(new Date()), origKey));