Added DELETE operation
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / NormalizeNodeTest.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import static org.junit.Assert.*;
4
5 import java.net.URI;
6 import java.net.URISyntaxException;
7
8 import org.junit.BeforeClass;
9 import org.junit.Test;
10 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
11 import org.opendaylight.controller.sal.restconf.impl.ResponseException;
12 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
13 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
14
15 public class NormalizeNodeTest extends YangAndXmlAndDataSchemaLoader {
16
17     @BeforeClass
18     public static void initialization() {
19         dataLoad("/normalize-node/yang/");
20     }
21
22     @Test
23     public void namespaceNotNullAndInvalidNamespaceAndNoModuleNameTest() {
24         boolean exceptionReised = false;
25         try {
26             TestUtils.normalizeCompositeNode(prepareCnSn("wrongnamespace"), modules, schemaNodePath);
27         } catch (ResponseException e) {
28             exceptionReised = true;
29         }
30         assertTrue(exceptionReised);
31     }
32
33     @Test
34     public void namespaceNullTest() {
35         String exceptionMessage = null;
36         try {
37             TestUtils.normalizeCompositeNode(prepareCnSn(null), modules, schemaNodePath);
38         } catch (ResponseException e) {
39             exceptionMessage = String.valueOf(e.getResponse().getEntity());
40         }
41         assertNull(exceptionMessage);
42     }
43
44     @Test
45     public void namespaceValidNamespaceTest() {
46         String exceptionMessage = null;
47         try {
48             TestUtils.normalizeCompositeNode(prepareCnSn("normalize:node:module"), modules, schemaNodePath);
49         } catch (ResponseException e) {
50             exceptionMessage = String.valueOf(e.getResponse().getEntity());
51         }
52         assertNull(exceptionMessage);
53     }
54
55     @Test
56     public void namespaceValidModuleNameTest() {
57         String exceptionMessage = null;
58         try {
59             TestUtils.normalizeCompositeNode(prepareCnSn("normalize-node-module"), modules, schemaNodePath);
60         } catch (ResponseException e) {
61             exceptionMessage = String.valueOf(e.getResponse().getEntity());
62         }
63         assertNull(exceptionMessage);
64     }
65
66     private CompositeNode prepareCnSn(String namespace) {
67         URI uri = null;
68         if (namespace != null) {
69             try {
70                 uri = new URI(namespace);
71             } catch (URISyntaxException e) {
72             }
73             assertNotNull(uri);
74         }
75
76         SimpleNodeWrapper lf1 = new SimpleNodeWrapper(uri, "lf1", 43);
77         CompositeNodeWrapper cont = new CompositeNodeWrapper(uri, "cont");
78         cont.addValue(lf1);
79
80         return cont;
81     }
82
83 }