use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class ServerDtoTest method testSimpleDtoDeserializer.
@Test
public void testSimpleDtoDeserializer() throws Exception {
final String fooString = "Something";
final int fooId = 1;
final String _default = "test_default_keyword";
JsonObject json = new JsonObject();
json.add("name", new JsonPrimitive(fooString));
json.add("id", new JsonPrimitive(fooId));
json.add("default", new JsonPrimitive(_default));
SimpleDto dto = dtoFactory.createDtoFromJson(json.toString(), SimpleDto.class);
// Check to make sure things are in a sane state.
checkSimpleDto(dto, fooString, fooId, _default);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class ServerDtoTest method testCloneWithNullAny.
@Test
public void testCloneWithNullAny() throws Exception {
DtoWithAny dto1 = dtoFactory.createDto(DtoWithAny.class);
DtoWithAny dto2 = dtoFactory.clone(dto1);
Assert.assertEquals(dto1, dto2);
JsonElement json = new JsonParser().parse(dtoFactory.toJson(dto1));
JsonObject expJson = new JsonObject();
expJson.addProperty("id", 0);
expJson.add("objects", new JsonArray());
assertEquals(expJson, json);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class ServerDtoTest method testListSimpleDtoDeserializer.
@Test
public void testListSimpleDtoDeserializer() throws Exception {
final String fooString_1 = "Something 1";
final int fooId_1 = 1;
final String _default_1 = "test_default_keyword_1";
final String fooString_2 = "Something 2";
final int fooId_2 = 2;
final String _default_2 = "test_default_keyword_2";
JsonObject json1 = new JsonObject();
json1.add("name", new JsonPrimitive(fooString_1));
json1.add("id", new JsonPrimitive(fooId_1));
json1.add("default", new JsonPrimitive(_default_1));
JsonObject json2 = new JsonObject();
json2.add("name", new JsonPrimitive(fooString_2));
json2.add("id", new JsonPrimitive(fooId_2));
json2.add("default", new JsonPrimitive(_default_2));
JsonArray jsonArray = new JsonArray();
jsonArray.add(json1);
jsonArray.add(json2);
org.eclipse.che.dto.shared.JsonArray<SimpleDto> listDtoFromJson = dtoFactory.createListDtoFromJson(jsonArray.toString(), SimpleDto.class);
assertEquals(listDtoFromJson.get(0).getName(), fooString_1);
assertEquals(listDtoFromJson.get(0).getId(), fooId_1);
assertEquals(listDtoFromJson.get(0).getDefault(), _default_1);
assertEquals(listDtoFromJson.get(1).getName(), fooString_2);
assertEquals(listDtoFromJson.get(1).getId(), fooId_2);
assertEquals(listDtoFromJson.get(1).getDefault(), _default_2);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class WorkspaceConfigJsonAdapterTest method testWorkspaceConfigAdaptationBasedOnDockerfileLocationSource.
@Test
public void testWorkspaceConfigAdaptationBasedOnDockerfileLocationSource() throws Exception {
final String content = loadContent("ws_conf_machine_source_dockerfile_location.json");
final JsonObject wsConfig = new JsonParser().parse(content).getAsJsonObject();
configAdapter.adaptModifying(wsConfig);
// The type of environments must be changed from array to map
assertTrue(wsConfig.has("environments"), "contains environments object");
assertTrue(wsConfig.get("environments").isJsonObject(), "environments is json object");
// Environment must be moved out of the environment object
final JsonObject environmentsObj = wsConfig.get("environments").getAsJsonObject();
assertTrue(environmentsObj.has("dev-env"), "'dev-env' is present in environments list");
assertTrue(environmentsObj.get("dev-env").isJsonObject(), "'dev-env' is json object");
final JsonObject environmentObj = environmentsObj.get("dev-env").getAsJsonObject();
// 'machineConfigs' -> 'machines'
assertTrue(environmentObj.has("machines"), "'machines' are present in environment object");
assertTrue(environmentObj.get("machines").isJsonObject(), "'machines' is json object");
final JsonObject machinesObj = environmentObj.get("machines").getAsJsonObject();
assertEquals(machinesObj.entrySet().size(), 1, "machines size");
// check 'dev' machine
assertTrue(machinesObj.has("dev"), "'machines' contains machine with name 'dev-machine'");
assertTrue(machinesObj.get("dev").isJsonObject(), "dev machine is json object");
final JsonObject devMachineObj = machinesObj.get("dev").getAsJsonObject();
assertTrue(devMachineObj.has("servers"), "dev machine contains servers field");
assertTrue(devMachineObj.get("servers").isJsonObject(), "dev machine servers is json object");
final JsonObject devMachineServersObj = devMachineObj.get("servers").getAsJsonObject();
assertTrue(devMachineServersObj.has("ref"), "contains servers with reference 'ref'");
assertTrue(devMachineServersObj.get("ref").isJsonObject(), "server is json object");
final JsonObject devMachineServerObj = devMachineServersObj.get("ref").getAsJsonObject();
assertEquals(devMachineServerObj.get("port").getAsString(), "9090/udp");
assertEquals(devMachineServerObj.get("protocol").getAsString(), "protocol");
assertTrue(devMachineObj.has("agents"), "dev machine has agents");
assertTrue(devMachineObj.has("attributes"), "dev machine has attributes");
assertTrue(devMachineObj.get("attributes").isJsonObject(), "dev machine attributes is json object");
final JsonObject attributes = devMachineObj.getAsJsonObject("attributes");
assertTrue(attributes.has("memoryLimitBytes"), "has memory limit");
assertEquals(attributes.get("memoryLimitBytes").getAsString(), "2147483648");
// check environment recipe
assertTrue(environmentObj.has("recipe"), "environment contains recipe");
assertTrue(environmentObj.get("recipe").isJsonObject(), "environment recipe is json object");
final JsonObject recipeObj = environmentObj.get("recipe").getAsJsonObject();
assertEquals(recipeObj.get("type").getAsString(), "dockerfile");
assertEquals(recipeObj.get("contentType").getAsString(), "text/x-dockerfile");
assertEquals(recipeObj.get("location").getAsString(), "https://somewhere/Dockerfile");
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class WorkspaceConfigJsonAdapterTest method testAdaptionOfWorkspaceConfigWithSourceBasedOnDockerImage.
@Test(dependsOnMethods = "testWorkspaceConfigAdaptationBasedOnDockerfileLocationSource")
public void testAdaptionOfWorkspaceConfigWithSourceBasedOnDockerImage() throws Exception {
final String content = loadContent("ws_conf_machine_source_dockerimage.json");
final JsonObject wsConfig = new JsonParser().parse(content).getAsJsonObject();
configAdapter.adaptModifying(wsConfig);
// check environment recipe
final JsonObject recipeObj = wsConfig.getAsJsonObject("environments").getAsJsonObject("dev-env").getAsJsonObject("recipe");
assertEquals(recipeObj.get("type").getAsString(), "dockerimage");
assertEquals(recipeObj.get("location").getAsString(), "codenvy/ubuntu_jdk8");
}
Aggregations