urbanairship-core/src/test/java/com/urbanairship/push/ChannelApiClientTest.java
@Test
    public void testCreateChannelSucceedsRequest() throws Exception {
        String channelLocation = "https://go.urbanairship.com/api/channels/someChannelId";

        Map<String, List<String>> headers = new HashMap<>();
        headers.put("Location", Arrays.asList(new String[] { channelLocation }));

        testRequest.response = new Response.Builder(HttpURLConnection.HTTP_OK)
                .setResponseHeaders(headers)
                .setResponseMessage("OK")
                .setResponseBody("{ \"ok\": true, \"channel_id\": \"someChannelId\"}")
                .create();

        Response response = client.createChannelWithPayload(payload);

        assertNotNull("Channel response should not be null", response);
        assertEquals("Channel request should be the JSON payload", testRequest.getRequestBody(), payload.toJsonValue().toString());
        assertEquals("Channel response status should be 200", HttpURLConnection.HTTP_OK,
                response.getStatus());
        assertEquals("Channel ID should match with response", "someChannelId",
                JsonValue.parseString(response.getResponseBody()).optMap().opt(CHANNEL_ID_KEY).getString());
        assertEquals("Channel location should match with response", channelLocation,
                response.getResponseHeader(CHANNEL_LOCATION_KEY));
    }
/**
     * Test create channel succeeds request if the status is 200
     */
Test create channel succeeds request if the status is 200
Test create channel succeeds request if the status is 200
@Test
    public void testCreateChannelSucceedsRequest() throws Exception {
        String channelLocation = "https://go.urbanairship.com/api/channels/someChannelId";
        Map<String, List<String>> headers = new HashMap<>();
        headers.put("Location", Arrays.asList(new String[] { channelLocation }));
        testRequest.response = new Response.Builder(HttpURLConnection.HTTP_OK)
                .setResponseHeaders(headers)
                .setResponseMessage("OK")
                .setResponseBody("{ \"ok\": true, \"channel_id\": \"someChannelId\"}")
                .create();
        Response response = client.createChannelWithPayload(payload);
        assertNotNull("Channel response should not be null", response);
        assertEquals("Channel request should be the JSON payload", testRequest.getRequestBody(), payload.toJsonValue().toString());
        assertEquals("Channel response status should be 200", HttpURLConnection.HTTP_OK,
                response.getStatus());
        assertEquals("Channel ID should match with response", "someChannelId",
                JsonValue.parseString(response.getResponseBody()).optMap().opt(CHANNEL_ID_KEY).getString());
        assertEquals("Channel location should match with response", channelLocation,
                response.getResponseHeader(CHANNEL_LOCATION_KEY));
    }
@ Test public void testCreateChannelSucceedsRequest ( ) throws Exception { String channelLocation = "https://go.urbanairship.com/api/channels/someChannelId" ; Map < String , List < String > > headers = new HashMap < > ( ) ; headers . put ( "Location" , Arrays . asList ( new String [ ] { channelLocation } ) ) ; testRequest . response = new Response . Builder ( HttpURLConnection . HTTP_OK ) . setResponseHeaders ( headers ) . setResponseMessage ( "OK" ) . setResponseBody ( "{ \"ok\": true, \"channel_id\": \"someChannelId\"}" ) . create ( ) ; Response response = client . createChannelWithPayload ( payload ) ; assertNotNull ( "Channel response should not be null" , response ) ; assertEquals ( "Channel request should be the JSON payload" , testRequest . getRequestBody ( ) , payload . toJsonValue ( ) . toString ( ) ) ; assertEquals ( "Channel response status should be 200" , HttpURLConnection . HTTP_OK , response . getStatus ( ) ) ; assertEquals ( "Channel ID should match with response" , "someChannelId" , JsonValue . parseString ( response . getResponseBody ( ) ) . optMap ( ) . opt ( CHANNEL_ID_KEY ) . getString ( ) ) ; assertEquals ( "Channel location should match with response" , channelLocation , response . getResponseHeader ( CHANNEL_LOCATION_KEY ) ) ; }
Test create channel succeeds request if the status is 200
Test create channel succeeds request if the status is 200