/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListUsageRecordsResponseTest.java

https://github.com/andreisavu/jclouds · Java · 78 lines · 46 code · 10 blank · 22 comment · 0 complexity · 0ed3e2ad18f5e7e2c1f111f90688b810 MD5 · raw file

  1. /**
  2. * Licensed to jclouds, Inc. (jclouds) under one or more
  3. * contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. jclouds licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.jclouds.cloudstack.parse;
  20. import java.util.Calendar;
  21. import java.util.Date;
  22. import java.util.Set;
  23. import java.util.TimeZone;
  24. import org.jclouds.cloudstack.config.CloudStackParserModule;
  25. import org.jclouds.cloudstack.domain.UsageRecord;
  26. import org.jclouds.json.BaseSetParserTest;
  27. import org.jclouds.json.config.GsonModule;
  28. import org.jclouds.rest.annotations.SelectJson;
  29. import org.testng.annotations.Test;
  30. import com.google.common.collect.ImmutableSet;
  31. import com.google.inject.Guice;
  32. import com.google.inject.Injector;
  33. /**
  34. *
  35. * @author Richard Downer
  36. */
  37. @Test(groups = "unit")
  38. public class ListUsageRecordsResponseTest extends BaseSetParserTest<UsageRecord> {
  39. @Override
  40. public String resource() {
  41. return "/listusagerecordsresponse.json";
  42. }
  43. @Override
  44. @SelectJson("usagerecord")
  45. public Set<UsageRecord> expected() {
  46. Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  47. c.set(Calendar.YEAR, 2011);
  48. c.set(Calendar.MONTH, Calendar.DECEMBER);
  49. c.set(Calendar.DAY_OF_MONTH, 15);
  50. c.set(Calendar.HOUR_OF_DAY, 0);
  51. c.set(Calendar.MINUTE, 0);
  52. c.set(Calendar.SECOND, 0);
  53. c.set(Calendar.MILLISECOND, 0);
  54. Date start = c.getTime();
  55. c.add(Calendar.DAY_OF_MONTH, 1);
  56. c.add(Calendar.SECOND, -1);
  57. Date end = c.getTime();
  58. return ImmutableSet.of(UsageRecord.builder()
  59. .accountName("admin").accountId("2").domainId("1").zoneId("1")
  60. .description("Template Id:203 Size:3117171712")
  61. .usage("24 Hrs").usageType(UsageRecord.UsageType.TEMPLATE).rawUsageHours(24)
  62. .templateId("0").id("203").startDate(start).endDate(end).build());
  63. }
  64. @Override
  65. protected Injector injector() {
  66. return Guice.createInjector(new GsonModule(), new CloudStackParserModule());
  67. }
  68. }