ce1b4afababd1841f0718410b74158d43ef9d6ac
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / ToJsonIdentityrefTest.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.IOException;
7 import java.util.regex.*;
8
9 import javax.ws.rs.WebApplicationException;
10
11 import org.junit.*;
12 import org.opendaylight.yangtools.yang.data.api.*;
13 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
14
15 public class ToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
16
17     @BeforeClass
18     public static void initialization() {
19         dataLoad("/yang-to-json-conversion/identityref", 2, "identityref-module", "cont");
20     }
21
22     @Test
23     public void identityrefToJsonTest() {
24         String json = null;
25         try {
26             json = TestUtils
27                     .writeCompNodeWithSchemaContextToJson(prepareCompositeNode(), null, modules, dataSchemaNode);
28         } catch (WebApplicationException | IOException e) {
29             // shouldn't end here
30             assertTrue(false);
31         }
32         assertNotNull(json);
33         Pattern ptrn = Pattern.compile(".*\"lf1\"\\p{Space}*:\\p{Space}*\"identityref-module:name_test\".*",
34                 Pattern.DOTALL);
35         Matcher mtch = ptrn.matcher(json);
36
37         assertTrue(mtch.matches());
38     }
39
40     private CompositeNode prepareCompositeNode() {
41         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
42                 ModifyAction.CREATE, null);
43         MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont,
44                 TestUtils.buildQName("name_test", "identityref:module", "2013-12-2"), ModifyAction.CREATE, null);
45         cont.getChildren().add(lf1);
46         cont.init();
47
48         return cont;
49     }
50
51 }