Bug 1010: Implement restconf error responses
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / NormalizeNodeTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.restconf.impl.test;
9
10 import static org.junit.Assert.*;
11
12 import java.net.URI;
13 import java.net.URISyntaxException;
14
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
18 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
19 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
20 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
21
22 public class NormalizeNodeTest extends YangAndXmlAndDataSchemaLoader {
23
24     @BeforeClass
25     public static void initialization() {
26         dataLoad("/normalize-node/yang/");
27     }
28
29     @Test(expected=RestconfDocumentedException.class)
30     public void namespaceNotNullAndInvalidNamespaceAndNoModuleNameTest() {
31
32         TestUtils.normalizeCompositeNode(prepareCnSn("wrongnamespace"), modules, schemaNodePath);
33     }
34
35     @Test
36     public void namespaceNullTest() {
37
38         TestUtils.normalizeCompositeNode(prepareCnSn(null), modules, schemaNodePath);
39     }
40
41     @Test
42     public void namespaceValidNamespaceTest() {
43
44         TestUtils.normalizeCompositeNode(prepareCnSn("normalize:node:module"), modules, schemaNodePath);
45     }
46
47     @Test
48     public void namespaceValidModuleNameTest() {
49
50         TestUtils.normalizeCompositeNode(prepareCnSn("normalize-node-module"), modules, schemaNodePath);
51     }
52
53     private CompositeNode prepareCnSn(String namespace) {
54         URI uri = null;
55         if (namespace != null) {
56             try {
57                 uri = new URI(namespace);
58             } catch (URISyntaxException e) {
59             }
60             assertNotNull(uri);
61         }
62
63         SimpleNodeWrapper lf1 = new SimpleNodeWrapper(uri, "lf1", 43);
64         CompositeNodeWrapper cont = new CompositeNodeWrapper(uri, "cont");
65         cont.addValue(lf1);
66
67         return cont;
68     }
69
70 }