Add name to the top level pom for rest-client
[aai/rest-client.git] / src / test / java / org / openecomp / restclient / client / OperationResultTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.openecomp.restclient.client;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30
31 import javax.ws.rs.core.MultivaluedMap;
32
33 import org.junit.Before;
34 import org.junit.Test;
35
36 import com.sun.jersey.core.util.MultivaluedMapImpl;
37
38 public class OperationResultTest {
39
40   /**
41    * Test case initialization
42    * 
43    * @throws Exception the exception
44    */
45   @Before
46   public void init() throws Exception {
47   }
48   
49   @Test
50   public void validateConstruction() {
51     
52     OperationResult opResult = new OperationResult();
53     assertEquals(opResult.getNumRetries(),0);
54     assertFalse(opResult.isFromCache());
55     assertFalse(opResult.wasSuccessful());
56     opResult.setResultCode(612);
57     assertFalse(opResult.wasSuccessful());
58     assertNull(opResult.getHeaders());
59     
60     opResult = new OperationResult(204,"no content found");
61     assertEquals(opResult.getResultCode(),204);
62     assertEquals(opResult.getResult(),"no content found");
63     assertTrue(opResult.wasSuccessful());
64     
65     MultivaluedMap<String,String> multiMap = new MultivaluedMapImpl();
66     multiMap.add("p1","v1");
67     multiMap.add("p2","v2");
68     opResult.setHeaders(multiMap);
69     assertNotNull(opResult.getHeaders());
70     assertEquals(opResult.getHeaders().size(), 2);
71     
72   }
73   
74   @Test
75   public void validateAccesors() {
76     
77     OperationResult opResult = new OperationResult();
78     
79     opResult.setFailureCause("failure");
80     opResult.setFromCache(false);
81     opResult.setNumRetries(101);
82     opResult.setRequestedLink("http://localhost:1234");
83     opResult.setResult("result");
84     opResult.setResultCode(555);
85
86     assertEquals(opResult.getFailureCause(), "failure");
87     assertFalse(opResult.isFromCache());
88     assertEquals(opResult.getNumRetries(),101);
89     assertEquals(opResult.getRequestedLink(),"http://localhost:1234");
90     assertEquals(opResult.getResult(), "result");
91     assertEquals(opResult.getResultCode(),555);
92     
93     opResult.setResult(212, "mostly successful");
94     assertEquals(opResult.getResultCode(),212);
95     assertEquals(opResult.getResult(), "mostly successful");
96     
97     assertTrue(opResult.toString().contains("OperationResult"));
98     
99     opResult.setFailureCause(511, "things melting");
100     assertEquals(opResult.getResultCode(),511);
101     assertEquals(opResult.getFailureCause(), "things melting");
102     
103   }
104     
105 }