View Javadoc

1   package com.atlassian.plugins.rest.sample.entities;
2   
3   import org.junit.Test;
4   
5   import javax.ws.rs.core.HttpHeaders;
6   import java.util.ArrayList;
7   
8   import static org.easymock.EasyMock.*;
9   import static org.junit.Assert.assertEquals;
10  
11  public class EntityTest
12  {
13      private EntityResource entity = new EntityResource();
14  
15      @Test
16      public void testApplesForOranges()
17      {
18          HttpHeaders headers = createMock(HttpHeaders.class);
19          expect(headers.getRequestHeader("Content-Type")).andReturn(new ArrayList<String>()).once();
20          expect(headers.getRequestHeader("Accept")).andReturn(new ArrayList<String>()).once();
21          replay(headers);
22          Apple apple = (Apple) entity.applesForOranges(new Orange("valencia"), headers).getEntity();
23          assertEquals("apple-valencia", apple.getName());
24          assertEquals("N/A", apple.getReqAccept());
25          assertEquals("N/A", apple.getReqContentType());
26          verify(headers);
27  
28          reset(headers);
29          expect(headers.getRequestHeader("Content-Type")).andReturn(new ArrayList<String>()
30          {{
31                  add("application/json");
32              }}).once();
33          expect(headers.getRequestHeader("Accept")).andReturn(new ArrayList<String>()
34          {{
35                  add("application/xml");
36              }}).once();
37          replay(headers);
38          apple = (Apple) entity.applesForOranges(new Orange("delfino"), headers).getEntity();
39          assertEquals("apple-delfino", apple.getName());
40          assertEquals("application/json", apple.getReqContentType());
41          assertEquals("application/xml", apple.getReqAccept());
42          verify(headers);
43  
44          reset(headers);
45          expect(headers.getRequestHeader("Content-Type")).andReturn(new ArrayList<String>()
46          {{
47                  add("application/json");
48              }}).once();
49          expect(headers.getRequestHeader("Accept")).andReturn(new ArrayList<String>()
50          {{
51                  add("application/xml");
52                  add("application/json");
53                  add("image/png");
54              }}).once();
55          replay(headers);
56          apple = (Apple) entity.applesForOranges(new Orange("delfino"), headers).getEntity();
57          assertEquals("apple-delfino", apple.getName());
58          assertEquals("application/json", apple.getReqContentType());
59          assertEquals("application/xml,application/json,image/png", apple.getReqAccept());
60          verify(headers);
61      }
62  
63  }