add junit coverage
[so.git] / so-optimization-clients / src / test / java / org / onap / so / client / oof / OofValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2021 Nokia
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.so.client.oof;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.fail;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.Map;
29 import org.apache.logging.log4j.util.Strings;
30 import org.junit.Test;
31 import org.onap.so.client.exception.BadResponseException;
32
33 public class OofValidatorTest {
34
35     @Test
36     public void validateDemandsResponse_success() throws Exception {
37         Map<String, String> map = new LinkedHashMap<>();
38         map.put("requestStatus", "accepted");
39         new OofValidator().validateDemandsResponse(map);
40     }
41
42     @Test(expected = BadResponseException.class)
43     public void validateDemandsResponse_mapIsEmpty() throws Exception {
44         new OofValidator().validateDemandsResponse(Collections.emptyMap());
45     }
46
47     @Test(expected = BadResponseException.class)
48     public void validateDemandsResponse_lackOfRequestStatus() throws Exception {
49         Map<String, String> map = new LinkedHashMap<>();
50         map.put("a", "a");
51         new OofValidator().validateDemandsResponse(map);
52     }
53
54     @Test(expected = BadResponseException.class)
55     public void validateDemandsResponse_lackOfRequestStatusProperValue() throws Exception {
56         Map<String, String> map = new HashMap<>();
57         map.put("requestStatus", "a");
58         map.put("statusMessage", "a");
59         new OofValidator().validateDemandsResponse(map);
60     }
61
62     @Test
63     public void validateSolution_success() throws Exception {
64         String json = "{\"value\" : \"test1\"}";
65         new OofValidator().validateSolution(json);
66     }
67
68     @Test
69     public void validateSolution_EmptyResponse() {
70         try {
71             new OofValidator().validateSolution("");
72         } catch (BadResponseException e) {
73             assertThat(e.getMessage()).contains("oofs asynchronous response is empty");
74         }
75     }
76
77     @Test
78     public void validateSolution_serviceExceptionWithMessage() {
79         String json = "{\"serviceException\" : {\"text\" : \"serviceExceptionOccurred\"}}";
80         try {
81             new OofValidator().validateSolution(json);
82             fail("Exception should be thrown");
83         } catch (BadResponseException e) {
84             assertThat(e.getMessage()).contains("serviceExceptionOccurred");
85         }
86     }
87
88     @Test
89     public void validateSolution_serviceExceptionWithEmptyMessage() {
90         String json = "{\"serviceException\" : {\"text\" : \"\"}}";
91         try {
92             new OofValidator().validateSolution(json);
93             fail("Exception should be thrown");
94         } catch (BadResponseException e) {
95             assertThat(e.getMessage()).contains("error message not provided");
96         }
97     }
98 }