2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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
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.namingservice;
23 import static org.junit.Assert.assertEquals;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.Test;
27 import org.onap.namingservice.model.NameGenDeleteResponse;
28 import org.onap.namingservice.model.NameGenResponse;
29 import org.onap.namingservice.model.Respelement;
30 import org.onap.so.bpmn.common.data.TestDataSetup;
31 import org.onap.so.client.exception.BadResponseException;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.ResponseEntity;
35 public class NamingClientResponseValidatorTest extends TestDataSetup {
37 private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator();
38 private String instanceGroupName = "generatedInstanceGroupName";
41 public void validateNameGenResponseSuccessTest() throws BadResponseException {
42 NameGenResponse name = new NameGenResponse();
43 Respelement respElement = new Respelement();
44 respElement.setResourceName("instance-group-name");
45 respElement.setResourceValue(instanceGroupName);
46 List<Respelement> respList = new ArrayList<Respelement>();
47 respList.add(respElement);
48 name.setElements(respList);
49 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
51 String actual = responseValidator.validateNameGenResponse(resp);
53 assertEquals(actual, "generatedInstanceGroupName");
57 public void validateNameGenResponseNoNameGeneratedTest() throws BadResponseException {
58 NameGenResponse name = new NameGenResponse();
59 Respelement respElement = new Respelement();
60 respElement.setResourceName("instance-group");
61 respElement.setResourceValue(instanceGroupName);
62 List<Respelement> respList = new ArrayList<Respelement>();
63 respList.add(respElement);
64 name.setElements(respList);
65 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
67 String actual = responseValidator.validateNameGenResponse(resp);
69 assertEquals(actual, "");
73 public void validateNameGenResponseBadStatusTest() throws BadResponseException {
74 NameGenResponse name = new NameGenResponse();
76 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
78 expectedException.expect(BadResponseException.class);
79 responseValidator.validateNameGenResponse(resp);
83 public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException {
84 NameGenDeleteResponse name = new NameGenDeleteResponse();
85 ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
87 String actual = responseValidator.validateNameGenDeleteResponse(resp);
89 assertEquals(actual, "");
93 public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException {
94 NameGenDeleteResponse name = new NameGenDeleteResponse();
96 ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
98 expectedException.expect(BadResponseException.class);
99 responseValidator.validateNameGenDeleteResponse(resp);