PageRenderTime 75ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/api-audit/src/test/java/com/capitalone/dashboard/common/TestUtils.java

https://bitbucket.org/vijayda/hygieia
Java | 79 lines | 68 code | 11 blank | 0 comment | 0 complexity | 16d5587dec731d217e306e10f8982cca MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.capitalone.dashboard.common;
  2. import com.capitalone.dashboard.config.GsonUtil;
  3. import com.capitalone.dashboard.model.Collector;
  4. import com.capitalone.dashboard.model.CollectorItem;
  5. import com.capitalone.dashboard.model.Commit;
  6. import com.capitalone.dashboard.model.Component;
  7. import com.capitalone.dashboard.model.Dashboard;
  8. import com.capitalone.dashboard.model.GitRequest;
  9. import com.capitalone.dashboard.repository.BuildRepository;
  10. import com.capitalone.dashboard.repository.CodeQualityRepository;
  11. import com.capitalone.dashboard.repository.CollectorItemRepository;
  12. import com.capitalone.dashboard.repository.CollectorRepository;
  13. import com.capitalone.dashboard.repository.CommitRepository;
  14. import com.capitalone.dashboard.repository.ComponentRepository;
  15. import com.capitalone.dashboard.repository.DashboardRepository;
  16. import com.capitalone.dashboard.repository.GitRequestRepository;
  17. import com.capitalone.dashboard.repository.LibraryPolicyResultsRepository;
  18. import com.capitalone.dashboard.repository.TestResultRepository;
  19. import com.google.common.io.Resources;
  20. import com.google.gson.Gson;
  21. import com.google.gson.reflect.TypeToken;
  22. import com.mongodb.DB;
  23. import com.mongodb.DBCollection;
  24. import com.mongodb.DBObject;
  25. import com.mongodb.util.JSON;
  26. import org.apache.commons.io.IOUtils;
  27. import org.bson.types.ObjectId;
  28. import java.io.IOException;
  29. import java.lang.reflect.Type;
  30. import java.util.List;
  31. public class TestUtils {
  32. public static void loadDashBoard(DashboardRepository dashboardRepository) throws IOException {
  33. Gson gson = GsonUtil.getGson();
  34. String json = IOUtils.toString(Resources.getResource("./dashboard/dashboard.json"));
  35. Dashboard dashboard = gson.fromJson(json, Dashboard.class);
  36. dashboardRepository.save(dashboard);
  37. }
  38. public static void loadCollector (CollectorRepository collectorRepository) throws IOException {
  39. Gson gson = GsonUtil.getGson();
  40. String json = IOUtils.toString(Resources.getResource("./collectors/coll.json"));
  41. Collector collector = gson.fromJson(json, Collector.class);
  42. collectorRepository.save(collector);
  43. }
  44. public static void loadComponent(ComponentRepository componentRepository) throws IOException {
  45. Gson gson = GsonUtil.getGson();
  46. String json = IOUtils.toString(Resources.getResource("./component/component.json"));
  47. Component component = gson.fromJson(json, Component.class);
  48. componentRepository.save(component);
  49. }
  50. public static void loadCollectorItems(CollectorItemRepository collectorItemRepository) throws IOException {
  51. Gson gson = GsonUtil.getGson();
  52. String json = IOUtils.toString(Resources.getResource("./collector_items/items.json"));
  53. List<CollectorItem> collectorItem = gson.fromJson(json, new TypeToken<List<CollectorItem>>(){}.getType());
  54. collectorItemRepository.save(collectorItem);
  55. }
  56. public static void loadCommits(CommitRepository commitRepository) throws IOException {
  57. Gson gson = GsonUtil.getGson();
  58. String json = IOUtils.toString(Resources.getResource("./commits/commits.json"));
  59. List<Commit> commits = gson.fromJson(json, new TypeToken<List<Commit>>(){}.getType());
  60. commitRepository.save(commits);
  61. }
  62. public static void loadPullRequests(GitRequestRepository gitRequestRepository) throws IOException {
  63. Gson gson = GsonUtil.getGson();
  64. String json = IOUtils.toString(Resources.getResource("./gitrequests/prs.json"));
  65. List<GitRequest> prs = gson.fromJson(json, new TypeToken<List<GitRequest>>(){}.getType());
  66. gitRequestRepository.save(prs);
  67. }
  68. }