2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.restclient.client;
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;
31 import javax.ws.rs.core.MultivaluedMap;
33 import org.junit.Before;
34 import org.junit.Test;
36 import com.sun.jersey.core.util.MultivaluedMapImpl;
38 public class OperationResultTest {
41 * Test case initialization
43 * @throws Exception the exception
46 public void init() throws Exception {
50 public void validateConstruction() {
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());
60 opResult = new OperationResult(204,"no content found");
61 assertEquals(opResult.getResultCode(),204);
62 assertEquals(opResult.getResult(),"no content found");
63 assertTrue(opResult.wasSuccessful());
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);
75 public void validateAccesors() {
77 OperationResult opResult = new OperationResult();
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);
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);
93 opResult.setResult(212, "mostly successful");
94 assertEquals(opResult.getResultCode(),212);
95 assertEquals(opResult.getResult(), "mostly successful");
97 assertTrue(opResult.toString().contains("OperationResult"));
99 opResult.setFailureCause(511, "things melting");
100 assertEquals(opResult.getResultCode(),511);
101 assertEquals(opResult.getFailureCause(), "things melting");