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.MultivaluedMap;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aai.restclient.client.OperationResult;
37 import com.sun.jersey.core.util.MultivaluedMapImpl;
39 public class OperationResultTest {
42 * Test case initialization
44 * @throws Exception the exception
47 public void init() throws Exception {
51 public void validateConstruction() {
53 OperationResult opResult = new OperationResult();
54 assertEquals(opResult.getNumRetries(),0);
55 assertFalse(opResult.isFromCache());
56 assertFalse(opResult.wasSuccessful());
57 opResult.setResultCode(612);
58 assertFalse(opResult.wasSuccessful());
59 assertNull(opResult.getHeaders());
61 opResult = new OperationResult(204,"no content found");
62 assertEquals(opResult.getResultCode(),204);
63 assertEquals(opResult.getResult(),"no content found");
64 assertTrue(opResult.wasSuccessful());
66 MultivaluedMap<String,String> multiMap = new MultivaluedMapImpl();
67 multiMap.add("p1","v1");
68 multiMap.add("p2","v2");
69 opResult.setHeaders(multiMap);
70 assertNotNull(opResult.getHeaders());
71 assertEquals(opResult.getHeaders().size(), 2);
76 public void validateAccesors() {
78 OperationResult opResult = new OperationResult();
80 opResult.setFailureCause("failure");
81 opResult.setFromCache(false);
82 opResult.setNumRetries(101);
83 opResult.setRequestedLink("http://localhost:1234");
84 opResult.setResult("result");
85 opResult.setResultCode(555);
87 assertEquals(opResult.getFailureCause(), "failure");
88 assertFalse(opResult.isFromCache());
89 assertEquals(opResult.getNumRetries(),101);
90 assertEquals(opResult.getRequestedLink(),"http://localhost:1234");
91 assertEquals(opResult.getResult(), "result");
92 assertEquals(opResult.getResultCode(),555);
94 opResult.setResult(212, "mostly successful");
95 assertEquals(opResult.getResultCode(),212);
96 assertEquals(opResult.getResult(), "mostly successful");
98 assertTrue(opResult.toString().contains("OperationResult"));
100 opResult.setFailureCause(511, "things melting");
101 assertEquals(opResult.getResultCode(),511);
102 assertEquals(opResult.getFailureCause(), "things melting");