@Test public void testVirtualGuestWithOperatingSystem() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("https: VirtualGuestToJson binder = new VirtualGuestToJson(json); VirtualGuest virtualGuestWithOS = VirtualGuest.builder() .hostname("hostname") .domain("domain") .startCpus(1) .maxMemory(1024) .datacenter(Datacenter.builder() .name("datacenterName") .build()) .operatingSystem(OperatingSystem.builder().id("123456789") .operatingSystemReferenceCode("UBUNTU_12_64") .build()) .localDiskFlag(true) .networkComponents(ImmutableSet.<VirtualGuestNetworkComponent>of()) .build(); request = binder.bindToRequest(request, virtualGuestWithOS); assertEquals(request.getPayload().getRawContent(), "{" + "\"parameters\":[{\"hostname\":\"hostname\",\"domain\":\"domain\",\"startCpus\":1,\"maxMemory\":1024,\"hourlyBillingFlag\":false,\"localDiskFlag\":true,\"dedicatedAccountHostOnlyFlag\":false,\"privateNetworkOnlyFlag\":false,\"operatingSystemReferenceCode\":\"UBUNTU_12_64\",\"datacenter\":{\"name\":\"datacenterName\"}}]}"); }
@Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof VirtualGuest); VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); request.setPayload(buildJson(virtualGuest)); return request; }
VirtualGuestToJson implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof VirtualGuest); VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); request.setPayload(buildJson(virtualGuest)); return request; } }
VirtualGuestToJson implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof VirtualGuest); VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); request.setPayload(buildJson(virtualGuest)); return request; } @Inject  VirtualGuestToJson(Json json); }
VirtualGuestToJson implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof VirtualGuest); VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); request.setPayload(buildJson(virtualGuest)); return request; } @Inject  VirtualGuestToJson(Json json); @Override R bindToRequest(R request, Object input); }
VirtualGuestToJson implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof VirtualGuest); VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); request.setPayload(buildJson(virtualGuest)); return request; } @Inject  VirtualGuestToJson(Json json); @Override R bindToRequest(R request, Object input); static final String USER_DATA_KEY; }