View Javadoc
1   /**
2    * Portions of this software was developed by employees of the National Institute
3    * of Standards and Technology (NIST), an agency of the Federal Government and is
4    * being made available as a public service. Pursuant to title 17 United States
5    * Code Section 105, works of NIST employees are not subject to copyright
6    * protection in the United States. This software may be subject to foreign
7    * copyright. Permission in the United States and in foreign countries, to the
8    * extent that NIST may hold copyright, to use, copy, modify, create derivative
9    * works, and distribute this software and its documentation without fee is hereby
10   * granted on a non-exclusive basis, provided that this notice and disclaimer
11   * of warranty appears in all copies.
12   *
13   * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14   * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15   * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17   * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18   * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE.  IN NO EVENT
19   * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20   * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21   * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22   * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23   * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24   * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25   */
26  
27  package gov.nist.secauto.decima.xml.testing;
28  
29  import gov.nist.secauto.decima.core.requirement.AbstractBaseRequirement;
30  import gov.nist.secauto.decima.core.requirement.AbstractRequirement;
31  import gov.nist.secauto.decima.core.requirement.BaseRequirement;
32  import gov.nist.secauto.decima.core.requirement.DerivedRequirement;
33  import gov.nist.secauto.decima.core.requirement.RequirementType;
34  import gov.nist.secauto.decima.core.requirement.RequirementsManager;
35  import gov.nist.secauto.decima.core.requirement.SpecificationReference;
36  
37  import java.net.URI;
38  import java.util.Collection;
39  import java.util.Collections;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Map;
43  import java.util.Set;
44  
45  public class StubRequirementsManager implements RequirementsManager {
46    private static final String STUB_STATEMENT = "something";
47  
48    public Map<String, BaseRequirement> baseRequirements;
49  
50    /**
51     * Construct a new requirements manager that does not require a requirements definition.
52     * 
53     * @param testedDerivedRequirements
54     *          the set of derived requirements that have been reported during testing
55     */
56    public StubRequirementsManager(Set<String> testedDerivedRequirements) {
57      this.baseRequirements = new HashMap<>();
58      for (String derivedReqId : testedDerivedRequirements) {
59        StubBaseRequirement base = new StubBaseRequirement(derivedReqId);
60        baseRequirements.put(derivedReqId, base);
61        base.addDerivedRequirement(new StubDerivedRequirement(derivedReqId, base));
62      }
63    }
64  
65    @Override
66    public List<URI> getRequirementDefinitions() {
67      return Collections.emptyList();
68    }
69  
70    @Override
71    public BaseRequirement getBaseRequirementById(String id) {
72      return baseRequirements.get(id);
73    }
74  
75    @Override
76    public Collection<BaseRequirement> getBaseRequirements() {
77      return baseRequirements.values();
78    }
79  
80    @Override
81    public DerivedRequirement getDerivedRequirementById(String id) {
82      BaseRequirement base = getBaseRequirementById(id);
83      return base == null ? null : base.getDerivedRequirementById(id);
84    }
85  
86    private static class StubBaseRequirement
87        extends AbstractBaseRequirement {
88  
89      public StubBaseRequirement(String id) {
90        super(id, STUB_STATEMENT);
91      }
92  
93      @Override
94      public SpecificationReference getSpecificationReference() {
95        throw new UnsupportedOperationException();
96      }
97  
98    }
99  
100   private static class StubDerivedRequirement
101       extends AbstractRequirement
102       implements DerivedRequirement {
103     private final BaseRequirement baseRequirement;
104 
105     public StubDerivedRequirement(String id, BaseRequirement base) {
106       super(id, STUB_STATEMENT);
107       this.baseRequirement = base;
108     }
109 
110     @Override
111     public BaseRequirement getBaseRequirement() {
112       return baseRequirement;
113     }
114 
115     @Override
116     public RequirementType getType() {
117       return RequirementType.MUST;
118     }
119 
120     @Override
121     public String getMessageText(String... args) {
122       return "message";
123     }
124 
125     @Override
126     public boolean isConditional() {
127       // never conditional, since no requirements XML is used. This simplifies unit test writing.
128       return false;
129     }
130   }
131 }