328e4facbd99d0a5b0c7ac14311d325e443965cc
[policy/models.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.actorserviceprovider.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertSame;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.ObjectValidationResult;
30 import org.onap.policy.common.parameters.ValidationResult;
31 import org.onap.policy.common.parameters.ValidationStatus;
32
33 public class ParameterValidationRuntimeExceptionTest {
34
35     private static final String THE_MESSAGE = "the message";
36     private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception");
37
38     private ValidationResult result;
39
40     @Before
41     public void setUp() {
42         result = new ObjectValidationResult("param", null, ValidationStatus.INVALID, "null");
43     }
44
45     @Test
46     public void testParameterValidationExceptionValidationResult() {
47         ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(result);
48         assertSame(result, ex.getResult());
49         assertNull(ex.getMessage());
50     }
51
52     @Test
53     public void testParameterValidationExceptionValidationResultString() {
54         ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(THE_MESSAGE, result);
55         assertSame(result, ex.getResult());
56         assertEquals(THE_MESSAGE, ex.getMessage());
57     }
58
59     @Test
60     public void testParameterValidationExceptionValidationResultThrowable() {
61         ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(EXPECTED_EXCEPTION, result);
62         assertSame(result, ex.getResult());
63         assertEquals(EXPECTED_EXCEPTION.toString(), ex.getMessage());
64         assertEquals(EXPECTED_EXCEPTION, ex.getCause());
65     }
66
67     @Test
68     public void testParameterValidationExceptionValidationResultStringThrowable() {
69         ParameterValidationRuntimeException ex =
70                 new ParameterValidationRuntimeException(THE_MESSAGE, EXPECTED_EXCEPTION, result);
71         assertSame(result, ex.getResult());
72         assertEquals(THE_MESSAGE, ex.getMessage());
73         assertEquals(EXPECTED_EXCEPTION, ex.getCause());
74     }
75
76     @Test
77     public void testGetResult() {
78         ParameterValidationRuntimeException ex = new ParameterValidationRuntimeException(result);
79         assertSame(result, ex.getResult());
80     }
81 }