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.utils.schema.context;
11 import java.text.SimpleDateFormat;
12 import java.util.ArrayList;
13 import java.util.Date;
14 import java.util.List;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
23 * Unit tests for {@link RestconfSchemaUtil}
25 public class RestconfSchemaUtilTest {
28 public void findInCollectionTest() {
29 final SchemaNode origSchNode = mockSchemaNode("key");
30 final SchemaNode actualSch = findSchemaNodeInCollection("key", origSchNode);
31 Assert.assertEquals(origSchNode, actualSch);
34 @Test(expected = RestconfDocumentedException.class)
35 public void findInCollectionFailedTest() {
36 final SchemaNode origSchNode = mockSchemaNode("key");
37 findSchemaNodeInCollection("bad_key", origSchNode);
40 private static SchemaNode findSchemaNodeInCollection(final String key, final SchemaNode... origSchNode) {
41 final List<SchemaNode> collection = new ArrayList<>();
42 for (SchemaNode element : origSchNode) {
43 collection.add(element);
45 return RestconfSchemaUtil.findSchemaNodeInCollection(collection, key);
48 private static SchemaNode mockSchemaNode(final String origKey) {
49 final SchemaNode mockSchNode = Mockito.mock(SchemaNode.class);
50 Mockito.when(mockSchNode.getQName())
51 .thenReturn(QName.create("ns", new SimpleDateFormat("yyyy-MM-dd").format(new Date()), origKey));