Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9a6c64fe4ab2c8ce650dd4f8f235b2837ceb04e6 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*******************************************************************************
 * 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.blam.operation;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
import org.eclipse.osee.framework.ui.skynet.results.XResultData;
import org.eclipse.osee.framework.ui.skynet.results.html.XResultPage.Manipulations;

public class TestPlanComplianceReport extends AbstractBlam {
   private static final String MISSING = "?";
   private static final String EMPTY = " ";
   private String[] previousCells = {MISSING, MISSING, MISSING, MISSING, MISSING};
   private final String[] columnHeaders =
         {"Test Plan & Paragraph", "Perf Spec Requirement(s)", "Test Procedure", "Test Status", "Test Result"};
   private Collection<Artifact> inputArtifacts;
   private Collection<Artifact> testPlans;
   private StringBuilder report;

   @Override
   public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception {
      init(variableMap);

      for (Artifact input : inputArtifacts) {
         processArtifacts(input);
      }

      report();
   }

   private void processArtifacts(Artifact node) throws OseeCoreException, IOException {
      Collection<Artifact> children = node.getChildren();

      if (isTestPlan(node)) {
         processTestPlan(node);
      } else {
         reportLine(node, "N/A (" + node.getArtifactTypeName() + ")", EMPTY, EMPTY);
      }
      for (Artifact child : children) {
         processArtifacts(child);
      }
   }

   private boolean isTestPlan(Artifact src) {
      ArtifactType temp = src.getArtifactType();
      if (temp.inheritsFrom(CoreArtifactTypes.TestPlanElement)) {
         return true;
      }

      return false;
   }

   private void processTestPlan(Artifact testPlan) throws OseeCoreException, IOException {
      Collection<Artifact> testProcedures = getTestProcedures(testPlan);

      if (testProcedures.isEmpty()) {
         reportLine(testPlan, MISSING, MISSING, MISSING);
      } else {
         for (Artifact testProc : testProcedures) {
            processTestProcedure(testPlan, testProc);
         }
      }
   }

   private void processTestProcedure(Artifact testPlan, Artifact testProc) throws IOException, OseeCoreException {
      Collection<Artifact> testResults = getTestResults(testProc);
      if (testResults.isEmpty()) {
         reportLine(testPlan, testProc.getName(), MISSING, MISSING);
      } else {
         for (Artifact testResult : testResults) {
            reportLine(testPlan, testProc.getName(), getStatus(testProc), testResult.getName());
         }
      }
   }

   private String getStatus(Artifact testProc) throws OseeCoreException {
      String returnValue = testProc.getSoleAttributeValue(CoreAttributeTypes.TEST_PROCEDURE_STATUS);

      return returnValue;
   }

   private String getName(Artifact art) throws OseeCoreException {
      String testPlanNumber = art.getSoleAttributeValue(CoreAttributeTypes.PARAGRAPH_NUMBER, "");
      String testPlanOutput = testPlanNumber + " " + art.getName();
      return testPlanOutput;
   }

   private Collection<Artifact> getTestProcedures(Artifact testPlan) throws OseeCoreException {
      Collection<Artifact> ret = testPlan.getRelatedArtifacts(CoreRelationTypes.Executes__Test_Procedure);

      return ret;
   }

   private Collection<Artifact> getTestResults(Artifact testProc) throws OseeCoreException {
      Collection<Artifact> ret = testProc.getRelatedArtifacts(CoreRelationTypes.Test_Unit_Result__Test_Result);

      return ret;
   }

   private String getRequirementsCellOutput(Artifact art) throws OseeCoreException {
      if (art.getArtifactType().inheritsFrom(CoreArtifactTypes.TestPlanElement)) {
         return getRequirementsCellOutputForTestPlan(art);
      }

      return EMPTY;
   }

   private String getRequirementsCellOutputForTestPlan(Artifact testPlan) throws OseeCoreException {
      String ret = getRequirementsAsString(testPlan);
      if (ret.isEmpty()) {
         ret = MISSING;
      }

      return ret;
   }

   private String getRequirementsAsString(Artifact testPlan) throws OseeCoreException {
      Collection<Artifact> requirementArtifacts =
            testPlan.getRelatedArtifacts(CoreRelationTypes.Verification_Plan__Requirement);
      Collection<String> requirementNames = new ArrayList<String>();
      for (Artifact req : requirementArtifacts) {
         String paragraphNumber = req.getSoleAttributeValue(CoreAttributeTypes.PARAGRAPH_NUMBER, "");
         requirementNames.add(paragraphNumber + " " + req.getName());
      }

      return StringUtils.join(requirementNames, "\n");
   }

   private void reportLine(Artifact art, String testProc, String testStatus, String testResult) throws IOException, OseeCoreException {
      String[] outputCells = new String[5];
      String testPlanOutput = getName(art);
      String requirements = getRequirementsCellOutput(art);
      String[] cells = new String[] {testPlanOutput, requirements, testProc, testStatus, testResult};
      for (int i = 0; i < cells.length; i++) {
         if (previousCells[i].equals(cells[i])) {
            if (i == 0 || outputCells[i - 1].equals(" ")) {
               outputCells[i] = " ";
            } else {
               outputCells[i] = cells[i];
            }
         } else {
            outputCells[i] = cells[i];
         }
      }
      previousCells = cells.clone();
      report.append(AHTML.addRowMultiColumnTable(outputCells));
   }

   private void report() throws OseeCoreException, IOException {
      report.append(AHTML.endMultiColumnTable());
      XResultData rd = new XResultData();
      rd.addRaw(report.toString());
      rd.report("Test Plan Compliance Report", Manipulations.RAW_HTML);
   }

   private void init(VariableMap variableMap) throws OseeCoreException, IOException {
      inputArtifacts = variableMap.getArtifacts("artifacts");
      initReport();
      load();
   }

   private void initReport() throws OseeCoreException, IOException {
      report = new StringBuilder(AHTML.beginMultiColumnTable(100, 1));
      report.append(AHTML.addHeaderRowMultiColumnTable(columnHeaders));
   }

   private void load() throws OseeCoreException {
      testPlans = new ArrayList<Artifact>();
      for (Artifact input : inputArtifacts) {
         testPlans.addAll(input.getDescendants());
      }
      RelationManager.getRelatedArtifacts(testPlans, 1, CoreRelationTypes.Verification_Plan__Requirement);
      Collection<Artifact> temp =
            RelationManager.getRelatedArtifacts(testPlans, 1, CoreRelationTypes.Executes__Test_Procedure);
      RelationManager.getRelatedArtifacts(temp, 1, CoreRelationTypes.Test_Unit_Result__Test_Result);
   }

   @Override
   public String getXWidgetsXml() {
      return "<xWidgets><XWidget xwidgetType=\"XListDropViewer\" displayName=\"artifacts\" /></xWidgets>";
   }

   @Override
   public Collection<String> getCategories() {
      return Arrays.asList("Define");
   }

   @Override
   public String getName() {
      return "Test Plan Compliance Report";
   }
}

Back to the top