2 * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
11 import static org.junit.Assert.assertEquals;
13 import com.google.common.collect.Lists;
14 import com.google.common.collect.Sets;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
18 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
19 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
22 * Unit test for {@link ParametersUtil}.
24 public class ParametersUtilTest {
27 * Test when all parameters are allowed.
30 public void checkParametersTypesTest() {
31 ParametersUtil.checkParametersTypes(
32 RestconfDataServiceConstant.ReadData.READ_TYPE_TX,
33 Sets.newHashSet("content"),
34 RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH);
38 * Test when not allowed parameter type is used.
41 public void checkParametersTypesNegativeTest() {
43 ParametersUtil.checkParametersTypes(
44 RestconfDataServiceConstant.ReadData.READ_TYPE_TX,
45 Sets.newHashSet("not-allowed-parameter"),
46 RestconfDataServiceConstant.ReadData.CONTENT, RestconfDataServiceConstant.ReadData.DEPTH);
48 Assert.fail("Test expected to fail due to not allowed parameter used with operation");
49 } catch (final RestconfDocumentedException e) {
50 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
51 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
52 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
57 * Test when parameter is present at most once.
60 public void checkParameterCountTest() {
61 ParametersUtil.checkParameterCount(Lists.newArrayList("all"), RestconfDataServiceConstant.ReadData.CONTENT);
65 * Test when parameter is present more than once.
68 public void checkParameterCountNegativeTest() {
70 ParametersUtil.checkParameterCount(Lists.newArrayList("config", "nonconfig", "all"),
71 RestconfDataServiceConstant.ReadData.CONTENT);
73 Assert.fail("Test expected to fail due to multiple values of the same parameter");
74 } catch (final RestconfDocumentedException e) {
75 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
76 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
77 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());