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.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.restconf.common.errors.RestconfDocumentedException;
18 import org.opendaylight.restconf.common.util.RestconfSchemaUtil;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
24 * Unit tests for {@link RestconfSchemaUtil}.
26 public class RestconfSchemaUtilTest {
29 public void findInCollectionTest() {
30 final SchemaNode origSchNode = mockSchemaNode("key");
31 final SchemaNode actualSch = findSchemaNodeInCollection("key", origSchNode);
32 Assert.assertEquals(origSchNode, actualSch);
35 @Test(expected = RestconfDocumentedException.class)
36 public void findInCollectionFailedTest() {
37 final SchemaNode origSchNode = mockSchemaNode("key");
38 findSchemaNodeInCollection("bad_key", origSchNode);
41 private static SchemaNode findSchemaNodeInCollection(final String key, final SchemaNode... origSchNode) {
42 final List<SchemaNode> collection = new ArrayList<>();
43 for (SchemaNode element : origSchNode) {
44 collection.add(element);
46 return RestconfSchemaUtil.findSchemaNodeInCollection(collection, key);
49 private static SchemaNode mockSchemaNode(final String origKey) {
50 final SchemaNode mockSchNode = Mockito.mock(SchemaNode.class);
51 Mockito.when(mockSchNode.getQName())
52 .thenReturn(QName.create("ns", SimpleDateFormatUtil.getRevisionFormat().format(new Date()), origKey));