Skip to content

Commit 49f8740

Browse files
authored
Merge pull request #11 from Anshukumar123975/main
Add BDD Tests for Concepts, Enums, Namespaces and Imports Validations
2 parents a81a9de + 06af990 commit 49f8740

File tree

4 files changed

+335
-0
lines changed

4 files changed

+335
-0
lines changed

semantic/features/concepts.feature

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
Feature: Semantic Validation for CTO Class Declarations
2+
3+
Scenario: Property name uses system-reserved name
4+
Given I load the following models:
5+
| model_file | alias |
6+
| concepts/models/CLASS_DECLARATION_001/class_declaration_001_system_property_name.cto | main |
7+
Then an error should be thrown with message "Invalid field name '$class'"
8+
9+
Scenario: Valid property names that are not system-reserved
10+
Given I load the following models:
11+
| model_file | alias |
12+
| concepts/models/CLASS_DECLARATION_001/class_declaration_001_valid_property_name.cto | main |
13+
Then no error should be thrown
14+
15+
Scenario: $class property with invalid type
16+
Given I load the following models:
17+
| model_file | alias |
18+
| concepts/models/CLASS_DECLARATION_002/class_declaration_002_invalid_$class_type.cto | main |
19+
Then an error should be thrown with message "Invalid field name '$class'"
20+
21+
Scenario: Model without explicit $class declaration
22+
Given I load the following models:
23+
| model_file | alias |
24+
| concepts/models/CLASS_DECLARATION_002/class_declaration_002_valid_$class_type.cto | main |
25+
Then no error should be thrown
26+
27+
Scenario: Duplicate concept declarations in the same file
28+
Given I load the following models:
29+
| model_file | alias |
30+
| concepts/models/CLASS_DECLARATION_003/class_declaration_003_duplicate_class_name.cto | main |
31+
When I validate the models
32+
Then an error should be thrown with message "Duplicate class name"
33+
34+
Scenario: Uniquely named concept declarations
35+
Given I load the following models:
36+
| model_file | alias |
37+
| concepts/models/CLASS_DECLARATION_003/class_declaration_003_unique_class_name.cto | main |
38+
When I validate the models
39+
Then no error should be thrown
40+
41+
Scenario: Supertype does not exist
42+
Given I load the following models:
43+
| model_file | alias |
44+
| concepts/models/CLASS_DECLARATION_004/class_declaration_004_supertype_not_exist.cto | main |
45+
When I validate the models
46+
Then an error should be thrown with message "Could not find super type"
47+
48+
Scenario: Supertype is declared correctly
49+
Given I load the following models:
50+
| model_file | alias |
51+
| concepts/models/CLASS_DECLARATION_004/class_declaration_004_supertype_exist.cto | main |
52+
When I validate the models
53+
Then no error should be thrown
54+
55+
Scenario: Identifier field is not of type String or scalar
56+
Given I load the following models:
57+
| model_file | alias |
58+
| concepts/models/CLASS_DECLARATION_005/class_declaration_005_invalid_identifier_type.cto | main |
59+
When I validate the models
60+
Then an error should be thrown with message 'Class \"Entity\" is identified by field \"id\", but the type of the field is not \"String\"'
61+
62+
Scenario: Identifier field is of type String
63+
Given I load the following models:
64+
| model_file | alias |
65+
| concepts/models/CLASS_DECLARATION_005/class_declaration_005_valid_identifier_type_string.cto | main |
66+
When I validate the models
67+
Then no error should be thrown
68+
69+
Scenario: Identifier field is a String-based scalar
70+
Given I load the following models:
71+
| model_file | alias |
72+
| concepts/models/CLASS_DECLARATION_005/class_declaration_005_valid_identifier_type_scalar.cto | main |
73+
When I validate the models
74+
Then no error should be thrown
75+
76+
Scenario: Identifier field is optional
77+
Given I load the following models:
78+
| model_file | alias |
79+
| concepts/models/CLASS_DECLARATION_006/class_declaration_006_optional_identifier.cto | main |
80+
When I validate the models
81+
Then an error should be thrown with message "Identifying fields cannot be optional"
82+
83+
Scenario: Identifier field is required
84+
Given I load the following models:
85+
| model_file | alias |
86+
| concepts/models/CLASS_DECLARATION_006/class_declaration_006_required_identifier.cto | main |
87+
When I validate the models
88+
Then no error should be thrown
89+
90+
Scenario: Supertype is not system-identified
91+
Given I load the following models:
92+
| model_file | alias |
93+
| concepts/models/CLASS_DECLARATION_007/class_declaration_007_supertype_not_system_identified.cto | main |
94+
Then an error should be thrown with message 'Expected \"{\", comment, end of line, or whitespace but \"i\" found'
95+
96+
Scenario: Supertype is system-identified
97+
Given I load the following models:
98+
| model_file | alias |
99+
| concepts/models/CLASS_DECLARATION_007/class_declaration_007_supertype_system_identified.cto | main |
100+
When I validate the models
101+
Then no error should be thrown
102+
103+
Scenario: Property name duplicated from supertype
104+
Given I load the following models:
105+
| model_file | alias |
106+
| concepts/models/CLASS_DECLARATION_008/class_declaration_008_duplicate_property_from_super.cto | main |
107+
When I validate the models
108+
Then an error should be thrown with message "has more than one field named"
109+
110+
Scenario: Unique property names across inheritance
111+
Given I load the following models:
112+
| model_file | alias |
113+
| concepts/models/CLASS_DECLARATION_008/class_declaration_008_unique_property_from_super.cto | main |
114+
When I validate the models
115+
Then no error should be thrown
116+
117+
Scenario: Duplicate declarations should throw
118+
Given I load the following models:
119+
| model_file | alias |
120+
| concepts/models/DECLARATION_001/declaration_001_duplicate_within_model.cto | main |
121+
When I validate the models
122+
Then an error should be thrown with message "has more than one field named"
123+
124+
Scenario: Unique declarations should pass
125+
Given I load the following models:
126+
| model_file | alias |
127+
| concepts/models/DECLARATION_001/declaration_001_unique_within_model.cto | main |
128+
When I validate the models
129+
Then no error should be thrown
130+
131+
Scenario: Invalid identifier should throw
132+
Given I load the following models:
133+
| model_file | alias |
134+
| concepts/models/MODEL_ELEMENT_002/model_element_002_invalid_identifier_name.cto | main |
135+
Then an error should be thrown with message ""
136+
137+
Scenario: Valid identifier should pass
138+
Given I load the following models:
139+
| model_file | alias |
140+
| concepts/models/MODEL_ELEMENT_002/model_element_002_valid_identifier_name.cto | main |
141+
When I validate the models
142+
Then no error should be thrown
143+
144+
Scenario: Relationship to primitive should throw
145+
Given I load the following models:
146+
| model_file | alias |
147+
| concepts/models/RELATIONSHIP_001/relationship_001_non-primitive_type_relationship.cto | main |
148+
When I validate the models
149+
Then an error should be thrown with message "cannot be to the primitive type"
150+
151+
Scenario: Valid relationship to non-primitive should pass
152+
Given I load the following models:
153+
| model_file | alias |
154+
| concepts/models/RELATIONSHIP_001/relationship_001_primitive_type_relationship.cto | main |
155+
When I validate the models
156+
Then no error should be thrown
157+
158+
Scenario: Missing relationship type should throw
159+
Given I load the following models:
160+
| model_file | alias |
161+
| concepts/models/RELATIONSHIP_002/relationship_002_type_not_exist.cto | main |
162+
When I validate the models
163+
Then an error should be thrown with message "Undeclared type"
164+
165+
Scenario: Existing relationship type should pass
166+
Given I load the following models:
167+
| model_file | alias |
168+
| concepts/models/RELATIONSHIP_002/relationship_002_existing_type.cto | main |
169+
When I validate the models
170+
Then no error should be thrown
171+
172+
Scenario: Non-identified relationship target should throw
173+
Given I load the following models:
174+
| model_file | alias |
175+
| concepts/models/RELATIONSHIP_003/relationship_003_not_identified_type.cto | main |
176+
When I validate the models
177+
Then an error should be thrown with message "must be to a class that has an identifier"
178+
179+
Scenario: Identified relationship target should pass
180+
Given I load the following models:
181+
| model_file | alias |
182+
| concepts/models/RELATIONSHIP_003/relationship_003_identified_type.cto | main |
183+
When I validate the models
184+
Then no error should be thrown
185+
186+
Scenario: Undeclared non-primitive type should throw
187+
Given I load the following models:
188+
| model_file | alias |
189+
| concepts/models/PROPERTY_002/property_002_type_does_not_exist.cto | main |
190+
When I validate the models
191+
Then an error should be thrown with message "Undeclared type"
192+
193+
Scenario: Declared non-primitive type should pass
194+
Given I load the following models:
195+
| model_file | alias |
196+
| concepts/models/PROPERTY_002/property_002_type_exist.cto | main |
197+
When I validate the models
198+
Then no error should be thrown
199+
200+
Scenario: Invalid property meta type should throw
201+
Given I load the following models:
202+
| model_file | alias |
203+
| concepts/models/PROPERTY_003/property_003_meta_type_invalid.cto | main |
204+
Then an error should be thrown with message ""
205+
206+
Scenario: Valid property meta type should pass
207+
Given I load the following models:
208+
| model_file | alias |
209+
| concepts/models/PROPERTY_003/property_003_meta_type_valid.cto | main |
210+
When I validate the models
211+
Then no error should be thrown
212+
213+
Scenario: Duplicate decorator should throw
214+
Given I load the following models:
215+
| model_file | alias |
216+
| concepts/models/DECORATED_001/decorated_001_duplicate_decorator.cto | main |
217+
When I validate the models
218+
Then an error should be thrown with message "Duplicate decorator"
219+
220+
Scenario: Single decorator should pass
221+
Given I load the following models:
222+
| model_file | alias |
223+
| concepts/models/DECORATED_001/decorated_001_unique_decorator.cto | main |
224+
When I validate the models
225+
Then no error should be thrown

