Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / namingservice / NamingClientResponseValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.namingservice;
22
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;
34
35 public class NamingClientResponseValidatorTest extends TestDataSetup {
36
37     private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator();
38     private String instanceGroupName = "generatedInstanceGroupName";
39
40     @Test
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);
50
51         String actual = responseValidator.validateNameGenResponse(resp);
52
53         assertEquals(actual, "generatedInstanceGroupName");
54     }
55
56     @Test
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);
66
67         String actual = responseValidator.validateNameGenResponse(resp);
68
69         assertEquals(actual, "");
70     }
71
72     @Test
73     public void validateNameGenResponseBadStatusTest() throws BadResponseException {
74         NameGenResponse name = new NameGenResponse();
75
76         ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
77
78         expectedException.expect(BadResponseException.class);
79         responseValidator.validateNameGenResponse(resp);
80     }
81
82     @Test
83     public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException {
84         NameGenDeleteResponse name = new NameGenDeleteResponse();
85         ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
86
87         String actual = responseValidator.validateNameGenDeleteResponse(resp);
88
89         assertEquals(actual, "");
90     }
91
92     @Test
93     public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException {
94         NameGenDeleteResponse name = new NameGenDeleteResponse();
95
96         ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
97
98         expectedException.expect(BadResponseException.class);
99         responseValidator.validateNameGenDeleteResponse(resp);
100     }
101
102 }