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;
25 import java.util.ArrayList;
26 import java.util.List;
28 import org.junit.Test;
29 import org.onap.namingservice.model.NameGenDeleteResponse;
30 import org.onap.namingservice.model.NameGenResponse;
31 import org.onap.namingservice.model.Respelement;
32 import org.onap.so.bpmn.common.data.TestDataSetup;
33 import org.onap.so.client.exception.BadResponseException;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
37 public class NamingClientResponseValidatorTest extends TestDataSetup {
39 private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator();
40 private String instanceGroupName = "generatedInstanceGroupName";
43 public void validateNameGenResponseSuccessTest() throws BadResponseException {
44 NameGenResponse name = new NameGenResponse();
45 Respelement respElement = new Respelement();
46 respElement.setResourceName("instance-group-name");
47 respElement.setResourceValue(instanceGroupName);
48 List<Respelement> respList = new ArrayList<Respelement>();
49 respList.add(respElement);
50 name.setElements(respList);
51 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
53 String actual = responseValidator.validateNameGenResponse(resp);
55 assertEquals(actual, "generatedInstanceGroupName");
59 public void validateNameGenResponseNoNameGeneratedTest() throws BadResponseException {
60 NameGenResponse name = new NameGenResponse();
61 Respelement respElement = new Respelement();
62 respElement.setResourceName("instance-group");
63 respElement.setResourceValue(instanceGroupName);
64 List<Respelement> respList = new ArrayList<Respelement>();
65 respList.add(respElement);
66 name.setElements(respList);
67 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
69 String actual = responseValidator.validateNameGenResponse(resp);
71 assertEquals(actual, "");
75 public void validateNameGenResponseBadStatusTest() throws BadResponseException {
76 NameGenResponse name = new NameGenResponse();
78 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
80 expectedException.expect(BadResponseException.class);
81 responseValidator.validateNameGenResponse(resp);
85 public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException {
86 NameGenDeleteResponse name = new NameGenDeleteResponse();
87 ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
89 String actual = responseValidator.validateNameGenDeleteResponse(resp);
91 assertEquals(actual, "");
95 public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException {
96 NameGenDeleteResponse name = new NameGenDeleteResponse();
98 ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
100 expectedException.expect(BadResponseException.class);
101 responseValidator.validateNameGenDeleteResponse(resp);