This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
/
ShaclMaxLengthValidationTest.java
88 lines (70 loc) · 2.57 KB
/
ShaclMaxLengthValidationTest.java
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
/*-*****************************************************************************
* Copyright (c) 2017 Yash Khatri.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* Contributors:
* Yash Khatri - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.lyo.validation;
import java.math.BigInteger;
import java.net.URI;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
/**
* The Class ShaclMaxLengthValidationTest.
*
* @author Yash Khatri
* @version $version-stub$
* @since 2.3.0
*/
public class ShaclMaxLengthValidationTest {
/**
* The a resource.
*/
AResource aResource;
/**
* Shacl max length negativetest.
* <p>
* This test is failing because the allowed max length of the StringProperty is 10 but here it
* is more than 10
*/
@Test
public void ShaclMaxLengthNegativetest() {
try {
aResource = new AResource(new URI("http://www.sampledomain.org/sam#AResource"));
//Invalid Value. The max allowed length of String is 10.
aResource.setAStringProperty("Between two and four");
aResource.setAnotherIntegerProperty(new BigInteger("12"));
aResource.addASetOfDates(new Date());
TestHelper.assertNegative(TestHelper.performTest(aResource), "maxLength violation. Expected length(\"Between two and four\") <= 10");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception should not be thrown");
}
}
/**
* Shacl max length positivetest.
*/
@Test
public void ShaclMaxLengthPositivetest() {
try {
aResource = new AResource(new URI("http://www.sampledomain.org/sam#AResource"));
aResource.setAnotherIntegerProperty(new BigInteger("12"));
aResource.setAStringProperty("Between");
aResource.addASetOfDates(new Date());
TestHelper.assertPositive(TestHelper.performTest(aResource));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception should not be thrown");
}
}
}