/*
* Copyright © 2019 FRINX s.r.o. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.skyscreamer.jsonassert.JSONAssert;
@RunWith(Parameterized.class)
public class RestconfDocumentedExceptionMapperTest {
private static final String EMPTY_XML = "";
private static final String EMPTY_JSON = "{}";
private static final QNameModule MONITORING_MODULE_INFO = QNameModule.create(
XMLNamespace.of("instance:identifier:patch:module"), Revision.of("2015-11-21"));
private static RestconfDocumentedExceptionMapper exceptionMapper;
@BeforeClass
public static void setupExceptionMapper() {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(
RestconfDocumentedExceptionMapperTest.class, "/restconf/impl/ietf-restconf@2017-01-26.yang",
"/instanceidentifier/yang/instance-identifier-patch-module.yang");
final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
doReturn(schemaContext).when(schemaContextHandler).get();
exceptionMapper = new RestconfDocumentedExceptionMapper(schemaContextHandler);
}
/**
* Testing entries 0 - 6: testing of media types and empty responses.
* Testing entries 7 - 8: testing of deriving of status codes from error entries.
* Testing entries 9 - 10: testing of serialization of different optional fields of error entries (JSON/XML).
*
* @return Testing data for parametrized test.
*/
@Parameters(name = "{index}: {0}: {1}")
public static Iterable