7c58038f6513f76ac1efe432b4ad5110fac8b699
[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
25 import java.util.ArrayList;
26 import java.util.List;
27
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;
36
37 public class NamingClientResponseValidatorTest extends TestDataSetup {
38         
39         private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator();  
40         private String instanceGroupName = "generatedInstanceGroupName";
41         
42         @Test
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);         
52                 
53                 String actual = responseValidator.validateNameGenResponse(resp);
54                 
55                 assertEquals(actual, "generatedInstanceGroupName");
56         }
57         
58         @Test
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);         
68                 
69                 String actual = responseValidator.validateNameGenResponse(resp);
70                 
71                 assertEquals(actual, "");
72         }
73         
74         @Test
75         public void validateNameGenResponseBadStatusTest() throws BadResponseException {
76                 NameGenResponse name = new NameGenResponse();
77                         
78                 ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);          
79                 
80                 expectedException.expect(BadResponseException.class);
81                 responseValidator.validateNameGenResponse(resp);                
82         }
83         
84         @Test
85         public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException {
86                 NameGenDeleteResponse name = new NameGenDeleteResponse();               
87                 ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);           
88                 
89                 String actual = responseValidator.validateNameGenDeleteResponse(resp);
90                 
91                 assertEquals(actual, "");
92         }       
93         
94         @Test
95         public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException {
96                 NameGenDeleteResponse name = new NameGenDeleteResponse();
97                         
98                 ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);            
99                 
100                 expectedException.expect(BadResponseException.class);
101                 responseValidator.validateNameGenDeleteResponse(resp);          
102         }
103         
104 }