1
2
3
4
5
6
7
8 package dev.metaschema.model.testing.testsuite;
9
10 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
11 import org.apache.commons.lang3.builder.ToStringStyle;
12
13 import java.net.URI;
14 import java.util.LinkedList;
15 import java.util.List;
16
17 import dev.metaschema.core.datatype.adapter.StringAdapter;
18 import dev.metaschema.core.datatype.adapter.UriReferenceAdapter;
19 import dev.metaschema.core.model.IBoundObject;
20 import dev.metaschema.core.model.IMetaschemaData;
21 import dev.metaschema.core.model.JsonGroupAsBehavior;
22 import dev.metaschema.core.util.ObjectUtils;
23 import dev.metaschema.databind.model.annotations.BoundAssembly;
24 import dev.metaschema.databind.model.annotations.BoundFlag;
25 import dev.metaschema.databind.model.annotations.GroupAs;
26 import dev.metaschema.databind.model.annotations.MetaschemaAssembly;
27 import edu.umd.cs.findbugs.annotations.NonNull;
28
29
30
31
32 @MetaschemaAssembly(
33 formalName = "Test Collection",
34 description = "A collection of test scenarios located at a specific path.",
35 name = "test-collection",
36 moduleClass = MetaschemaTestSuiteModule.class)
37 public class TestCollection implements IBoundObject {
38 private final IMetaschemaData __metaschemaData;
39
40
41
42
43 @BoundFlag(
44 formalName = "Location",
45 description = "A URI reference to the location of this test collection.",
46 name = "location",
47 required = true,
48 typeAdapter = UriReferenceAdapter.class)
49 private URI _location;
50
51
52
53
54 @BoundFlag(
55 formalName = "Name",
56 description = "The name of this test collection.",
57 name = "name",
58 required = true,
59 typeAdapter = StringAdapter.class)
60 private String _name;
61
62
63
64
65 @BoundAssembly(
66 formalName = "Test Scenario",
67 description = "A test scenario that validates a metaschema and its content.",
68 useName = "test-scenario",
69 minOccurs = 1,
70 maxOccurs = -1,
71 groupAs = @GroupAs(name = "test-scenarios", inJson = JsonGroupAsBehavior.LIST))
72 private List<TestScenario> _testScenarios;
73
74
75
76
77
78
79 public TestCollection() {
80 this(null);
81 }
82
83
84
85
86
87
88
89
90
91 public TestCollection(IMetaschemaData data) {
92 this.__metaschemaData = data;
93 }
94
95 @Override
96 public IMetaschemaData getMetaschemaData() {
97 return __metaschemaData;
98 }
99
100
101
102
103
104
105
106
107
108 @NonNull
109 public URI getLocation() {
110 return _location;
111 }
112
113
114
115
116
117
118
119
120
121
122 public void setLocation(@NonNull URI value) {
123 _location = value;
124 }
125
126
127
128
129
130
131
132
133
134 @NonNull
135 public String getName() {
136 return _name;
137 }
138
139
140
141
142
143
144
145
146
147
148 public void setName(@NonNull String value) {
149 _name = value;
150 }
151
152
153
154
155
156
157
158
159
160 @NonNull
161 public List<TestScenario> getTestScenarios() {
162 if (_testScenarios == null) {
163 _testScenarios = new LinkedList<>();
164 }
165 return ObjectUtils.notNull(_testScenarios);
166 }
167
168
169
170
171
172
173
174
175
176
177 public void setTestScenarios(@NonNull List<TestScenario> value) {
178 _testScenarios = value;
179 }
180
181
182
183
184
185
186
187
188 public boolean addTestScenario(TestScenario item) {
189 TestScenario value = ObjectUtils.requireNonNull(item, "item cannot be null");
190 if (_testScenarios == null) {
191 _testScenarios = new LinkedList<>();
192 }
193 return _testScenarios.add(value);
194 }
195
196
197
198
199
200
201
202
203
204 public boolean removeTestScenario(TestScenario item) {
205 TestScenario value = ObjectUtils.requireNonNull(item, "item cannot be null");
206 return _testScenarios != null && _testScenarios.remove(value);
207 }
208
209 @Override
210 public String toString() {
211 return ObjectUtils.notNull(new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString());
212 }
213 }