play.libs.Json.stringify()

Here are the examples of the java api play.libs.Json.stringify() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

23 Examples 7

18 Source : TestRestliStreamServerComponent.java
with BSD 2-Clause "Simplified" License
from linkedin

private byte[] jsonToBytes(JsonNode json) throws UnsupportedEncodingException {
    return Json.stringify(json).getBytes(CHARSET);
}

18 Source : StorageWriteLock.java
with MIT License
from Azure

private CompletionStage<String> updateValueAsync(T value, String etag) throws ResourceNotFoundException, ExternalDependencyException, ConflictingResourceException {
    return this.client.updateAsync(this.collectionId, this.key, Json.stringify(Json.toJson(value)), etag).thenApplyAsync(m -> m.getETag());
}

18 Source : Storage.java
with MIT License
from Azure

private static <T> String toJson(T o) {
    return Json.stringify(Json.toJson(o));
}

17 Source : StorageTest.java
with MIT License
from Azure

@Test(timeout = StorageTest.TIMEOUT)
@Category({ UnitTest.clreplaced })
public void getDeviceGroupsAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String groupId = rand.NextString();
    String displayName = rand.NextString();
    Iterable<DeviceGroupCondition> conditions = null;
    String etag = rand.NextString();
    ValueApiModel model = new ValueApiModel(groupId, null, etag, null);
    DeviceGroup group = new DeviceGroup();
    group.setDisplayName(displayName);
    group.setConditions(conditions);
    model.setData(Json.stringify(Json.toJson(group)));
    Mockito.when(mockClient.getAsync(Mockito.any(String.clreplaced), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    DeviceGroup result = storage.getDeviceGroupAsync(groupId).toCompletableFuture().get();
    replacedertEquals(result.getDisplayName(), displayName);
    replacedertEquals(result.getConditions(), conditions);
}

16 Source : Jobs.java
with MIT License
from Azure

@Override
public CompletionStage<JobServiceModel> scheduleTwinUpdateAsync(String jobId, String queryCondition, TwinServiceModel twin, Date startTime, long maxExecutionTimeInSeconds) throws ExternalDependencyException {
    try {
        DevicePropertyServiceModel model = new DevicePropertyServiceModel();
        if (twin.getTags() != null) {
            model.setTags(new HashSet<String>(twin.getTags().keySet()));
        }
        if (twin.getProperties() != null && twin.getProperties().getReported() != null) {
            model.setReported(new HashSet<String>(twin.getProperties().getReported().keySet()));
        }
        // Update the deviceProperties cache, no need to wait
        CompletionStage unused = this.deviceProperties.updateListAsync(model);
        JobResult result = this.jobClient.scheduleUpdateTwin(jobId, queryCondition, twin.toDeviceTwinDevice(), startTime, maxExecutionTimeInSeconds);
        JobServiceModel jobModel = new JobServiceModel(result, null);
        return CompletableFuture.supplyAsync(() -> jobModel);
    } catch (IOException | IotHubException e) {
        String message = String.format("Unable to schedule twin update job: %s, %s, %s", jobId, queryCondition, Json.stringify(Json.toJson(twin)));
        log.error(message, e);
        throw new ExternalDependencyException(message, e);
    } catch (InterruptedException e) {
        String message = String.format("Unable to update cache");
        throw new CompletionException(new Exception(message, e));
    }
}

16 Source : Devices.java
with MIT License
from Azure

public CompletionStage<MethodResultServiceModel> invokeDeviceMethodAsync(final String id, MethodParameterServiceModel parameter) throws ExternalDependencyException {
    try {
        MethodResult result = this.deviceMethodClient.invoke(id, parameter.getName(), parameter.getResponseTimeout().getSeconds(), parameter.getConnectionTimeout().getSeconds(), parameter.getJsonPayload());
        return CompletableFuture.supplyAsync(() -> new MethodResultServiceModel(result));
    } catch (IOException | IotHubException e) {
        String message = String.format("Unable to invoke device method: %s, %s", id, Json.stringify(Json.toJson(parameter)));
        log.error(message, e);
        throw new ExternalDependencyException(message, e);
    }
}

16 Source : StorageTest.java
with MIT License
from Azure

@Test(timeout = StorageTest.TIMEOUT)
@Category({ UnitTest.clreplaced })
public void createDeviceGroupAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String groupId = rand.NextString();
    String displayName = rand.NextString();
    Iterable<DeviceGroupCondition> conditions = null;
    String etag = rand.NextString();
    ValueApiModel model = new ValueApiModel(groupId, null, etag, null);
    DeviceGroup group = new DeviceGroup();
    group.setConditions(conditions);
    group.setDisplayName(displayName);
    model.setData(Json.stringify(Json.toJson(group)));
    Mockito.when(mockClient.createAsync(Mockito.any(String.clreplaced), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    DeviceGroup result = storage.createDeviceGroupAsync(group).toCompletableFuture().get();
    replacedertEquals(result.getId(), groupId);
    replacedertEquals(result.getDisplayName(), displayName);
    replacedertEquals(result.getConditions(), conditions);
    replacedertEquals(result.getETag(), etag);
}

15 Source : Jobs.java
with MIT License
from Azure

@Override
public CompletionStage<JobServiceModel> scheduleDeviceMethodAsync(String jobId, String queryCondition, MethodParameterServiceModel parameter, Date startTime, long maxExecutionTimeInSeconds) throws ExternalDependencyException, InvalidInputException {
    // The json payload needs to be preplaceded in the form of HashMap otherwise java will double escape it.
    Map<String, Object> mapPayload = new Hashtable<String, Object>();
    ObjectMapper mapper = new ObjectMapper();
    if (parameter.getJsonPayload() != "") {
        try {
            // convert JSON string to Map
            mapPayload = mapper.readValue(parameter.getJsonPayload(), new TypeReference<HashMap<String, String>>() {
            });
        } catch (Exception e) {
            String message = String.format("Unable to parse cloudToDeviceMethod: %s", parameter.getJsonPayload());
            log.error(message, e);
            throw new InvalidInputException(message, e);
        }
    }
    try {
        JobResult result = this.jobClient.scheduleDeviceMethod(jobId, queryCondition, parameter.getName(), parameter.getResponseTimeout() == null ? null : parameter.getResponseTimeout().getSeconds(), parameter.getConnectionTimeout() == null ? null : parameter.getConnectionTimeout().getSeconds(), mapPayload, startTime, maxExecutionTimeInSeconds);
        JobServiceModel jobModel = new JobServiceModel(result, null);
        return CompletableFuture.supplyAsync(() -> jobModel);
    } catch (IOException | IotHubException e) {
        String message = String.format("Unable to schedule device method job: %s, %s, %s", jobId, queryCondition, Json.stringify(Json.toJson(parameter)));
        log.error(message, e);
        throw new ExternalDependencyException(message, e);
    }
}

15 Source : DeviceProperties.java
with MIT License
from Azure

/**
 * @summary Update Cache when devices are modified/created
 */
@Override
public CompletionStage<DevicePropertyServiceModel> updateListAsync(DevicePropertyServiceModel devicePropertyServiceModel) throws InterruptedException, ExternalDependencyException {
    if (devicePropertyServiceModel.getReported() == null) {
        devicePropertyServiceModel.setReported(new HashSet<>());
    }
    if (devicePropertyServiceModel.getTags() == null) {
        devicePropertyServiceModel.setTags(new HashSet<>());
    }
    String etag = null;
    while (true) {
        ValueApiModel model = null;
        try {
            model = this.getCurrentDevicePropertiesFromStorage();
        } catch (ExternalDependencyException e) {
            log.error("updateListAsync: External connection unavailable. Retrying after %s seconds", SERVICE_QUERY_INTERVAL_SECS);
            Thread.sleep(this.SERVICE_QUERY_INTERVAL_MS);
        } catch (ResourceNotFoundException e) {
            log.debug("updateListAsync: DeviceProperties doesn't exist in storage.");
        } catch (ConflictingResourceException e) {
            log.debug("updateListAsync: Access to deviceProperties conflicted");
        }
        if (model != null) {
            etag = model.getETag();
            DevicePropertyServiceModel devicePropertiesFromStorage = Json.fromJson(Json.parse(model.getData()), DevicePropertyServiceModel.clreplaced);
            this.updateDevicePropertyValues(model, devicePropertyServiceModel);
            // If the new set of deviceProperties are already there in cache, return
            if (devicePropertyServiceModel.getTags().size() == devicePropertiesFromStorage.getTags().size() && devicePropertyServiceModel.getReported().size() == devicePropertiesFromStorage.getReported().size()) {
                return CompletableFuture.completedFuture(devicePropertyServiceModel);
            }
        }
        String value = Json.stringify(Json.toJson(devicePropertyServiceModel));
        try {
            return this.storageClient.updateAsync(CacheCollectionId, CacheKey, value, etag).thenApplyAsync(m -> Json.fromJson(Json.parse(m.getData()), DevicePropertyServiceModel.clreplaced));
        } catch (ConflictingResourceException e) {
            log.debug("updateListAsync: Access to deviceProperties in storage conflicted with another process.");
            continue;
        } catch (ResourceNotFoundException e) {
            log.debug("updateListAsync: DeviceProperties not found in storage");
            continue;
        }
    }
}

15 Source : StorageTest.java
with MIT License
from Azure

@Test
@Category({ UnitTest.clreplaced })
public void addEdgePackageTest() throws BaseException, ExecutionException, InterruptedException {
    // Arrange
    PackageServiceModel pkg = new PackageServiceModel(null, rand.NextString(), PackageType.edgeManifest, null, this.createConfiguration());
    ValueApiModel model = new ValueApiModel(rand.NextString(), null, null, null);
    model.setData(Json.stringify(Json.toJson(pkg)));
    Mockito.when(mockClient.createAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    // Act
    PackageServiceModel result = storage.addPackageAsync(pkg).toCompletableFuture().get();
    // replacedert
    replacedertEquals(pkg.getName(), result.getName());
    replacedertEquals(pkg.getPackageType(), result.getPackageType());
    replacedertEquals(pkg.getContent(), result.getContent());
}

14 Source : WsTest.java
with MIT License
from vangav

@Test
public void jsonResponseShouldAutomaticallyDetectCharset() throws Exception {
    ObjectNode json = Json.newObject();
    json.put("string", "äüö");
    String js = Json.stringify(json);
    ToReturn toReturn = new ToReturn();
    toReturn.body = js.getBytes("utf-8");
    Response response = slave(toReturn);
    replacedertThat(Json.stringify(response.asJson()), equalTo(js));
    toReturn.body = js.getBytes("utf-16");
    response = slave(toReturn);
    replacedertThat(Json.stringify(response.asJson()), equalTo(js));
    toReturn.body = js.getBytes("utf-32");
    response = slave(toReturn);
    replacedertThat(Json.stringify(response.asJson()), equalTo(js));
}

14 Source : DeviceGroupControllerTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void getAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String groupId = rand.NextString();
    String displayName = rand.NextString();
    Iterable<DeviceGroupCondition> conditions = null;
    String etag = rand.NextString();
    DeviceGroup model = new DeviceGroup(groupId, displayName, conditions, etag);
    Mockito.when(mockStorage.getDeviceGroupAsync(Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    controller = new DeviceGroupController(mockStorage);
    String resultStr = TestUtils.getString(controller.getAsync(groupId).toCompletableFuture().get());
    DeviceGroupApiModel result = Json.fromJson(Json.parse(resultStr), DeviceGroupApiModel.clreplaced);
    replacedertEquals(result.getDisplayName(), displayName);
    replacedertEquals(Json.stringify(Json.toJson(result.getConditions())), Json.stringify(Json.toJson(conditions)));
    replacedertEquals(result.getETag(), etag);
}

14 Source : StorageTest.java
with MIT License
from Azure

@Test
@Category({ UnitTest.clreplaced })
public void addADMPackageTest() throws BaseException, ExecutionException, InterruptedException {
    // Arrange
    final String config = ConfigType.firmware.toString();
    final String configKey = "config-types";
    PackageServiceModel pkg = new PackageServiceModel(null, rand.NextString(), PackageType.deviceConfiguration, config, this.createConfiguration());
    ValueApiModel model = new ValueApiModel(rand.NextString(), null, null, null);
    model.setData(Json.stringify(Json.toJson(pkg)));
    Mockito.when(mockClient.createAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    Mockito.when(mockClient.updateAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.eq(configKey), Mockito.eq(config), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    Mockito.when(mockClient.getAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.eq(configKey))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    // Act
    PackageServiceModel result = storage.addPackageAsync(pkg).toCompletableFuture().get();
    // replacedert
    replacedertEquals(pkg.getName(), result.getName());
    replacedertEquals(pkg.getPackageType(), result.getPackageType());
    replacedertEquals(pkg.getConfigType(), result.getConfigType());
    replacedertEquals(pkg.getContent(), result.getContent());
}

14 Source : StorageTest.java
with MIT License
from Azure

@Test
@Category({ UnitTest.clreplaced })
public void addADMCustomPackageTest() throws BaseException, ExecutionException, InterruptedException {
    // Arrange
    final String config = "CustomConfig";
    final String configKey = "config-types";
    PackageServiceModel pkg = new PackageServiceModel(null, rand.NextString(), PackageType.edgeManifest, config, this.createConfiguration());
    ValueApiModel model = new ValueApiModel(rand.NextString(), null, null, null);
    model.setData(Json.stringify(Json.toJson(pkg)));
    Mockito.when(mockClient.createAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    Mockito.when(mockClient.updateAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.eq(configKey), Mockito.eq(config), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    Mockito.when(mockClient.getAsync(Mockito.eq(PACKAGES_COLLECTION_ID), Mockito.eq(configKey))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    // Act
    PackageServiceModel result = storage.addPackageAsync(pkg).toCompletableFuture().get();
    // replacedert
    replacedertEquals(pkg.getName(), result.getName());
    replacedertEquals(pkg.getPackageType(), result.getPackageType());
    replacedertEquals(pkg.getConfigType(), config);
    replacedertEquals(pkg.getContent(), result.getContent());
}

13 Source : WsTest.java
with MIT License
from vangav

@Test
public void jsonRequestShouldBeUtf8() throws Exception {
    ObjectNode json = Json.newObject();
    json.put("string", "äüö");
    Echo echo = getEcho(echo().post(json));
    replacedertThat(echo.headers, hasKey("Content-Type"));
    replacedertThat(echo.headers.get("Content-Type")[0], equalTo("application/json; charset=utf-8"));
    replacedertThat(new String(echo.body, "utf-8"), equalTo(Json.stringify(json)));
}

13 Source : DeviceGroupControllerTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void updateAsyncTest() throws Exception {
    String groupId = rand.NextString();
    String displayName = rand.NextString();
    Iterable<DeviceGroupCondition> conditions = Json.fromJson(Json.parse(condition), new ArrayList<DeviceGroupCondition>().getClreplaced());
    String etagOld = rand.NextString();
    String etagNew = rand.NextString();
    DeviceGroup model = new DeviceGroup(groupId, displayName, conditions, etagNew);
    Mockito.when(mockStorage.updateDeviceGroupAsync(Mockito.any(String.clreplaced), Mockito.any(DeviceGroup.clreplaced), Mockito.any(String.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    controller = new DeviceGroupController(mockStorage);
    TestUtils.setRequest(String.format("{\"DisplayName\":\"%s\",\"Conditions\":%s,\"ETag\":\"%s\"}", displayName, condition, etagOld));
    String resultStr = TestUtils.getString(controller.updateAsync(groupId).toCompletableFuture().get());
    DeviceGroupApiModel result = Json.fromJson(Json.parse(resultStr), DeviceGroupApiModel.clreplaced);
    replacedertEquals(result.getId(), groupId);
    replacedertEquals(result.getDisplayName(), displayName);
    replacedertEquals(Json.stringify(Json.toJson(result.getConditions())), Json.stringify(Json.toJson(conditions)));
    replacedertEquals(result.getETag(), etagNew);
}

12 Source : DeviceGroupControllerTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void creatAsyncTest() throws Exception {
    String groupId = rand.NextString();
    String displayName = rand.NextString();
    Iterable<DeviceGroupCondition> conditions = Json.fromJson(Json.parse(condition), new ArrayList<DeviceGroupCondition>().getClreplaced());
    String etag = rand.NextString();
    DeviceGroup model = new DeviceGroup(groupId, displayName, conditions, etag);
    Mockito.when(mockStorage.createDeviceGroupAsync(Mockito.any(DeviceGroup.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> model));
    controller = new DeviceGroupController(mockStorage);
    TestUtils.setRequest(String.format("{\"DisplayName\":\"%s\",\"Conditions\":%s}", displayName, condition));
    String resultStr = TestUtils.getString(controller.createAsync().toCompletableFuture().get());
    DeviceGroupApiModel result = Json.fromJson(Json.parse(resultStr), DeviceGroupApiModel.clreplaced);
    replacedertEquals(result.getId(), groupId);
    replacedertEquals(result.getDisplayName(), displayName);
    replacedertEquals(Json.stringify(Json.toJson(result.getConditions())), Json.stringify(Json.toJson(conditions)));
    replacedertEquals(result.getETag(), etag);
}

9 Source : StorageAdapterClientTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void getAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String collectionId = rand.NextString();
    String key = rand.NextString();
    String data = rand.NextString();
    String etag = rand.NextString();
    ValueApiModel model = new ValueApiModel(key, data, etag, null);
    HttpResponse response = new HttpResponse();
    response.setContent(Json.stringify(Json.toJson(model)));
    response.setStatusCode(200);
    Mockito.when(mockHttpClient.getAsync(Mockito.any(HttpRequest.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> response));
    client = new StorageAdapterClient(mockHttpClient, new ServicesConfig(null, MockServiceUri, MockServiceUri, null, null, null, null));
    ValueApiModel result = client.getAsync(collectionId, key).toCompletableFuture().get();
    replacedertEquals(result.getData(), data);
    replacedertEquals(result.getKey(), key);
    replacedertEquals(result.getETag(), etag);
}

8 Source : DeviceGroupControllerTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void getAllAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    List<DeviceGroup> models = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        DeviceGroup model = new DeviceGroup(rand.NextString(), rand.NextString(), null, rand.NextString());
        models.add(model);
    }
    Mockito.when(mockStorage.getAllDeviceGroupsAsync()).thenReturn(CompletableFuture.supplyAsync(() -> models));
    controller = new DeviceGroupController(mockStorage);
    String resultStr = TestUtils.getString(controller.getAllAsync().toCompletableFuture().get());
    DeviceGroupListApiModel result = Json.fromJson(Json.parse(resultStr), DeviceGroupListApiModel.clreplaced);
    replacedertEquals(result.gereplacedems().spliterator().getExactSizeIfKnown(), models.size());
    for (DeviceGroupApiModel item : result.gereplacedems()) {
        DeviceGroup model = models.stream().filter(m -> m.getId().equals(item.getId())).findFirst().get();
        replacedertEquals(model.getDisplayName(), item.getDisplayName());
        replacedertEquals(Json.stringify(Json.toJson(model.getConditions())), Json.stringify(Json.toJson(item.getConditions())));
        replacedertEquals(model.getETag(), item.getETag());
    }
}

8 Source : StorageAdapterClientTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void createAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String collectionId = rand.NextString();
    String key = rand.NextString();
    String data = rand.NextString();
    String etag = rand.NextString();
    HttpResponse response = new HttpResponse();
    response.setStatusCode(200);
    ValueApiModel model = new ValueApiModel(key, data, etag, null);
    response.setContent(Json.stringify(Json.toJson(model)));
    Mockito.when(mockHttpClient.postAsync(Mockito.any(HttpRequest.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> response));
    client = new StorageAdapterClient(mockHttpClient, new ServicesConfig(null, MockServiceUri, MockServiceUri, null, null, null, null));
    ValueApiModel result = client.createAsync(collectionId, data).toCompletableFuture().get();
    replacedertEquals(result.getKey(), key);
    replacedertEquals(result.getData(), data);
    replacedertEquals(result.getETag(), etag);
}

8 Source : StorageAdapterClientTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void updateAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String collectionId = rand.NextString();
    String key = rand.NextString();
    String data = rand.NextString();
    String etagOld = rand.NextString();
    String etagNew = rand.NextString();
    HttpResponse response = new HttpResponse();
    response.setStatusCode(200);
    ValueApiModel model = new ValueApiModel(key, data, etagNew, null);
    response.setContent(Json.stringify(Json.toJson(model)));
    Mockito.when(mockHttpClient.putAsync(Mockito.any(HttpRequest.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> response));
    client = new StorageAdapterClient(mockHttpClient, new ServicesConfig(null, MockServiceUri, MockServiceUri, null, null, null, null));
    ValueApiModel result = client.updateAsync(collectionId, key, data, etagOld).toCompletableFuture().get();
    replacedertEquals(result.getKey(), key);
    replacedertEquals(result.getData(), data);
    replacedertEquals(result.getETag(), etagNew);
}

7 Source : EmailActionExecutor.java
with MIT License
from Azure

private String generatePayload(EmailActionServiceModel emailAction, AsaAlarmApiModel alarm) {
    DateTime alarmDate = new DateTime(Long.parseLong(alarm.getDateCreated()));
    String emailBody = this.emailTemplate.replace("${subject}", emailAction.getSubject()).replace("${notes}", emailAction.getNotes()).replace("${alarmDate}", alarmDate.toString(DATE_FORMAT_STRING)).replace("${ruleId}", alarm.getRuleId()).replace("${ruleDescription}", alarm.getRuleDescription()).replace("${ruleSeverity}", alarm.getRuleSeverity()).replace("${deviceId}", alarm.getDeviceId()).replace("${alarmUrl}", this.generateRuleDetailUrl(alarm.getRuleId()));
    EmailActionPayload payload = new EmailActionPayload(emailAction.getRecipients(), emailAction.getSubject(), emailBody);
    return Json.stringify(Json.toJson(payload));
}

5 Source : StorageAdapterClientTest.java
with MIT License
from Azure

@Test(timeout = 100000)
@Category({ UnitTest.clreplaced })
public void getAllAsyncTest() throws BaseException, ExecutionException, InterruptedException {
    String collectionId = rand.NextString();
    List<ValueApiModel> models = new ArrayList<ValueApiModel>();
    for (int i = 0; i < 5; i++) {
        ValueApiModel model = new ValueApiModel(rand.NextString(), rand.NextString(), rand.NextString(), null);
        models.add(model);
    }
    ValueListApiModel listApiModel = new ValueListApiModel();
    listApiModel.Items = models;
    HttpResponse response = new HttpResponse();
    response.setStatusCode(200);
    response.setContent(Json.stringify(Json.toJson(listApiModel)));
    Mockito.when(mockHttpClient.getAsync(Mockito.any(HttpRequest.clreplaced))).thenReturn(CompletableFuture.supplyAsync(() -> response));
    client = new StorageAdapterClient(mockHttpClient, new ServicesConfig(null, MockServiceUri, MockServiceUri, null, null, null, null));
    ValueListApiModel result = client.getAllAsync(collectionId).toCompletableFuture().get();
    replacedertEquals(Lists.newArrayList(result.Items).size(), models.size());
    for (ValueApiModel item : result.Items) {
        ValueApiModel model = models.stream().filter(m -> m.getKey().equals(item.getKey())).findFirst().get();
        replacedertEquals(model.getData(), item.getData());
        replacedertEquals(model.getETag(), item.getETag());
    }
}