import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeGetter;
import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeNavigator;
+import org.opendaylight.controller.cluster.datastore.node.utils.PathUtils;
import org.opendaylight.controller.cluster.datastore.util.TestModel;
import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Container;
import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertEquals;
}
private YangInstanceIdentifier instanceIdentifierFromString(String s) {
-
- String[] ids = s.split("/");
-
- List<YangInstanceIdentifier.PathArgument> pathArguments = new ArrayList<>();
- for (String nodeId : ids) {
- if (!"".equals(nodeId)) {
- pathArguments.add(NodeIdentifierFactory.getArgument(nodeId));
- }
- }
- final YangInstanceIdentifier instanceIdentifier =
- YangInstanceIdentifier.create(pathArguments);
- return instanceIdentifier;
+ return PathUtils.toYangInstanceIdentifier(s);
}
-
@Test
public void testNormalizeNodeAttributesToProtoBuffNode() {
final NormalizedNode<?, ?> documentOne = TestModel.createTestContainer();
NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id);
new NormalizedNodeNavigator(normalizedNodeGetter).navigate(
- YangInstanceIdentifier.builder().build().toString(), documentOne);
+ PathUtils.toString(YangInstanceIdentifier.builder().build()), documentOne);
// Validate the value of id can be retrieved from the normalized node
NormalizedNode output = normalizedNodeGetter.getOutput();
NormalizedNodeToNodeCodec codec =
new NormalizedNodeToNodeCodec(schemaContext);
+ long start = System.currentTimeMillis();
Container container =
codec.encode(instanceIdentifierFromString(id), output);
+ long end = System.currentTimeMillis();
+
+ System.out.println("Timetaken to encode :"+(end-start));
assertNotNull(container);
assertEquals(id, container.getParentPath() + "/"
// first get the node representation of normalized node
final Node node = container.getNormalizedNode();
+ start = System.currentTimeMillis();
NormalizedNode<?, ?> normalizedNode =
codec.decode(instanceIdentifierFromString(id), node);
+ end = System.currentTimeMillis();
+
+ System.out.println("Timetaken to decode :"+(end-start));
assertEquals(normalizedNode.getValue().toString(), output.getValue()
.toString());