2 * Copyright (c) 2023 PANTHEON.tech s.r.o. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.server.spi;
10 import java.io.IOException;
11 import java.util.List;
12 import org.junit.Test;
13 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
14 import org.opendaylight.restconf.server.api.PatchStatusContext;
15 import org.opendaylight.restconf.server.api.PatchStatusEntity;
16 import org.opendaylight.restconf.server.api.ServerError;
17 import org.opendaylight.yangtools.yang.common.ErrorTag;
18 import org.opendaylight.yangtools.yang.common.ErrorType;
20 public class YangPatchStatusBodyTest extends AbstractJukeboxTest {
21 private final ServerError error = new ServerError(ErrorType.PROTOCOL, new ErrorTag("data-exists"),
22 "Data already exists");
23 private final PatchStatusEntity statusEntity = new PatchStatusEntity("patch1", true, null);
24 private final PatchStatusEntity statusEntityError = new PatchStatusEntity("patch1", false, List.of(error));
27 * Test if per-operation status is omitted if global error is present.
30 public void testOutputWithGlobalError() throws IOException {
31 final var body = new YangPatchStatusBody(new PatchStatusContext("patch", List.of(statusEntity), false,
36 "ietf-yang-patch:yang-patch-status": {
41 "error-type": "protocol",
42 "error-tag": "data-exists",
43 "error-message": "Data already exists"
48 }""", body::formatToJSON, true);
50 <yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
51 <patch-id>patch</patch-id>
53 <error-type>protocol</error-type>
54 <error-tag>data-exists</error-tag>
55 <error-message>Data already exists</error-message>
57 </yang-patch-status>""", body::formatToXML, true);
61 * Test if per-operation status is present if there is no global error present.
64 public void testOutputWithoutGlobalError() throws IOException {
65 final var body = new YangPatchStatusBody(new PatchStatusContext("patch", List.of(statusEntityError), false,
70 "ietf-yang-patch:yang-patch-status": {
79 "error-type": "protocol",
80 "error-tag": "data-exists",
81 "error-message": "Data already exists"
89 }""", body::formatToJSON, true);
91 <yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
92 <patch-id>patch</patch-id>
95 <edit-id>patch1</edit-id>
97 <error-type>protocol</error-type>
98 <error-tag>data-exists</error-tag>
99 <error-message>Data already exists</error-message>
103 </yang-patch-status>""", body::formatToXML, true);