Changed POST 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.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertNull;
6
7 import java.net.URI;
8 import java.net.URISyntaxException;
9
10 import org.junit.BeforeClass;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
13 import org.opendaylight.controller.sal.restconf.impl.ResponseException;
14 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16
17 public class NormalizeNodeTest extends YangAndXmlAndDataSchemaLoader {
18
19     @BeforeClass
20     public static void initialization() {
21         dataLoad("/normalize-node/yang/");
22     }
23
24     @Test
25     public void namespaceNotNullAndInvalidNamespaceAndNoModuleNameTest() {
26         String exceptionMessage = null;
27         try {
28             TestUtils.normalizeCompositeNode(prepareCnSn("wrongnamespace"), modules, schemaNodePath);
29         } catch (ResponseException e) {
30             exceptionMessage = String.valueOf(e.getResponse().getEntity());
31         }
32         assertEquals(
33                 exceptionMessage,
34                 "Data has bad format.\nIf data is in XML format then namespace for cont should be normalize:node:module.\nIf data is in Json format then module name for cont should be normalize-node-module.");
35     }
36
37     @Test
38     public void namespaceNullTest() {
39         String exceptionMessage = null;
40         try {
41             TestUtils.normalizeCompositeNode(prepareCnSn(null), modules, schemaNodePath);
42         } catch (ResponseException e) {
43             exceptionMessage = String.valueOf(e.getResponse().getEntity());
44         }
45         assertNull(exceptionMessage);
46     }
47
48     @Test
49     public void namespaceValidNamespaceTest() {
50         String exceptionMessage = null;
51         try {
52             TestUtils.normalizeCompositeNode(prepareCnSn("normalize:node:module"), modules, schemaNodePath);
53         } catch (ResponseException e) {
54             exceptionMessage = String.valueOf(e.getResponse().getEntity());
55         }
56         assertNull(exceptionMessage);
57     }
58
59     @Test
60     public void namespaceValidModuleNameTest() {
61         String exceptionMessage = null;
62         try {
63             TestUtils.normalizeCompositeNode(prepareCnSn("normalize-node-module"), modules, schemaNodePath);
64         } catch (ResponseException e) {
65             exceptionMessage = String.valueOf(e.getResponse().getEntity());
66         }
67         assertNull(exceptionMessage);
68     }
69
70     private CompositeNode prepareCnSn(String namespace) {
71         URI uri = null;
72         if (namespace != null) {
73             try {
74                 uri = new URI(namespace);
75             } catch (URISyntaxException e) {
76             }
77             assertNotNull(uri);
78         }
79
80         SimpleNodeWrapper lf1 = new SimpleNodeWrapper(uri, "lf1", 43);
81         CompositeNodeWrapper cont = new CompositeNodeWrapper(uri, "cont");
82         cont.addValue(lf1);
83
84         return cont;
85     }
86
87 }