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 static org.mockito.Mockito.mock;
12 import java.io.IOException;
13 import java.util.List;
14 import org.junit.Test;
15 import org.opendaylight.restconf.common.errors.RestconfError;
16 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
17 import org.opendaylight.restconf.server.api.DatabindContext;
18 import org.opendaylight.restconf.server.api.PatchStatusContext;
19 import org.opendaylight.restconf.server.api.PatchStatusEntity;
20 import org.opendaylight.yangtools.yang.common.ErrorTag;
21 import org.opendaylight.yangtools.yang.common.ErrorType;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 public class YangPatchStatusBodyTest extends AbstractJukeboxTest {
25 private final RestconfError error = new RestconfError(ErrorType.PROTOCOL, new ErrorTag("data-exists"),
26 "Data already exists");
27 private final PatchStatusEntity statusEntity = new PatchStatusEntity("patch1", true, null);
28 private final PatchStatusEntity statusEntityError = new PatchStatusEntity("patch1", false, List.of(error));
29 private final DatabindContext databind = DatabindContext.ofModel(mock(EffectiveModelContext.class));
32 * Test if per-operation status is omitted if global error is present.
35 public void testOutputWithGlobalError() throws IOException {
36 final var body = new YangPatchStatusBody(new PatchStatusContext(databind, "patch", List.of(statusEntity), false,
41 "ietf-yang-patch:yang-patch-status": {
46 "error-type": "protocol",
47 "error-tag": "data-exists",
48 "error-message": "Data already exists"
53 }""", body::formatToJSON, true);
55 <yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
56 <patch-id>patch</patch-id>
58 <error-type>protocol</error-type>
59 <error-tag>data-exists</error-tag>
60 <error-message>Data already exists</error-message>
62 </yang-patch-status>""", body::formatToXML, true);
66 * Test if per-operation status is present if there is no global error present.
69 public void testOutputWithoutGlobalError() throws IOException {
70 final var body = new YangPatchStatusBody(new PatchStatusContext(databind,"patch", List.of(statusEntityError),
75 "ietf-yang-patch:yang-patch-status": {
84 "error-type": "protocol",
85 "error-tag": "data-exists",
86 "error-message": "Data already exists"
94 }""", body::formatToJSON, true);
96 <yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
97 <patch-id>patch</patch-id>
100 <edit-id>patch1</edit-id>
102 <error-type>protocol</error-type>
103 <error-tag>data-exists</error-tag>
104 <error-message>Data already exists</error-message>
108 </yang-patch-status>""", body::formatToXML, true);