Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0a80e4d3530ba4a64128f3c51147c35edcc4ef82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.define.traceability.data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;

/**
 * @author Roberto E. Escobar
 */
public class TestUnitData extends BaseTraceDataCache {

   private final List<Artifact> testCases;
   private final List<Artifact> testProcedures;
   private final List<Artifact> testSupportItems;
   private final Set<Artifact> allTestUnits;

   private final HashMap<String, Artifact> testCaseMap;
   private final HashMap<String, Artifact> testProcedureMap;
   private final HashMap<String, Artifact> testSupportMap;

   public TestUnitData(BranchId branch) {
      super("Test Unit Data", branch);
      this.testCaseMap = new HashMap<>();
      this.testProcedureMap = new HashMap<>();
      this.testSupportMap = new HashMap<>();

      this.testCases = new ArrayList<>();
      this.testProcedures = new ArrayList<>();
      this.testSupportItems = new ArrayList<>();

      this.allTestUnits = new TreeSet<>();
   }

   @Override
   public void reset() {
      super.reset();
      this.testCaseMap.clear();
      this.testProcedureMap.clear();
      this.testSupportMap.clear();

      this.testCases.clear();
      this.testProcedures.clear();
      this.testSupportItems.clear();

      this.allTestUnits.clear();
   }

   @Override
   protected void doBulkLoad(IProgressMonitor monitor) throws Exception {
      IProgressMonitor subMonitor = SubMonitor.convert(monitor);
      testCases.addAll(ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.TestCase, getBranch()));
      populateTraceMap(monitor, testCases, testCaseMap);
      subMonitor.worked(20);

      if (!monitor.isCanceled()) {
         monitor.subTask(String.format("Load Test Support from: [%s]", getBranch()));

         testSupportItems.addAll(ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.TestSupport, getBranch()));
         populateTraceMap(monitor, testSupportItems, testSupportMap);
         subMonitor.worked(20);
      }

      if (!monitor.isCanceled()) {
         monitor.subTask(String.format("Load Test Procedures from: [%s]", getBranch()));
         testProcedures.addAll(ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.TestProcedure, getBranch()));
         testProcedures.addAll(ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.TestProcedureWML, getBranch()));
         populateTraceMap(monitor, testProcedures, testProcedureMap);
         subMonitor.worked(20);
      }

      if (!monitor.isCanceled()) {
         allTestUnits.addAll(testCases);
         allTestUnits.addAll(testProcedures);
         allTestUnits.addAll(testSupportItems);
         subMonitor.worked(1);
      }
   }

   /**
    * @return the test cases
    */
   public Collection<Artifact> getTestCases() {
      return testCases;
   }

   /**
    * @return the test support items
    */
   public Collection<Artifact> getTestSupportItems() {
      return testSupportItems;
   }

   /**
    * @return the test procedures
    */
   public Collection<Artifact> getTestProcedures() {
      return testProcedures;
   }

   /**
    * @return the allTestUnits
    */
   public Set<Artifact> getAllTestUnits() {
      return allTestUnits;
   }

   /**
    * @return the testUnitArtifact
    */
   public Artifact getTestUnitByName(String testUnitName) {
      Artifact testUnit = testCaseMap.get(testUnitName);
      if (testUnit == null) {
         testUnit = testSupportMap.get(testUnitName);
      }
      if (testUnit == null) {
         testUnit = testProcedureMap.get(testUnitName);
      }
      return testUnit;
   }
}

Back to the top