2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.oof;
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;
29 import org.apache.logging.log4j.util.Strings;
30 import org.junit.Test;
31 import org.onap.so.client.exception.BadResponseException;
33 public class OofValidatorTest {
36 public void validateDemandsResponse_success() throws Exception {
37 Map<String, String> map = new LinkedHashMap<>();
38 map.put("requestStatus", "accepted");
39 new OofValidator().validateDemandsResponse(map);
42 @Test(expected = BadResponseException.class)
43 public void validateDemandsResponse_mapIsEmpty() throws Exception {
44 new OofValidator().validateDemandsResponse(Collections.emptyMap());
47 @Test(expected = BadResponseException.class)
48 public void validateDemandsResponse_lackOfRequestStatus() throws Exception {
49 Map<String, String> map = new LinkedHashMap<>();
51 new OofValidator().validateDemandsResponse(map);
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);
63 public void validateSolution_success() throws Exception {
64 String json = "{\"value\" : \"test1\"}";
65 new OofValidator().validateSolution(json);
69 public void validateSolution_EmptyResponse() {
71 new OofValidator().validateSolution("");
72 } catch (BadResponseException e) {
73 assertThat(e.getMessage()).contains("oofs asynchronous response is empty");
78 public void validateSolution_serviceExceptionWithMessage() {
79 String json = "{\"serviceException\" : {\"text\" : \"serviceExceptionOccurred\"}}";
81 new OofValidator().validateSolution(json);
82 fail("Exception should be thrown");
83 } catch (BadResponseException e) {
84 assertThat(e.getMessage()).contains("serviceExceptionOccurred");
89 public void validateSolution_serviceExceptionWithEmptyMessage() {
90 String json = "{\"serviceException\" : {\"text\" : \"\"}}";
92 new OofValidator().validateSolution(json);
93 fail("Exception should be thrown");
94 } catch (BadResponseException e) {
95 assertThat(e.getMessage()).contains("error message not provided");