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.onap.aai.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.MultivaluedHashMap;
32 import javax.ws.rs.core.MultivaluedMap;
33 import org.junit.Before;
34 import org.junit.Test;
36 public class OperationResultTest {
39 * Test case initialization
41 * @throws Exception the exception
44 public void init() throws Exception {
48 public void validateConstruction() {
50 OperationResult opResult = new OperationResult();
51 assertEquals(opResult.getNumRetries(),0);
52 assertFalse(opResult.isFromCache());
53 assertFalse(opResult.wasSuccessful());
54 opResult.setResultCode(612);
55 assertFalse(opResult.wasSuccessful());
56 assertNull(opResult.getHeaders());
58 opResult = new OperationResult(204,"no content found");
59 assertEquals(opResult.getResultCode(),204);
60 assertEquals(opResult.getResult(),"no content found");
61 assertTrue(opResult.wasSuccessful());
63 MultivaluedMap<String,String> multiMap = new MultivaluedHashMap<>();
64 multiMap.add("p1","v1");
65 multiMap.add("p2","v2");
66 opResult.setHeaders(multiMap);
67 assertNotNull(opResult.getHeaders());
68 assertEquals(opResult.getHeaders().size(), 2);
73 public void validateAccesors() {
75 OperationResult opResult = new OperationResult();
77 opResult.setFailureCause("failure");
78 opResult.setFromCache(false);
79 opResult.setNumRetries(101);
80 opResult.setRequestedLink("http://localhost:1234");
81 opResult.setResult("result");
82 opResult.setResultCode(555);
84 assertEquals(opResult.getFailureCause(), "failure");
85 assertFalse(opResult.isFromCache());
86 assertEquals(opResult.getNumRetries(),101);
87 assertEquals(opResult.getRequestedLink(),"http://localhost:1234");
88 assertEquals(opResult.getResult(), "result");
89 assertEquals(opResult.getResultCode(),555);
91 opResult.setResult(212, "mostly successful");
92 assertEquals(opResult.getResultCode(),212);
93 assertEquals(opResult.getResult(), "mostly successful");
95 assertTrue(opResult.toString().contains("OperationResult"));
97 opResult.setFailureCause(511, "things melting");
98 assertEquals(opResult.getResultCode(),511);
99 assertEquals(opResult.getFailureCause(), "things melting");