urbanairship-core/src/test/java/com/urbanairship/remotedata/RemoteDataApiClientTest.java
@Test
    public void testFetchRemoteDataRequestSuccess() throws Exception {
        String responseTimestamp = DateUtils.createIso8601TimeStamp(System.currentTimeMillis());

        Map<String, List<String>> headers = new HashMap<>();
        headers.put("Last-Modified", Arrays.asList(new String[] { responseTimestamp }));

        JsonMap map = JsonMap.newBuilder().put("foo", "bar").build();
        JsonMap payload = JsonMap.newBuilder().put("type", "test").put("timestamp", responseTimestamp).put("data", map).build();
        JsonList list = new JsonList(Arrays.asList(payload.toJsonValue()));

        testRequest.response = new Response.Builder(HttpURLConnection.HTTP_OK)
                .setResponseHeaders(headers)
                .setResponseMessage("OK")
                .setResponseBody(list.toString())
                .create();

        String requestTimestamp = DateUtils.createIso8601TimeStamp(0);
        Response response = client.fetchRemoteData(requestTimestamp);

        assertEquals("https://remote-data.urbanairship.com/api/remote-data/app/appKey/android?sdk_version=" + UAirship.getVersion(), testRequest.getURL().toString());
        assertEquals("Headers should contain timestamp", testRequest.getRequestHeaders().get("If-Modified-Since"), requestTimestamp);
        assertNotNull("Response should not be null", response);
        assertEquals("Response status should be 200", HttpURLConnection.HTTP_OK, response.getStatus());
        assertEquals("Response should be the JSON list", response.getResponseBody(), list.toString());
        assertEquals("Last-Modified should match with timestamp", responseTimestamp, response.getResponseHeader("Last-Modified"));
    }
/**
     * Test fetch remote data request on success
     */
Test fetch remote data request on success
Test fetch remote data request on success
@Test
    public void testFetchRemoteDataRequestSuccess() throws Exception {
        String responseTimestamp = DateUtils.createIso8601TimeStamp(System.currentTimeMillis());
        Map<String, List<String>> headers = new HashMap<>();
        headers.put("Last-Modified", Arrays.asList(new String[] { responseTimestamp }));
        JsonMap map = JsonMap.newBuilder().put("foo", "bar").build();
        JsonMap payload = JsonMap.newBuilder().put("type", "test").put("timestamp", responseTimestamp).put("data", map).build();
        JsonList list = new JsonList(Arrays.asList(payload.toJsonValue()));
        testRequest.response = new Response.Builder(HttpURLConnection.HTTP_OK)
                .setResponseHeaders(headers)
                .setResponseMessage("OK")
                .setResponseBody(list.toString())
                .create();
        String requestTimestamp = DateUtils.createIso8601TimeStamp(0);
        Response response = client.fetchRemoteData(requestTimestamp);
        assertEquals("https://remote-data.urbanairship.com/api/remote-data/app/appKey/android?sdk_version=" + UAirship.getVersion(), testRequest.getURL().toString());
        assertEquals("Headers should contain timestamp", testRequest.getRequestHeaders().get("If-Modified-Since"), requestTimestamp);
        assertNotNull("Response should not be null", response);
        assertEquals("Response status should be 200", HttpURLConnection.HTTP_OK, response.getStatus());
        assertEquals("Response should be the JSON list", response.getResponseBody(), list.toString());
        assertEquals("Last-Modified should match with timestamp", responseTimestamp, response.getResponseHeader("Last-Modified"));
    }
@ Test public void testFetchRemoteDataRequestSuccess ( ) throws Exception { String responseTimestamp = DateUtils . createIso8601TimeStamp ( System . currentTimeMillis ( ) ) ; Map < String , List < String > > headers = new HashMap < > ( ) ; headers . put ( "Last-Modified" , Arrays . asList ( new String [ ] { responseTimestamp } ) ) ; JsonMap map = JsonMap . newBuilder ( ) . put ( "foo" , "bar" ) . build ( ) ; JsonMap payload = JsonMap . newBuilder ( ) . put ( "type" , "test" ) . put ( "timestamp" , responseTimestamp ) . put ( "data" , map ) . build ( ) ; JsonList list = new JsonList ( Arrays . asList ( payload . toJsonValue ( ) ) ) ; testRequest . response = new Response . Builder ( HttpURLConnection . HTTP_OK ) . setResponseHeaders ( headers ) . setResponseMessage ( "OK" ) . setResponseBody ( list . toString ( ) ) . create ( ) ; String requestTimestamp = DateUtils . createIso8601TimeStamp ( 0 ) ; Response response = client . fetchRemoteData ( requestTimestamp ) ; assertEquals ( "https://remote-data.urbanairship.com/api/remote-data/app/appKey/android?sdk_version=" + UAirship . getVersion ( ) , testRequest . getURL ( ) . toString ( ) ) ; assertEquals ( "Headers should contain timestamp" , testRequest . getRequestHeaders ( ) . get ( "If-Modified-Since" ) , requestTimestamp ) ; assertNotNull ( "Response should not be null" , response ) ; assertEquals ( "Response status should be 200" , HttpURLConnection . HTTP_OK , response . getStatus ( ) ) ; assertEquals ( "Response should be the JSON list" , response . getResponseBody ( ) , list . toString ( ) ) ; assertEquals ( "Last-Modified should match with timestamp" , responseTimestamp , response . getResponseHeader ( "Last-Modified" ) ) ; }
Test fetch remote data request on success
Test fetch remote data request on success