final Object identityref;
try {
identityref = idRefCodec.deserialize(input);
- } catch (UncheckedExecutionException | ExecutionError e) {
+ } catch (UncheckedExecutionException | ExecutionError | ClassCastException e) {
LOG.debug("Deserialization of {} as identityref failed", e);
return deserializeString(input);
}
registry.onBindingRuntimeContextUpdated(getRuntimeContext());
}
- @Test
- public void bug6006Test() {
- UnionType unionType = UnionTypeBuilder.getDefaultInstance(identOneString);
+ private DataObject createValueNode(final String valueString) {
+ UnionType unionType = UnionTypeBuilder.getDefaultInstance(valueString);
UnionNode unionNode = new UnionNodeBuilder().setValue(unionType).build();
NormalizedNode<?, ?> normalizedUnionNode = registry
.toNormalizedNode(InstanceIdentifier.builder(UnionNode.class).build(), unionNode)
YangInstanceIdentifier.of(normalizedUnionNode.getNodeType()), normalizedUnionNode);
DataObject unionNodeObj = unionNodeEntry.getValue();
assertTrue(unionNodeObj instanceof UnionNode);
+ return unionNodeObj;
+ }
+
+ @Test
+ public void bug6006Test() {
+ DataObject unionNodeObj = createValueNode(identOneString);
UnionType unionTypeObj = ((UnionNode) unionNodeObj).getValue();
assertEquals(null, unionTypeObj.getUint8());
assertEquals(IdentOne.class, unionTypeObj.getIdentityref());
}
+
+ @Test
+ public void bug6112Test() {
+ DataObject unionNodeObj = createValueNode("1");
+ UnionType unionTypeObj = ((UnionNode) unionNodeObj).getValue();
+ assertEquals(Short.valueOf((short)1), unionTypeObj.getUint8());
+ assertEquals(null, unionTypeObj.getIdentityref());
+ }
}
public class UnionTypeBuilder {
public static UnionType getDefaultInstance(java.lang.String defaultValue) {
- Class<? extends IdentBase> identityref = null;
if (defaultValue.equals("IdentOne")) {
return new UnionType(IdentOne.class);
}
if (defaultValue.equals("IdentTwo")) {
return new UnionType(IdentTwo.class);
}
+
+ try {
+ return new UnionType(Short.valueOf(defaultValue));
+ } catch(NumberFormatException e) {
+ /* do nothing */;
+ }
+
throw new IllegalArgumentException("Unknown UnionType string " + defaultValue);
}