1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
7 import java.util.regex.*;
9 import javax.ws.rs.WebApplicationException;
12 import org.opendaylight.yangtools.yang.data.api.*;
13 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
14 import org.opendaylight.yangtools.yang.model.api.*;
16 public class ToJsonIdentityrefTest {
18 private static Set<Module> modules;
19 private static DataSchemaNode dataSchemaNode;
22 public static void initialization() {
23 modules = TestUtils.resolveModules("/yang-to-json-conversion/identityref");
24 assertEquals(2, modules.size());
25 Module module = TestUtils.resolveModule("identityref-module", modules);
26 assertNotNull(module);
27 dataSchemaNode = TestUtils.resolveDataSchemaNode(module, "cont");
28 assertNotNull(dataSchemaNode);
33 public void identityrefToJsonTest() {
37 .writeCompNodeWithSchemaContextToJson(prepareCompositeNode(), null, modules, dataSchemaNode);
38 } catch (WebApplicationException | IOException e) {
43 Pattern ptrn = Pattern.compile(".*\"lf1\"\\p{Space}*:\\p{Space}*\"identityref-module:name_test\".*",
45 Matcher mtch = ptrn.matcher(json);
47 assertTrue(mtch.matches());
50 private CompositeNode prepareCompositeNode() {
51 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
52 ModifyAction.CREATE, null);
53 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont,
54 TestUtils.buildQName("name_test", "identityref:module", "2013-12-2"), ModifyAction.CREATE, null);
55 cont.getChildren().add(lf1);