aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openecomp/restclient/client/OperationResultTest.java
blob: df8587730fcba3298b5977d359c5bf72e72b652e (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
package org.openecomp.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.MultivaluedMap;

import org.junit.Before;
import org.junit.Test;

import com.sun.jersey.core.util.MultivaluedMapImpl;

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 MultivaluedMapImpl();
    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");
    
  }
    
}