2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. 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.nb.rfc8040.databind.jaxrs;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
13 import java.util.List;
14 import javax.ws.rs.core.MultivaluedHashMap;
15 import org.junit.Test;
16 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
17 import org.opendaylight.restconf.common.errors.RestconfError;
18 import org.opendaylight.restconf.nb.rfc8040.ContentParameter;
19 import org.opendaylight.yangtools.yang.common.ErrorTag;
20 import org.opendaylight.yangtools.yang.common.ErrorType;
22 public class QueryParamsTest {
24 * Test when parameter is present at most once.
27 public void getSingleParameterTest() {
28 final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
29 parameters.putSingle(ContentParameter.uriName(), "all");
30 assertEquals("all", QueryParams.getSingleParameter(parameters, ContentParameter.uriName()));
34 * Test when parameter is present more than once.
37 public void getSingleParameterNegativeTest() {
38 final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
39 parameters.put(ContentParameter.uriName(), List.of("config", "nonconfig", "all"));
41 final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
42 () -> QueryParams.getSingleParameter(parameters, ContentParameter.uriName()));
43 final List<RestconfError> errors = ex.getErrors();
44 assertEquals(1, errors.size());
46 final RestconfError error = errors.get(0);
47 assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
48 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());