@Test public void testAndroidRequest() throws AuthException, MalformedURLException, RequestException { runtimeConfig.setPlatform(UAirship.ANDROID_PLATFORM); when(mockAuthManager.getToken()).thenReturn("some_token"); URL url = new URL("https: client.performRequest(url, "channel", null, EMPTY_TAGS, EMPTY_ATTRIBUTES); assertEquals(url, testRequest.getUrl()); assertEquals("POST", testRequest.getRequestMethod()); assertEquals("Bearer some_token", testRequest.getRequestHeaders().get("Authorization")); JsonMap expected = JsonMap.newBuilder() .put("platform", "android") .put("channel_id", "channel") .build(); assertEquals(expected.toString(), testRequest.getRequestBody()); }
public Response<Result> performRequest(@NonNull URL url, @NonNull String channelId, @Nullable TriggerContext triggerContext, @NonNull List<TagGroupsMutation> tagOverrides, @NonNull List<AttributeMutation> attributeOverrides) throws RequestException, AuthException { String token = authManager.getToken(); JsonMap.Builder requestBodyBuilder = JsonMap.newBuilder() .put(PLATFORM_KEY, runtimeConfig.getPlatform() == UAirship.AMAZON_PLATFORM ? PLATFORM_AMAZON : PLATFORM_ANDROID) .put(CHANNEL_ID_KEY, channelId); if (triggerContext != null) { requestBodyBuilder.put(TRIGGER_KEY, JsonMap.newBuilder() .put(TRIGGER_TYPE_KEY, triggerContext.getTrigger().getTriggerName()) .put(TRIGGER_GOAL_KEY, triggerContext.getTrigger().getGoal()) .put(TRIGGER_EVENT_KEY, triggerContext.getEvent()) .build()); } if (!tagOverrides.isEmpty()) { requestBodyBuilder.put(TAG_OVERRIDES_KEY, JsonValue.wrapOpt(tagOverrides)); } if (!attributeOverrides.isEmpty()) { requestBodyBuilder.put(ATTRIBUTE_OVERRIDES_KEY, JsonValue.wrapOpt(attributeOverrides)); } JsonMap requestBody = requestBodyBuilder.build(); Response<Result> response = performRequest(url, token, requestBody); if (response.getStatus() == HttpsURLConnection.HTTP_UNAUTHORIZED) { authManager.tokenExpired(token); return performRequest(url, authManager.getToken(), requestBody); } else { return response; } }
DeferredScheduleClient { public Response<Result> performRequest(@NonNull URL url, @NonNull String channelId, @Nullable TriggerContext triggerContext, @NonNull List<TagGroupsMutation> tagOverrides, @NonNull List<AttributeMutation> attributeOverrides) throws RequestException, AuthException { String token = authManager.getToken(); JsonMap.Builder requestBodyBuilder = JsonMap.newBuilder() .put(PLATFORM_KEY, runtimeConfig.getPlatform() == UAirship.AMAZON_PLATFORM ? PLATFORM_AMAZON : PLATFORM_ANDROID) .put(CHANNEL_ID_KEY, channelId); if (triggerContext != null) { requestBodyBuilder.put(TRIGGER_KEY, JsonMap.newBuilder() .put(TRIGGER_TYPE_KEY, triggerContext.getTrigger().getTriggerName()) .put(TRIGGER_GOAL_KEY, triggerContext.getTrigger().getGoal()) .put(TRIGGER_EVENT_KEY, triggerContext.getEvent()) .build()); } if (!tagOverrides.isEmpty()) { requestBodyBuilder.put(TAG_OVERRIDES_KEY, JsonValue.wrapOpt(tagOverrides)); } if (!attributeOverrides.isEmpty()) { requestBodyBuilder.put(ATTRIBUTE_OVERRIDES_KEY, JsonValue.wrapOpt(attributeOverrides)); } JsonMap requestBody = requestBodyBuilder.build(); Response<Result> response = performRequest(url, token, requestBody); if (response.getStatus() == HttpsURLConnection.HTTP_UNAUTHORIZED) { authManager.tokenExpired(token); return performRequest(url, authManager.getToken(), requestBody); } else { return response; } } }
DeferredScheduleClient { public Response<Result> performRequest(@NonNull URL url, @NonNull String channelId, @Nullable TriggerContext triggerContext, @NonNull List<TagGroupsMutation> tagOverrides, @NonNull List<AttributeMutation> attributeOverrides) throws RequestException, AuthException { String token = authManager.getToken(); JsonMap.Builder requestBodyBuilder = JsonMap.newBuilder() .put(PLATFORM_KEY, runtimeConfig.getPlatform() == UAirship.AMAZON_PLATFORM ? PLATFORM_AMAZON : PLATFORM_ANDROID) .put(CHANNEL_ID_KEY, channelId); if (triggerContext != null) { requestBodyBuilder.put(TRIGGER_KEY, JsonMap.newBuilder() .put(TRIGGER_TYPE_KEY, triggerContext.getTrigger().getTriggerName()) .put(TRIGGER_GOAL_KEY, triggerContext.getTrigger().getGoal()) .put(TRIGGER_EVENT_KEY, triggerContext.getEvent()) .build()); } if (!tagOverrides.isEmpty()) { requestBodyBuilder.put(TAG_OVERRIDES_KEY, JsonValue.wrapOpt(tagOverrides)); } if (!attributeOverrides.isEmpty()) { requestBodyBuilder.put(ATTRIBUTE_OVERRIDES_KEY, JsonValue.wrapOpt(attributeOverrides)); } JsonMap requestBody = requestBodyBuilder.build(); Response<Result> response = performRequest(url, token, requestBody); if (response.getStatus() == HttpsURLConnection.HTTP_UNAUTHORIZED) { authManager.tokenExpired(token); return performRequest(url, authManager.getToken(), requestBody); } else { return response; } } DeferredScheduleClient(@NonNull AirshipRuntimeConfig runtimeConfig, @NonNull AuthManager authManager); @VisibleForTesting  DeferredScheduleClient(@NonNull AirshipRuntimeConfig runtimeConfig,
                           @NonNull AuthManager authManager,
                           @NonNull RequestFactory requestFactory); }
DeferredScheduleClient { public Response<Result> performRequest(@NonNull URL url, @NonNull String channelId, @Nullable TriggerContext triggerContext, @NonNull List<TagGroupsMutation> tagOverrides, @NonNull List<AttributeMutation> attributeOverrides) throws RequestException, AuthException { String token = authManager.getToken(); JsonMap.Builder requestBodyBuilder = JsonMap.newBuilder() .put(PLATFORM_KEY, runtimeConfig.getPlatform() == UAirship.AMAZON_PLATFORM ? PLATFORM_AMAZON : PLATFORM_ANDROID) .put(CHANNEL_ID_KEY, channelId); if (triggerContext != null) { requestBodyBuilder.put(TRIGGER_KEY, JsonMap.newBuilder() .put(TRIGGER_TYPE_KEY, triggerContext.getTrigger().getTriggerName()) .put(TRIGGER_GOAL_KEY, triggerContext.getTrigger().getGoal()) .put(TRIGGER_EVENT_KEY, triggerContext.getEvent()) .build()); } if (!tagOverrides.isEmpty()) { requestBodyBuilder.put(TAG_OVERRIDES_KEY, JsonValue.wrapOpt(tagOverrides)); } if (!attributeOverrides.isEmpty()) { requestBodyBuilder.put(ATTRIBUTE_OVERRIDES_KEY, JsonValue.wrapOpt(attributeOverrides)); } JsonMap requestBody = requestBodyBuilder.build(); Response<Result> response = performRequest(url, token, requestBody); if (response.getStatus() == HttpsURLConnection.HTTP_UNAUTHORIZED) { authManager.tokenExpired(token); return performRequest(url, authManager.getToken(), requestBody); } else { return response; } } DeferredScheduleClient(@NonNull AirshipRuntimeConfig runtimeConfig, @NonNull AuthManager authManager); @VisibleForTesting  DeferredScheduleClient(@NonNull AirshipRuntimeConfig runtimeConfig,
                           @NonNull AuthManager authManager,
                           @NonNull RequestFactory requestFactory); Response<Result> performRequest(@NonNull URL url,
                                           @NonNull String channelId,
                                           @Nullable TriggerContext triggerContext,
                                           @NonNull List<TagGroupsMutation> tagOverrides,
                                           @NonNull List<AttributeMutation> attributeOverrides); }
DeferredScheduleClient { public Response<Result> performRequest(@NonNull URL url, @NonNull String channelId, @Nullable TriggerContext triggerContext, @NonNull List<TagGroupsMutation> tagOverrides, @NonNull List<AttributeMutation> attributeOverrides) throws RequestException, AuthException { String token = authManager.getToken(); JsonMap.Builder requestBodyBuilder = JsonMap.newBuilder() .put(PLATFORM_KEY, runtimeConfig.getPlatform() == UAirship.AMAZON_PLATFORM ? PLATFORM_AMAZON : PLATFORM_ANDROID) .put(CHANNEL_ID_KEY, channelId); if (triggerContext != null) { requestBodyBuilder.put(TRIGGER_KEY, JsonMap.newBuilder() .put(TRIGGER_TYPE_KEY, triggerContext.getTrigger().getTriggerName()) .put(TRIGGER_GOAL_KEY, triggerContext.getTrigger().getGoal()) .put(TRIGGER_EVENT_KEY, triggerContext.getEvent()) .build()); } if (!tagOverrides.isEmpty()) { requestBodyBuilder.put(TAG_OVERRIDES_KEY, JsonValue.wrapOpt(tagOverrides)); } if (!attributeOverrides.isEmpty()) { requestBodyBuilder.put(ATTRIBUTE_OVERRIDES_KEY, JsonValue.wrapOpt(attributeOverrides)); } JsonMap requestBody = requestBodyBuilder.build(); Response<Result> response = performRequest(url, token, requestBody); if (response.getStatus() == HttpsURLConnection.HTTP_UNAUTHORIZED) { authManager.tokenExpired(token); return performRequest(url, authManager.getToken(), requestBody); } else { return response; } } DeferredScheduleClient(@NonNull AirshipRuntimeConfig runtimeConfig, @NonNull AuthManager authManager); @VisibleForTesting  DeferredScheduleClient(@NonNull AirshipRuntimeConfig runtimeConfig,
                           @NonNull AuthManager authManager,
                           @NonNull RequestFactory requestFactory); Response<Result> performRequest(@NonNull URL url,
                                           @NonNull String channelId,
                                           @Nullable TriggerContext triggerContext,
                                           @NonNull List<TagGroupsMutation> tagOverrides,
                                           @NonNull List<AttributeMutation> attributeOverrides);  }