ApiResponseHelper implements ResponseGenerator { public String getDateStringInternal(Date inputDate) { if (inputDate == null) { return null; } final TimeZone tz = _usageSvc.getUsageTimezone(); final Calendar cal = Calendar.getInstance(tz); cal.setTime(inputDate); final StringBuilder sb = new StringBuilder(32); sb.append(cal.get(Calendar.YEAR)).append('-'); final int month = cal.get(Calendar.MONTH) + 1; if (month < 10) { sb.append('0'); } sb.append(month).append('-'); final int day = cal.get(Calendar.DAY_OF_MONTH); if (day < 10) { sb.append('0'); } sb.append(day); sb.append("'T'"); final int hour = cal.get(Calendar.HOUR_OF_DAY); if (hour < 10) { sb.append('0'); } sb.append(hour).append(':'); final int minute = cal.get(Calendar.MINUTE); if (minute < 10) { sb.append('0'); } sb.append(minute).append(':'); final int seconds = cal.get(Calendar.SECOND); if (seconds < 10) { sb.append('0'); } sb.append(seconds); double offset = cal.get(Calendar.ZONE_OFFSET); if (tz.inDaylightTime(inputDate)) { offset += 1.0 * tz.getDSTSavings(); } offset = offset / (1000d * 60d * 60d); final int hourOffset = (int)offset; final double decimalVal = Math.abs(offset) - Math.abs(hourOffset); final int minuteOffset = (int)(decimalVal * 60); if (hourOffset < 0) { if (hourOffset > -10) { sb.append("-0"); } else { sb.append('-'); } sb.append(Math.abs(hourOffset)); } else { if (hourOffset < 10) { sb.append("+0"); } else { sb.append("+"); } sb.append(hourOffset); } sb.append(':'); if (minuteOffset == 0) { sb.append("00"); } else if (minuteOffset < 10) { sb.append('0').append(minuteOffset); } else { sb.append(minuteOffset); } return sb.toString(); }  @Override UserResponse createUserResponse(User user); @Override AccountResponse createUserAccountResponse(ResponseView view, UserAccount user); @Override AccountResponse createAccountResponse(ResponseView view, Account account); @Override UserResponse createUserResponse(UserAccount user); @Override DomainResponse createDomainResponse(Domain domain); @Override DiskOfferingResponse createDiskOfferingResponse(DiskOffering offering); @Override ResourceLimitResponse createResourceLimitResponse(ResourceLimit limit); @Override ResourceCountResponse createResourceCountResponse(ResourceCount resourceCount); @Override ServiceOfferingResponse createServiceOfferingResponse(ServiceOffering offering); @Override ConfigurationResponse createConfigurationResponse(Configuration cfg); @Override SnapshotResponse createSnapshotResponse(Snapshot snapshot); static DataStoreRole getDataStoreRole(Snapshot snapshot, SnapshotDataStoreDao snapshotStoreDao, DataStoreManager dataStoreMgr); @Override VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot); @Override SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy); @Override HostResponse createHostResponse(Host host); @Override HostResponse createHostResponse(Host host, EnumSet<HostDetails> details); @Override HostForMigrationResponse createHostForMigrationResponse(Host host); @Override HostForMigrationResponse createHostForMigrationResponse(Host host, EnumSet<HostDetails> details); @Override VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan); @Override IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr); @Override LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer); @Override GlobalLoadBalancerResponse createGlobalLoadBalancerResponse(GlobalLoadBalancerRule globalLoadBalancerRule); @Override PodResponse createPodResponse(Pod pod, Boolean showCapacities); @Override ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities); static List<CapacityResponse> getDataCenterCapacityResponse(Long zoneId); @Override VolumeResponse createVolumeResponse(ResponseView view, Volume volume); @Override InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group); @Override StoragePoolResponse createStoragePoolResponse(StoragePool pool); @Override ImageStoreResponse createImageStoreResponse(ImageStore os); @Override StoragePoolResponse createStoragePoolForMigrationResponse(StoragePool pool); @Override ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities); @Override FirewallRuleResponse createPortForwardingRuleResponse(PortForwardingRule fwRule); @Override IpForwardingRuleResponse createIpForwardingRuleResponse(StaticNatRule fwRule); @Override List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details, UserVm... userVms); @Override List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, UserVm... userVms); @Override DomainRouterResponse createDomainRouterResponse(VirtualRouter router); @Override SystemVmResponse createSystemVmResponse(VirtualMachine vm); @Override Host findHostById(Long hostId); @Override User findUserById(Long userId); @Override UserVm findUserVmById(Long vmId); @Override VolumeVO findVolumeById(Long volumeId); @Override Account findAccountByNameDomain(String accountName, Long domainId); @Override VirtualMachineTemplate findTemplateById(Long templateId); @Override VpnUsersResponse createVpnUserResponse(VpnUser vpnUser); @Override RemoteAccessVpnResponse createRemoteAccessVpnResponse(RemoteAccessVpn vpn); @Override TemplateResponse createTemplateUpdateResponse(ResponseView view, VirtualMachineTemplate result); @Override List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachineTemplate result, Long zoneId, boolean readyOnly); @Override List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long zoneId, boolean readyOnly); @Override List<TemplateResponse> createIsoResponses(ResponseView view, VirtualMachineTemplate result, Long zoneId, boolean readyOnly); @Override SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group); @Override ExtractResponse createExtractResponse(Long id, Long zoneId, Long accountId, String mode, String url); @Override ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url); @Override String toSerializedString(CreateCmdResponse response, String responseType); @Override List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId, boolean readyOnly); @Override List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long vmId); @Override EventResponse createEventResponse(Event event); @Override List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format); @Override TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String> accountNames, Long id); @Override AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd); AsyncJobResponse createAsyncJobResponse(AsyncJob job); @Override SecurityGroupResponse createSecurityGroupResponseFromSecurityGroupRule(List<? extends SecurityRule> securityRules); @Override NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering); @Override NetworkResponse createNetworkResponse(ResponseView view, Network network); @Override Long getSecurityGroupId(String groupName, long accountId); @Override ProjectResponse createProjectResponse(Project project); @Override FirewallResponse createFirewallResponse(FirewallRule fwRule); @Override NetworkACLItemResponse createNetworkACLItemResponse(NetworkACLItem aclItem); @Override HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities); static void populateOwner(ControlledViewEntityResponse response, ControlledViewEntity object); @Override ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount); @Override ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite); @Override SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm); @Override PhysicalNetworkResponse createPhysicalNetworkResponse(PhysicalNetwork result); @Override GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan vlan); @Override ServiceResponse createNetworkServiceResponse(Service service); @Override ProviderResponse createNetworkServiceProviderResponse(PhysicalNetworkServiceProvider result); @Override TrafficTypeResponse createTrafficTypeResponse(PhysicalNetworkTrafficType result); @Override VirtualRouterProviderResponse createVirtualRouterProviderResponse(VirtualRouterProvider result); @Override LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb); @Override LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb); @Override LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies, LoadBalancer lb); @Override LBHealthCheckResponse createLBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckPolicy, LoadBalancer lb); @Override StorageNetworkIpRangeResponse createStorageNetworkIpRangeResponse(StorageNetworkIpRange result); @Override RegionResponse createRegionResponse(Region region); @Override ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag, boolean keyValueOnly); @Override VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering); @Override VpcResponse createVpcResponse(ResponseView view, Vpc vpc); @Override PrivateGatewayResponse createPrivateGatewayResponse(PrivateGateway result); @Override CounterResponse createCounterResponse(Counter counter); @Override ConditionResponse createConditionResponse(Condition condition); @Override AutoScaleVmProfileResponse createAutoScaleVmProfileResponse(AutoScaleVmProfile profile); @Override AutoScalePolicyResponse createAutoScalePolicyResponse(AutoScalePolicy policy); @Override AutoScaleVmGroupResponse createAutoScaleVmGroupResponse(AutoScaleVmGroup vmGroup); @Override StaticRouteResponse createStaticRouteResponse(StaticRoute result); @Override Site2SiteVpnGatewayResponse createSite2SiteVpnGatewayResponse(Site2SiteVpnGateway result); @Override Site2SiteCustomerGatewayResponse createSite2SiteCustomerGatewayResponse(Site2SiteCustomerGateway result); @Override Site2SiteVpnConnectionResponse createSite2SiteVpnConnectionResponse(Site2SiteVpnConnection result); @Override GuestOSResponse createGuestOSResponse(GuestOS guestOS); @Override GuestOsMappingResponse createGuestOSMappingResponse(GuestOSHypervisor guestOSHypervisor); @Override SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule snapshotSchedule); @Override UsageRecordResponse createUsageResponse(Usage usageRecord); String getDateStringInternal(Date inputDate); @Override TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor); @Override NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result); @Override NicResponse createNicResponse(Nic result); @Override ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances); @Override AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group); @Override Long getAffinityGroupId(String groupName, long accountId); @Override PortableIpRangeResponse createPortableIPRangeResponse(PortableIpRange ipRange); @Override PortableIpResponse createPortableIPResponse(PortableIp portableIp); @Override InternalLoadBalancerElementResponse createInternalLbElementResponse(VirtualRouterProvider result); @Override IsolationMethodResponse createIsolationMethodResponse(IsolationType method); @Override NetworkACLResponse createNetworkACLResponse(NetworkACL networkACL); @Override ListResponse<UpgradeRouterTemplateResponse> createUpgradeRouterTemplateResponse(List<Long> jobIds); @Override SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);  }
@Test public void getDateStringInternal() throws ParseException { Mockito.when(usageService.getUsageTimezone()).thenReturn( TimeZone.getTimeZone("UTC")); Assert.assertEquals("2014-06-29'T'23:45:00+00:00", helper .getDateStringInternal(dateFormat.parse("2014-06-29 23:45:00 UTC"))); Assert.assertEquals("2014-06-29'T'23:45:01+00:00", helper .getDateStringInternal(dateFormat.parse("2014-06-29 23:45:01 UTC"))); Assert.assertEquals("2014-06-29'T'23:45:11+00:00", helper .getDateStringInternal(dateFormat.parse("2014-06-29 23:45:11 UTC"))); Assert.assertEquals("2014-06-29'T'23:05:11+00:00", helper .getDateStringInternal(dateFormat.parse("2014-06-29 23:05:11 UTC"))); Assert.assertEquals("2014-05-29'T'08:45:11+00:00", helper .getDateStringInternal(dateFormat.parse("2014-05-29 08:45:11 UTC"))); }