/api-audit/src/test/java/com/capitalone/dashboard/common/TestUtils.java
Java | 79 lines | 68 code | 11 blank | 0 comment | 0 complexity | 16d5587dec731d217e306e10f8982cca MD5 | raw file
Possible License(s): Apache-2.0
- package com.capitalone.dashboard.common;
- import com.capitalone.dashboard.config.GsonUtil;
- import com.capitalone.dashboard.model.Collector;
- import com.capitalone.dashboard.model.CollectorItem;
- import com.capitalone.dashboard.model.Commit;
- import com.capitalone.dashboard.model.Component;
- import com.capitalone.dashboard.model.Dashboard;
- import com.capitalone.dashboard.model.GitRequest;
- import com.capitalone.dashboard.repository.BuildRepository;
- import com.capitalone.dashboard.repository.CodeQualityRepository;
- import com.capitalone.dashboard.repository.CollectorItemRepository;
- import com.capitalone.dashboard.repository.CollectorRepository;
- import com.capitalone.dashboard.repository.CommitRepository;
- import com.capitalone.dashboard.repository.ComponentRepository;
- import com.capitalone.dashboard.repository.DashboardRepository;
- import com.capitalone.dashboard.repository.GitRequestRepository;
- import com.capitalone.dashboard.repository.LibraryPolicyResultsRepository;
- import com.capitalone.dashboard.repository.TestResultRepository;
- import com.google.common.io.Resources;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.mongodb.DB;
- import com.mongodb.DBCollection;
- import com.mongodb.DBObject;
- import com.mongodb.util.JSON;
- import org.apache.commons.io.IOUtils;
- import org.bson.types.ObjectId;
- import java.io.IOException;
- import java.lang.reflect.Type;
- import java.util.List;
- public class TestUtils {
- public static void loadDashBoard(DashboardRepository dashboardRepository) throws IOException {
- Gson gson = GsonUtil.getGson();
- String json = IOUtils.toString(Resources.getResource("./dashboard/dashboard.json"));
- Dashboard dashboard = gson.fromJson(json, Dashboard.class);
- dashboardRepository.save(dashboard);
- }
- public static void loadCollector (CollectorRepository collectorRepository) throws IOException {
- Gson gson = GsonUtil.getGson();
- String json = IOUtils.toString(Resources.getResource("./collectors/coll.json"));
- Collector collector = gson.fromJson(json, Collector.class);
- collectorRepository.save(collector);
- }
- public static void loadComponent(ComponentRepository componentRepository) throws IOException {
- Gson gson = GsonUtil.getGson();
- String json = IOUtils.toString(Resources.getResource("./component/component.json"));
- Component component = gson.fromJson(json, Component.class);
- componentRepository.save(component);
- }
- public static void loadCollectorItems(CollectorItemRepository collectorItemRepository) throws IOException {
- Gson gson = GsonUtil.getGson();
- String json = IOUtils.toString(Resources.getResource("./collector_items/items.json"));
- List<CollectorItem> collectorItem = gson.fromJson(json, new TypeToken<List<CollectorItem>>(){}.getType());
- collectorItemRepository.save(collectorItem);
- }
- public static void loadCommits(CommitRepository commitRepository) throws IOException {
- Gson gson = GsonUtil.getGson();
- String json = IOUtils.toString(Resources.getResource("./commits/commits.json"));
- List<Commit> commits = gson.fromJson(json, new TypeToken<List<Commit>>(){}.getType());
- commitRepository.save(commits);
- }
- public static void loadPullRequests(GitRequestRepository gitRequestRepository) throws IOException {
- Gson gson = GsonUtil.getGson();
- String json = IOUtils.toString(Resources.getResource("./gitrequests/prs.json"));
- List<GitRequest> prs = gson.fromJson(json, new TypeToken<List<GitRequest>>(){}.getType());
- gitRequestRepository.save(prs);
- }
- }