use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlTest method nnAsYangUnionToXmlTest.
@Test
public void nnAsYangUnionToXmlTest() throws Exception {
final BitsTypeDefinition.Bit mockBit1 = Mockito.mock(BitsTypeDefinition.Bit.class);
Mockito.when(mockBit1.getName()).thenReturn("first");
Mockito.when(mockBit1.getPosition()).thenReturn(Uint32.ONE);
final BitsTypeDefinition.Bit mockBit2 = Mockito.mock(BitsTypeDefinition.Bit.class);
Mockito.when(mockBit2.getName()).thenReturn("second");
Mockito.when(mockBit2.getPosition()).thenReturn(Uint32.TWO);
final BitsTypeBuilder bitsTypeBuilder = BaseTypes.bitsTypeBuilder(QName.create("foo", "foo"));
bitsTypeBuilder.addBit(mockBit1);
bitsTypeBuilder.addBit(mockBit2);
final UnionTypeBuilder unionTypeBuilder = BaseTypes.unionTypeBuilder(QName.create("foo", "foo"));
unionTypeBuilder.addType(BaseTypes.int8Type());
unionTypeBuilder.addType(bitsTypeBuilder.build());
unionTypeBuilder.addType(BaseTypes.booleanType());
unionTypeBuilder.addType(BaseTypes.stringType());
final String elName = "lfUnion";
// test int8
final String int8 = "15";
NormalizedNodeContext normalizedNodeContext = prepareNNC(TypeDefinitionAwareCodec.from(unionTypeBuilder.build()).deserialize(int8), elName);
nnToXml(normalizedNodeContext, "<" + elName + ">15</" + elName + ">");
// test bits
final String bits = "first second";
normalizedNodeContext = prepareNNC(TypeDefinitionAwareCodec.from(unionTypeBuilder.build()).deserialize(bits), elName);
nnToXml(normalizedNodeContext, "<" + elName + ">[first, second]</" + elName + ">");
// test boolean
final String bool = "true";
normalizedNodeContext = prepareNNC(TypeDefinitionAwareCodec.from(unionTypeBuilder.build()).deserialize(bool), elName);
nnToXml(normalizedNodeContext, "<" + elName + ">true</" + elName + ">");
// test string
final String s = "Hi!";
normalizedNodeContext = prepareNNC(TypeDefinitionAwareCodec.from(unionTypeBuilder.build()).deserialize(s), elName);
nnToXml(normalizedNodeContext, "<" + elName + ">Hi!</" + elName + ">");
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlTest method nnAsYangStringToXmlTest.
@Test
public void nnAsYangStringToXmlTest() throws Exception {
final NormalizedNodeContext normalizedNodeContext = prepareNNC(TypeDefinitionAwareCodec.from(BaseTypes.stringType()).deserialize("lfStr value"), "lfStr");
nnToXml(normalizedNodeContext, "<lfStr>lfStr value</lfStr>");
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlTest method nnAsYangLeafrefWithPrefixToXMLNegativeTest.
/**
* Negative test when leaf of type leafref references to not-existing leaf.
* {@code VerifyException} is expected.
*/
@Test
public void nnAsYangLeafrefWithPrefixToXMLNegativeTest() throws Exception {
final NormalizedNodeContext normalizedNodeContext = prepareLeafrefNegativeData();
final IOException ex = assertThrows(IOException.class, () -> nnToXml(normalizedNodeContext, "<not-existing>value</not-existing>", "<lfLfrefNegative>value</lfLfrefnegative>"));
final Throwable rootCause = Throwables.getRootCause(ex);
assertThat(rootCause, instanceOf(IllegalArgumentException.class));
assertEquals("Data tree child (basic:module?revision=2013-12-02)not-existing not present in schema parent " + "(basic:module?revision=2013-12-02)cont", rootCause.getMessage());
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlTest method nnAsYangIdentityrefToXMLTest.
@Test
public void nnAsYangIdentityrefToXMLTest() throws Exception {
final NormalizedNodeContext normalizedNodeContext = prepareIdrefData(null, true);
nnToXml(normalizedNodeContext, "<lf11 xmlns:x=\"referenced:module\">x:iden</lf11>");
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlTest method nnAsYangIdentityrefWithPrefixToXMLTest.
@Test
public void nnAsYangIdentityrefWithPrefixToXMLTest() throws Exception {
final NormalizedNodeContext normalizedNodeContext = prepareIdrefData("prefix", false);
nnToXml(normalizedNodeContext, "<lf11>no qname value</lf11>");
}
Aggregations