1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
6 import java.io.IOException;
7 import java.util.regex.Matcher;
8 import java.util.regex.Pattern;
10 import javax.ws.rs.WebApplicationException;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
15 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
16 import org.opendaylight.yangtools.yang.data.api.*;
17 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
19 public class ToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
22 public static void initialization() {
23 dataLoad("/cnsn-to-json/identityref", 2, "identityref-module", "cont");
27 public void identityrefToJsonTest() {
30 json = TestUtils.writeCompNodeWithSchemaContextToJson(prepareCompositeNode(), modules, dataSchemaNode);
31 } catch (WebApplicationException | IOException e) {
36 Pattern ptrn = Pattern.compile(".*\"lf1\"\\p{Space}*:\\p{Space}*\"identityref-module:name_test\".*",
38 Matcher mtch = ptrn.matcher(json);
40 assertTrue(mtch.matches());
43 private CompositeNode prepareCompositeNode() {
44 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
45 ModifyAction.CREATE, null);
46 MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1"), cont, null,
47 ModifyAction.CREATE, null);
48 cont.getChildren().add(cont1);
50 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont1,
51 TestUtils.buildQName("name_test", "identityref:module", "2013-12-2"), ModifyAction.CREATE, null);
52 cont1.getChildren().add(lf1);