Search in sources :

Example 71 with NormalizedNodeContext

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 + ">");
}
Also used : BitsTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition) BitsTypeBuilder(org.opendaylight.yangtools.yang.model.ri.type.BitsTypeBuilder) UnionTypeBuilder(org.opendaylight.yangtools.yang.model.ri.type.UnionTypeBuilder) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 72 with NormalizedNodeContext

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>");
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 73 with NormalizedNodeContext

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());
}
Also used : IOException(java.io.IOException) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 74 with NormalizedNodeContext

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>");
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 75 with NormalizedNodeContext

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>");
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Aggregations

NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)105 Test (org.junit.Test)70 InputStream (java.io.InputStream)36 AbstractBodyReaderTest (org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)34 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)34 QName (org.opendaylight.yangtools.yang.common.QName)25 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)22 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)18 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)13 Module (org.opendaylight.yangtools.yang.model.api.Module)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 OutputStream (java.io.OutputStream)9 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)9 UriInfo (javax.ws.rs.core.UriInfo)8 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)8 IOException (java.io.IOException)7