Generated code issue fix for enum with space
Change-Id: I509d3df564a08559e9f396b0f7e787544ddc161f
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index f2095e7..81844ba 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1147,7 +1147,7 @@
/**
* Static attribute for regex for all the special characters.
*/
- public static final String REGEX_WITH_ALL_SPECIAL_CHAR = "\\p{Punct}+";
+ public static final String REGEX_WITH_ALL_SPECIAL_CHAR = "[\\p{Punct}\\s]+";
/**
* Static attribute for regex for three special characters used in
diff --git a/compiler/plugin/maven/src/test/resources/EnumTranslator.yang b/compiler/plugin/maven/src/test/resources/EnumTranslator.yang
index 1957c1f..d52475a 100644
--- a/compiler/plugin/maven/src/test/resources/EnumTranslator.yang
+++ b/compiler/plugin/maven/src/test/resources/EnumTranslator.yang
@@ -9,6 +9,7 @@
type enumeration {
enum zero;
enum one;
+ enum "twenty three";
enum seven {
value 7;
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
index 9cb0419..b2af409 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
@@ -19,6 +19,8 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yang.gen.v1.simple.data.types.rev20131112.simpledatatypes.DefaultCont;
+import org.onosproject.yang.gen.v1.simple.data.types.rev20131112.simpledatatypes.Tpdfun0;
import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.container.rev20160826.ytbmodulewithcontainer.DefaultSched;
import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.YtbIetfSchedule;
import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.ytbietfschedule.Enum1Enum;
@@ -58,6 +60,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.gen.v1.simple.data.types.rev20131112.simpledatatypes.Cont.LeafIdentifier.LFENUM1;
+import static org.onosproject.yang.gen.v1.simple.data.types.rev20131112.simpledatatypes.tpdfun0.Tpdfun0Enum.SUCCESSFUL_EXIT;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
@@ -1103,4 +1107,42 @@
SINGLE_INSTANCE_NODE,
true, null);
}
+
+ /**
+ * Unit test for leaf node with enumeration type.
+ */
+ @Test
+ public void processEnumeration() {
+ setUp();
+ data = new DefaultModelObjectData.Builder();
+ ModelObjectId.Builder moIdBdlr = ModelObjectId.builder()
+ .addChild(DefaultCont.class);
+ LeafModelObject mo = new LeafModelObject();
+ mo.leafIdentifier(LFENUM1);
+ mo.addValue(new Tpdfun0(SUCCESSFUL_EXIT));
+ data.addModelObject(mo);
+ data.identifier(moIdBdlr.build());
+ DefaultDataTreeBuilder builder = new DefaultDataTreeBuilder(registry);
+ rscData = builder.getResourceData(data.build());
+
+ nameSpace = "simple:data:types";
+ id = rscData.resourceId();
+ keys = id.nodeKeys();
+ assertThat(2, is(keys.size()));
+
+ sid = keys.get(0).schemaId();
+ assertThat("/", is(sid.name()));
+ assertThat(null, is(sid.namespace()));
+
+ sid = keys.get(1).schemaId();
+ assertThat("cont", is(sid.name()));
+ assertThat(nameSpace, is(sid.namespace()));
+
+ dataNodes = rscData.dataNodes();
+ assertThat(1, is(dataNodes.size()));
+ node = dataNodes.get(0);
+ validateDataNode(node, "lfenum1", nameSpace,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ true, "successful exit");
+ }
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
index 3c2ba15..c219434 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
@@ -29,6 +29,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.gen.v1.simple.data.types.ll.rev20131112.simpledatatypesll.cont1.Lfenum1Enum.GRACE_PERIOD_EXPIRED;
+import static org.onosproject.yang.gen.v1.simple.data.types.rev20131112.simpledatatypes.tpdfun0.Tpdfun0Enum.SUCCESSFUL_EXIT;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
@@ -213,6 +215,10 @@
value = "iden";
dBlr = addDataNode(dBlr, "identityref1", DATA_TYPE_NAME_SPACE, value, null);
dBlr = exitDataNode(dBlr);
+
+ value = "successful exit";
+ dBlr = addDataNode(dBlr, "lfenum1", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
dBlr = exitDataNode(dBlr);
return dBlr.build();
}
@@ -386,6 +392,10 @@
value = "iden";
dBlr = addDataNode(dBlr, "identityref1", null, value, null);
dBlr = exitDataNode(dBlr);
+
+ value = "grace period expired";
+ dBlr = addDataNode(dBlr, "lfenum1", null, value, null);
+ dBlr = exitDataNode(dBlr);
dBlr = exitDataNode(dBlr);
return dBlr.build();
}
@@ -458,6 +468,7 @@
assertThat(cont.lfunion13().toString(), is("b2 "));
assertThat(cont.lfunion14().toString(), is("one"));
assertThat(cont.identityref1().getSimpleName(), is("Iden"));
+ assertThat(cont.lfenum1().enumeration(), is(SUCCESSFUL_EXIT));
}
@@ -530,5 +541,6 @@
assertThat(cont.lfunion14().get(0).toString(), is("one"));
assertThat(cont.identityref1().get(0).getSimpleName().toString(),
is("Iden"));
+ assertThat(cont.lfenum1().get(0), is(GRACE_PERIOD_EXPIRED));
}
}
diff --git a/runtime/src/test/resources/yobTestYangFiles/simple-data-types-leaf-list.yang b/runtime/src/test/resources/yobTestYangFiles/simple-data-types-leaf-list.yang
index 401cdaa..fa85b57 100644
--- a/runtime/src/test/resources/yobTestYangFiles/simple-data-types-leaf-list.yang
+++ b/runtime/src/test/resources/yobTestYangFiles/simple-data-types-leaf-list.yang
@@ -252,5 +252,16 @@
base iden;
}
}
+
+ leaf-list lfenum1 {
+ type enumeration {
+ enum "successful exit" {
+ value 1;
+ }
+ enum "grace period expired" {
+ value 2;
+ }
+ }
+ }
}
}
diff --git a/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang b/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
index 602c37b..f6b64d2 100644
--- a/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
+++ b/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
@@ -47,6 +47,17 @@
}
}
+ typedef tpdfun0 {
+ type enumeration {
+ enum "successful exit" {
+ value 1;
+ }
+ enum "grace period expired" {
+ value 2;
+ }
+ }
+ }
+
container cont {
leaf lfnint8Min {
type int8;
@@ -252,5 +263,9 @@
base iden;
}
}
+
+ leaf lfenum1 {
+ type tpdfun0;
+ }
}
}