use of com.google.gson.Gson in project che by eclipse.
the class StackLoaderTest method dtoShouldBeSerialized.
@Test
public void dtoShouldBeSerialized() {
StackDto stackDtoDescriptor = newDto(StackDto.class).withName("nameWorkspaceConfig");
StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("java").withVersion("1.8");
stackDtoDescriptor.setComponents(Collections.singletonList(stackComponentDto));
stackDtoDescriptor.setTags(Arrays.asList("some teg1", "some teg2"));
stackDtoDescriptor.setDescription("description");
stackDtoDescriptor.setId("someId");
stackDtoDescriptor.setScope("scope");
stackDtoDescriptor.setCreator("Created in Codenvy");
Map<String, String> attributes = new HashMap<>();
attributes.put("attribute1", "valute attribute1");
Link link = newDto(Link.class).withHref("some url").withMethod("get").withRel("someRel").withConsumes("consumes").withProduces("produces");
HashMap<String, List<String>> projectMap = new HashMap<>();
projectMap.put("test", Arrays.asList("test", "test2"));
ProjectProblemDto projectProblem = newDto(ProjectProblemDto.class).withCode(100).withMessage("message");
SourceStorageDto sourceStorageDto = newDto(SourceStorageDto.class).withType("some type").withParameters(attributes).withLocation("location");
ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName("project").withPath("somePath").withAttributes(projectMap).withType("maven type").withDescription("some project description").withLinks(Collections.singletonList(link)).withMixins(Collections.singletonList("mixin time")).withProblems(Collections.singletonList(projectProblem)).withSource(sourceStorageDto);
EnvironmentRecipeDto environmentRecipe = newDto(EnvironmentRecipeDto.class).withContent("some content").withContentType("some content type").withType("someType");
Map<String, ServerConf2Dto> servers = new HashMap<>();
servers.put("server1Ref", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("http").withProperties(singletonMap("key", "value")));
Map<String, ExtendedMachineDto> machines = new HashMap<>();
machines.put("someMachineName", newDto(ExtendedMachineDto.class).withAgents(Arrays.asList("agent1", "agent2")).withServers(servers).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L)));
EnvironmentDto environmentDto = newDto(EnvironmentDto.class).withRecipe(environmentRecipe).withMachines(machines);
CommandDto commandDto = newDto(CommandDto.class).withType("command type").withName("command name").withCommandLine("command line");
WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("SomeWorkspaceConfig").withDescription("some workspace").withLinks(Collections.singletonList(link)).withDefaultEnv("some Default Env name").withProjects(Collections.singletonList(projectConfigDto)).withEnvironments(singletonMap("name", environmentDto)).withCommands(Collections.singletonList(commandDto));
stackDtoDescriptor.setWorkspaceConfig(workspaceConfigDto);
Gson GSON = new GsonBuilder().create();
GSON.fromJson(stackDtoDescriptor.toString(), StackImpl.class);
}
use of com.google.gson.Gson in project buck by facebook.
the class XctoolOutputParsing method streamOutputFromReader.
/**
* Decodes a stream of JSON objects as produced by {@code xctool -reporter json-stream}
* and invokes the callbacks in {@code eventCallback} with each event in the stream.
*/
public static void streamOutputFromReader(Reader reader, XctoolEventCallback eventCallback) {
Gson gson = new Gson();
JsonStreamParser streamParser = new JsonStreamParser(reader);
try {
while (streamParser.hasNext()) {
dispatchEventCallback(gson, streamParser.next(), eventCallback);
}
} catch (JsonParseException e) {
LOG.warn(e, "Couldn't parse xctool JSON stream");
}
}
use of com.google.gson.Gson in project cw-omnibus by commonsguy.
the class PresoRoster method load.
void load(Context ctxt) {
Gson gson = new Gson();
AssetManager assets = ctxt.getAssets();
for (String presoDir : PRESO_ASSET_DIRS) {
PresoContents c = loadPreso(gson, assets, presoDir);
if (c != null) {
c.id = presos.size();
presos.add(c);
}
}
}
use of com.google.gson.Gson in project elastic-job by dangdangdotcom.
the class GsonFactoryTest method assertRegisterTypeAdapter.
@Test
public void assertRegisterTypeAdapter() {
Gson beforeRegisterGson = GsonFactory.getGson();
GsonFactory.registerTypeAdapter(GsonFactoryTest.class, new TypeAdapter() {
@Override
public Object read(final JsonReader in) throws IOException {
return null;
}
@Override
public void write(final JsonWriter out, final Object value) throws IOException {
out.jsonValue("test");
}
});
assertThat(beforeRegisterGson.toJson(new GsonFactoryTest()), is("{}"));
assertThat(GsonFactory.getGson().toJson(new GsonFactoryTest()), is("test"));
}
use of com.google.gson.Gson in project che by eclipse.
the class WorkspaceServiceTest method shouldBeAbleToGetSettings.
@Test
public void shouldBeAbleToGetSettings() throws Exception {
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/settings");
assertEquals(response.getStatusCode(), 200);
final Map<String, String> settings = new Gson().fromJson(response.print(), new TypeToken<Map<String, String>>() {
}.getType());
assertEquals(settings, //
ImmutableMap.of(//
"che.workspace.auto_snapshot", //
"true", //
"che.workspace.auto_restore", //
"false", "che.workspace.auto_start", "true"));
}
Aggregations