aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/restclient/client/OperationResultTest.java
blob: c002b97600c128445876b158c8c699ce811a1181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017 Amdocs
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 *
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 */
package org.onap.aai.restclient.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.junit.Before;
import org.junit.Test;

public class OperationResultTest {

  /**
   * Test case initialization
   * 
   * @throws Exception the exception
   */
  @Before
  public void init() throws Exception {
  }
  
  @Test
  public void validateConstruction() {
    
    OperationResult opResult = new OperationResult();
    assertEquals(opResult.getNumRetries(),0);
    assertFalse(opResult.isFromCache());
    assertFalse(opResult.wasSuccessful());
    opResult.setResultCode(612);
    assertFalse(opResult.wasSuccessful());
    assertNull(opResult.getHeaders());
    
    opResult = new OperationResult(204,"no content found");
    assertEquals(opResult.getResultCode(),204);
    assertEquals(opResult.getResult(),"no content found");
    assertTrue(opResult.wasSuccessful());
    
    MultivaluedMap<String,String> multiMap = new MultivaluedHashMap<>();
    multiMap.add("p1","v1");
    multiMap.add("p2","v2");
    opResult.setHeaders(multiMap);
    assertNotNull(opResult.getHeaders());
    assertEquals(opResult.getHeaders().size(), 2);
    
  }
  
  @Test
  public void validateAccesors() {
    
    OperationResult opResult = new OperationResult();
    
    opResult.setFailureCause("failure");
    opResult.setFromCache(false);
    opResult.setNumRetries(101);
    opResult.setRequestedLink("http://localhost:1234");
    opResult.setResult("result");
    opResult.setResultCode(555);

    assertEquals(opResult.getFailureCause(), "failure");
    assertFalse(opResult.isFromCache());
    assertEquals(opResult.getNumRetries(),101);
    assertEquals(opResult.getRequestedLink(),"http://localhost:1234");
    assertEquals(opResult.getResult(), "result");
    assertEquals(opResult.getResultCode(),555);
    
    opResult.setResult(212, "mostly successful");
    assertEquals(opResult.getResultCode(),212);
    assertEquals(opResult.getResult(), "mostly successful");
    
    assertTrue(opResult.toString().contains("OperationResult"));
    
    opResult.setFailureCause(511, "things melting");
    assertEquals(opResult.getResultCode(),511);
    assertEquals(opResult.getFailureCause(), "things melting");
    
  }
    
}