View Javadoc

1   package it.com.atlassian.rest.json;
2   
3   import com.atlassian.rest.jersey.client.WebResourceFactory;
4   import com.sun.jersey.api.client.WebResource;
5   import com.sun.jersey.core.util.MultivaluedMapImpl;
6   import org.junit.Before;
7   import org.junit.Test;
8   
9   import javax.ws.rs.core.MediaType;
10  import javax.ws.rs.core.MultivaluedMap;
11  
12  import static com.atlassian.rest.jersey.client.WebResourceFactory.REST_VERSION;
13  import static it.com.atlassian.rest.test.ProjectsTest.JSONP_CALLBACK_PARAMETER_NAME;
14  import static it.com.atlassian.rest.test.ProjectsTest.JSONP_CALLBACK_TEST_FUNCTION_NAME;
15  import static org.hamcrest.CoreMatchers.equalTo;
16  import static org.hamcrest.core.IsNot.not;
17  import static org.junit.Assert.assertThat;
18  import static org.junit.matchers.JUnitMatchers.containsString;
19  
20  /**
21   * Json with Padding must be DISABLED in the REST plugin module for these tests to pass.
22   * Currently this is done by setting the following system property {@link com.atlassian.plugins.rest.module.json.JsonWithPaddingResponseFilter#ATLASSIAN_ALLOW_JSONP}
23   * to 'true'
24   */
25  public class JsonWithPaddingDisabledTest {
26      private WebResource webResourceWithVersion;
27  
28      @Before
29      public void setUp() {
30          webResourceWithVersion = WebResourceFactory.authenticated(REST_VERSION).path("projects");
31      }
32  
33      @Test
34      public void testGetProjectsWithJsonDoesNotContainJsonpCallbackWhenJsonPDisabled() {
35          final String projectsJson = webResourceWithVersion.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
36  
37          final MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
38          queryParams.putSingle(JSONP_CALLBACK_PARAMETER_NAME, JSONP_CALLBACK_TEST_FUNCTION_NAME);
39  
40          final String projectsJsonP = webResourceWithVersion.queryParams(queryParams).accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
41          assertThat(projectsJsonP, not(containsString(JSONP_CALLBACK_TEST_FUNCTION_NAME)));
42  
43          assertThat(projectsJsonP, equalTo(projectsJson));
44      }
45  
46  }