AttributeApiClient { @NonNull Response<Void> updateAttributes(@NonNull String identifier, @NonNull List<AttributeMutation> mutations) throws RequestException { URL url = urlFactory.createUrl(runtimeConfig, identifier); JsonMap attributePayload = JsonMap.newBuilder() .putOpt(ATTRIBUTE_PAYLOAD_KEY, mutations) .build(); Logger.verbose("Updating attributes for Id:%s with payload: %s", identifier, attributePayload); return requestFactory.createRequest() .setOperation("POST", url) .setCredentials(runtimeConfig.getConfigOptions().appKey, runtimeConfig.getConfigOptions().appSecret) .setRequestBody(attributePayload) .setAirshipJsonAcceptsHeader() .execute(); } @VisibleForTesting  AttributeApiClient(@NonNull AirshipRuntimeConfig runtimeConfig,
                       @NonNull RequestFactory requestFactory,
                       @NonNull UrlFactory urlFactory); static AttributeApiClient namedUserClient(AirshipRuntimeConfig runtimeConfig); static AttributeApiClient channelClient(AirshipRuntimeConfig runtimeConfig);  }
@Test public void testAttributeUpdateAndroidChannel() throws JsonException, RequestException { AttributeApiClient client = new AttributeApiClient(runtimeConfig, requestFactory, AttributeApiClient.CHANNEL_URL_FACTORY); testRequest.responseStatus = 200; Response<Void> response = client.updateAttributes("expected_identifier", mutations); JsonMap expectedBody = JsonMap.newBuilder() .putOpt("attributes", mutations) .build(); assertEquals("https: assertEquals("POST", testRequest.getRequestMethod()); assertEquals(expectedBody, JsonValue.parseString(testRequest.getRequestBody())); assertEquals(200, response.getStatus()); }
@Test public void testAttributeUpdateAmazonChannel() throws JsonException, RequestException { runtimeConfig.setPlatform(UAirship.AMAZON_PLATFORM); AttributeApiClient client = new AttributeApiClient(runtimeConfig, requestFactory, AttributeApiClient.CHANNEL_URL_FACTORY); testRequest.responseStatus = 200; Response<Void> response = client.updateAttributes("expected_identifier", mutations); JsonMap expectedBody = JsonMap.newBuilder() .putOpt("attributes", mutations) .build(); assertEquals("https: assertEquals("POST", testRequest.getRequestMethod()); assertEquals(expectedBody, JsonValue.parseString(testRequest.getRequestBody())); assertEquals(200, response.getStatus()); }
@Test public void testAttributeUpdateNamedUser() throws JsonException, RequestException { AttributeApiClient client = new AttributeApiClient(runtimeConfig, requestFactory, AttributeApiClient.NAMED_USER_URL_FACTORY); testRequest.responseStatus = 200; Response<Void> response = client.updateAttributes("expected_identifier", mutations); JsonMap expectedBody = JsonMap.newBuilder() .putOpt("attributes", mutations) .build(); assertEquals("https: assertEquals("POST", testRequest.getRequestMethod()); assertEquals(expectedBody, JsonValue.parseString(testRequest.getRequestBody())); assertEquals(200, response.getStatus()); }