Bulk-add copyright headers to java files
[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.ResponseException;
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
30     public void namespaceNotNullAndInvalidNamespaceAndNoModuleNameTest() {
31         boolean exceptionReised = false;
32         try {
33             TestUtils.normalizeCompositeNode(prepareCnSn("wrongnamespace"), modules, schemaNodePath);
34         } catch (ResponseException e) {
35             exceptionReised = true;
36         }
37         assertTrue(exceptionReised);
38     }
39
40     @Test
41     public void namespaceNullTest() {
42         String exceptionMessage = null;
43         try {
44             TestUtils.normalizeCompositeNode(prepareCnSn(null), modules, schemaNodePath);
45         } catch (ResponseException e) {
46             exceptionMessage = String.valueOf(e.getResponse().getEntity());
47         }
48         assertNull(exceptionMessage);
49     }
50
51     @Test
52     public void namespaceValidNamespaceTest() {
53         String exceptionMessage = null;
54         try {
55             TestUtils.normalizeCompositeNode(prepareCnSn("normalize:node:module"), modules, schemaNodePath);
56         } catch (ResponseException e) {
57             exceptionMessage = String.valueOf(e.getResponse().getEntity());
58         }
59         assertNull(exceptionMessage);
60     }
61
62     @Test
63     public void namespaceValidModuleNameTest() {
64         String exceptionMessage = null;
65         try {
66             TestUtils.normalizeCompositeNode(prepareCnSn("normalize-node-module"), modules, schemaNodePath);
67         } catch (ResponseException e) {
68             exceptionMessage = String.valueOf(e.getResponse().getEntity());
69         }
70         assertNull(exceptionMessage);
71     }
72
73     private CompositeNode prepareCnSn(String namespace) {
74         URI uri = null;
75         if (namespace != null) {
76             try {
77                 uri = new URI(namespace);
78             } catch (URISyntaxException e) {
79             }
80             assertNotNull(uri);
81         }
82
83         SimpleNodeWrapper lf1 = new SimpleNodeWrapper(uri, "lf1", 43);
84         CompositeNodeWrapper cont = new CompositeNodeWrapper(uri, "cont");
85         cont.addValue(lf1);
86
87         return cont;
88     }
89
90 }