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.rest.impl.StructuredDataToJsonProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
16 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.*;
19 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
21 public class CnSnToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
24 public static void initialization() {
25 dataLoad("/cnsn-to-json/identityref", 2, "identityref-module", "cont");
29 public void identityrefToJsonTest() {
32 QName valueAsQname = TestUtils.buildQName("name_test", "identityref:module", "2013-12-2");
33 json = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(valueAsQname), modules,
34 dataSchemaNode, StructuredDataToJsonProvider.INSTANCE);
35 } catch (WebApplicationException | IOException e) {
40 Pattern ptrn = Pattern.compile(".*\"lf1\"\\p{Space}*:\\p{Space}*\"identityref-module:name_test\".*",
42 Matcher mtch = ptrn.matcher(json);
44 assertTrue(mtch.matches());
48 public void identityrefToJsonWithoutQNameTest() {
51 String value = "not q name value";
52 json = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(value), modules,
53 dataSchemaNode, StructuredDataToJsonProvider.INSTANCE);
54 } catch (WebApplicationException | IOException e) {
58 System.out.println(json);
60 Pattern ptrn = Pattern.compile(".*\"lf1\"\\p{Space}*:\\p{Space}*\"not q name value\".*", Pattern.DOTALL);
61 Matcher mtch = ptrn.matcher(json);
63 assertTrue(mtch.matches());
66 private CompositeNode prepareCompositeNode(Object value) {
67 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
68 ModifyAction.CREATE, null);
69 MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1"), cont, null,
70 ModifyAction.CREATE, null);
71 cont.getChildren().add(cont1);
73 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont1, value,
74 ModifyAction.CREATE, null);
76 cont1.getChildren().add(lf1);