Github user GERey commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/232#discussion_r28729020
  
    --- Diff: 
stack/rest/src/test/java/org/apache/usergrid/rest/filters/ContentTypeResourceIT.java
 ---
    @@ -105,106 +75,84 @@ public void correctHeaders() throws Exception {
          */
         @Test
         public void textPlainContentType() throws Exception {
    -        Map<String, String> data = hashMap( "name", "Solitaire2" );
    -
    -        String json = JsonUtils.mapToFormattedJsonString( data );
    -
    -        DefaultHttpClient client = new DefaultHttpClient();
    -
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), 
super.getBaseURI().getPort() );
    +        refreshIndex();
    +        String json = JsonUtils.mapToFormattedJsonString(hashMap("name", 
"Solitaire2"));
    +        WebResource.Builder builder = 
app().collection("games").getResource(true, getAdminToken())
    +            .accept(MediaType.APPLICATION_JSON)
    +            .type(MediaType.APPLICATION_JSON);
     
    -        HttpPost post = new HttpPost( String.format( "/%s/%s/games", 
context.getOrgUuid(), context.getAppUuid() ) );
    -        post.setEntity( new StringEntity( json ) );
    -        post.setHeader( HttpHeaders.AUTHORIZATION, "Bearer " + 
context.getActiveUser().getToken() );
    -        post.setHeader( HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON );
    -        post.setHeader( HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN );
    +        ClientResponse clientResponse = builder.post(ClientResponse.class, 
json);
     
    -        HttpResponse rsp = client.execute( host, post );
    +        assertEquals(200, clientResponse.getStatus());
     
    -        printResponse( rsp );
    +        MultivaluedMap<String, String> headers = 
clientResponse.getHeaders();
     
    -        assertEquals( 200, rsp.getStatusLine().getStatusCode() );
    +        List<String> contentType = headers.get("Content-Type");
    +        assertEquals(1, contentType.size());
    +        assertEquals(MediaType.APPLICATION_JSON, contentType.get(0));
     
    -        Header[] headers = rsp.getHeaders( HttpHeaders.CONTENT_TYPE );
    -
    -        assertEquals( 1, headers.length );
    -
    -        assertEquals( MediaType.APPLICATION_JSON, headers[0].getValue() );
         }
     
     
    -    /** Tests that application/x-www-url-form-encoded works correctly */
    +    /**
    +     * Tests that application/x-www-url-form-encoded works correctly
    +     */
         @Test
         public void formEncodedContentType() throws Exception {
     
    -        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
     
    -        pairs.add( new BasicNameValuePair( "organization", 
"formContentOrg" ) );
    -        pairs.add( new BasicNameValuePair( "username", "formContentOrg" ) 
);
    -        pairs.add( new BasicNameValuePair( "name", "Test User" ) );
    -        pairs.add( new BasicNameValuePair( "email", 
UUIDUtils.newTimeUUID() + "@usergrid.org" ) );
    -        pairs.add( new BasicNameValuePair( "password", "foobar" ) );
    +        Form payload = new Form();
    +        payload.add("access_token", getAdminToken().toString());
    +        payload.add("organization", "formContentOrg");
    +        payload.add("username", "formContentOrg");
    +        payload.add("name", "Test User");
    +        payload.add("email", UUIDUtils.newTimeUUID() + "@usergrid.org");
    +        payload.add("password", "foobar");
     
    -        UrlEncodedFormEntity entity = new UrlEncodedFormEntity( pairs, 
"UTF-8" );
     
    -        DefaultHttpClient client = new DefaultHttpClient();
    +        ClientResponse clientResponse = app().users().getResource(false)
    +            .accept(MediaType.APPLICATION_JSON)
    +            .type(MediaType.APPLICATION_FORM_URLENCODED)
    +            .post(ClientResponse.class, payload);
     
    -        HttpHost host = new HttpHost( super.getBaseURI().getHost(), 
super.getBaseURI().getPort() );
    +        assertEquals(200, clientResponse.getStatus());
     
    -        HttpPost post = new HttpPost( "/management/orgs" );
    -        post.setEntity( entity );
    -        // post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + 
context.getActiveUser().getToken());
    +        MultivaluedMap<String, String> headers = 
clientResponse.getHeaders();
     
    -        post.setHeader( HttpHeaders.CONTENT_TYPE, 
MediaType.APPLICATION_FORM_URLENCODED );
    -
    -        HttpResponse rsp = client.execute( host, post );
    -
    -        printResponse( rsp );
    -
    -        // should be an error, no content type was set
    -        assertEquals( 200, rsp.getStatusLine().getStatusCode() );
    -
    -        Header[] headers = rsp.getHeaders( HttpHeaders.CONTENT_TYPE );
    -
    -        assertEquals( 1, headers.length );
    -
    -        assertEquals( MediaType.APPLICATION_JSON, headers[0].getValue() );
    +        List<String> contentType = headers.get("Content-Type");
    +        assertEquals(1, contentType.size());
    +        assertEquals(MediaType.APPLICATION_JSON, contentType.get(0));
         }
     
     
    -    /** Tests that application/x-www-url-form-encoded works correctly */
    +    /**
    +     * Tests that application/x-www-url-form-encoded works correctly
    +     */
         @Test
         @Ignore("This will only pass in tomcat, and shouldn't pass in grizzly")
    --- End diff --
    
    We aren't using grizzly anymore ( at least I'm pretty sure we don't ). So 
this test should pass.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to