803083321f159000f1fb856dd17f5d8990b0517d
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / RestObjectTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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.vid.mso;
22
23 import org.hamcrest.MatcherAssert;
24 import org.testng.annotations.BeforeSuite;
25 import org.testng.annotations.Test;
26
27 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
28 import static org.assertj.core.api.Assertions.assertThat;
29
30 public class RestObjectTest {
31
32     private RestObject restObject;
33
34     @BeforeSuite
35     private void setUp() {
36         restObject = new RestObject();
37     }
38
39     @Test
40     public void shouldHaveValidGettersAndSetters(){
41         MatcherAssert.assertThat(RestObject.class, hasValidGettersAndSettersExcluding("t"));
42     }
43
44     @Test
45     public void shouldHaveValidGetterAndSetterForBody() {
46         //  given
47         String testString = "set/get_testString";
48
49         //  when
50         restObject.set(testString);
51
52         //  then
53         assertThat(testString).isSameAs(restObject.get());
54     }
55
56     @Test
57     public void shouldProperlyCopyRestObject() {
58         //  given
59         MsoResponseWrapper testResponseWraper = new MsoResponseWrapper();
60         String rawTestString = "rawTestString";
61         int statusCode = 404;
62
63         RestObject restObjectToCopyFrom = new RestObject<>();
64         restObjectToCopyFrom.set(testResponseWraper);
65         restObjectToCopyFrom.setRaw(rawTestString);
66         restObjectToCopyFrom.setStatusCode(statusCode);
67
68         //  when
69         restObject.copyFrom(restObjectToCopyFrom);
70
71         //  then
72         assertThat(restObject).isEqualToComparingFieldByField(restObjectToCopyFrom);
73     }
74
75     @Test
76     public void shouldProperlyConvertRestObjectToString() {
77         //  given
78         String testString = "testString";
79         String rawTestString = "rawTestString";
80         int statusCode = 202;
81
82         restObject.set(testString);
83         restObject.setRaw(rawTestString);
84         restObject.setStatusCode(statusCode);
85
86         String properString = "RestObject{t=testString, rawT=rawTestString, statusCode=202}";
87
88         //  when
89         String toStringResponse = restObject.toString();
90
91         //  then
92         assertThat(toStringResponse).isEqualTo(properString);
93     }
94 }