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.util.LinkedList;
14 import java.util.List;
15
16 import dev.metaschema.core.datatype.adapter.TokenAdapter;
17 import dev.metaschema.core.model.IBoundObject;
18 import dev.metaschema.core.model.IMetaschemaData;
19 import dev.metaschema.core.model.JsonGroupAsBehavior;
20 import dev.metaschema.core.model.constraint.IConstraint;
21 import dev.metaschema.core.util.ObjectUtils;
22 import dev.metaschema.databind.model.annotations.AllowedValue;
23 import dev.metaschema.databind.model.annotations.AllowedValues;
24 import dev.metaschema.databind.model.annotations.BoundAssembly;
25 import dev.metaschema.databind.model.annotations.BoundFlag;
26 import dev.metaschema.databind.model.annotations.GroupAs;
27 import dev.metaschema.databind.model.annotations.MetaschemaAssembly;
28 import dev.metaschema.databind.model.annotations.ValueConstraints;
29 import edu.umd.cs.findbugs.annotations.NonNull;
30 import edu.umd.cs.findbugs.annotations.Nullable;
31
32
33
34
35 @MetaschemaAssembly(
36 formalName = "Generate Schema",
37 description = "Defines schema generation parameters and expected results.",
38 name = "generate-schema",
39 moduleClass = MetaschemaTestSuiteModule.class)
40 public class GenerateSchema implements IBoundObject {
41 private final IMetaschemaData __metaschemaData;
42
43
44
45
46 @BoundFlag(
47 formalName = "Generation Result",
48 description = "The expected result of schema generation.",
49 name = "generation-result",
50 defaultValue = "SUCCESS",
51 typeAdapter = TokenAdapter.class,
52 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {
53 @AllowedValue(value = "SUCCESS", description = "Generation succeeded."),
54 @AllowedValue(value = "FAILURE", description = "Generation resulted in failure caused by some error.") })))
55 private String _generationResult;
56
57
58
59
60 @BoundFlag(
61 formalName = "Validation Result",
62 description = "The expected result of content validation.",
63 name = "validation-result",
64 defaultValue = "VALID",
65 typeAdapter = TokenAdapter.class,
66 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR,
67 values = { @AllowedValue(value = "VALID", description = "Validation succeeded."),
68 @AllowedValue(value = "INVALID",
69 description = "Validation resulted in failure caused by some content defect or error.") })))
70 private String _validationResult;
71
72
73
74
75 @BoundAssembly(
76 formalName = "Metaschema",
77 description = "Reference to a metaschema module to load.",
78 useName = "metaschema",
79 minOccurs = 1)
80 private Metaschema _metaschema;
81
82
83
84
85 @BoundAssembly(
86 formalName = "Generation Case",
87 description = "A schema generation comparison test case.",
88 useName = "generation-case",
89 maxOccurs = -1,
90 groupAs = @GroupAs(name = "generation-cases", inJson = JsonGroupAsBehavior.LIST))
91 private List<GenerationCase> _generationCases;
92
93
94
95
96
97
98 public GenerateSchema() {
99 this(null);
100 }
101
102
103
104
105
106
107
108
109
110 public GenerateSchema(IMetaschemaData data) {
111 this.__metaschemaData = data;
112 }
113
114 @Override
115 public IMetaschemaData getMetaschemaData() {
116 return __metaschemaData;
117 }
118
119
120
121
122
123
124
125
126
127 @Nullable
128 public String getGenerationResult() {
129 return _generationResult;
130 }
131
132
133
134
135
136
137
138
139
140
141 public void setGenerationResult(@Nullable String value) {
142 _generationResult = value;
143 }
144
145
146
147
148
149
150
151
152
153 @Nullable
154 public String getValidationResult() {
155 return _validationResult;
156 }
157
158
159
160
161
162
163
164
165
166
167 public void setValidationResult(@Nullable String value) {
168 _validationResult = value;
169 }
170
171
172
173
174
175
176
177
178
179 @NonNull
180 public Metaschema getMetaschema() {
181 return _metaschema;
182 }
183
184
185
186
187
188
189
190
191
192
193 public void setMetaschema(@NonNull Metaschema value) {
194 _metaschema = value;
195 }
196
197
198
199
200
201
202
203
204
205 @NonNull
206 public List<GenerationCase> getGenerationCases() {
207 if (_generationCases == null) {
208 _generationCases = new LinkedList<>();
209 }
210 return ObjectUtils.notNull(_generationCases);
211 }
212
213
214
215
216
217
218
219
220
221
222 public void setGenerationCases(@NonNull List<GenerationCase> value) {
223 _generationCases = value;
224 }
225
226
227
228
229
230
231
232
233 public boolean addGenerationCase(GenerationCase item) {
234 GenerationCase value = ObjectUtils.requireNonNull(item, "item cannot be null");
235 if (_generationCases == null) {
236 _generationCases = new LinkedList<>();
237 }
238 return _generationCases.add(value);
239 }
240
241
242
243
244
245
246
247
248
249 public boolean removeGenerationCase(GenerationCase item) {
250 GenerationCase value = ObjectUtils.requireNonNull(item, "item cannot be null");
251 return _generationCases != null && _generationCases.remove(value);
252 }
253
254 @Override
255 public String toString() {
256 return ObjectUtils.notNull(new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString());
257 }
258 }