semantic/features/enums.feature

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Feature: Semantic Validation of Enum Declarations in CTO Models
2+
3+
Scenario: Duplicate enum names in the same file should throw an error
4+
Given I load the following models:
5+
| model_file | alias |
6+
| enums/models/DECLARATION_001/declaration_001_duplicate_enum_names.cto | main |
7+
When I validate the models
8+
Then an error should be thrown with message "Duplicate"
9+
10+
Scenario: Unique enum names in the same file should pass validation
11+
Given I load the following models:
12+
| model_file | alias |
13+
| enums/models/DECLARATION_001/declaration_001_unique_enum_names.cto | main |
14+
When I validate the models
15+
Then no error should be thrown
16+
17+
Scenario: Local enum name does not conflict with imported enum
18+
Given I load the following models:
19+
| model_file | alias |
20+
| enums/models/DECLARATION_002/importedTypes.cto | imported |
21+
| enums/models/DECLARATION_002/declaration_002_non_conflicting_name.cto | main |
22+
When I validate the models
23+
Then no error should be thrown
24+
25+
Scenario: Enum name conflicts with imported enum should throw an error
26+
Given I load the following models:
27+
| model_file | alias |
28+
| enums/models/DECLARATION_002/importedTypes.cto | imported |
29+
| enums/models/DECLARATION_002/declaration_002_name_conflict_with_import.cto | main |
30+
When I validate the models
31+
Then an error should be thrown with message "already defined in an imported model"
32+
33+
Scenario: Valid enum identifier name should pass validation
34+
Given I load the following models:
35+
| model_file | alias |
36+
| enums/models/MODEL_ELEMENT_002/model_element_002_valid_enum_name.cto | main |
37+
When I validate the models
38+
Then no error should be thrown
39+
40+
Scenario: Invalid enum identifier name should throw an error
41+
Given I load the following models:
42+
| model_file | alias |
43+
| enums/models/MODEL_ELEMENT_002/model_element_002_invalid_enum_name.cto | main |
44+
Then an error should be thrown with message "Expected"

