@@ -2062,48 +2062,117 @@ TEST_CASE("Data Node manipulation")
2062
2062
ctx.loadModule (" ietf-netconf-nmda" );
2063
2063
2064
2064
DOCTEST_SUBCASE (" notifications" ) {
2065
- std::string payload;
2066
- auto opType = libyang::OperationType::DataYang;
2065
+ DOCTEST_SUBCASE (" restconf/netconf" ) {
2066
+ std::string payload;
2067
+ auto opType = libyang::OperationType::DataYang;
2067
2068
2068
- DOCTEST_SUBCASE (" RESTCONF JSON" ) {
2069
- payload = R"(
2070
- {
2071
- "ietf-restconf:notification" : {
2072
- "eventTime" : "2013-12-21T00:01:00Z",
2073
- "example-schema:event" : {
2074
- "event-class" : "fault"
2069
+ DOCTEST_SUBCASE (" RESTCONF JSON" ) {
2070
+ payload = R"(
2071
+ {
2072
+ "ietf-restconf:notification" : {
2073
+ "eventTime" : "2013-12-21T00:01:00Z",
2074
+ "example-schema:event" : {
2075
+ "event-class" : "fault"
2076
+ }
2077
+ }
2075
2078
}
2076
- }
2079
+ )" ;
2080
+ opType = libyang::OperationType::NotificationRestconf;
2077
2081
}
2078
- )" ;
2079
- opType = libyang::OperationType::NotificationRestconf;
2080
- }
2081
-
2082
- DOCTEST_SUBCASE (" NETCONF XML" ) {
2083
- payload = R"(
2084
- <notification
2085
- xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
2086
- <eventTime>2013-12-21T00:01:00Z</eventTime>
2087
- <event xmlns="http://example.com/coze">
2088
- <event-class>fault</event-class>
2089
- </event>
2090
- </notification>
2091
- )" ;
2092
- opType = libyang::OperationType::NotificationNetconf;
2082
+
2083
+ DOCTEST_SUBCASE (" NETCONF XML" ) {
2084
+ payload = R"(
2085
+ <notification
2086
+ xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
2087
+ <eventTime>2013-12-21T00:01:00Z</eventTime>
2088
+ <event xmlns="http://example.com/coze">
2089
+ <event-class>fault</event-class>
2090
+ </event>
2091
+ </notification>
2092
+ )" ;
2093
+ opType = libyang::OperationType::NotificationNetconf;
2094
+ }
2095
+
2096
+ auto notif = ctx.parseOp (payload, dataTypeFor (payload), opType);
2097
+ REQUIRE (notif.tree );
2098
+ REQUIRE (notif.tree ->path () == " /notification" );
2099
+ auto node = notif.tree ->child ();
2100
+ REQUIRE (node);
2101
+ REQUIRE (node->path () == " /notification/eventTime" );
2102
+ REQUIRE (node->asOpaque ().value () == " 2013-12-21T00:01:00Z" );
2103
+
2104
+ REQUIRE (notif.op );
2105
+ node = notif.op ->findPath (" /example-schema:event/event-class" );
2106
+ REQUIRE (!!node);
2107
+ REQUIRE (std::visit (libyang::ValuePrinter{}, node->asTerm ().value ()) == " fault" );
2093
2108
}
2094
2109
2095
- auto notif = ctx.parseOp (payload, dataTypeFor (payload), opType);
2096
- REQUIRE (notif.tree );
2097
- REQUIRE (notif.tree ->path () == " /notification" );
2098
- auto node = notif.tree ->child ();
2099
- REQUIRE (node);
2100
- REQUIRE (node->path () == " /notification/eventTime" );
2101
- REQUIRE (node->asOpaque ().value () == " 2013-12-21T00:01:00Z" );
2110
+ DOCTEST_SUBCASE (" yang" )
2111
+ {
2112
+ std::string payload;
2102
2113
2103
- REQUIRE (notif.op );
2104
- node = notif.op ->findPath (" /example-schema:event/event-class" );
2105
- REQUIRE (!!node);
2106
- REQUIRE (std::visit (libyang::ValuePrinter{}, node->asTerm ().value ()) == " fault" );
2114
+ DOCTEST_SUBCASE (" top-level" )
2115
+ {
2116
+ DOCTEST_SUBCASE (" json" )
2117
+ {
2118
+ payload = R"( {
2119
+ "example-schema:event" : {
2120
+ "event-class" : "fault"
2121
+ }
2122
+ })" ;
2123
+ }
2124
+ DOCTEST_SUBCASE (" xml" )
2125
+ {
2126
+ payload = R"(
2127
+ <event xmlns="http://example.com/coze">
2128
+ <event-class>fault</event-class>
2129
+ </event>
2130
+ )" ;
2131
+ }
2132
+ auto notif = ctx.parseOp (payload, dataTypeFor (payload), libyang::OperationType::NotificationYang);
2133
+ REQUIRE (notif.tree );
2134
+ REQUIRE (notif.op );
2135
+ REQUIRE (notif.op == notif.tree );
2136
+ REQUIRE (notif.tree ->path () == " /example-schema:event" );
2137
+ auto node = notif.op ->findPath (" /example-schema:event/event-class" );
2138
+ REQUIRE (!!node);
2139
+ REQUIRE (std::visit (libyang::ValuePrinter{}, node->asTerm ().value ()) == " fault" );
2140
+ }
2141
+
2142
+ DOCTEST_SUBCASE (" nested" )
2143
+ {
2144
+ DOCTEST_SUBCASE (" json" )
2145
+ {
2146
+ payload = R"( {
2147
+ "example-schema:person" : [{
2148
+ "name": "John",
2149
+ "event": {
2150
+ "description" : "fault"
2151
+ }
2152
+ }]
2153
+ })" ;
2154
+ }
2155
+ DOCTEST_SUBCASE (" xml" )
2156
+ {
2157
+ payload = R"(
2158
+ <person xmlns="http://example.com/coze">
2159
+ <name>John</name>
2160
+ <event>
2161
+ <description>fault</description>
2162
+ </event>
2163
+ </person>
2164
+ )" ;
2165
+ }
2166
+ auto notif = ctx.parseOp (payload, dataTypeFor (payload), libyang::OperationType::NotificationYang);
2167
+ REQUIRE (notif.tree );
2168
+ REQUIRE (notif.op );
2169
+ REQUIRE (notif.op != notif.tree );
2170
+ REQUIRE (notif.tree ->path () == " /example-schema:person[name='John']" );
2171
+ auto node = notif.op ->findPath (" /example-schema:person[name='John']/event/description" );
2172
+ REQUIRE (!!node);
2173
+ REQUIRE (std::visit (libyang::ValuePrinter{}, node->asTerm ().value ()) == " fault" );
2174
+ }
2175
+ }
2107
2176
}
2108
2177
2109
2178
DOCTEST_SUBCASE (" invalid notification" ) {
@@ -2116,6 +2185,9 @@ TEST_CASE("Data Node manipulation")
2116
2185
REQUIRE_THROWS_WITH_AS (ctx.parseOp (" " , libyang::DataFormat::XML, libyang::OperationType::NotificationNetconf),
2117
2186
" Can't parse a standalone rpc/action/notification into operation data tree: LY_ENOT" , libyang::Error);
2118
2187
2188
+ REQUIRE_THROWS_WITH_AS (ctx.parseOp (" asd" , libyang::DataFormat::XML, libyang::OperationType::NotificationYang),
2189
+ " Can't parse a standalone rpc/action/notification into operation data tree: LY_EVALID" , libyang::Error);
2190
+
2119
2191
/* libyang::setLogOptions(libyang::LogOptions::Log | libyang::LogOptions::Store); */
2120
2192
REQUIRE_THROWS_WITH_AS (ctx.parseOp (R"(
2121
2193
{
0 commit comments