Merge "[ONOS-6812] RpcContext API definition."
diff --git a/compiler/api/pom.xml b/compiler/api/pom.xml
index a168ca1..5a125f9 100644
--- a/compiler/api/pom.xml
+++ b/compiler/api/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-api</artifactId>
diff --git a/compiler/base/datamodel/pom.xml b/compiler/base/datamodel/pom.xml
index 1a84c0e..fc288b6 100644
--- a/compiler/base/datamodel/pom.xml
+++ b/compiler/base/datamodel/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-base</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-datamodel</artifactId>
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java
index 0b1c3b5..3f8b22c 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/ObjectProvider.java
@@ -73,9 +73,10 @@
return new BigInteger(leafValue);
case EMPTY:
if (leafValue == null || leafValue.equals("")) {
- return true;
- } else {
- throw new IllegalArgumentException(E_NONEMPTY);
+ return null;
+ } else if (leafValue.equals("true") ||
+ leafValue.equals("false")) {
+ return Boolean.parseBoolean(leafValue);
}
case BOOLEAN:
return Boolean.parseBoolean(leafValue);
@@ -87,6 +88,7 @@
case IDENTITYREF:
case ENUMERATION:
case STRING:
+ case INSTANCE_IDENTIFIER:
return leafValue;
case DECIMAL64:
return new BigDecimal(leafValue);
diff --git a/compiler/base/linker/pom.xml b/compiler/base/linker/pom.xml
index 522703b..3af2615 100644
--- a/compiler/base/linker/pom.xml
+++ b/compiler/base/linker/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-base</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-linker</artifactId>
diff --git a/compiler/base/parser/pom.xml b/compiler/base/parser/pom.xml
index 131b4f1..bc73e2d 100644
--- a/compiler/base/parser/pom.xml
+++ b/compiler/base/parser/pom.xml
@@ -21,11 +21,11 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-base</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-parser</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
diff --git a/compiler/base/pom.xml b/compiler/base/pom.xml
index b11f7bc..bf9b8d4 100644
--- a/compiler/base/pom.xml
+++ b/compiler/base/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-base</artifactId>
diff --git a/compiler/base/tool/pom.xml b/compiler/base/tool/pom.xml
index a3172be..8fcd3ed 100644
--- a/compiler/base/tool/pom.xml
+++ b/compiler/base/tool/pom.xml
@@ -23,11 +23,11 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-base</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-tool</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
@@ -40,12 +40,12 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-parser</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-api</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
diff --git a/compiler/base/translator/pom.xml b/compiler/base/translator/pom.xml
index b7c0e18..d01c3c0 100644
--- a/compiler/base/translator/pom.xml
+++ b/compiler/base/translator/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-base</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-translator</artifactId>
diff --git a/compiler/base/utils/pom.xml b/compiler/base/utils/pom.xml
index 04fa4bd..9b71581 100644
--- a/compiler/base/utils/pom.xml
+++ b/compiler/base/utils/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-base</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-utils</artifactId>
diff --git a/compiler/plugin/buck/pom.xml b/compiler/plugin/buck/pom.xml
index 055d2fe..da995fb 100644
--- a/compiler/plugin/buck/pom.xml
+++ b/compiler/plugin/buck/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-plugin</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-buck-plugin</artifactId>
diff --git a/compiler/plugin/maven/pom.xml b/compiler/plugin/maven/pom.xml
index edec90b..ac3cbe2 100644
--- a/compiler/plugin/maven/pom.xml
+++ b/compiler/plugin/maven/pom.xml
@@ -21,11 +21,11 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-plugin</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-maven-plugin</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<dependencies>
diff --git a/compiler/plugin/pom.xml b/compiler/plugin/pom.xml
index 008fc7f..be4bbfd 100644
--- a/compiler/plugin/pom.xml
+++ b/compiler/plugin/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler-plugin</artifactId>
diff --git a/compiler/pom.xml b/compiler/pom.xml
index 46b4b62..f6ffbbd 100644
--- a/compiler/pom.xml
+++ b/compiler/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-tools</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-compiler</artifactId>
diff --git a/model/pom.xml b/model/pom.xml
index 9929a7d..7c8e4f6 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-tools</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-model</artifactId>
@@ -45,5 +45,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava-testlib</artifactId>
+ <version>${guava.version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git a/model/src/main/java/org/onosproject/yang/model/ListKey.java b/model/src/main/java/org/onosproject/yang/model/ListKey.java
index 297a660..9f643a4 100644
--- a/model/src/main/java/org/onosproject/yang/model/ListKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/ListKey.java
@@ -30,6 +30,7 @@
*/
public final class ListKey extends NodeKey<ListKey> implements Comparable<ListKey> {
+ // effectively final, but not possible due to clone()
private List<KeyLeaf> keyLeafs;
/**
@@ -39,7 +40,7 @@
*/
private ListKey(ListKeyBuilder builder) {
super(builder);
- keyLeafs = builder.keyLeafs;
+ keyLeafs = ImmutableList.copyOf(builder.keyLeafs);
}
/**
@@ -50,7 +51,7 @@
* @return List of key leaf nodes
*/
public List<KeyLeaf> keyLeafs() {
- return ImmutableList.copyOf(keyLeafs);
+ return keyLeafs;
}
/**
@@ -60,19 +61,21 @@
* @throws CloneNotSupportedException if the object's class does not
* support the {@code Cloneable} interface
*/
+ @Override
public ListKey clone() throws CloneNotSupportedException {
ListKey clonedListKey = (ListKey) super.clone();
- List<KeyLeaf> clonedKeyLeafs = new LinkedList<>();
+ ImmutableList.Builder<KeyLeaf> clonedKeyLeafs = ImmutableList.builder();
for (KeyLeaf leaf : keyLeafs) {
clonedKeyLeafs.add(leaf.clone());
}
- clonedListKey.keyLeafs = clonedKeyLeafs;
+ clonedListKey.keyLeafs = clonedKeyLeafs.build();
return clonedListKey;
}
+ @Override
public int compareTo(ListKey o) {
//TODO: implement me
- return 0;
+ throw new UnsupportedOperationException();
}
@Override
@@ -129,7 +132,7 @@
* Adds the key leaf for the list resource.
*
* @param name key leaf name
- * @param nameSpace key laef namespace
+ * @param nameSpace key leaf namespace
* @param val value of key
*/
public void addKeyLeaf(String name, String nameSpace, Object val) {
@@ -142,6 +145,7 @@
*
* @return list key
*/
+ @Override
public ListKey build() {
return new ListKey(this);
}
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcHandler.java b/model/src/main/java/org/onosproject/yang/model/RegisterException.java
similarity index 60%
rename from model/src/main/java/org/onosproject/yang/model/RpcHandler.java
rename to model/src/main/java/org/onosproject/yang/model/RegisterException.java
index c1d92cd..5665445 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcHandler.java
+++ b/model/src/main/java/org/onosproject/yang/model/RegisterException.java
@@ -13,23 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.onosproject.yang.model;
-
-import com.google.common.annotations.Beta;
-
/**
- * Service for entities that would execute RPC methods invoked through
- * Dynamic Config RPC brokerage.
+ * Exceptions for use by the {@code DynamicConfigService}.
*/
-@Beta
-public interface RpcHandler {
- /*
- * Executes the RPC.
- *
- * @param msgId of the RPC message to be executed
- * @param cmd to be executed
- * @param input data to the RPC command
+public class RegisterException extends RuntimeException {
+ /**
+ * Constructs a new runtime exception with no error message.
*/
- void executeRpc(Integer msgId, RpcCommand cmd, RpcInput input);
+ public RegisterException() {
+ super();
+ }
+
+ /**
+ * Constructs a new runtime exception with the given error message.
+ *
+ * @param message error message
+ */
+ public RegisterException(String message) {
+ super(message);
+ }
}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceId.java b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
index 2ccd09a..4222f55 100644
--- a/model/src/main/java/org/onosproject/yang/model/ResourceId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -86,7 +86,10 @@
@Override
public boolean equals(Object obj) {
- if (obj == null) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof ResourceId)) {
return false;
}
ResourceId that = (ResourceId) obj;
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcCaller.java b/model/src/main/java/org/onosproject/yang/model/RpcCaller.java
deleted file mode 100644
index 7039fc8..0000000
--- a/model/src/main/java/org/onosproject/yang/model/RpcCaller.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Service for entities that would invoke RPCs and receive RPC responses,
- * through the Dynamic Config brokerage.
- */
-@Beta
-public interface RpcCaller {
- /*
- * Receives an RPC response.
- *
- * @param msgId of a previously invoked RPC
- * @param output from the RPC execution
- */
- void receiveResponse(Integer msgId, RpcOutput output);
-}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcCommand.java b/model/src/main/java/org/onosproject/yang/model/RpcCommand.java
deleted file mode 100644
index 3aeb562..0000000
--- a/model/src/main/java/org/onosproject/yang/model/RpcCommand.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Abstract implementation of an RPC command.
- */
-@Beta
-public abstract class RpcCommand {
- /**
- * Identifier of an RPC command.
- */
- ResourceId cmdId;
-
- /**
- * Creates an instance of RpcCommand.
- *
- * @param cmdId of RPC command
- */
- public RpcCommand(ResourceId cmdId) {
- this.cmdId = cmdId;
- }
-
- /**
- * Returns the RPC command id.
- *
- * @return cmdId
- */
- public ResourceId cmdId() {
- return this.cmdId;
- }
-
- /**
- * Executes the RPC command.
- *
- * @param input input data to the RPC command.
- */
- public abstract void execute(RpcInput input);
-}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcInput.java b/model/src/main/java/org/onosproject/yang/model/RpcInput.java
index 08e54bb..27f75e6 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcInput.java
+++ b/model/src/main/java/org/onosproject/yang/model/RpcInput.java
@@ -16,17 +16,14 @@
package org.onosproject.yang.model;
-import com.google.common.annotations.Beta;
-
/**
* Abstraction for RPC input.
*/
-@Beta
public class RpcInput {
/**
* Input data to the RPC execution.
*/
- DataNode input;
+ private DataNode data;
/**
* TODO
@@ -39,18 +36,18 @@
/**
* Creates an instance of RpcInput.
*
- * @param input to RPC execution
+ * @param data input for thr Rpc execution
*/
- public RpcInput(DataNode input) {
- this.input = input;
+ public RpcInput(DataNode data) {
+ this.data = data;
}
/**
- * Returns RPC input.
+ * Returns the data specified in this input.
*
- * @return DataNode
+ * @return data specified in this input
*/
- public DataNode input() {
- return this.input;
+ public DataNode data() {
+ return this.data;
}
}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcOutput.java b/model/src/main/java/org/onosproject/yang/model/RpcOutput.java
index 8e6b255..dd13ada 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcOutput.java
+++ b/model/src/main/java/org/onosproject/yang/model/RpcOutput.java
@@ -16,12 +16,9 @@
package org.onosproject.yang.model;
-import com.google.common.annotations.Beta;
-
/**
* Abstraction for RPC output.
*/
-@Beta
public class RpcOutput {
public enum Status {
/**
@@ -41,7 +38,10 @@
*/
RPC_TIMEOUT,
}
-
+ /**
+ * Message id of the Rpc request.
+ */
+ String messageId;
/**
* Status of RPC execution.
*/
@@ -49,23 +49,45 @@
/**
* Output data from the RPC execution.
*/
- DataNode output;
+ DataNode data;
/**
* Creates an instance of RpcOutput.
*
* @param status of RPC execution
- * @param output of RPC execution
+ * @param data of RPC execution
*/
- public RpcOutput(Status status, DataNode output) {
+ public RpcOutput(Status status, DataNode data) {
this.status = status;
- this.output = output;
+ this.data = data;
+ }
+
+ /**
+ * Creates an instance of RpcOutput.
+ *
+ * @param messageId of the Rpc request
+ * @param status of RPC execution
+ * @param data of RPC execution
+ */
+ public RpcOutput(String messageId, Status status, DataNode data) {
+ this.messageId = messageId;
+ this.status = status;
+ this.data = data;
+ }
+
+ /**
+ * Returns messageId of the Rpc request.
+ *
+ * @return messageId
+ */
+ public String messageId() {
+ return this.messageId;
}
/**
* Returns RPC status.
*
- * @return Status
+ * @return status
*/
public RpcOutput.Status status() {
return this.status;
@@ -74,9 +96,17 @@
/**
* Returns RPC output.
*
- * @return DataNode
+ * @return output data
*/
- public DataNode output() {
- return this.output;
+ public DataNode data() {
+ return this.data;
+ }
+
+ /**
+ * Sets the messageId in the Rpc output.
+ * @param msgId the msgId to be set in the Rpc output
+ */
+ public void messageId(String msgId) {
+ this.messageId = msgId;
}
}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcRegistry.java b/model/src/main/java/org/onosproject/yang/model/RpcRegistry.java
new file mode 100644
index 0000000..0f554f4
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/RpcRegistry.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import com.google.common.annotations.Beta;
+
+import java.util.Set;
+
+/**
+ * Entity capable of tracking RPC service end-points.
+ */
+@Beta
+public interface RpcRegistry {
+ /**
+ * Returns the set of all registered service implementations.
+ *
+ * @return set of service implementations
+ */
+ Set<RpcService> getRpcServices();
+
+ /**
+ * Returns the RPC service implementation registered with the specified
+ * RPC service interface.
+ *
+ * @param serviceInterface RPC service interface
+ * @return RPC service implementation
+ */
+ RpcService getRpcService(Class<? extends RpcService> serviceInterface);
+
+ /**
+ * Registers the specified RPC service.
+ *
+ * @param service service implementation to be registered
+ * @throws RegisterException if register failed
+ */
+ void registerRpcService(RpcService service);
+
+ /**
+ * Registers the specified RPC service.
+ *
+ * @param service service implementation to be registered
+ * @throws RegisterException if unregister failed
+ */
+ void unregisterRpcService(RpcService service);
+}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcService.java b/model/src/main/java/org/onosproject/yang/model/RpcService.java
index 2f19b5f..5e4fabd 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcService.java
+++ b/model/src/main/java/org/onosproject/yang/model/RpcService.java
@@ -18,8 +18,8 @@
/**
* Token representation of a YANG RPC end-point.
- * <p>
+ *
* All generated RPC interfaces will extend this interface.
*/
public interface RpcService {
-}
+}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/YangRpcService.java b/model/src/main/java/org/onosproject/yang/model/YangRpcService.java
deleted file mode 100644
index c9d28f2..0000000
--- a/model/src/main/java/org/onosproject/yang/model/YangRpcService.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-/**
- * Representation of an entity that provides YANG RPC service.
- */
-public interface YangRpcService {
-
- /**
- * Registers an RPC handler.
- *
- * @param handler RPC handler
- * @param command RPC command
- */
- void registerHandler(RpcHandler handler, RpcCommand command);
-
- /**
- * Unregisters an RPC receiver.
- *
- * @param handler RPC handler
- * @param command RPC command
- */
- void unRegisterHandler(RpcHandler handler, RpcCommand command);
-
- /**
- * Invokes an RPC.
- *
- * @param caller of the of the RPC
- * @param msgId RPC message id
- * @param command RPC command
- * @param input RPC input
- */
- void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command,
- RpcInput input);
-
- /**
- * Provides response to a a previously invoked RPC.
- *
- * @param msgId of a previously invoked RPC
- * @param output data from the RPC execution
- */
- void rpcResponse(Integer msgId, RpcOutput output);
-}
diff --git a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
index 6a5075d..f9a3474 100644
--- a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
+++ b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
@@ -8,7 +8,9 @@
package org.onosproject.yang.model;
+import org.junit.Before;
import org.junit.Test;
+import com.google.common.testing.EqualsTester;
import java.util.List;
@@ -20,6 +22,27 @@
public class ResourceIdTest {
+ ResourceId ridA;
+ ResourceId ridAcopy;
+
+ @Before
+ public void setUp() throws Exception {
+ ridA = ResourceId.builder()
+ .addBranchPointSchema("/", "")
+ .addBranchPointSchema("devices", "onos")
+ .addBranchPointSchema("device", "onos")
+ .addKeyLeaf("device-id", "onos", "test:A")
+ .build();
+ ridAcopy = ridA.copyBuilder().build();
+ }
+
+ @Test
+ public void random() {
+ new EqualsTester()
+ .addEqualityGroup(ridA, ridAcopy)
+ .testEquals();
+ }
+
@Test
public void resourceIdConstruction() {
String sampleResId = "/card=8/port=5,eth/stats";
diff --git a/pom.xml b/pom.xml
index f87b5d6..fe34af8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
</parent>
<artifactId>onos-yang-tools</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
diff --git a/runtime/pom.xml b/runtime/pom.xml
index fa04b81..77f9b2c 100644
--- a/runtime/pom.xml
+++ b/runtime/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-tools</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-runtime</artifactId>
@@ -42,12 +42,12 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-model</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-compiler-tool</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java
index a33e41f..667f958 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java
@@ -22,16 +22,12 @@
import org.onosproject.yang.compiler.datamodel.YangAugmentableNode;
import org.onosproject.yang.compiler.datamodel.YangCase;
import org.onosproject.yang.compiler.datamodel.YangChoice;
-import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
-import org.onosproject.yang.compiler.datamodel.YangLeafRef;
import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
import org.onosproject.yang.compiler.datamodel.YangList;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
-import org.onosproject.yang.compiler.datamodel.YangType;
-import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.LeafNode;
@@ -39,7 +35,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,27 +44,26 @@
import static org.onosproject.yang.compiler.datamodel.TraversalType.ROOT;
import static org.onosproject.yang.compiler.datamodel.TraversalType.SIBLING;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.nonEmpty;
-import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
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;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.runtime.RuntimeHelper.DEFAULT_CAPS;
+import static org.onosproject.yang.runtime.RuntimeHelper.PERIOD;
+import static org.onosproject.yang.runtime.RuntimeHelper.getCapitalCase;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAttributeOfObject;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAugmentObject;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getClassLoaderForAugment;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getInterfaceClassFromImplClass;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getJavaName;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafListObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafObject;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getParentObjectOfNode;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getStringFromType;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isAugmentNode;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isMultiInstanceNode;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isNodeProcessCompleted;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isNonProcessableNode;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypePrimitive;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isValueOrSelectLeafSet;
-import static org.onosproject.yang.runtime.RuntimeHelper.DEFAULT_CAPS;
-import static org.onosproject.yang.runtime.RuntimeHelper.PERIOD;
-import static org.onosproject.yang.runtime.RuntimeHelper.getCapitalCase;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypeEmpty;
/**
@@ -79,7 +73,6 @@
public class DataTreeBuilderHelper {
private static final String TRUE = "true";
- private static final String IS_LEAF_VALUE_SET_METHOD = "isLeafValueSet";
private static final String AUGMENTATIONS = "augmentations";
private static final String FALSE = "false";
@@ -759,8 +752,18 @@
} catch (NoSuchMethodException e) {
throw new ModelConvertorException(e);
}
-
- addLeafWithValue(yangNode, yangLeaf, parentObj, leafType);
+ Object obj = getLeafObject(yangNode, yangLeaf, parentObj,
+ leafType, false);
+ if (obj != null) {
+ if (isTypeEmpty(yangLeaf.getDataType())) {
+ String empty = String.valueOf(obj);
+ if (!empty.equals(TRUE)) {
+ continue;
+ }
+ obj = null;
+ }
+ createLeafNode(yangLeaf, obj);
+ }
}
}
}
@@ -815,43 +818,20 @@
throw new ModelConvertorException(e);
}
if (obj != null) {
- return addLeafListValue(yangNode, parentObj, leafList, obj);
- }
- return null;
- }
-
- /**
- * Adds the leaf list value to the data tree builder by taking the string
- * value from the data type.
- *
- * @param yangNode YANG node
- * @param parentObj parent object
- * @param leafList YANG leaf list
- * @param obj list of objects
- */
- List<DataNode.Builder> addLeafListValue(
- YangSchemaNode yangNode, Object parentObj,
- YangLeafList leafList, List<Object> obj) {
-
- Set<String> leafListVal = new LinkedHashSet<>();
- boolean isEmpty = false;
- for (Object object : obj) {
- String val = getStringFromType(yangNode, parentObj,
- getJavaName(leafList), object,
- leafList.getDataType());
- isEmpty = isTypeEmpty(val, leafList.getDataType());
- if (isEmpty) {
- if (val.equals(TRUE)) {
- addLeafList(leafListVal, leafList);
+ Set<Object> objects = getLeafListObject(yangNode, leafList,
+ parentObj, obj);
+ if (!objects.isEmpty()) {
+ Object o = objects.iterator().next();
+ if (isTypeEmpty(leafList.getDataType())) {
+ objects.clear();
+ String empty = String.valueOf(o);
+ if (!empty.equals(TRUE)) {
+ return null;
+ }
+ objects.add(null);
}
- break;
+ return addLeafList(objects, leafList);
}
- if (!val.equals("")) {
- leafListVal.add(val);
- }
- }
- if (!isEmpty && !leafListVal.isEmpty()) {
- return addLeafList(leafListVal, leafList);
}
return null;
}
@@ -863,13 +843,13 @@
* @param leafListVal set of values
* @param leafList YANG leaf list
*/
- private List<DataNode.Builder> addLeafList(Set<String> leafListVal, YangLeafList
- leafList) {
+ List<DataNode.Builder> addLeafList(Set<Object> leafListVal,
+ YangLeafList leafList) {
if (extBuilder != null) {
- for (String val : leafListVal) {
+ for (Object val : leafListVal) {
DataNode.Builder leaf = extBuilder.createChildBuilder(
- leafList.getName(), leafList.getNameSpace().getModuleNamespace(),
- val);
+ leafList.getName(), leafList.getNameSpace()
+ .getModuleNamespace(), val);
leaf.type(MULTI_INSTANCE_LEAF_VALUE_NODE);
leaf.addLeafListValue(val);
extBuilder = leaf.exitNode();
@@ -878,10 +858,10 @@
}
//In case of root node leaf lists.
List<DataNode.Builder> builders = new ArrayList<>();
- for (String val : leafListVal) {
+ for (Object val : leafListVal) {
DataNode.Builder leaf = LeafNode.builder(
- leafList.getName(), leafList.getNameSpace().getModuleNamespace())
- .value(val);
+ leafList.getName(), leafList.getNameSpace()
+ .getModuleNamespace()).value(val);
leaf.type(MULTI_INSTANCE_LEAF_VALUE_NODE);
leaf.addLeafListValue(val);
builders.add(leaf);
@@ -917,92 +897,17 @@
}
/**
- * Adds leaf to data tree when value is present. For primitive types, in
- * order to avoid default values, the value select is set or not is checked and
- * then added.
- *
- * @param holder leaf holder
- * @param yangLeaf YANG leaf node
- * @param parentObj leaf holder object
- * @param leafType object of leaf type
- */
- DataNode.Builder addLeafWithValue(YangSchemaNode holder, YangLeaf yangLeaf,
- Object parentObj, Object leafType) {
- String fieldValue = null;
- if (isTypePrimitive(yangLeaf.getDataType())) {
- fieldValue = getLeafValueFromValueSetFlag(holder, parentObj,
- yangLeaf, leafType);
- /*
- * Checks the object is present or not, when type is
- * non-primitive. And adds the value from the respective data type.
- */
- } else if (leafType != null) {
- fieldValue = getStringFromType(holder, parentObj,
- getJavaName(yangLeaf), leafType,
- yangLeaf.getDataType());
- }
-
- if (ModelConverterUtil.nonEmpty(fieldValue)) {
- boolean isEmpty = isTypeEmpty(fieldValue,
- yangLeaf.getDataType());
- if (isEmpty) {
- if (!fieldValue.equals(TRUE)) {
- return null;
- }
- fieldValue = null;
- }
-
- //Create leaf node.
- return createLeafNode(yangLeaf, fieldValue);
- }
- return null;
- }
-
- /**
- * Returns the value as true if direct or referred type from leaf-ref or
- * derived points to empty data type; false otherwise.
- *
- * @param fieldValue value of the leaf
- * @param dataType type of the leaf
- * @return true if type is empty; false otherwise.
- */
- private boolean isTypeEmpty(String fieldValue, YangType<?> dataType) {
- if (fieldValue.equals(TRUE) || fieldValue.equals(FALSE)) {
- switch (dataType.getDataType()) {
- case EMPTY:
- return true;
-
- case LEAFREF:
- YangLeafRef leafRef =
- (YangLeafRef) dataType.getDataTypeExtendedInfo();
- return isTypeEmpty(fieldValue,
- leafRef.getEffectiveDataType());
- case DERIVED:
- YangDerivedInfo info =
- (YangDerivedInfo) dataType
- .getDataTypeExtendedInfo();
- YangDataTypes type = info.getEffectiveBuiltInType();
- return type == EMPTY;
-
- default:
- return false;
- }
- }
- return false;
- }
-
- /**
* Creates data leaf node.
*
* @param yangLeaf YANG leaf
* @param val value for the leaf
*/
- private DataNode.Builder createLeafNode(YangLeaf yangLeaf, Object val) {
+ DataNode.Builder createLeafNode(YangLeaf yangLeaf, Object val) {
if (extBuilder != null) {
//Add leaf to key leaves.
if (yangLeaf.isKeyLeaf()) {
- extBuilder.addKeyLeaf(yangLeaf.getName(), yangLeaf.getNameSpace()
- .getModuleNamespace(), val);
+ extBuilder.addKeyLeaf(yangLeaf.getName(), yangLeaf
+ .getNameSpace().getModuleNamespace(), val);
}
//build leaf node and add to parent node.
DataNode.Builder leaf = extBuilder.createChildBuilder(
@@ -1020,35 +925,6 @@
}
/**
- * Returns the value of type, after checking the value leaf flag. If the
- * flag is set, then it takes the value else returns null.
- *
- * @param holder leaf holder
- * @param parentObj parent object
- * @param yangLeaf YANG leaf node
- * @param leafType object of leaf type
- * @return value of type
- */
- private String getLeafValueFromValueSetFlag(YangSchemaNode holder, Object parentObj,
- YangLeaf yangLeaf, Object leafType) {
-
- String valueOfLeaf;
- try {
- valueOfLeaf = isValueOrSelectLeafSet(holder, parentObj,
- getJavaName(yangLeaf),
- IS_LEAF_VALUE_SET_METHOD);
- } catch (NoSuchMethodException e) {
- throw new ModelConvertorException(e);
- }
- if (valueOfLeaf.equals(TRUE)) {
- return getStringFromType(holder, parentObj,
- getJavaName(yangLeaf), leafType,
- yangLeaf.getDataType());
- }
- return null;
- }
-
- /**
* Returns the node info which can be processed, by eliminating the nodes
* which need not to be processed at normal conditions such as RPC,
* notification and augment.
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java
index bef158e..31e5147 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java
@@ -33,6 +33,7 @@
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultResourceData;
+import org.onosproject.yang.model.DefaultResourceData.Builder;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.LeafModelObject;
import org.onosproject.yang.model.LeafNode;
@@ -44,6 +45,7 @@
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.nonEmpty;
@@ -53,11 +55,15 @@
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAttributeOfObject;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getJavaName;
import static org.onosproject.yang.runtime.RuntimeHelper.DEFAULT_CAPS;
import static org.onosproject.yang.runtime.RuntimeHelper.PERIOD;
import static org.onosproject.yang.runtime.RuntimeHelper.getCapitalCase;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.TRUE;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAttributeOfObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getJavaName;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafListObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypeEmpty;
/**
* Representation of data tree builder which generates YANG data tree from the
@@ -106,7 +112,7 @@
List<ModelObject> modelObjects = modelData.modelObjects();
ModelObjectId id = modelData.identifier();
- DefaultResourceData.Builder rscData = DefaultResourceData.builder();
+ Builder rscData = DefaultResourceData.builder();
//Create resource identifier.
ModIdToRscIdConverter converter = new ModIdToRscIdConverter(reg);
@@ -169,7 +175,7 @@
*/
private void processDataNodeConversion(
YangNode curNode, DataTreeBuilderHelper helper,
- DefaultResourceData.Builder rscData, Object curObj) {
+ Builder rscData, Object curObj) {
if (curNode == null) {
return;
}
@@ -209,7 +215,7 @@
* @return input/output node
*/
private YangSchemaNode handleRpcChild(
- Object obj, YangNode parent, DefaultResourceData.Builder rscData) {
+ Object obj, YangNode parent, Builder rscData) {
if (obj != null && parent != null) {
//process all the node which are in data model tree.
String name = obj.getClass().getName();
@@ -410,54 +416,110 @@
/**
* Process leaf and leaf list information.
*
- * @param rootNode root node
- * @param rscData resource data
+ * @param holder holder node
+ * @param rscData resource data
+ * @param lObj leaf model object
*/
- private void processLeafObj(YangSchemaNode rootNode,
- DefaultResourceData.Builder rscData,
- LeafModelObject rootObj) {
+ private void processLeafObj(YangSchemaNode holder, Builder rscData,
+ LeafModelObject lObj) {
//handle leaf nodes.
- YangLeavesHolder holder = (YangLeavesHolder) rootNode;
- if (rootObj.leafIdentifier() != null) {
- String name = rootObj.leafIdentifier().toString().toLowerCase();
- List<Object> values = rootObj.values();
+ YangLeavesHolder lHolder = (YangLeavesHolder) holder;
+ if (lObj.leafIdentifier() != null) {
+ String name = lObj.leafIdentifier().toString().toLowerCase();
+ List<Object> values = lObj.values();
// handle all leaf nodes and add their data nodes to resource data.
- List<YangLeaf> leaves = holder.getListOfLeaf();
+ List<YangLeaf> leaves = lHolder.getListOfLeaf();
if (nonEmpty(leaves)) {
- for (YangLeaf leaf : leaves) {
- //Add node for leaf with value.
- if (name.equals(leaf.getJavaAttributeName().toLowerCase())) {
- DataNode node = LeafNode.builder(leaf.getName(), leaf
- .getNameSpace().getModuleNamespace())
- .value(values.get(0))
- .type(SINGLE_INSTANCE_LEAF_VALUE_NODE).build();
- rscData.addDataNode(node);
- break;
- }
- }
+ updateLeafDataNode(name, leaves, values.get(0), rscData,
+ holder, lObj);
}
- // handle all leaf list nodes and add their data nodes to resource data.
- List<YangLeafList> leafLists = holder.getListOfLeafList();
+ // handle all leaf-list nodes and add their data nodes to
+ // resource data.
+ List<YangLeafList> leafLists = lHolder.getListOfLeafList();
if (nonEmpty(leafLists)) {
- for (YangLeafList leafList : leafLists) {
- if (name.equals(leafList.getJavaAttributeName().toLowerCase())) {
- //for leaf list we need to add multi instance of leaf
- // node.
- for (Object o : values) {
- DataNode node = LeafNode
- .builder(leafList.getName(),
- leafList.getNameSpace().getModuleNamespace())
- .value(o)
- .type(MULTI_INSTANCE_LEAF_VALUE_NODE).build();
- rscData.addDataNode(node);
- }
- break;
- }
- }
+ updateLeafListDataNode(name, leafLists, values, rscData,
+ holder, lObj);
}
}
}
+ /**
+ * Updates the processed leaf-list objects from the leaf-list type to the
+ * data node.
+ *
+ * @param name leaf-list name
+ * @param leafLists YANG leaf-lists
+ * @param values leaf-list objects
+ * @param rscData data node
+ * @param holder leaf-list holder
+ * @param lObj leaf model object
+ */
+ private void updateLeafListDataNode(String name, List<YangLeafList> leafLists,
+ List<Object> values, Builder rscData,
+ YangSchemaNode holder, LeafModelObject lObj) {
+ for (YangLeafList leafList : leafLists) {
+ if (name.equals(leafList.getJavaAttributeName().toLowerCase())) {
+ Set<Object> objects = getLeafListObject(holder, leafList,
+ lObj, values);
+ if (!objects.isEmpty()) {
+ Object o = objects.iterator().next();
+ if (isTypeEmpty(leafList.getDataType())) {
+ objects.clear();
+ String empty = String.valueOf(o);
+ if (!empty.equals(TRUE)) {
+ break;
+ }
+ objects.add(null);
+ }
+ for (Object obj : objects) {
+ DataNode node = LeafNode
+ .builder(leafList.getName(), leafList
+ .getNameSpace().getModuleNamespace())
+ .value(obj)
+ .type(MULTI_INSTANCE_LEAF_VALUE_NODE).build();
+ rscData.addDataNode(node);
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Updates the processed leaf object from the leaf type to the data node.
+ *
+ * @param lName leaf name
+ * @param leaves YANG leaves
+ * @param val leaf object
+ * @param rscData data node
+ * @param rootNode holder node
+ * @param lObj leaf model object
+ */
+ private void updateLeafDataNode(String lName, List<YangLeaf> leaves,
+ Object val, Builder rscData,
+ YangSchemaNode rootNode, LeafModelObject lObj) {
+ for (YangLeaf leaf : leaves) {
+ if (lName.equals(leaf.getJavaAttributeName().toLowerCase())) {
+ Object obj = getLeafObject(rootNode, leaf, lObj,
+ val, true);
+ if (obj != null) {
+ if (isTypeEmpty(leaf.getDataType())) {
+ String empty = String.valueOf(obj);
+ if (!empty.equals(TRUE)) {
+ break;
+ }
+ obj = null;
+ }
+ DataNode node = LeafNode.builder(leaf.getName(), leaf
+ .getNameSpace().getModuleNamespace())
+ .value(obj)
+ .type(SINGLE_INSTANCE_LEAF_VALUE_NODE).build();
+ rscData.addDataNode(node);
+ break;
+ }
+ }
+ }
+ }
/**
* Process single instance/multi instance nodes and build there data nodes.
@@ -494,7 +556,7 @@
* @param yangObj object for node
*/
private void processModelObjects(DataTreeBuilderHelper modYo, YangSchemaNode lastIndexNode,
- DefaultResourceData.Builder rscData, Object
+ Builder rscData, Object
yangObj) {
//Process all the leaf nodes of root node.
processRootLeafInfo(modYo, lastIndexNode, rscData, yangObj);
@@ -510,59 +572,114 @@
/**
* Process leaf and leaf list information.
*
- * @param modYo module builder
- * @param rootNode root node
- * @param rscData resource data
+ * @param modYo module builder
+ * @param holder root node
+ * @param rscData resource data
*/
- private void processRootLeafInfo(
- DataTreeBuilderHelper modYo, YangSchemaNode rootNode,
- DefaultResourceData.Builder rscData, Object rootObj) {
+ private void processRootLeafInfo(DataTreeBuilderHelper modYo,
+ YangSchemaNode holder, Builder rscData,
+ Object hObj) {
//handle leaf nodes.
- YangLeavesHolder holder = (YangLeavesHolder) rootNode;
- if (rootNode instanceof YangCase) {
- if (((YangCase) rootNode).getParent().getParent() instanceof
+ YangLeavesHolder lHolder = (YangLeavesHolder) holder;
+ if (holder instanceof YangCase) {
+ if (((YangCase) holder).getParent().getParent() instanceof
RpcNotificationContainer) {
modYo.setExtBuilder(null);
}
}
// handle all leaf nodes and add their data nodes to resource data.
- List<YangLeaf> leaves = holder.getListOfLeaf();
- DataNode.Builder builder;
+ List<YangLeaf> leaves = lHolder.getListOfLeaf();
if (nonEmpty(leaves)) {
- for (YangLeaf leaf : leaves) {
- try {
- //Add node for leaf with value.
- builder = modYo.addLeafWithValue(
- rootNode, leaf, rootObj, getAttributeOfObject(
- rootObj, leaf.getJavaAttributeName()));
- addDataNode(builder, rscData);
- } catch (NoSuchMethodException e) {
- throw new ModelConvertorException("failed to create data node for " +
- "leaf " + leaf.getName());
- }
- }
+ updateLeaf(leaves, modYo, holder, hObj, rscData);
}
// handle all leaf list nodes and add their data nodes to resource data.
- List<YangLeafList> leafLists = holder.getListOfLeafList();
- List<DataNode.Builder> nodes;
+ List<YangLeafList> leafLists = lHolder.getListOfLeafList();
if (nonEmpty(leafLists)) {
- List<Object> obj;
- for (YangLeafList leafList : leafLists) {
- try {
- obj = (List<Object>) getAttributeOfObject(
- rootObj, getJavaName(leafList));
- if (obj != null) {
- nodes = modYo.addLeafListValue(rootNode, rootObj,
- leafList, obj);
+ updateLeafList(leafLists, modYo, holder, hObj, rscData);
+ }
+ }
+
+ /**
+ * Updates leaf values inside the holder node by taking the processed
+ * leaf object and checking for empty type.
+ *
+ * @param leafLists list of leaf-list
+ * @param modYo data tree builder
+ * @param holder leaf-list holder
+ * @param hObj holder object
+ * @param rscData resource data
+ */
+ private void updateLeafList(List<YangLeafList> leafLists,
+ DataTreeBuilderHelper modYo, YangSchemaNode holder,
+ Object hObj, Builder rscData) {
+ List<Object> obj;
+ List<DataNode.Builder> nodes;
+ for (YangLeafList leafList : leafLists) {
+ try {
+ obj = (List<Object>) getAttributeOfObject(
+ hObj, getJavaName(leafList));
+ if (obj != null) {
+ Set<Object> objects = getLeafListObject(holder, leafList,
+ hObj, obj);
+ if (!objects.isEmpty()) {
+ Object o = objects.iterator().next();
+ if (isTypeEmpty(leafList.getDataType())) {
+ objects.clear();
+ String empty = String.valueOf(o);
+ if (!empty.equals(TRUE)) {
+ continue;
+ }
+ objects.add(null);
+ }
+ nodes = modYo.addLeafList(objects, leafList);
if (nodes != null) {
for (DataNode.Builder node : nodes) {
rscData.addDataNode(node.build());
}
}
}
- } catch (NoSuchMethodException e) {
- throw new ModelConvertorException(e);
}
+ } catch (NoSuchMethodException e) {
+ throw new ModelConvertorException(e);
+ }
+ }
+ }
+
+ /**
+ * Updates leaf values inside the holder node by taking the processed
+ * leaf object and checking for empty type.
+ *
+ * @param leaves list of leaf
+ * @param modYo data tree builder
+ * @param holder leaf holder
+ * @param hObj holder object
+ * @param rscData resource data
+ */
+ private void updateLeaf(List<YangLeaf> leaves, DataTreeBuilderHelper modYo,
+ YangSchemaNode holder, Object hObj, Builder rscData) {
+ DataNode.Builder builder;
+ for (YangLeaf leaf : leaves) {
+ try {
+ Object leafObj = getAttributeOfObject(
+ hObj, leaf.getJavaAttributeName());
+ Object obj = getLeafObject(holder, leaf, hObj, leafObj,
+ false);
+
+ if (obj != null) {
+ if (isTypeEmpty(leaf.getDataType())) {
+ String empty = String.valueOf(obj);
+ if (!empty.equals(TRUE)) {
+ continue;
+ }
+ obj = null;
+ }
+ builder = modYo.createLeafNode(leaf, obj);
+ addDataNode(builder, rscData);
+ }
+ } catch (NoSuchMethodException e) {
+ throw new ModelConvertorException(
+ "Failed to create data node for leaf "
+ + leaf.getName());
}
}
}
@@ -578,7 +695,7 @@
*/
private void processRootLevelListNode(
DataTreeBuilderHelper helper, YangSchemaNode curRootNode,
- DefaultResourceData.Builder rscData, Object curRootObj) {
+ Builder rscData, Object curRootObj) {
YangNode curNode = ((YangNode) curRootNode).getChild();
DataTreeNodeInfo parentInfo = new DataTreeNodeInfo();
@@ -646,7 +763,7 @@
*/
private void processRootLevelSingleInNode(
DataTreeBuilderHelper helper, YangSchemaNode rootNode,
- DefaultResourceData.Builder rscData, Object rootObj) {
+ Builder rscData, Object rootObj) {
YangNode curNode = ((YangNode) rootNode).getChild();
@@ -723,7 +840,7 @@
* @return single instance node
*/
private YangNode verifyAndDoNotGetList(YangNode curNode, DataTreeBuilderHelper
- helper, DataTreeNodeInfo info, DefaultResourceData.Builder rscData) {
+ helper, DataTreeNodeInfo info, Builder rscData) {
if (curNode == null) {
return null;
}
@@ -762,7 +879,7 @@
*/
private YangNode processReCheckSibling(
YangNode curNode, DataTreeBuilderHelper helper, DataTreeNodeInfo info,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
curNode = curNode.getNextSibling();
curNode = verifyAndDoNotGetList(curNode, helper, info, rscData);
return curNode;
@@ -778,7 +895,7 @@
*/
private void handleChoiceNode(
YangNode curNode, DataTreeNodeInfo info, DataTreeBuilderHelper helper,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
// get the choice object.
Object childObj = helper.processChoiceNode(curNode, info);
YangNode tempNode = curNode;
@@ -820,7 +937,7 @@
*/
private void processCaseNode(
YangNode curNode, DataTreeNodeInfo info, DataTreeBuilderHelper helper,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
Object childObj = helper.processCaseNode(curNode, info);
if (childObj != null) {
processModelObjects(helper, curNode, rscData, childObj);
@@ -839,7 +956,7 @@
*/
private void handleCaseNode(
YangNode curNode, DataTreeNodeInfo info, DataTreeBuilderHelper yo,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
Object obj = info.getYangObject();
if (obj != null) {
@@ -854,7 +971,7 @@
* @param builder resource data builder
*/
private void addDataNode(DataNode.Builder node,
- DefaultResourceData.Builder builder) {
+ Builder builder) {
if (node != null) {
builder.addDataNode(node.build());
}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java
index 9ffbedd..9324b89 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java
@@ -20,8 +20,11 @@
import org.onosproject.yang.compiler.datamodel.TraversalType;
import org.onosproject.yang.compiler.datamodel.YangAugment;
import org.onosproject.yang.compiler.datamodel.YangCase;
+import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
import org.onosproject.yang.compiler.datamodel.YangIdentity;
import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
+import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNotification;
@@ -31,6 +34,7 @@
import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.model.AtomicPath;
+import org.onosproject.yang.model.LeafSchemaContext;
import org.onosproject.yang.model.MultiInstanceLeaf;
import org.onosproject.yang.model.MultiInstanceNode;
import org.onosproject.yang.model.SingleInstanceLeaf;
@@ -39,8 +43,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
-import java.util.Base64;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -71,13 +75,15 @@
* Static attribute for string value having null.
*/
static final String STR_NULL = "null";
-
+ static final String FALSE = "false";
+ static final String TRUE = "true";
private static final int ONE = 1;
private static final String ENUM_LEAF_IDENTIFIER = "$LeafIdentifier";
private static final Set<YangDataTypes> PRIMITIVE_TYPES =
new HashSet<>(Arrays.asList(INT8, INT16, INT32, INT64, UINT8,
UINT16, UINT32, BOOLEAN, EMPTY));
private static final String TO_STRING = "toString";
+ private static final String IS_VAL_SET = "isLeafValueSet";
// No instantiation.
private ModelConverterUtil() {
@@ -214,19 +220,15 @@
}
/**
- * Returns the string true, if the leaf data is actually set; false
- * otherwise.
+ * Returns true, if the leaf data is actually set; false otherwise.
*
- * @param holder leaf holder
- * @param nodeObj object if the node
- * @param javaName java name of the leaf
- * @param methodName getter method name
- * @return string value of the boolean method
- * @throws NoSuchMethodException if the method is not present
+ * @param holder leaf holder
+ * @param nodeObj object if the node
+ * @param javaName java name of the leaf
+ * @return status of the value set flag
*/
- static String isValueOrSelectLeafSet(YangSchemaNode holder, Object nodeObj,
- String javaName, String methodName)
- throws NoSuchMethodException {
+ static boolean isLeafValueSet(YangSchemaNode holder, Object nodeObj,
+ String javaName) {
Class<?> nodeClass = nodeObj.getClass();
@@ -239,13 +241,13 @@
Class leafEnum;
try {
leafEnum = classLoader.loadClass(enumPackage);
- Method getterMethod = nodeClass.getMethod(methodName, leafEnum);
+ Method getterMethod = nodeClass.getMethod(IS_VAL_SET, leafEnum);
// Gets the value of the enum.
Enum<?> value = Enum.valueOf(leafEnum, javaName.toUpperCase());
// Invokes the method with the value of enum as param.
- return String.valueOf(getterMethod.invoke(nodeObj, value));
+ return (boolean) getterMethod.invoke(nodeObj, value);
} catch (IllegalAccessException | InvocationTargetException |
- ClassNotFoundException e) {
+ ClassNotFoundException | NoSuchMethodException e) {
throw new ModelConvertorException(e);
}
}
@@ -259,13 +261,15 @@
* @param name leaf/leaf-list name
* @param fieldObj object of the leaf/leaf-list field
* @param dataType type of the leaf/leaf-list
- * @return string value from the type
+ * @return finalized object
*/
- static String getStringFromType(YangSchemaNode holder, Object holderObj,
- String name, Object fieldObj, YangType dataType) {
+ static Object getObjFromType(YangSchemaNode holder, Object holderObj,
+ Object leaf, String name, Object fieldObj,
+ YangType dataType) {
if (fieldObj == null) {
- throw new ModelConvertorException("Value of " + holder.getName() + " is null");
+ throw new ModelConvertorException("Value of " + holder.getName()
+ + " is null");
}
YangDataTypes type = dataType.getDataType();
@@ -278,39 +282,44 @@
case UINT16:
case UINT32:
case UINT64:
- case EMPTY:
case STRING:
- case DECIMAL64:
- case INSTANCE_IDENTIFIER:
- case DERIVED:
- case UNION:
- case ENUMERATION:
case BOOLEAN:
+ case DECIMAL64:
+ case EMPTY:
+ return fieldObj;
+
+ case INSTANCE_IDENTIFIER:
+ case ENUMERATION:
return String.valueOf(fieldObj).trim();
+ case BINARY:
+ return new String((byte[]) fieldObj);
+
case BITS:
return getBitsValue(holder, holderObj, name, fieldObj).trim();
- case BINARY:
- return Base64.getEncoder().encodeToString((byte[]) fieldObj);
-
case IDENTITYREF:
- YangIdentityRef ir =
- (YangIdentityRef) dataType.getDataTypeExtendedInfo();
+ YangIdentityRef ir = (YangIdentityRef) dataType
+ .getDataTypeExtendedInfo();
if (ir.isInGrouping()) {
return String.valueOf(fieldObj).trim();
}
return getIdentityRefValue(fieldObj, ir, holderObj);
case LEAFREF:
- YangLeafRef leafRef =
- (YangLeafRef) dataType.getDataTypeExtendedInfo();
- return getStringFromType(holder, holderObj, name, fieldObj,
- leafRef.getEffectiveDataType());
+ YangLeafRef leafRef = (YangLeafRef) dataType
+ .getDataTypeExtendedInfo();
+ return getObjFromType(holder, holderObj, leaf, name, fieldObj,
+ leafRef.getEffectiveDataType());
+
+ case DERIVED:
+ case UNION:
+ String val = String.valueOf(fieldObj).trim();
+ return ((LeafSchemaContext) leaf).fromString(val);
default:
- throw new ModelConvertorException("Unsupported data type. Cannot be " +
- "processed.");
+ throw new ModelConvertorException(
+ "Unsupported data type. Cannot be processed.");
}
}
@@ -532,4 +541,85 @@
}
return builder.toString();
}
+
+ /**
+ * Returns leaf object when value is present. For primitive types, in
+ * order to avoid default values, the value select is set or not is checked
+ * and then returned.
+ *
+ * @param holder leaf holder
+ * @param leaf YANG leaf
+ * @param parentObj leaf holder object
+ * @param leafObj object of leaf type
+ * @param isRoot if it is root leaf object
+ * @return processed leaf object
+ */
+ static Object getLeafObject(YangSchemaNode holder, YangLeaf leaf,
+ Object parentObj, Object leafObj,
+ boolean isRoot) {
+ String jLeaf = getJavaName(leaf);
+ YangType<?> type = leaf.getDataType();
+ if (!isRoot && isTypePrimitive(type)) {
+ if (!isLeafValueSet(holder, parentObj, jLeaf)) {
+ return null;
+ }
+ }
+
+ if (leafObj == null) {
+ return null;
+ }
+ return getObjFromType(holder, parentObj, leaf, jLeaf,
+ leafObj, type);
+ }
+
+ /**
+ * Returns processed leaf-list objects from the data type.
+ *
+ * @param holder leaf-list holder
+ * @param leafList YANG leaf-list
+ * @param parentObj leaf-list holder object
+ * @param objects leaf-list objects
+ * @return processed leaf-list objects
+ */
+ static Set<Object> getLeafListObject(YangSchemaNode holder,
+ YangLeafList leafList,
+ Object parentObj,
+ List<Object> objects) {
+ Set<Object> leafListVal = new LinkedHashSet<>();
+ YangType<?> type = leafList.getDataType();
+ for (Object object : objects) {
+ Object obj = getObjFromType(holder, parentObj, leafList,
+ getJavaName(leafList), object, type);
+ leafListVal.add(obj);
+ }
+ return leafListVal;
+ }
+
+
+ /**
+ * Returns the value as true if direct or referred type from leaf-ref or
+ * derived points to empty data type; false otherwise.
+ *
+ * @param dataType type of the leaf
+ * @return true if type is empty; false otherwise.
+ */
+ static boolean isTypeEmpty(YangType<?> dataType) {
+ switch (dataType.getDataType()) {
+ case EMPTY:
+ return true;
+
+ case LEAFREF:
+ YangLeafRef leafRef = (YangLeafRef) dataType
+ .getDataTypeExtendedInfo();
+ return isTypeEmpty(leafRef.getEffectiveDataType());
+ case DERIVED:
+ YangDerivedInfo info = (YangDerivedInfo) dataType
+ .getDataTypeExtendedInfo();
+ YangDataTypes type = info.getEffectiveBuiltInType();
+ return type == EMPTY;
+
+ default:
+ return false;
+ }
+ }
}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobLeafNodeHandler.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobLeafNodeHandler.java
index f407d13..8a496cd 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobLeafNodeHandler.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobLeafNodeHandler.java
@@ -18,6 +18,7 @@
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
+import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.LeafNode;
@@ -29,6 +30,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypeEmpty;
import static org.onosproject.yang.runtime.impl.YobConstants.E_FAIL_TO_INVOKE_METHOD;
import static org.onosproject.yang.runtime.impl.YobConstants.L_FAIL_TO_INVOKE_METHOD;
import static org.onosproject.yang.runtime.impl.YobUtils.getChildSchemaNode;
@@ -76,16 +78,13 @@
String setterInParent = referredSchema.getJavaAttributeName();
Object parentObj = curWb.getParentObject(registry, schemaNode);
parentClass = parentObj.getClass();
- YangDataTypes dataType = ((YangLeaf) referredSchema).getDataType()
- .getDataType();
- if (((LeafNode) leafNode).value() != null ||
- dataType == YangDataTypes.EMPTY) {
+ YangType<?> type = ((YangLeaf) referredSchema).getDataType();
+ YangDataTypes dataType = type.getDataType();
+ if (((LeafNode) leafNode).value() != null || isTypeEmpty(type)) {
Field leafName = parentClass.getDeclaredField(setterInParent);
- Method setterMethod = parentClass.getDeclaredMethod(setterInParent,
- leafName.getType());
-
- setDataFromStringValue(dataType,
- ((LeafNode) leafNode).value(),
+ Method setterMethod = parentClass.getDeclaredMethod(
+ setterInParent, leafName.getType());
+ setDataFromStringValue(dataType, ((LeafNode) leafNode).value(),
setterMethod, parentObj, referredSchema,
curWb.schemaNode());
}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
index 6dfdfd5..9fe5691 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
@@ -17,12 +17,12 @@
package org.onosproject.yang.runtime.impl;
import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
-import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
import org.onosproject.yang.compiler.datamodel.YangIdentity;
import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
+import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
import org.onosproject.yang.compiler.datamodel.YangList;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
@@ -51,7 +51,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
@@ -80,8 +79,8 @@
*/
final class YobUtils {
- private static final Logger log = LoggerFactory.getLogger(YobUtils.class);
public static final String FORWARD_SLASH = "/";
+ private static final Logger log = LoggerFactory.getLogger(YobUtils.class);
private static final String ENUM_LEAF_IDENTIFIER = "$LeafIdentifier";
// no instantiation
@@ -120,23 +119,23 @@
case INT64:
case UINT64:
case BOOLEAN:
- case EMPTY:
case STRING:
+ case DECIMAL64:
+ case INSTANCE_IDENTIFIER:
parentSetter.invoke(parentObj, value);
break;
+
case BINARY:
parentSetter.invoke(parentObj, ((String) value).getBytes());
break;
+
case BITS:
parseBitSetTypeInfo(parentSetter, parentObj, value,
schemaNode, parentSchema);
break;
- case DECIMAL64:
- parentSetter.invoke(parentObj, new BigDecimal(value.toString()));
- break;
case DERIVED:
- parseDerivedTypeInfo(parentSetter, parentObj, value.toString(),
+ parseDerivedTypeInfo(parentSetter, parentObj, value,
false, schemaNode);
break;
@@ -146,13 +145,13 @@
break;
case UNION:
- parseDerivedTypeInfo(parentSetter, parentObj, value.toString(),
+ parseDerivedTypeInfo(parentSetter, parentObj, value,
false, schemaNode);
break;
case LEAFREF:
parseLeafRefTypeInfo(parentSetter, parentObj, value,
- schemaNode, parentSchema);
+ schemaNode);
break;
case ENUMERATION:
@@ -160,6 +159,12 @@
true, schemaNode);
break;
+ case EMPTY:
+ if (value == null) {
+ parentSetter.invoke(parentObj, true);
+ }
+ break;
+
default:
log.error(E_DATA_TYPE_NOT_SUPPORT);
}
@@ -180,11 +185,17 @@
*/
static void parseDerivedTypeInfo(Method parentSetter,
Object parentObj,
- String value,
+ Object value,
boolean isEnum,
YangSchemaNode leaf)
throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
+ String val;
+ if (value == null) {
+ val = "true";
+ } else {
+ val = value.toString();
+ }
Class<?> childSetClass = null;
Constructor<?> childConstructor = null;
Object childValue = null;
@@ -196,6 +207,7 @@
String qualifiedClassName = leaf.getJavaPackage() + PERIOD +
getCapitalCase(leaf.getJavaClassNameOrBuiltInType());
+
ClassLoader classLoader = parentObj.getClass().getClassLoader();
try {
childSetClass = classLoader.loadClass(qualifiedClassName);
@@ -229,7 +241,7 @@
}
}
if (childMethod != null) {
- childValue = childMethod.invoke(childObject, value);
+ childValue = childMethod.invoke(childObject, val);
}
parentSetter.invoke(parentObj, childValue);
}
@@ -263,9 +275,11 @@
leaf = leaf.getReferredSchema();
}
+ String pName = parentSchema.getJavaClassNameOrBuiltInType()
+ .toLowerCase() + PERIOD;
+
String qualifiedClassName = parentSchema.getJavaPackage() + PERIOD +
- parentSchema.getJavaAttributeName().toLowerCase() +
- PERIOD + getCapitalCase(leaf.getJavaAttributeName());
+ pName + getCapitalCase(leaf.getJavaAttributeName());
ClassLoader classLoader = parentObject.getClass().getClassLoader();
@@ -289,21 +303,18 @@
/**
* To set data into parent setter method from string value for leafref type.
*
- * @param parentSetterMethod the parent setter method to be invoked
- * @param parentObject the parent build object on which to invoke
- * the method
- * @param leafValue leaf value to be set
- * @param schemaNode schema information
- * @param parentSchema schema information of parent
+ * @param parentSetter the parent setter method to be invoked
+ * @param parentObject the parent build object on which to invoke
+ * the method
+ * @param leafValue leaf value to be set
+ * @param schemaNode schema information
* @throws InvocationTargetException if method could not be invoked
* @throws IllegalAccessException if method could not be accessed
* @throws NoSuchMethodException if method does not exist
*/
- static void parseLeafRefTypeInfo(Method parentSetterMethod,
- Object parentObject,
+ static void parseLeafRefTypeInfo(Method parentSetter, Object parentObject,
Object leafValue,
- YangSchemaNode schemaNode,
- YangSchemaNode parentSchema)
+ YangSchemaNode schemaNode)
throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
while (schemaNode.getReferredSchema() != null) {
@@ -320,25 +331,16 @@
}
YangType type = leafRef.getEffectiveDataType();
- if (type.getDataType() == YangDataTypes.DERIVED &&
- schemaNode.getJavaPackage().equals(YobConstants.JAVA_LANG)) {
- /*
- * If leaf is inside grouping, then its return type will be of type
- * Object and if its actual type is derived type then get the
- * effective built-in type and set the value.
- */
- YangDerivedInfo derivedInfo = (YangDerivedInfo) leafRef
- .getEffectiveDataType()
- .getDataTypeExtendedInfo();
- YobUtils.setDataFromStringValue(derivedInfo.getEffectiveBuiltInType(),
- leafValue, parentSetterMethod,
- parentObject, schemaNode, parentSchema);
+ Object refLeaf = leafRef.getReferredLeafOrLeafList();
+ YangLeavesHolder parent;
+ if (refLeaf instanceof YangLeaf) {
+ parent = ((YangLeaf) refLeaf).getContainedIn();
} else {
- YobUtils.setDataFromStringValue(type.getDataType(),
- leafValue, parentSetterMethod,
- parentObject,
- schemaNode, parentSchema);
+ parent = ((YangLeafList) refLeaf).getContainedIn();
}
+ setDataFromStringValue(type.getDataType(), leafValue, parentSetter,
+ parentObject, (YangSchemaNode) refLeaf,
+ (YangSchemaNode) parent);
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java
index a6a05ec..171ca85 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java
@@ -18,24 +18,6 @@
import org.junit.Test;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.ChoiceContainer;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.DefaultChoiceContainer;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.DefaultPredict;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.Predict;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.DefaultReproduce;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.Reproduce;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.currentvalue.DefaultYtbAbsent;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.DefaultCont1;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.DefaultCont2;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.DefaultAugmentedCont2;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.Cont1s;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.DefaultCont1s;
-import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.DefaultYtbFood;
-import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.ytbfood.ytbsnack.DefaultYtbLateNight;
-import org.onosproject.yang.gen.v1.modulelistandkey.rev20160826.modulelistandkey.DefaultModKey;
-import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.DefaultAugmentedSchModKey;
-import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.AugListModKey;
-import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.DefaultAugListModKey;
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.BinaryTypedef;
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.DefaultFirstLevel;
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.UnionTypedef;
@@ -57,6 +39,24 @@
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.group1.DefaultGroupContainer;
import org.onosproject.yang.gen.v1.modeldatatoresourcedatainterfile.rev20160826.modeldatatoresourcedatainterfile.firstlevel.containerchoice.choicecase.augmentedschchoicecase.DefaultLeafInterAug;
import org.onosproject.yang.gen.v1.modeldatatoresourcedatainterfile.rev20160826.modeldatatoresourcedatainterfile.firstlevel.containerchoice.choicecase.leafcase.DefaultAugmentedSchLeafCase;
+import org.onosproject.yang.gen.v1.modulelistandkey.rev20160826.modulelistandkey.DefaultModKey;
+import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.DefaultAugmentedSchModKey;
+import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.AugListModKey;
+import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.DefaultAugListModKey;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.ChoiceContainer;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.DefaultChoiceContainer;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.DefaultPredict;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.Predict;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.DefaultReproduce;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.Reproduce;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.currentvalue.DefaultYtbAbsent;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.DefaultCont1;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.DefaultCont2;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.DefaultAugmentedCont2;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.Cont1s;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.DefaultCont1s;
+import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.DefaultYtbFood;
+import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.ytbfood.ytbsnack.DefaultYtbLateNight;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultModelObjectData;
import org.onosproject.yang.model.InnerNode;
@@ -91,6 +91,8 @@
private static final String CHOC = "choc";
private static final String VAL = "val";
private static final String IND = "ind";
+ private final TestYangSchemaNodeProvider schemaProvider = new
+ TestYangSchemaNodeProvider();
private ResourceData rscData;
private DefaultDataTreeBuilder treeBuilder;
private ResourceId id;
@@ -101,8 +103,6 @@
private DataNode node;
private ModelObjectId mid;
private DefaultModelObjectData.Builder data;
- private final TestYangSchemaNodeProvider schemaProvider = new
- TestYangSchemaNodeProvider();
/**
* Do the prior setup for each UT.
@@ -1191,7 +1191,7 @@
c1.leaf3(120);
DefaultAugmentedLeafCase aug1 = new DefaultAugmentedLeafCase();
- aug1.leafAug(BinaryTypedef.fromString("1011"));
+ aug1.leafAug(BinaryTypedef.fromString("MTAxMQ=="));
c1.addAugmentation(aug1);
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 a016fda..3951a26 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
@@ -29,6 +29,18 @@
import org.onosproject.yang.gen.v1.yrtietfte.rev20170310.yrtietfte.tunnelsgrouping.DefaultTunnels;
import org.onosproject.yang.gen.v1.yrtietfte.rev20170310.yrtietfte.tunnelsgrouping.tunnels.DefaultTunnel;
import org.onosproject.yang.gen.v1.yrtietftetypes.rev20160320.yrtietftetypes.TunnelP2p;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Cont1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def3;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.DefaultCont1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Physical;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Virtual;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.Cont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.DefaultCont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.cont2.AugmentedCont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.cont2.DefaultAugmentedCont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def1.Def1Union;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.YtbIetfSchedule;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum1Enum;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum2Enum;
@@ -46,12 +58,15 @@
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.DefaultApplicationAreas;
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.TypesEnum;
import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.DefaultModelObjectData.Builder;
+import org.onosproject.yang.model.InnerModelObject;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafIdentifier;
import org.onosproject.yang.model.LeafListKey;
import org.onosproject.yang.model.LeafModelObject;
import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.ModelObject;
import org.onosproject.yang.model.ModelObjectId;
import org.onosproject.yang.model.NodeKey;
import org.onosproject.yang.model.ResourceData;
@@ -64,6 +79,8 @@
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.Base64;
+import java.util.BitSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -73,6 +90,31 @@
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.Cont.LeafIdentifier.LFENUM1;
import static org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.tpdfun0.Tpdfun0Enum.SUCCESSFUL_EXIT;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF1;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF10;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF11;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF12;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF2;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF3;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF4;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF5;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF6;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF7;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF8;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF9;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL1;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL10;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL11;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL12;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL2;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL3;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL4;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL5;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL6;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL7;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL8;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL9;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def1.def1union.Def1UnionEnum1.of;
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;
@@ -111,7 +153,7 @@
private List<DataNode> dataNodes;
private DataNode node;
private ModelObjectId mid;
- private DefaultModelObjectData.Builder data;
+ private Builder data;
/**
* Do the prior setup for each UT.
@@ -140,7 +182,7 @@
objects.add(9);
modelObject.values(objects);
// Builds YANG tree in YTB.
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(modelObject);
rscData = treeBuilder.getResourceData(data.build());
@@ -183,7 +225,7 @@
modelObject.values(objects);
//Builds YANG tree in YTB.
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(modelObject);
rscData = treeBuilder.getResourceData(data.build());
@@ -226,7 +268,7 @@
DefaultModKey m1 = new DefaultModKey();
m1.types(1);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(m1);
rscData = treeBuilder.getResourceData(data.build());
@@ -280,7 +322,7 @@
DefaultModKey m3 = new DefaultModKey();
m3.types(3);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(m1).addModelObject(m2).addModelObject(m3);
rscData = treeBuilder.getResourceData(data.build());
@@ -358,7 +400,7 @@
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
LeafModelObject object = new LeafModelObject();
object.leafIdentifier(ModKey.LeafIdentifier.TYPES);
@@ -447,8 +489,7 @@
setUp();
- data = new DefaultModelObjectData
- .Builder();
+ data = new Builder();
ModKeyKeys keyKeys = new ModKeyKeys();
keyKeys.types(10);
mid = ModelObjectId.builder()
@@ -502,7 +543,7 @@
public void processWithTypeEnum() {
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
//As an application, creates the object.
LeafModelObject object = new LeafModelObject();
object.leafIdentifier(YtbIetfSchedule.LeafIdentifier.TIME);
@@ -582,7 +623,7 @@
sched.predict(dec);
// Builds YANG tree in YTB.
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(sched);
rscData = treeBuilder.getResourceData(data.build());
@@ -625,7 +666,7 @@
public void processModuleWithContainerModId() {
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
//As an application, creates the object.
LeafModelObject object = new LeafModelObject();
object.leafIdentifier(DefaultSched.LeafIdentifier.PREDICT);
@@ -671,14 +712,14 @@
setUp();
// Creates two binary leaf -lists for two list app areas.
List<byte[]> destArea1 = new ArrayList<>();
- byte[] arr = new byte[]{1, 6, 3};
- byte[] arr1 = new byte[]{2, 7, 4};
+ byte[] arr = Base64.getDecoder().decode("QXdnRQ==");
+ byte[] arr1 = Base64.getDecoder().decode("QlFZQg==");
destArea1.add(arr);
destArea1.add(arr1);
List<byte[]> destArea2 = new ArrayList<>();
- byte[] arr2 = new byte[]{3, 8, 4};
- byte[] arr3 = new byte[]{5, 6, 1};
+ byte[] arr2 = Base64.getDecoder().decode("QndjSA==");
+ byte[] arr3 = Base64.getDecoder().decode("QUFFPQ==");
destArea2.add(arr2);
destArea2.add(arr3);
@@ -699,14 +740,14 @@
//Creates two binary leaf -lists for two list app areas.
List<byte[]> destArea3 = new ArrayList<>();
- byte[] arrB = new byte[]{0, 0, 1};
- byte[] arr1B = new byte[]{1, 0, 0};
+ byte[] arrB = Base64.getDecoder().decode("QUtqaA==");
+ byte[] arr1B = Base64.getDecoder().decode("TkJGag==");
destArea3.add(arrB);
destArea3.add(arr1B);
List<byte[]> destArea4 = new ArrayList<>();
- byte[] arr2B = new byte[]{7, 7, 7};
- byte[] arr3B = new byte[]{0, 1};
+ byte[] arr2B = Base64.getDecoder().decode("SkhJOA==");
+ byte[] arr3B = Base64.getDecoder().decode("MTExMQ==");
destArea4.add(arr2B);
destArea4.add(arr3B);
@@ -733,7 +774,7 @@
DefaultCarrier carrier = new DefaultCarrier();
carrier.multiplexes(multiplexList);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(carrier);
rscData = treeBuilder.getResourceData(data.build());
nameSpace = "yms:test:ytb:tree:builder:for:list:having:list";
@@ -793,7 +834,7 @@
assertThat(true, is(key instanceof LeafListKey));
LeafListKey leafListKey = (LeafListKey) key;
- assertThat("AwgE", is(leafListKey.value()));
+ assertThat("BwcH", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -804,7 +845,7 @@
assertThat(true, is(key instanceof LeafListKey));
leafListKey = (LeafListKey) key;
- assertThat("BQYB", is(leafListKey.value()));
+ assertThat("AAE=", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -846,7 +887,7 @@
assertThat(true, is(key instanceof LeafListKey));
leafListKey = (LeafListKey) key;
- assertThat("BwcH", is(leafListKey.value()));
+ assertThat("JHI8", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -857,7 +898,7 @@
assertThat(true, is(key instanceof LeafListKey));
leafListKey = (LeafListKey) key;
- assertThat("AAE=", is(leafListKey.value()));
+ assertThat("1111", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -876,7 +917,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithNotification();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestNotification.class).build();
data.identifier(mid);
@@ -913,7 +954,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithNotification();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestNotification.class).build();
data.identifier(mid);
@@ -957,7 +998,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithRpc();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestInput.class).build();
data.identifier(mid);
@@ -1000,7 +1041,7 @@
DefaultTestInput input = new DefaultTestInput();
input.testContainer(new DefaultTestContainer());
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(input);
registry = ut.reg;
@@ -1040,7 +1081,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithRpc();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(new DefaultTestOutput());
registry = ut.reg;
@@ -1080,7 +1121,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithRpc();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestInput.class).build();
data.identifier(mid);
@@ -1124,7 +1165,7 @@
@Test
public void processEnumeration() {
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
ModelObjectId.Builder moIdBdlr = ModelObjectId.builder()
.addChild(DefaultCont.class);
LeafModelObject mo = new LeafModelObject();
@@ -1171,7 +1212,7 @@
DefaultTe te = new DefaultTe();
te.tunnels(tunnels);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(te);
DefaultDataTreeBuilder builder = new DefaultDataTreeBuilder(registry);
rscData = builder.getResourceData(data.build());
@@ -1203,7 +1244,7 @@
con.conIn(typedef);
input.in(con);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(input);
rscData = treeBuilder.getResourceData(data.build());
@@ -1232,7 +1273,7 @@
first.call(ll);
output.outCh(first);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(output);
rscData = treeBuilder.getResourceData(data.build());
@@ -1252,4 +1293,394 @@
node = inDn.get(0);
validateDataNode(node, "output", ns, SINGLE_INSTANCE_NODE, true, null);
}
+
+ /**
+ * Unit test for proper conversion of data types to data node.
+ */
+ @Test
+ public void processDataTypesToDataNode() {
+ setUp();
+ data = new Builder();
+ data = buildRootLeafAndLeafList(data);
+ data = buildContainer(data);
+ rscData = treeBuilder.getResourceData(data.build());
+
+ List<DataNode> inDn = rscData.dataNodes();
+ String ns = "yms:test:ytb:data:types";
+ Iterator<DataNode> it = inDn.iterator();
+
+ it = validate(it, ns);
+
+ DataNode cont1 = it.next();
+ validateDataNode(cont1, "cont1", ns, SINGLE_INSTANCE_NODE, true, null);
+
+ Map<NodeKey, DataNode> c1 = ((InnerNode) cont1).childNodes();
+ List<DataNode> cont1DN = new LinkedList<>();
+ for (Map.Entry<NodeKey, DataNode> c : c1.entrySet()) {
+ cont1DN.add(c.getValue());
+ }
+ Iterator<DataNode> it1 = cont1DN.iterator();
+ it1 = validate(it1, ns);
+
+ DataNode cont2 = it1.next();
+ validateDataNode(cont2, "cont2", ns, SINGLE_INSTANCE_NODE, true, null);
+
+ Map<NodeKey, DataNode> c2 = ((InnerNode) cont2).childNodes();
+ List<DataNode> cont2DN = new LinkedList<>();
+ for (Map.Entry<NodeKey, DataNode> c : c2.entrySet()) {
+ cont2DN.add(c.getValue());
+ }
+ Iterator<DataNode> it2 = cont2DN.iterator();
+ validate(it2, ns);
+ }
+
+ /**
+ * Validates the leaf and leaf-list value under the specified node.
+ *
+ * @param it data node iterator
+ * @param ns name space
+ * @return data node iterator
+ */
+ private Iterator<DataNode> validate(Iterator<DataNode> it, String ns) {
+
+ validateDataNode(it.next(), "leaf1", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "leaf1");
+ validateDataNode(it.next(), "leaf2", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "leaf3", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "leaf4", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "leaf5", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+ validateDataNode(it.next(), "leaf6", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "/cont1");
+ validateDataNode(it.next(), "leaf7", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "leaf8", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "leaf9", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "leaf11", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "leaf12", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "ll1", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "leaf-list1");
+ validateDataNode(it.next(), "ll1", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "leaf-list1-2");
+ validateDataNode(it.next(), "ll2", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "ll2", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "ten");
+ validateDataNode(it.next(), "ll3", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "ll3", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "110111");
+ validateDataNode(it.next(), "ll4", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "ll4", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "ten");
+ validateDataNode(it.next(), "ll5", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+ validateDataNode(it.next(), "ll5", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "virtual");
+ validateDataNode(it.next(), "ll6", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "/cont1");
+ validateDataNode(it.next(), "ll6", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "/cont1/cont2");
+ validateDataNode(it.next(), "ll7", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "ll7", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2 b3");
+ validateDataNode(it.next(), "ll8", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "ll9", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "ll9", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2 b3");
+ validateDataNode(it.next(), "ll11", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "ll12", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "ll12", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "110111");
+ return it;
+ }
+
+ /**
+ * Builds the container node with required value and returns the model
+ * object data.
+ *
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder buildContainer(Builder data) {
+ Cont2 cont2 = buildAugmentForCont2();
+ Def1Union union = new Def1Union(of(1000));
+ Def1 def1 = new Def1(union);
+ Def1Union union2 = new Def1Union(of(10));
+ Def1 def12 = new Def1(union2);
+ byte[] arr = Base64.getDecoder().decode("MTEwMTE=");
+ byte[] arr1 = Base64.getDecoder().decode("MTEwMTEx");
+ BitSet bits = new BitSet();
+ bits.set(0, 2, true);
+ BitSet bits1 = new BitSet();
+ bits1.set(0, 3, true);
+ Def2 def2 = new Def2(bits);
+ Def2 def21 = new Def2(bits1);
+ Def3 def3 = new Def3(false);
+ Def3 def31 = new Def3(true);
+ Cont1 cont1 = new DefaultCont1();
+ cont1.leaf1("leaf1");
+ cont1.leaf2(def1);
+ cont1.leaf3(arr);
+ cont1.leaf4(def1);
+ cont1.leaf5(Physical.class);
+ cont1.leaf6("/cont1");
+ cont1.leaf7(bits);
+ cont1.leaf8(true);
+ cont1.leaf9(def2);
+ cont1.leaf10(def3);
+ cont1.leaf11(true);
+ cont1.leaf12(arr);
+ cont1.addToLl1("leaf-list1");
+ cont1.addToLl1("leaf-list1-2");
+ cont1.addToLl2(def1);
+ cont1.addToLl2(def12);
+ cont1.addToLl3(arr);
+ cont1.addToLl3(arr1);
+ cont1.addToLl4(def1);
+ cont1.addToLl4(def12);
+ cont1.addToLl5(Physical.class);
+ cont1.addToLl5(Virtual.class);
+ cont1.addToLl6("/cont1");
+ cont1.addToLl6("/cont1/cont2");
+ cont1.addToLl7(bits);
+ cont1.addToLl7(bits1);
+ cont1.addToLl8(true);
+ cont1.addToLl8(false);
+ cont1.addToLl9(def2);
+ cont1.addToLl9(def21);
+ cont1.addToLl10(def3);
+ cont1.addToLl10(def31);
+ cont1.addToLl11(true);
+ cont1.addToLl11(true);
+ cont1.addToLl12(arr);
+ cont1.addToLl12(arr1);
+ cont1.cont2(cont2);
+ data.addModelObject((ModelObject) cont1);
+ return data;
+ }
+
+ /**
+ * Builds the augment node with required value and updates it in the
+ * container cont2.
+ *
+ * @return cont2
+ */
+ private Cont2 buildAugmentForCont2() {
+ Cont2 cont2 = new DefaultCont2();
+ AugmentedCont2 augC = new DefaultAugmentedCont2();
+ Def1Union union = new Def1Union(of(1000));
+ Def1 def1 = new Def1(union);
+ Def1Union union2 = new Def1Union(of(10));
+ Def1 def12 = new Def1(union2);
+ byte[] arr = Base64.getDecoder().decode("MTEwMTE=");
+ byte[] arr1 = Base64.getDecoder().decode("MTEwMTEx");
+ BitSet bits = new BitSet();
+ bits.set(0, 2, true);
+ BitSet bits1 = new BitSet();
+ bits1.set(0, 3, true);
+ Def2 def2 = new Def2(bits);
+ Def2 def21 = new Def2(bits1);
+ Def3 def3 = new Def3(false);
+ Def3 def31 = new Def3(true);
+ augC.leaf1("leaf1");
+ augC.leaf2(def1);
+ augC.leaf3(arr);
+ augC.leaf4(def1);
+ augC.leaf5(Physical.class);
+ augC.leaf6("/cont1");
+ augC.leaf7(bits);
+ augC.leaf8(true);
+ augC.leaf9(def2);
+ augC.leaf10(def3);
+ augC.leaf11(true);
+ augC.leaf12(arr);
+ augC.addToLl1("leaf-list1");
+ augC.addToLl1("leaf-list1-2");
+ augC.addToLl2(def1);
+ augC.addToLl2(def12);
+ augC.addToLl3(arr);
+ augC.addToLl3(arr1);
+ augC.addToLl4(def1);
+ augC.addToLl4(def12);
+ augC.addToLl5(Physical.class);
+ augC.addToLl5(Virtual.class);
+ augC.addToLl6("/cont1");
+ augC.addToLl6("/cont1/cont2");
+ augC.addToLl7(bits);
+ augC.addToLl7(bits1);
+ augC.addToLl8(true);
+ augC.addToLl8(false);
+ augC.addToLl9(def2);
+ augC.addToLl9(def21);
+ augC.addToLl10(def3);
+ augC.addToLl10(def31);
+ augC.addToLl11(true);
+ augC.addToLl11(true);
+ augC.addToLl12(arr);
+ augC.addToLl12(arr1);
+ cont2.addAugmentation((InnerModelObject) augC);
+ return cont2;
+ }
+
+ /**
+ * Builds the root leaf and leaf-list and adds it in the model object
+ * data builder.
+ *
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder buildRootLeafAndLeafList(Builder data) {
+
+ data = addLeafModelObject(LEAF1, "leaf1", data);
+
+ Def1Union union = new Def1Union(of("thousand"));
+ Def1 def1 = new Def1(union);
+ data = addLeafModelObject(LEAF2, def1, data);
+
+ byte[] arr = Base64.getDecoder().decode("MTEwMTE=");
+ data = addLeafModelObject(LEAF3, arr, data);
+
+ data = addLeafModelObject(LEAF4, def1, data);
+
+ data = addLeafModelObject(LEAF5, Physical.class, data);
+
+ data = addLeafModelObject(LEAF6, "/cont1", data);
+
+ BitSet bits = new BitSet();
+ bits.set(0, 2, true);
+ data = addLeafModelObject(LEAF7, bits, data);
+
+ data = addLeafModelObject(LEAF8, true, data);
+
+ Def2 def2 = new Def2(bits);
+ data = addLeafModelObject(LEAF9, def2, data);
+
+ Def3 def3 = new Def3(false);
+ data = addLeafModelObject(LEAF10, def3, data);
+
+ data = addLeafModelObject(LEAF11, true, data);
+
+ data = addLeafModelObject(LEAF12, arr, data);
+
+ List<Object> objs = new LinkedList<>();
+ objs.add("leaf-list1");
+ objs.add("leaf-list1-2");
+ data = addLeafListModelObject(LL1, objs, data);
+
+ Def1Union union2 = new Def1Union(of("ten"));
+ Def1 def12 = new Def1(union2);
+ objs = new LinkedList<>();
+ objs.add(def1);
+ objs.add(def12);
+ data = addLeafListModelObject(LL2, objs, data);
+
+ byte[] arr1 = Base64.getDecoder().decode("MTEwMTEx");
+ objs = new LinkedList<>();
+ objs.add(arr);
+ objs.add(arr1);
+ data = addLeafListModelObject(LL3, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(def1);
+ objs.add(def12);
+ data = addLeafListModelObject(LL4, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(Physical.class);
+ objs.add(Virtual.class);
+ data = addLeafListModelObject(LL5, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add("/cont1");
+ objs.add("/cont1/cont2");
+ data = addLeafListModelObject(LL6, objs, data);
+
+ BitSet bits2 = new BitSet();
+ bits2.set(0, 3, true);
+ objs = new LinkedList<>();
+ objs.add(bits);
+ objs.add(bits2);
+ data = addLeafListModelObject(LL7, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(true);
+ objs.add(false);
+ data = addLeafListModelObject(LL8, objs, data);
+
+ Def2 def21 = new Def2(bits2);
+ objs = new LinkedList<>();
+ objs.add(def2);
+ objs.add(def21);
+ data = addLeafListModelObject(LL9, objs, data);
+
+ Def3 def31 = new Def3(true);
+ objs = new LinkedList<>();
+ objs.add(def3);
+ objs.add(def31);
+ data = addLeafListModelObject(LL10, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(true);
+ objs.add(true);
+ data = addLeafListModelObject(LL11, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(arr);
+ objs.add(arr1);
+ data = addLeafListModelObject(LL12, objs, data);
+
+ return data;
+ }
+
+ /**
+ * Adds the leaf model object to the model object data builder with leaf
+ * value.
+ *
+ * @param lId leaf identifier
+ * @param object leaf object
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder addLeafModelObject(LeafIdentifier lId, Object object,
+ Builder data) {
+ LeafModelObject obj = new LeafModelObject();
+ obj.leafIdentifier(lId);
+ obj.addValue(object);
+ data.addModelObject(obj);
+ return data;
+ }
+
+ /**
+ * Adds the leaf-list model objects to the model object data builder with
+ * leaf-list values.
+ *
+ * @param lId leaf-list identifier
+ * @param object leaf-list object
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder addLeafListModelObject(LeafIdentifier lId,
+ List<Object> object, Builder data) {
+ LeafModelObject obj = new LeafModelObject();
+ obj.leafIdentifier(lId);
+ for (Object o : object) {
+ obj.addValue(o);
+ }
+ data.addModelObject(obj);
+ return data;
+ }
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAugmentTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAugmentTest.java
index 4c5ed88..ab29e12 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAugmentTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAugmentTest.java
@@ -17,24 +17,24 @@
package org.onosproject.yang.runtime.impl;
import org.junit.Test;
-
import org.onosproject.yang.gen.v1.ymsiptopology.rev20140101.ymsiptopology.node.DefaultAugmentedTopoNode;
import org.onosproject.yang.gen.v1.ymstopology.rev20140101.ymstopology.DefaultNode;
import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.DefaultNetworks;
import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.DefaultNetwork;
import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.Network;
+import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.TeTemplateName;
import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.networks.network.link.DefaultAugmentedNtLink;
import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.telinkaugment.te.Config;
import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.telinkconfig.bundlestacklevel.Bundle;
import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.telinkconfig.bundlestacklevel.bundle.bundledlinks.BundledLink;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.TpId;
import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.DefaultAugmentedNdNetwork;
-import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.DefaultLink;
import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.Link;
import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DefaultResourceData;
import org.onosproject.yang.model.ModelObject;
import org.onosproject.yang.model.ModelObjectData;
import org.onosproject.yang.model.ResourceData;
-import org.onosproject.yang.model.DefaultResourceData;
import java.util.List;
@@ -210,17 +210,19 @@
DefaultNetworks networks = ((DefaultNetworks) modelObject);
Network network = networks.network().get(0);
assertThat(network.networkId().toString(), is("network-id"));
- DefaultAugmentedNdNetwork augNw = ((DefaultNetwork) network)
- .augmentation(DefaultAugmentedNdNetwork.class);
+ DefaultAugmentedNdNetwork augNw = network.augmentation(
+ DefaultAugmentedNdNetwork.class);
Link link = augNw.link().get(0);
assertThat(link.linkId().toString(), is("link-id"));
- DefaultAugmentedNtLink augLink = ((DefaultLink) link)
- .augmentation(DefaultAugmentedNtLink.class);
+ DefaultAugmentedNtLink augLink = link.augmentation(
+ DefaultAugmentedNtLink.class);
Config config = augLink.te().config();
- assertThat(config.teLinkTemplate().get(0), is("abc"));
+ TeTemplateName tName = (TeTemplateName) config.teLinkTemplate().get(0);
+ assertThat(tName.string(), is("abc"));
BundledLink bundledLink = ((Bundle) config.bundleStackLevel())
.bundledLinks().bundledLink().get(0);
- assertThat(bundledLink.srcTpRef(), is("101"));
+ TpId id = (TpId) bundledLink.srcTpRef();
+ assertThat(id.uri().string(), is("101"));
assertThat(bundledLink.sequence(), is(100L));
}
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobL3VpnSvcTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobL3VpnSvcTest.java
index 478855c..191b40e 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobL3VpnSvcTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobL3VpnSvcTest.java
@@ -17,8 +17,8 @@
package org.onosproject.yang.runtime.impl;
import org.junit.Test;
-
import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.DefaultL3VpnSvc;
+import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.SvcId;
import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.accessvpnpolicy.vpnattachment.attachmentflavor.VpnId;
import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.l3vpnsvc.DefaultSites;
import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.l3vpnsvc.DefaultVpnServices;
@@ -304,8 +304,9 @@
assertThat(ipConnection.ipv6().addresses().mask(), is(mask));
assertThat(sna.routingProtocols().routingProtocol().get(0).type()
.getSimpleName(), is("Ospf"));
- assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).vpnId(),
- is("10"));
+ SvcId sId = (SvcId) ((VpnId) sna.vpnAttachment().attachmentFlavor())
+ .vpnId();
+ assertThat(sId.string(), is("10"));
assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).siteRole()
.getSimpleName(), is("HubRole"));
}
@@ -410,8 +411,9 @@
assertThat(ipConnection.ipv6().addresses().mask(), is(mask));
assertThat(sna.routingProtocols().routingProtocol().get(0).type()
.getSimpleName(), is("Ospf"));
- assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).vpnId(),
- is("10"));
+ SvcId sId = (SvcId) ((VpnId) sna.vpnAttachment().attachmentFlavor())
+ .vpnId();
+ assertThat(sId.string(), is("10"));
assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).siteRole()
.getSimpleName(), is("HubRole"));
DefaultSite site2 = ((DefaultSite) modelObjectList.get(1));
@@ -432,8 +434,9 @@
assertThat(ipConnection.ipv6().addresses().mask(), is(mask));
assertThat(sna.routingProtocols().routingProtocol().get(0).type()
.getSimpleName(), is("Ospf"));
- assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).vpnId(),
- is("10"));
+ sId = (SvcId) ((VpnId) sna.vpnAttachment().attachmentFlavor())
+ .vpnId();
+ assertThat(sId.string(), is("10"));
assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).siteRole()
.getSimpleName(), is("HubRole"));
}
@@ -513,8 +516,9 @@
assertThat(ipConnection.ipv6().addresses().mask(), is(mask));
assertThat(sna1.routingProtocols().routingProtocol().get(0).type()
.getSimpleName(), is("Ospf"));
- assertThat(((VpnId) sna1.vpnAttachment().attachmentFlavor()).vpnId(),
- is("10"));
+ SvcId sId = (SvcId) ((VpnId) sna1.vpnAttachment().attachmentFlavor())
+ .vpnId();
+ assertThat(sId.string(), is("10"));
assertThat(((VpnId) sna1.vpnAttachment().attachmentFlavor()).siteRole()
.getSimpleName(), is("HubRole"));
@@ -525,8 +529,8 @@
bearerAttach = bearer.augmentation(DefaultAugmentedL3VpnBearer.class);
assertThat(bearerAttach.bearerAttachment().peMgmtIp().string(), is("192.1.1.1"));
assertThat(bearerAttach.bearerAttachment().peName(), is("pe-name"));
- reqType = ((DefaultRequestedType) bearer.requestedType())
- .augmentation(DefaultAugmentedL3VpnRequestedType.class);
+ reqType = bearer.requestedType().augmentation(
+ DefaultAugmentedL3VpnRequestedType.class);
py = ((PhysicalCase) reqType.requestedTypeProfile()
.requestedTypeChoice()).physical();
assertThat(py.physicalIf(), is("eth0/0/0"));
@@ -542,8 +546,9 @@
assertThat(ipConnection.ipv6().addresses().mask(), is(mask));
assertThat(sna2.routingProtocols().routingProtocol().get(0).type()
.getSimpleName(), is("Ospf"));
- assertThat(((VpnId) sna2.vpnAttachment().attachmentFlavor()).vpnId(),
- is("10"));
+ sId = (SvcId) ((VpnId) sna2.vpnAttachment().attachmentFlavor())
+ .vpnId();
+ assertThat(sId.string(), is("10"));
assertThat(((VpnId) sna2.vpnAttachment().attachmentFlavor()).siteRole()
.getSimpleName(), is("HubRole"));
}
@@ -608,8 +613,9 @@
assertThat(ipConnection.ipv6().addresses().mask(), is(mask));
assertThat(sna.routingProtocols().routingProtocol().get(0).type()
.getSimpleName(), is("Ospf"));
- assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).vpnId(),
- is("10"));
+ SvcId sId = (SvcId) ((VpnId) sna.vpnAttachment().attachmentFlavor())
+ .vpnId();
+ assertThat(sId.string(), is("10"));
assertThat(((VpnId) sna.vpnAttachment().attachmentFlavor()).siteRole()
.getSimpleName(), is("HubRole"));
}
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 2e8c1f5..31e2c9d 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
@@ -17,20 +17,25 @@
package org.onosproject.yang.runtime.impl;
import org.junit.Test;
-import org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.DefaultCont1;
import org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.DefaultCont;
+import org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.gr.Cont3;
+import org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.DefaultCont1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Leaf7;
import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DataNode.Builder;
import org.onosproject.yang.model.DefaultResourceData;
import org.onosproject.yang.model.ModelObject;
import org.onosproject.yang.model.ModelObjectData;
import org.onosproject.yang.model.ResourceData;
+import java.util.Base64;
+import java.util.BitSet;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.cont1.Lfenum1Enum.GRACE_PERIOD_EXPIRED;
import static org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.tpdfun0.Tpdfun0Enum.SUCCESSFUL_EXIT;
+import static org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.cont1.Lfenum1Enum.GRACE_PERIOD_EXPIRED;
import static org.onosproject.yang.runtime.SerializerHelper.addDataNode;
import static org.onosproject.yang.runtime.SerializerHelper.exitDataNode;
import static org.onosproject.yang.runtime.SerializerHelper.initializeDataNode;
@@ -40,14 +45,14 @@
*/
public class YobSimpleDataTypeTest {
- TestYangSerializerContext context = new TestYangSerializerContext();
private static final String DATA_TYPE_NAME_SPACE = "simple:data:types";
private static final String DATA_TYPE_NAME_SPACE_LL =
"simple:data:types:ll";
- private DataNode.Builder dBlr;
+ TestYangSerializerContext context = new TestYangSerializerContext();
+ private Builder dBlr;
private String value;
- public DataNode buildDataNodeForSimpleDataTypes() {
+ private DataNode buildDataNodeForSimpleDataTypes() {
dBlr = initializeDataNode(context);
value = null;
dBlr = addDataNode(dBlr, "cont", DATA_TYPE_NAME_SPACE, value, null);
@@ -219,12 +224,217 @@
value = "successful exit";
dBlr = addDataNode(dBlr, "lfenum1", DATA_TYPE_NAME_SPACE, value, null);
dBlr = exitDataNode(dBlr);
+
+ value = "/cont";
+ dBlr = addDataNode(dBlr, "inst-iden", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ dBlr = getLeafRefData(dBlr);
dBlr = exitDataNode(dBlr);
return dBlr.build();
}
+ private Builder getLeafRefData(Builder dBlr) {
+ value = "8";
+ dBlr = addDataNode(dBlr, "lref1", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
- public DataNode buildDnForLeafListSimpleDataTypes() {
+ value = "val";
+ dBlr = addDataNode(dBlr, "lref2", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "zero";
+ dBlr = addDataNode(dBlr, "lref3", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "b2 b3";
+ dBlr = addDataNode(dBlr, "lref4", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "-92233720368547758.08";
+ dBlr = addDataNode(dBlr, "lref5", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "10";
+ dBlr = addDataNode(dBlr, "lref6", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "enum4";
+ dBlr = addDataNode(dBlr, "lref7", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "-9223372036854.775808";
+ dBlr = addDataNode(dBlr, "lref8", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "MTAxMDEwMTAx";
+ dBlr = addDataNode(dBlr, "lref9", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "";
+ dBlr = addDataNode(dBlr, "lref10", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "";
+ dBlr = addDataNode(dBlr, "lref11", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "b3";
+ dBlr = addDataNode(dBlr, "lref12", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "";
+ dBlr = addDataNode(dBlr, "lref13", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "b1 b2 b3";
+ dBlr = addDataNode(dBlr, "lref14", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "/cont";
+ dBlr = addDataNode(dBlr, "lref15", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "physical";
+ dBlr = addDataNode(dBlr, "lref16", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "784985";
+ dBlr = addDataNode(dBlr, "lref17", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "MTExMTExMTE=";
+ dBlr = addDataNode(dBlr, "lref18", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "hundred";
+ dBlr = addDataNode(dBlr, "lref19", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "leafref";
+ dBlr = addDataNode(dBlr, "lref20", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "val";
+ dBlr = addDataNode(dBlr, "iref1", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "pro";
+ dBlr = addDataNode(dBlr, "iref2", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "physical";
+ dBlr = addDataNode(dBlr, "iref3", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "virtual";
+ dBlr = addDataNode(dBlr, "iref4", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ dBlr = addDataNode(dBlr, "cont3", DATA_TYPE_NAME_SPACE, null, null);
+
+ value = "108";
+ dBlr = addDataNode(dBlr, "llref1", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "val";
+ dBlr = addDataNode(dBlr, "llref2", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "one";
+ dBlr = addDataNode(dBlr, "llref3", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "b1 b3";
+ dBlr = addDataNode(dBlr, "llref4", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "-922337203685470058.08";
+ dBlr = addDataNode(dBlr, "llref5", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "121";
+ dBlr = addDataNode(dBlr, "llref6", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "enum1";
+ dBlr = addDataNode(dBlr, "llref7", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "-9223372036000.775808";
+ dBlr = addDataNode(dBlr, "llref8", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "MTExMTExMTE=";
+ dBlr = addDataNode(dBlr, "llref9", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "";
+ dBlr = addDataNode(dBlr, "llref11", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "b2";
+ dBlr = addDataNode(dBlr, "llref12", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "";
+ dBlr = addDataNode(dBlr, "llref13", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "b1";
+ dBlr = addDataNode(dBlr, "llref14", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "/cont/con2";
+ dBlr = addDataNode(dBlr, "llref15", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "virtual";
+ dBlr = addDataNode(dBlr, "llref16", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "78498522";
+ dBlr = addDataNode(dBlr, "llref17", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "MDEwMTAxMDEw";
+ dBlr = addDataNode(dBlr, "llref18", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "ten";
+ dBlr = addDataNode(dBlr, "llref19", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "leaflistref";
+ dBlr = addDataNode(dBlr, "llref20", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "check";
+ dBlr = addDataNode(dBlr, "lref21", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "val";
+ dBlr = addDataNode(dBlr, "iref1", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "pro";
+ dBlr = addDataNode(dBlr, "iref2", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "physical";
+ dBlr = addDataNode(dBlr, "iref3", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "virtual";
+ dBlr = addDataNode(dBlr, "iref4", DATA_TYPE_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ dBlr = exitDataNode(dBlr);
+ return dBlr;
+ }
+
+
+ private DataNode buildDnForLeafListSimpleDataTypes() {
dBlr = initializeDataNode(context);
value = null;
dBlr = addDataNode(dBlr, "cont1", DATA_TYPE_NAME_SPACE_LL, value, null);
@@ -397,6 +607,7 @@
dBlr = addDataNode(dBlr, "lfenum1", null, value, null);
dBlr = exitDataNode(dBlr);
dBlr = exitDataNode(dBlr);
+
return dBlr.build();
}
@@ -469,6 +680,90 @@
assertThat(cont.lfunion14().toString(), is("one"));
assertThat(cont.identityref1().getSimpleName(), is("Iden"));
assertThat(cont.lfenum1().enumeration(), is(SUCCESSFUL_EXIT));
+ assertThat(cont.instIden(), is("/cont"));
+ value = 8;
+ assertThat(cont.lref1(), is(value));
+ assertThat(cont.lref2().toString(), is(
+ "class org.onosproject.yang.gen.v1.simpledatatypes" +
+ ".rev20131112.simpledatatypes.Val"));
+ assertThat(cont.lref3().toString(), is("zero"));
+ assertThat(cont.lref4().toString(), is("b2 b3 "));
+ assertThat(cont.lref5().toString(), is("-92233720368547758.08"));
+ value = 10;
+ assertThat(cont.lref6(), is(value));
+ assertThat(cont.lref7().toString(), is("enum4"));
+ assertThat(cont.lref8().toString(), is("-9223372036854.775808"));
+ byte[] arr = Base64.getDecoder().decode("MTAxMDEwMTAx");
+ assertThat(cont.lref9(), is(arr));
+ assertThat(cont.lref10(), is(true));
+ assertThat(cont.lref11().toString(), is("true"));
+ assertThat(cont.lref12().toString(), is("b3 "));
+ assertThat(cont.lref13(), is(true));
+ String bit = Leaf7.toString(cont.lref14());
+ assertThat(bit, is("b1 b2 b3 "));
+ assertThat(cont.lref15(), is("/cont"));
+ assertThat(cont.lref16().toString(), is(
+ "class org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826." +
+ "ytbdatatypes.Physical"));
+ assertThat(cont.lref17().toString(), is("784985"));
+ arr = Base64.getDecoder().decode("MTExMTExMTE=");
+ assertThat(cont.lref18(), is(arr));
+ assertThat(cont.lref19().toString(), is("hundred"));
+ assertThat(cont.lref20(), is("leafref"));
+ assertThat(cont.iref1().toString(), is(
+ "class org.onosproject.yang.gen.v1.simpledatatypes.rev201311" +
+ "12.simpledatatypes.Val"));
+ assertThat(cont.iref2().get(0).toString(), is(
+ "class org.onosproject.yang.gen.v1.simpledatatypes.rev201311" +
+ "12.simpledatatypes.Pro"));
+ assertThat(cont.iref3().toString(), is(
+ "class org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826." +
+ "ytbdatatypes.Physical"));
+ assertThat(cont.iref4().get(0).toString(), is(
+ "class org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826." +
+ "ytbdatatypes.Virtual"));
+ Cont3 cont3 = cont.cont3();
+ value = 108;
+ assertThat(cont3.llref1().get(0), is(value));
+ assertThat(cont3.llref2().get(0).toString(), is(
+ "class org.onosproject.yang.gen.v1.simpledatatypes" +
+ ".rev20131112.simpledatatypes.Val"));
+ assertThat(cont3.llref3().get(0).toString(), is("one"));
+ assertThat(cont3.llref4().get(0).toString(), is("b1 b3 "));
+ assertThat(cont3.llref5().get(0).toString(), is("-922337203685470058.08"));
+ value = 121;
+ assertThat(cont3.llref6().get(0), is(value));
+ assertThat(cont3.llref7().get(0).toString(), is("enum1"));
+ assertThat(cont3.llref8().get(0).toString(), is("-9223372036000.775808"));
+ arr = Base64.getDecoder().decode("MTExMTExMTE=");
+ assertThat(cont3.llref9().get(0), is(arr));
+ assertThat(cont3.llref11().get(0).toString(), is("true"));
+ assertThat(cont3.llref12().get(0).toString(), is("b2 "));
+ assertThat(cont3.llref13().get(0), is(true));
+ bit = Leaf7.toString((BitSet) cont3.llref14().get(0));
+ assertThat(bit, is("b1 "));
+ assertThat(cont3.llref15().get(0), is("/cont/con2"));
+ assertThat(cont3.llref16().get(0).toString(), is(
+ "class org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826." +
+ "ytbdatatypes.Virtual"));
+ assertThat(cont3.llref17().get(0).toString(), is("78498522"));
+ arr = Base64.getDecoder().decode("MDEwMTAxMDEw");
+ assertThat(cont3.llref18().get(0), is(arr));
+ assertThat(cont3.llref19().get(0).toString(), is("ten"));
+ assertThat(cont3.llref20().get(0), is("leaflistref"));
+ assertThat(cont3.lref21(), is("check"));
+ assertThat(cont3.iref1().toString(), is(
+ "class org.onosproject.yang.gen.v1.simpledatatypes.rev201311" +
+ "12.simpledatatypes.Val"));
+ assertThat(cont3.iref2().get(0).toString(), is(
+ "class org.onosproject.yang.gen.v1.simpledatatypes.rev201311" +
+ "12.simpledatatypes.Pro"));
+ assertThat(cont3.iref3().toString(), is(
+ "class org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826." +
+ "ytbdatatypes.Physical"));
+ assertThat(cont3.iref4().get(0).toString(), is(
+ "class org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826." +
+ "ytbdatatypes.Virtual"));
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
index 94d0a4b..9872c8d 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
@@ -130,14 +130,14 @@
dBlr = exitDataNode(dBlr);
//Tree validation
- nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "leaf_c1"};
- nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS};
- valA = new String[]{"1", "2", "3", "0"};
+ nA = new String[]{"/", "l1", "k1", "k2", "c1", "leaf_c1"};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
+ valA = new String[]{"1", "2", null, "0"};
validateResourceId(nA, nsA, valA, id);
- nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1"};
- nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
- valA = new String[]{"1", "2", "3"};
+ nA = new String[]{"/", "l1", "k1", "k2", "c1"};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS};
+ valA = new String[]{"1", "2", null};
validateResourceId(nA, nsA, valA, id1);
nA = new String[]{"/", "l1", "k1", "k2", "k3"};
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
index 4102e74..db25f51 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
@@ -167,14 +167,14 @@
dBlr = exitDataNode(dBlr);
//Tree validation
- nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "leaf_c1"};
- nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS};
- valA = new String[]{"1", "2", "3", "0"};
+ nA = new String[]{"/", "l1", "k1", "k2", "c1", "leaf_c1"};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
+ valA = new String[]{"1", "2", null, "0"};
validateResourceId(nA, nsA, valA, id);
- nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1"};
- nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
- valA = new String[]{"1", "2", "3"};
+ nA = new String[]{"/", "l1", "k1", "k2", "c1"};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS};
+ valA = new String[]{"1", "2", null};
validateResourceId(nA, nsA, valA, id1);
nA = new String[]{"/", "l1", "k1", "k2", "k3"};
diff --git a/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang b/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
index f6b64d2..1267a0a 100644
--- a/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
+++ b/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
@@ -1,271 +1,606 @@
module simple-data-types {
- namespace "simple:data:types";
+ namespace "simple:data:types";
- prefix "smpdtp";
- revision 2013-11-12 {
- }
+ prefix "smpdtp";
- identity iden {
- }
-
- typedef tpdfempty {
- type empty;
- }
-
- typedef tpdfbit {
- type bits {
- bit b1;
- bit b2;
- bit b3;
+ import YtbDataTypes {
+ prefix ytb;
}
- }
-
- typedef tpdfun4 {
- type boolean;
- }
-
- typedef tpdfun3 {
- type union {
- type tpdfbit;
- type tpdfempty;
- }
- }
-
- typedef tpdfun2 {
- type union {
- type tpdfun3;
- type tpdfun4;
- }
- }
-
- typedef tpdfun1 {
- type union {
- type uint8;
- type decimal64 {
- fraction-digits 2;
- }
- }
- }
-
- typedef tpdfun0 {
- type enumeration {
- enum "successful exit" {
- value 1;
- }
- enum "grace period expired" {
- value 2;
- }
- }
- }
-
- container cont {
- leaf lfnint8Min {
- type int8;
- }
- leaf lfnint8Max {
- type int8;
- }
- leaf lfnint16Min {
- type int16;
- }
- leaf lfnint16Max {
- type int16;
- }
- leaf lfnint32Min {
- type int32;
- }
- leaf lfnint32Max {
- type int32;
- }
- leaf lfnint64Min {
- type int64;
- }
- leaf lfnint64Max {
- type int64;
- }
- leaf lfnuint8Max {
- type uint8;
- }
- leaf lfnuint16Max {
- type uint16;
- }
- leaf lfnuint32Max {
- type uint32;
- }
- leaf lfuint64Max {
- type uint64;
- }
- leaf lfstr {
- type string;
- }
- leaf lfstr1 {
- type string;
- }
- leaf lfbool1 {
- type boolean;
- }
- leaf lfbool2 {
- type boolean;
- }
- leaf lfbool3 {
- type boolean;
- }
- leaf lfdecimal1 {
- type decimal64 {
- fraction-digits 1;
- }
- }
- leaf lfdecimal2 {
- type decimal64 {
- fraction-digits 2;
- }
- }
- leaf lfdecimal3 {
- type decimal64 {
- fraction-digits 3;
- }
- }
-
- leaf lfdecimal4 {
- type decimal64 {
- fraction-digits 4;
- }
- }
-
- leaf lfdecimal6 {
- type decimal64 {
- fraction-digits 6;
- }
- }
-
- leaf lfenum {
- type enumeration {
- enum enum1;
- enum enum2;
- enum enum3;
- enum enum4;
- }
+ revision 2013-11-12 {
}
- leaf lfbits {
- type bits {
- bit bit1;
- bit bit2;
- bit bit3;
- bit bit4;
- }
+ identity iden {
}
- leaf lfbinary {
- type binary;
- }
-
- leaf lfref1 { //reference to string type
- type leafref {
- path "../lfstr";
- }
+ identity val {
+ base iden;
}
- leaf lfref2 { //reference to number type
- type leafref {
- path "../lfnint8Max";
- }
+ identity pro {
+ base iden;
}
- leaf lfempty {
+ typedef tpdfempty {
type empty;
}
- leaf lfunion1 {
- type union {
- type uint16;
- type string;
+ typedef tpdfbit {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
}
}
- leaf lfunion2 {
+
+ typedef tpdfun4 {
+ type boolean;
+ }
+
+ typedef tpdfun3 {
type union {
+ type tpdfbit;
+ type tpdfempty;
+ }
+ }
+
+ typedef tpdfun2 {
+ type union {
+ type tpdfun3;
+ type tpdfun4;
+ }
+ }
+
+ typedef tpdfun1 {
+ type union {
+ type uint8;
type decimal64 {
fraction-digits 2;
}
- type string;
}
}
- leaf lfunion4 {
- type union {
- type boolean;
- type string;
- }
- }
-
- leaf lfunion5 {
- type union {
- type uint16;
- type string;
- }
- }
-
- leaf lfunion7 {
- type tpdfun3;
- }
-
- leaf lfunion8 {
- type union {
- type uint16;
- type string;
- }
- }
-
- leaf lfunion9 {
- type union {
- type uint16;
- type boolean;
- }
- }
-
- leaf lfunion10 {
- type union {
- type bits {
- bit bt1;
- bit bt2;
+ typedef tpdfun0 {
+ type enumeration {
+ enum "successful exit" {
+ value 1;
}
- type boolean;
+ enum "grace period expired" {
+ value 2;
+ }
}
}
- leaf lfunion11 {
- type union {
- type tpdfun1;
+ container cont {
+ leaf lfnint8Min {
+ type int8;
+ }
+
+ leaf lfnint8Max {
+ type int8;
+ }
+
+ leaf lfnint16Min {
+ type int16;
+ }
+
+ leaf lfnint16Max {
+ type int16;
+ }
+
+ leaf lfnint32Min {
+ type int32;
+ }
+
+ leaf lfnint32Max {
+ type int32;
+ }
+
+ leaf lfnint64Min {
+ type int64;
+ }
+
+ leaf lfnint64Max {
+ type int64;
+ }
+
+ leaf lfnuint8Max {
+ type uint8;
+ }
+
+ leaf lfnuint16Max {
+ type uint16;
+ }
+
+ leaf lfnuint32Max {
+ type uint32;
+ }
+
+ leaf lfuint64Max {
+ type uint64;
+ }
+
+ leaf lfstr {
+ type string;
+ }
+
+ leaf lfstr1 {
+ type string;
+ }
+
+ leaf lfbool1 {
+ type boolean;
+ }
+
+ leaf lfbool2 {
+ type boolean;
+ }
+
+ leaf lfbool3 {
+ type boolean;
+ }
+
+ leaf lfdecimal1 {
+ type decimal64 {
+ fraction-digits 1;
+ }
+ }
+
+ leaf lfdecimal2 {
+ type decimal64 {
+ fraction-digits 2;
+ }
+ }
+
+ leaf lfdecimal3 {
+ type decimal64 {
+ fraction-digits 3;
+ }
+ }
+
+ leaf lfdecimal4 {
+ type decimal64 {
+ fraction-digits 4;
+ }
+ }
+
+ leaf lfdecimal6 {
+ type decimal64 {
+ fraction-digits 6;
+ }
+ }
+
+ leaf lfenum {
+ type enumeration {
+ enum enum1;
+ enum enum2;
+ enum enum3;
+ enum enum4;
+ }
+ }
+
+ leaf lfbits {
+ type bits {
+ bit bit1;
+ bit bit2;
+ bit bit3;
+ bit bit4;
+ }
+ }
+
+ leaf lfbinary {
+ type binary;
+ }
+
+ leaf lfref1 { //reference to string type
+ type leafref {
+ path "../lfstr";
+ }
+ }
+
+ leaf lfref2 { //reference to number type
+ type leafref {
+ path "../lfnint8Max";
+ }
+ }
+
+ leaf lfempty {
+ type empty;
+ }
+
+ leaf lfunion1 {
+ type union {
+ type uint16;
+ type string;
+ }
+ }
+ leaf lfunion2 {
+ type union {
+ type decimal64 {
+ fraction-digits 2;
+ }
+ type string;
+ }
+ }
+
+ leaf lfunion4 {
+ type union {
+ type boolean;
+ type string;
+ }
+ }
+
+ leaf lfunion5 {
+ type union {
+ type uint16;
+ type string;
+ }
+ }
+
+ leaf lfunion7 {
+ type tpdfun3;
+ }
+
+ leaf lfunion8 {
+ type union {
+ type uint16;
+ type string;
+ }
+ }
+
+ leaf lfunion9 {
+ type union {
+ type uint16;
+ type boolean;
+ }
+ }
+
+ leaf lfunion10 {
+ type union {
+ type bits {
+ bit bt1;
+ bit bt2;
+ }
+ type boolean;
+ }
+ }
+
+ leaf lfunion11 {
+ type union {
+ type tpdfun1;
+ type tpdfun2;
+ }
+ }
+
+ leaf lfunion12 {
type tpdfun2;
}
- }
- leaf lfunion12 {
- type tpdfun2;
- }
+ leaf lfunion13 {
+ type tpdfbit;
+ }
- leaf lfunion13 {
- type tpdfbit;
- }
-
- leaf lfunion14 {
- type union {
- type enumeration {
- enum zero;
- enum one;
+ leaf lfunion14 {
+ type union {
+ type enumeration {
+ enum zero;
+ enum one;
+ }
+ type uint16;
}
- type uint16;
}
+
+ leaf identityref1 {
+ type identityref {
+ base iden;
+ }
+ }
+
+ leaf lfenum1 {
+ type tpdfun0;
+ }
+
+ leaf inst-iden {
+ type instance-identifier;
+ }
+
+ leaf lref1 {
+ type leafref {
+ path "../lfnint8Min";
+ }
+ }
+
+ leaf lref2 {
+ type leafref {
+ path "../identityref1";
+ }
+ }
+
+ leaf lref3 {
+ type leafref {
+ path "../lfunion14";
+ }
+ }
+
+ leaf lref4 {
+ type leafref {
+ path "../lfunion13";
+ }
+ }
+
+ leaf lref5 {
+ type leafref {
+ path "../lfunion11";
+ }
+ }
+
+ leaf lref6 {
+ type leafref {
+ path "../lfref2";
+ }
+ }
+
+ leaf lref7 {
+ type leafref {
+ path "../lfenum";
+ }
+ }
+
+ leaf lref8 {
+ type leafref {
+ path "../lfdecimal6";
+ }
+ }
+
+ leaf lref9 {
+ type leafref {
+ path "/ytb:leaf12";
+ }
+ }
+
+ leaf lref10 {
+ type leafref {
+ path "/ytb:leaf11";
+ }
+ }
+
+ leaf lref11 {
+ type leafref {
+ path "/ytb:leaf10";
+ }
+ }
+
+ leaf lref12 {
+ type leafref {
+ path "/ytb:leaf9";
+ }
+ }
+
+ leaf lref13 {
+ type leafref {
+ path "/ytb:leaf8";
+ }
+ }
+
+ leaf lref14 {
+ type leafref {
+ path "/ytb:leaf7";
+ }
+ }
+
+ leaf lref15 {
+ type leafref {
+ path "/ytb:leaf6";
+ }
+ }
+
+ leaf lref16 {
+ type leafref {
+ path "/ytb:leaf5";
+ }
+ }
+
+ leaf lref17 {
+ type leafref {
+ path "/ytb:leaf4";
+ }
+ }
+
+ leaf lref18 {
+ type leafref {
+ path "/ytb:leaf3";
+ }
+ }
+
+ leaf lref19 {
+ type leafref {
+ path "/ytb:leaf2";
+ }
+ }
+
+ leaf lref20 {
+ type leafref {
+ path "/ytb:leaf1";
+ }
+ }
+
+ leaf iref1 {
+ type identityref {
+ base iden;
+ }
+ }
+
+ leaf-list iref2 {
+ type identityref {
+ base iden;
+ }
+ }
+
+ leaf iref3 {
+ type identityref {
+ base ytb:type;
+ }
+ }
+
+ leaf-list iref4 {
+ type identityref {
+ base ytb:type;
+ }
+ }
+
+ uses gr;
}
- leaf identityref1 {
- type identityref {
- base iden;
+ grouping gr {
+ container cont3 {
+ leaf-list llref1 {
+ type leafref {
+ path "../../lfnint8Min";
+ }
+ }
+
+ leaf-list llref2 {
+ type leafref {
+ path "../../identityref1";
+ }
+ }
+
+ leaf-list llref3 {
+ type leafref {
+ path "../../lfunion14";
+ }
+ }
+
+ leaf-list llref4 {
+ type leafref {
+ path "../../lfunion13";
+ }
+ }
+
+ leaf-list llref5 {
+ type leafref {
+ path "../../lfunion11";
+ }
+ }
+
+ leaf-list llref6 {
+ type leafref {
+ path "../../lfref2";
+ }
+ }
+
+ leaf-list llref7 {
+ type leafref {
+ path "../../lfenum";
+ }
+ }
+
+ leaf-list llref8 {
+ type leafref {
+ path "../../lfdecimal6";
+ }
+ }
+
+ leaf-list llref9 {
+ type leafref {
+ path "/ytb:leaf12";
+ }
+ }
+
+ leaf-list llref10 {
+ type leafref {
+ path "/ytb:leaf11";
+ }
+ }
+
+ leaf-list llref11 {
+ type leafref {
+ path "/ytb:leaf10";
+ }
+ }
+
+ leaf-list llref12 {
+ type leafref {
+ path "/ytb:leaf9";
+ }
+ }
+
+ leaf-list llref13 {
+ type leafref {
+ path "/ytb:leaf8";
+ }
+ }
+
+ leaf-list llref14 {
+ type leafref {
+ path "/ytb:leaf7";
+ }
+ }
+
+ leaf-list llref15 {
+ type leafref {
+ path "/ytb:leaf6";
+ }
+ }
+
+ leaf-list llref16 {
+ type leafref {
+ path "/ytb:leaf5";
+ }
+ }
+
+ leaf-list llref17 {
+ type leafref {
+ path "/ytb:leaf4";
+ }
+ }
+
+ leaf-list llref18 {
+ type leafref {
+ path "/ytb:leaf3";
+ }
+ }
+
+ leaf-list llref19 {
+ type leafref {
+ path "/ytb:leaf2";
+ }
+ }
+
+ leaf-list llref20 {
+ type leafref {
+ path "/ytb:leaf1";
+ }
+ }
+
+ leaf lref21 {
+ type leafref {
+ path "/ytb:leaf1";
+ }
+ }
+
+ leaf iref1 {
+ type identityref {
+ base iden;
+ }
+ }
+
+ leaf-list iref2 {
+ type identityref {
+ base iden;
+ }
+ }
+
+ leaf iref3 {
+ type identityref {
+ base ytb:type;
+ }
+ }
+
+ leaf-list iref4 {
+ type identityref {
+ base ytb:type;
+ }
+ }
}
}
-
- leaf lfenum1 {
- type tpdfun0;
- }
- }
}
diff --git a/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang b/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
new file mode 100644
index 0000000..b966b8f
--- /dev/null
+++ b/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
@@ -0,0 +1,413 @@
+module YtbDataTypes {
+ yang-version 1;
+ namespace "yms:test:ytb:data:types";
+ prefix "data-types";
+ revision "2016-08-26";
+ // Enum with all combinations.
+
+ typedef def1 {
+ type union {
+ type uint64;
+ type enumeration {
+ enum ten {
+ value "10";
+ }
+ enum hundred {
+ value "100";
+ }
+ enum thousand {
+ value "1000";
+ }
+ }
+ }
+ }
+
+ typedef def2 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ typedef def3 {
+ type empty;
+ }
+
+ typedef def4 {
+ type empty;
+ }
+
+ typedef def5 {
+ type leafref {
+ path "/leaf3";
+ }
+ }
+
+ identity type {
+ description "type value";
+ }
+
+ identity physical {
+ base type;
+ }
+
+ identity virtual {
+ base type;
+ }
+
+ leaf leaf1 {
+ type string;
+ }
+
+ leaf leaf2 {
+ type def1;
+ }
+
+ leaf leaf3 {
+ type binary;
+ }
+
+ leaf leaf4 {
+ type leafref {
+ path "/leaf2";
+ }
+ }
+
+ leaf leaf5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf leaf6 {
+ type instance-identifier;
+ }
+
+ leaf leaf7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf leaf8 {
+ type empty;
+ }
+
+ leaf leaf9 {
+ type def2;
+ }
+
+ leaf leaf10 {
+ type def3;
+ }
+
+ leaf leaf11 {
+ type leafref {
+ path "/leaf8";
+ }
+ }
+
+ leaf leaf12 {
+ type def5;
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type string;
+ }
+
+ leaf leaf2 {
+ type def1;
+ }
+
+ leaf leaf3 {
+ type binary;
+ }
+
+ leaf leaf4 {
+ type leafref {
+ path "/leaf2";
+ }
+ }
+
+ leaf leaf5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf leaf6 {
+ type instance-identifier;
+ }
+
+ leaf leaf7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf leaf8 {
+ type empty;
+ }
+
+ leaf leaf9 {
+ type def2;
+ }
+
+ leaf leaf10 {
+ type def3;
+ }
+
+ leaf leaf11 {
+ type leafref {
+ path "/leaf8";
+ }
+ }
+
+ leaf leaf12 {
+ type def5;
+ }
+
+ leaf-list ll1 {
+ type string;
+ }
+
+ leaf-list ll2 {
+ type def1;
+ }
+
+ leaf-list ll3 {
+ type binary;
+ }
+
+ leaf-list ll4 {
+ type leafref {
+ path "/ll2";
+ }
+ }
+
+ leaf-list ll5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf-list ll6 {
+ type instance-identifier;
+ }
+
+ leaf-list ll7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf-list ll8 {
+ type empty;
+ }
+
+ leaf-list ll9 {
+ type def2;
+ }
+
+ leaf-list ll10 {
+ type def3;
+ }
+
+ leaf-list ll11 {
+ type leafref {
+ path "/ll8";
+ }
+ }
+
+ leaf-list ll12 {
+ type def5;
+ }
+
+ container cont2 {
+ }
+ }
+
+ leaf-list ll1 {
+ type string;
+ }
+
+ leaf-list ll2 {
+ type def1;
+ }
+
+ leaf-list ll3 {
+ type binary;
+ }
+
+ leaf-list ll4 {
+ type leafref {
+ path "/ll2";
+ }
+ }
+
+ leaf-list ll5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf-list ll6 {
+ type instance-identifier;
+ }
+
+ leaf-list ll7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf-list ll8 {
+ type empty;
+ }
+
+ leaf-list ll9 {
+ type def2;
+ }
+
+ leaf-list ll10 {
+ type def3;
+ }
+
+ leaf-list ll11 {
+ type leafref {
+ path "/ll8";
+ }
+ }
+
+ leaf-list ll12 {
+ type def5;
+ }
+
+ augment "/cont1/cont2" {
+ leaf leaf1 {
+ type string;
+ }
+
+ leaf leaf2 {
+ type def1;
+ }
+
+ leaf leaf3 {
+ type binary;
+ }
+
+ leaf leaf4 {
+ type leafref {
+ path "/leaf2";
+ }
+ }
+
+ leaf leaf5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf leaf6 {
+ type instance-identifier;
+ }
+
+ leaf leaf7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf leaf8 {
+ type empty;
+ }
+
+ leaf leaf9 {
+ type def2;
+ }
+
+ leaf leaf10 {
+ type def3;
+ }
+
+ leaf leaf11 {
+ type leafref {
+ path "/leaf8";
+ }
+ }
+
+ leaf leaf12 {
+ type def5;
+ }
+
+ leaf-list ll1 {
+ type string;
+ }
+
+ leaf-list ll2 {
+ type def1;
+ }
+
+ leaf-list ll3 {
+ type binary;
+ }
+
+ leaf-list ll4 {
+ type leafref {
+ path "/ll2";
+ }
+ }
+
+ leaf-list ll5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf-list ll6 {
+ type instance-identifier;
+ }
+
+ leaf-list ll7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf-list ll8 {
+ type empty;
+ }
+
+ leaf-list ll9 {
+ type def2;
+ }
+
+ leaf-list ll10 {
+ type def3;
+ }
+
+ leaf-list ll11 {
+ type leafref {
+ path "/ll8";
+ }
+ }
+
+ leaf-list ll12 {
+ type def5;
+ }
+ }
+}
diff --git a/serializers/json/pom.xml b/serializers/json/pom.xml
index e118b60..d8b8aae 100644
--- a/serializers/json/pom.xml
+++ b/serializers/json/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-serializers</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -53,7 +53,7 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-serializers-utils</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
diff --git a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
index 3b624d2..8ab4862 100644
--- a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
+++ b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
@@ -34,8 +34,6 @@
* Represents implementation of interfaces to build and obtain JSON data tree.
*/
public class DefaultJsonBuilder implements JsonBuilder {
- private Logger log = LoggerFactory.getLogger(getClass());
- private StringBuilder treeString;
private static final String LEFT_BRACE = "{";
private static final String RIGHT_BRACE = "}";
private static final String LEFT_BRACKET = "[";
@@ -44,7 +42,8 @@
private static final String COLON = ":";
private static final String QUOTE = "\"";
private static final String ROOT_MODULE_NAME = "ROOT";
-
+ private Logger log = LoggerFactory.getLogger(getClass());
+ private StringBuilder treeString;
private Stack<String> moduleNameStack;
public DefaultJsonBuilder(String rootName) {
@@ -81,9 +80,6 @@
return;
}
appendField(nodeName);
- if (value.isEmpty()) {
- return;
- }
treeString.append(QUOTE);
treeString.append(value);
treeString.append(QUOTE);
diff --git a/serializers/json/src/test/resources/demo1.yang b/serializers/json/src/test/resources/demo1.yang
index f3d8b0c..e3e3fa6 100644
--- a/serializers/json/src/test/resources/demo1.yang
+++ b/serializers/json/src/test/resources/demo1.yang
@@ -10,7 +10,7 @@
type string;
}
leaf Customs-supervisor {
- type string;
+ type empty;
description "name of the customs-supervisor.";
}
diff --git a/serializers/json/src/test/resources/test.json b/serializers/json/src/test/resources/test.json
index 0235997..0124173 100644
--- a/serializers/json/src/test/resources/test.json
+++ b/serializers/json/src/test/resources/test.json
@@ -2,7 +2,7 @@
"device": [
{
"deviceid": "string1-deviceid",
- "Customs-supervisor": "string2",
+ "Customs-supervisor": "",
"Merchandiser-supervisor": "string3",
"Warehouse-supervisor": [
"string41",
diff --git a/serializers/pom.xml b/serializers/pom.xml
index 7fdeb49..53895aa 100644
--- a/serializers/pom.xml
+++ b/serializers/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-tools</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -41,7 +41,7 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-runtime</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
diff --git a/serializers/utils/pom.xml b/serializers/utils/pom.xml
index 6792cce..d253035 100644
--- a/serializers/utils/pom.xml
+++ b/serializers/utils/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-serializers</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
diff --git a/serializers/xml/pom.xml b/serializers/xml/pom.xml
index bd2ae3a..7af054f 100644
--- a/serializers/xml/pom.xml
+++ b/serializers/xml/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-serializers</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-serializers-xml</artifactId>
@@ -37,7 +37,7 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-serializers-utils</artifactId>
- <version>2.2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
diff --git a/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java b/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
index 7b557ce..87dcb07 100644
--- a/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
+++ b/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
@@ -66,6 +66,201 @@
}
/**
+ * Validates and returns container data node.
+ *
+ * @param parent data node holding container
+ * @param name name of the container
+ * @param namespace namespace of the container
+ * @return container data node
+ */
+ private static DataNode validateContainerDataNode(DataNode parent,
+ String name,
+ String namespace) {
+ Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
+ NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
+ DataNode dataNode = childNodes.get(key);
+ SchemaId schemaId = dataNode.key().schemaId();
+ assertThat(schemaId.name(), is(name));
+ assertThat(schemaId.namespace(), is(namespace));
+ return dataNode;
+ }
+
+ /**
+ * Validates and returns list data node.
+ *
+ * @param parent data node holding list
+ * @param name name of the list
+ * @param namespace namespace of the list
+ * @param keynames list of key leaf names
+ * @param keyNs list of key leaf namespace
+ * @param keyVal list of key leaf values
+ * @return list data node
+ */
+ private static DataNode validateListDataNode(DataNode parent,
+ String name, String namespace,
+ List<String> keynames,
+ List<String> keyNs,
+ List<Object> keyVal) {
+ Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
+ NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
+ DataNode dataNode;
+ if (keynames != null && !keynames.isEmpty()) {
+ ListKey.ListKeyBuilder listKeyBldr = new ListKey.ListKeyBuilder();
+ listKeyBldr.schemaId(key.schemaId());
+ for (int i = 0; i < keynames.size(); i++) {
+ listKeyBldr.addKeyLeaf(keynames.get(i), keyNs.get(i),
+ keyVal.get(i));
+ }
+ dataNode = childNodes.get(listKeyBldr.build());
+ } else {
+ dataNode = childNodes.get(key);
+ }
+ SchemaId schemaId = dataNode.key().schemaId();
+ assertThat(schemaId.name(), is(name));
+ assertThat(schemaId.namespace(), is(namespace));
+ return dataNode;
+ }
+
+ /**
+ * Validates leaf data node.
+ *
+ * @param parent data node holding leaf
+ * @param name name of the leaf
+ * @param namespace namespace of the leaf
+ * @param value leaf value
+ */
+ private static void validateLeafDataNode(DataNode parent,
+ String name, String namespace,
+ Object value) {
+ Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
+ NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
+ LeafNode dataNode = ((LeafNode) childNodes.get(key));
+ SchemaId schemaId = dataNode.key().schemaId();
+ assertThat(schemaId.name(), is(name));
+ assertThat(schemaId.namespace(), is(namespace));
+ if (dataNode.value() != null) {
+ assertThat(dataNode.value().toString(), is(value));
+ }
+ }
+
+ /**
+ * Validates an empty leaf data node.
+ *
+ * @param parent data node holding leaf
+ * @param name name of the leaf
+ * @param namespace namespace of the leaf
+ * @param value leaf value
+ */
+ private static void validateNullLeafDataNode(DataNode parent,
+ String name, String namespace,
+ Object value) {
+ Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
+ NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
+ LeafNode dataNode = ((LeafNode) childNodes.get(key));
+ SchemaId schemaId = dataNode.key().schemaId();
+ assertThat(schemaId.name(), is(name));
+ assertThat(schemaId.namespace(), is(namespace));
+ assertThat(dataNode.value(), is(value));
+ }
+
+ /**
+ * Validates leaf-list data node.
+ *
+ * @param parent data node holding leaf-list
+ * @param name name of the leaf-list
+ * @param namespace namespace of the leaf-list
+ * @param value leaf-list value
+ */
+ private static void validateLeafListDataNode(DataNode parent,
+ String name, String namespace,
+ Object value) {
+ Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
+ NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
+ LeafListKey.LeafListKeyBuilder leafListBldr =
+ new LeafListKey.LeafListKeyBuilder();
+ leafListBldr.schemaId(key.schemaId());
+ leafListBldr.value(value);
+ DataNode leafListNode = childNodes.get(leafListBldr.build());
+ SchemaId schemaId = leafListNode.key().schemaId();
+ assertThat(schemaId.name(), is(name));
+ assertThat(schemaId.namespace(), is(namespace));
+ assertThat(((LeafNode) leafListNode).value().toString(), is(value));
+ }
+
+ /**
+ * Validates root data node.
+ *
+ * @param resourceData resource data which holds data node
+ * @return root data node
+ */
+ private static DataNode validateRootDataNode(ResourceData resourceData) {
+ List<DataNode> dataNodes = resourceData.dataNodes();
+ DataNode rootNode = dataNodes.get(0);
+ SchemaId rootSchemaId = rootNode.key().schemaId();
+ assertThat(rootSchemaId.name(), is("/"));
+ return rootNode;
+ }
+
+ /**
+ * Reads XML contents from file path and returns input stream.
+ *
+ * @param path path of XML file
+ * @return input stream
+ */
+ private static InputStream parseInput(String path) {
+ String temp;
+ StringBuilder sb = new StringBuilder();
+ try (BufferedReader br = new BufferedReader(new FileReader(path))) {
+ while ((temp = br.readLine()) != null) {
+ sb.append(temp);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return IOUtils.toInputStream(sb);
+ }
+
+ /**
+ * Reads XML contents from file path and returns input stream.
+ *
+ * @param path path of XML file
+ * @return input stream
+ */
+ private static String parseXml(String path) {
+ String temp;
+ StringBuilder sb = new StringBuilder();
+ try (BufferedReader br = new BufferedReader(new FileReader(path))) {
+ while ((temp = br.readLine()) != null) {
+ sb.append(temp);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Converts input stream to string format.
+ *
+ * @param inputStream input stream of xml
+ * @return XML string
+ */
+ private static String convertInputStreamToString(InputStream inputStream) {
+ BufferedReader br;
+ StringBuilder sb = new StringBuilder();
+ String xmlData;
+ br = new BufferedReader(new InputStreamReader(inputStream));
+ try {
+ while ((xmlData = br.readLine()) != null) {
+ sb.append(xmlData);
+ }
+ } catch (IOException e) {
+ throw new XmlSerializerException(e.getMessage());
+ }
+ return sb.toString();
+ }
+
+ /**
* Validates data node in which XML element is of type YANG container.
*/
@Test
@@ -282,199 +477,6 @@
assertThat(convertInputStreamToString(inputStream), is(parseXml(path)));
}
- /**
- * Validates and returns container data node.
- *
- * @param parent data node holding container
- * @param name name of the container
- * @param namespace namespace of the container
- * @return container data node
- */
- private static DataNode validateContainerDataNode(DataNode parent,
- String name,
- String namespace) {
- Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
- NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
- DataNode dataNode = childNodes.get(key);
- SchemaId schemaId = dataNode.key().schemaId();
- assertThat(schemaId.name(), is(name));
- assertThat(schemaId.namespace(), is(namespace));
- return dataNode;
- }
-
- /**
- * Validates and returns list data node.
- *
- * @param parent data node holding list
- * @param name name of the list
- * @param namespace namespace of the list
- * @param keynames list of key leaf names
- * @param keyNs list of key leaf namespace
- * @param keyVal list of key leaf values
- * @return list data node
- */
- private static DataNode validateListDataNode(DataNode parent,
- String name, String namespace,
- List<String> keynames,
- List<String> keyNs,
- List<Object> keyVal) {
- Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
- NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
- DataNode dataNode;
- if (keynames != null && !keynames.isEmpty()) {
- ListKey.ListKeyBuilder listKeyBldr = new ListKey.ListKeyBuilder();
- listKeyBldr.schemaId(key.schemaId());
- for (int i = 0; i < keynames.size(); i++) {
- listKeyBldr.addKeyLeaf(keynames.get(i), keyNs.get(i),
- keyVal.get(i));
- }
- dataNode = childNodes.get(listKeyBldr.build());
- } else {
- dataNode = childNodes.get(key);
- }
- SchemaId schemaId = dataNode.key().schemaId();
- assertThat(schemaId.name(), is(name));
- assertThat(schemaId.namespace(), is(namespace));
- return dataNode;
- }
-
- /**
- * Validates leaf data node.
- *
- * @param parent data node holding leaf
- * @param name name of the leaf
- * @param namespace namespace of the leaf
- * @param value leaf value
- */
- private static void validateLeafDataNode(DataNode parent,
- String name, String namespace,
- Object value) {
- Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
- NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
- LeafNode dataNode = ((LeafNode) childNodes.get(key));
- SchemaId schemaId = dataNode.key().schemaId();
- assertThat(schemaId.name(), is(name));
- assertThat(schemaId.namespace(), is(namespace));
- assertThat(dataNode.value().toString(), is(value));
- }
-
- /**
- * Validates an empty leaf data node.
- *
- * @param parent data node holding leaf
- * @param name name of the leaf
- * @param namespace namespace of the leaf
- * @param value leaf value
- */
- private static void validateNullLeafDataNode(DataNode parent,
- String name, String namespace,
- Object value) {
- Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
- NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
- LeafNode dataNode = ((LeafNode) childNodes.get(key));
- SchemaId schemaId = dataNode.key().schemaId();
- assertThat(schemaId.name(), is(name));
- assertThat(schemaId.namespace(), is(namespace));
- assertThat(dataNode.value(), is(value));
- }
-
- /**
- * Validates leaf-list data node.
- *
- * @param parent data node holding leaf-list
- * @param name name of the leaf-list
- * @param namespace namespace of the leaf-list
- * @param value leaf-list value
- */
- private static void validateLeafListDataNode(DataNode parent,
- String name, String namespace,
- Object value) {
- Map<NodeKey, DataNode> childNodes = ((InnerNode) parent).childNodes();
- NodeKey key = NodeKey.builder().schemaId(name, namespace).build();
- LeafListKey.LeafListKeyBuilder leafListBldr =
- new LeafListKey.LeafListKeyBuilder();
- leafListBldr.schemaId(key.schemaId());
- leafListBldr.value(value);
- DataNode leafListNode = childNodes.get(leafListBldr.build());
- SchemaId schemaId = leafListNode.key().schemaId();
- assertThat(schemaId.name(), is(name));
- assertThat(schemaId.namespace(), is(namespace));
- assertThat(((LeafNode) leafListNode).value().toString(), is(value));
- }
-
- /**
- * Validates root data node.
- *
- * @param resourceData resource data which holds data node
- * @return root data node
- */
- private static DataNode validateRootDataNode(ResourceData resourceData) {
- List<DataNode> dataNodes = resourceData.dataNodes();
- DataNode rootNode = dataNodes.get(0);
- SchemaId rootSchemaId = rootNode.key().schemaId();
- assertThat(rootSchemaId.name(), is("/"));
- return rootNode;
- }
-
- /**
- * Reads XML contents from file path and returns input stream.
- *
- * @param path path of XML file
- * @return input stream
- */
- private static InputStream parseInput(String path) {
- String temp;
- StringBuilder sb = new StringBuilder();
- try (BufferedReader br = new BufferedReader(new FileReader(path))) {
- while ((temp = br.readLine()) != null) {
- sb.append(temp);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return IOUtils.toInputStream(sb);
- }
-
- /**
- * Reads XML contents from file path and returns input stream.
- *
- * @param path path of XML file
- * @return input stream
- */
- private static String parseXml(String path) {
- String temp;
- StringBuilder sb = new StringBuilder();
- try (BufferedReader br = new BufferedReader(new FileReader(path))) {
- while ((temp = br.readLine()) != null) {
- sb.append(temp);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return sb.toString();
- }
-
- /**
- * Converts input stream to string format.
- *
- * @param inputStream input stream of xml
- * @return XML string
- */
- private static String convertInputStreamToString(InputStream inputStream) {
- BufferedReader br;
- StringBuilder sb = new StringBuilder();
- String xmlData;
- br = new BufferedReader(new InputStreamReader(inputStream));
- try {
- while ((xmlData = br.readLine()) != null) {
- sb.append(xmlData);
- }
- } catch (IOException e) {
- throw new XmlSerializerException(e.getMessage());
- }
- return sb.toString();
- }
-
private CompositeData getNewCompositeData(CompositeData data) {
List<AnnotatedNodeInfo> annotatedNodeInfos = data
.annotatedNodesInfo();
diff --git a/serializers/xml/src/test/resources/food.yang b/serializers/xml/src/test/resources/food.yang
index 4c87fa0..861ef3a 100644
--- a/serializers/xml/src/test/resources/food.yang
+++ b/serializers/xml/src/test/resources/food.yang
@@ -44,7 +44,7 @@
}
}
leaf p1 {
- type string;
+ type empty;
}
leaf-list p2 {
type string;
diff --git a/serializers/xml/src/test/resources/testContainer.xml b/serializers/xml/src/test/resources/testContainer.xml
index ee679b8..98d44f8 100644
--- a/serializers/xml/src/test/resources/testContainer.xml
+++ b/serializers/xml/src/test/resources/testContainer.xml
@@ -1,5 +1,5 @@
<food xmlns="yrt:food">
-<p1>p1_value</p1>
+<p1/>
<p2>p2_value</p2>
<p2>p2_value1</p2>
</food>