semantic/features/imports.feature

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Feature: Semantic Validation of CTO Model Imports
2+
3+
Scenario: Local and imported types have unique names and should pass validation
4+
Given I load the following models:
5+
| model_file | alias |
6+
| imports/models/DECLARATION_002/importedTypes.cto | imported |
7+
| imports/models/DECLARATION_002/declaration_002_unique_with_imported_type.cto | main |
8+
When I validate the models
9+
Then no error should be thrown
10+
11+
Scenario: Conflict with imported type name should throw an error
12+
Given I load the following models:
13+
| model_file | alias |
14+
| imports/models/DECLARATION_002/importedTypes.cto | imported |
15+
| imports/models/DECLARATION_002/declaration_002_conflict_with_imported_type.cto | main |
16+
When I validate the models
17+
Then an error should be thrown with message "already defined in an imported model"
18+
19+
Scenario: Valid import and reference of existing type should pass validation
20+
Given I load the following models:
21+
| model_file | alias |
22+
| imports/models/DECLARATION_002/importedTypes.cto | imported |
23+
| imports/models/MODEL_FILE_001/model_file_001_existing_import_type.cto | main |
24+
When I validate the models
25+
Then no error should be thrown
26+
27+
Scenario: Importing a non-existent type should throw an error
28+
Given I load the following models:
29+
| model_file | alias |
30+
| imports/models/MODEL_FILE_001/model_file_001_import_nonexistent_type.cto | main |
31+
When I validate the models
32+
Then an error should be thrown with message "Namespace is not defined"
33+
34+
Scenario: Unique namespace imports should pass validation
35+
Given I load the following models:
36+
| model_file | alias |
37+
| imports/models/DECLARATION_002/importedTypes.cto | import1 |
38+
| imports/models/DECLARATION_002/importedTypes2.cto | import2 |
39+
| imports/models/MODEL_FILE_002/model_file_002_unique_namespace_imports.cto | main |
40+
When I validate the models
41+
Then no error should be thrown
42+
43+
Scenario: Duplicate namespace imports should throw an error
44+
Given I load the following models:
45+
| model_file | alias |
46+
| imports/models/DECLARATION_002/importedTypes.cto | import1 |
47+
| imports/models/MODEL_FILE_002/model_file_002_duplicate_namespace_imports.cto | main |
48+
When I validate the models
49+
Then an error should be thrown with message "Import from namespace .* already exists"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Semantic Validation of CTO Namespace Imports
2+
3+
Scenario: Invalid duplicate namespace imports should throw an error
4+
Given I load the following models:
5+
| model_file | alias |
6+
| namespaces/models/MODEL_FILE_002/importedTypes.cto | imported |
7+
| namespaces/models/MODEL_FILE_002/model_file_002_duplicate_namespace_imports.cto | main |
8+
When I validate the models
9+
Then an error should be thrown with message "Namespace org.external.types is already defined"
10+
11+
Scenario: Valid unique namespace imports should pass
12+
Given I load the following models:
13+
| model_file | alias |
14+
| namespaces/models/MODEL_FILE_002/importedTypes.cto | imported |
15+
| namespaces/models/MODEL_FILE_002/model_file_002_unique_namespace_imports.cto | main |
16+
When I validate the models
17+
Then no error should be thrown

0 commit comments

Comments
 (0)