|
15 | 15 | import gov.nist.secauto.metaschema.core.model.ISource; |
16 | 16 | import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValue; |
17 | 17 | import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValuesConstraint; |
| 18 | +import gov.nist.secauto.metaschema.core.model.constraint.ICardinalityConstraint; |
18 | 19 | import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; |
| 20 | +import gov.nist.secauto.metaschema.core.model.constraint.IExpectConstraint; |
| 21 | +import gov.nist.secauto.metaschema.core.model.constraint.IIndexConstraint; |
| 22 | +import gov.nist.secauto.metaschema.core.model.constraint.IIndexHasKeyConstraint; |
| 23 | +import gov.nist.secauto.metaschema.core.model.constraint.IKeyField; |
19 | 24 | import gov.nist.secauto.metaschema.core.model.constraint.IMatchesConstraint; |
| 25 | +import gov.nist.secauto.metaschema.core.model.constraint.IUniqueConstraint; |
20 | 26 | import gov.nist.secauto.metaschema.core.testsupport.MockedModelTestSupport; |
21 | 27 | import gov.nist.secauto.metaschema.core.testsupport.builder.IConstraintSetBuilder; |
22 | 28 |
|
@@ -188,4 +194,115 @@ void testConstraintSetWithMultipleContexts() { |
188 | 194 | assertNotNull(constraintSet, "Constraint set should not be null"); |
189 | 195 | assertEquals(source, constraintSet.getSource(), "Source should match"); |
190 | 196 | } |
| 197 | + |
| 198 | + @Test |
| 199 | + void testConstraintSetWithExpectConstraint() { |
| 200 | + // Given |
| 201 | + MockedModelTestSupport mocking = new MockedModelTestSupport(); |
| 202 | + ISource source = ISource.externalSource(URI.create(TEST_NAMESPACE)); |
| 203 | + |
| 204 | + // When |
| 205 | + IConstraintSet constraintSet = mocking.constraintSet() |
| 206 | + .source(source) |
| 207 | + .context(ctx -> ctx |
| 208 | + .metapath("//item") |
| 209 | + .constraint(IExpectConstraint.builder() |
| 210 | + .source(source) |
| 211 | + .target(IMetapathExpression.compile(".")) |
| 212 | + .test(IMetapathExpression.compile("@id != ''")))) |
| 213 | + .build(); |
| 214 | + |
| 215 | + // Then |
| 216 | + assertNotNull(constraintSet, "Constraint set should not be null"); |
| 217 | + assertEquals(source, constraintSet.getSource(), "Source should match"); |
| 218 | + } |
| 219 | + |
| 220 | + @Test |
| 221 | + void testConstraintSetWithCardinalityConstraint() { |
| 222 | + // Given |
| 223 | + MockedModelTestSupport mocking = new MockedModelTestSupport(); |
| 224 | + ISource source = ISource.externalSource(URI.create(TEST_NAMESPACE)); |
| 225 | + |
| 226 | + // When |
| 227 | + IConstraintSet constraintSet = mocking.constraintSet() |
| 228 | + .source(source) |
| 229 | + .context(ctx -> ctx |
| 230 | + .metapath("//parent") |
| 231 | + .constraint(ICardinalityConstraint.builder() |
| 232 | + .source(source) |
| 233 | + .target(IMetapathExpression.compile("child")) |
| 234 | + .minOccurs(1) |
| 235 | + .maxOccurs(5))) |
| 236 | + .build(); |
| 237 | + |
| 238 | + // Then |
| 239 | + assertNotNull(constraintSet, "Constraint set should not be null"); |
| 240 | + assertEquals(source, constraintSet.getSource(), "Source should match"); |
| 241 | + } |
| 242 | + |
| 243 | + @Test |
| 244 | + void testConstraintSetWithIndexConstraint() { |
| 245 | + // Given |
| 246 | + MockedModelTestSupport mocking = new MockedModelTestSupport(); |
| 247 | + ISource source = ISource.externalSource(URI.create(TEST_NAMESPACE)); |
| 248 | + |
| 249 | + // When |
| 250 | + IConstraintSet constraintSet = mocking.constraintSet() |
| 251 | + .source(source) |
| 252 | + .context(ctx -> ctx |
| 253 | + .metapath("//items") |
| 254 | + .constraint(IIndexConstraint.builder("item-index") |
| 255 | + .source(source) |
| 256 | + .target(IMetapathExpression.compile("item")) |
| 257 | + .keyField(IKeyField.of(IMetapathExpression.compile("@id"), null, null)))) |
| 258 | + .build(); |
| 259 | + |
| 260 | + // Then |
| 261 | + assertNotNull(constraintSet, "Constraint set should not be null"); |
| 262 | + assertEquals(source, constraintSet.getSource(), "Source should match"); |
| 263 | + } |
| 264 | + |
| 265 | + @Test |
| 266 | + void testConstraintSetWithIndexHasKeyConstraint() { |
| 267 | + // Given |
| 268 | + MockedModelTestSupport mocking = new MockedModelTestSupport(); |
| 269 | + ISource source = ISource.externalSource(URI.create(TEST_NAMESPACE)); |
| 270 | + |
| 271 | + // When |
| 272 | + IConstraintSet constraintSet = mocking.constraintSet() |
| 273 | + .source(source) |
| 274 | + .context(ctx -> ctx |
| 275 | + .metapath("//reference") |
| 276 | + .constraint(IIndexHasKeyConstraint.builder("item-index") |
| 277 | + .source(source) |
| 278 | + .target(IMetapathExpression.compile(".")) |
| 279 | + .keyField(IKeyField.of(IMetapathExpression.compile("@item-ref"), null, null)))) |
| 280 | + .build(); |
| 281 | + |
| 282 | + // Then |
| 283 | + assertNotNull(constraintSet, "Constraint set should not be null"); |
| 284 | + assertEquals(source, constraintSet.getSource(), "Source should match"); |
| 285 | + } |
| 286 | + |
| 287 | + @Test |
| 288 | + void testConstraintSetWithUniqueConstraint() { |
| 289 | + // Given |
| 290 | + MockedModelTestSupport mocking = new MockedModelTestSupport(); |
| 291 | + ISource source = ISource.externalSource(URI.create(TEST_NAMESPACE)); |
| 292 | + |
| 293 | + // When |
| 294 | + IConstraintSet constraintSet = mocking.constraintSet() |
| 295 | + .source(source) |
| 296 | + .context(ctx -> ctx |
| 297 | + .metapath("//collection") |
| 298 | + .constraint(IUniqueConstraint.builder() |
| 299 | + .source(source) |
| 300 | + .target(IMetapathExpression.compile("entry")) |
| 301 | + .keyField(IKeyField.of(IMetapathExpression.compile("@key"), null, null)))) |
| 302 | + .build(); |
| 303 | + |
| 304 | + // Then |
| 305 | + assertNotNull(constraintSet, "Constraint set should not be null"); |
| 306 | + assertEquals(source, constraintSet.getSource(), "Source should match"); |
| 307 | + } |
191 | 308 | } |
0 commit comments