From b2a72ccad24dba9fb8d6472bb38210973b156e73 Mon Sep 17 00:00:00 2001 From: Stefan Blaginov Date: Tue, 21 Nov 2023 21:06:15 +0000 Subject: [PATCH 1/6] fix(parser): throw error when concept is extending itself in CTO Signed-off-by: Stefan Blaginov Signed-off-by: Stefan Blaginov --- packages/concerto-cto/lib/parser.js | 15 +++++++++++++++ packages/concerto-cto/lib/parser.pegjs | 15 +++++++++++++++ .../test/cto/bad/self-extending-asset.bad.cto | 5 +++++ .../cto/bad/self-extending-concept.bad.cto | 5 +++++ .../test/cto/bad/self-extending-event.bad.cto | 5 +++++ .../cto/bad/self-extending-participant.bad.cto | 5 +++++ .../cto/bad/self-extending-transaction.bad.cto | 5 +++++ packages/concerto-cto/test/parserMain.js | 18 ++++++++++++++++++ 8 files changed, 73 insertions(+) create mode 100644 packages/concerto-cto/test/cto/bad/self-extending-asset.bad.cto create mode 100644 packages/concerto-cto/test/cto/bad/self-extending-concept.bad.cto create mode 100644 packages/concerto-cto/test/cto/bad/self-extending-event.bad.cto create mode 100644 packages/concerto-cto/test/cto/bad/self-extending-participant.bad.cto create mode 100644 packages/concerto-cto/test/cto/bad/self-extending-transaction.bad.cto diff --git a/packages/concerto-cto/lib/parser.js b/packages/concerto-cto/lib/parser.js index a41df2eae..903085fc8 100644 --- a/packages/concerto-cto/lib/parser.js +++ b/packages/concerto-cto/lib/parser.js @@ -624,6 +624,9 @@ function peg$parse(input, options) { ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The asset "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -643,6 +646,9 @@ function peg$parse(input, options) { ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The participant "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -662,6 +668,9 @@ function peg$parse(input, options) { ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The transaction "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -681,6 +690,9 @@ function peg$parse(input, options) { ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The event "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -700,6 +712,9 @@ function peg$parse(input, options) { ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The concept "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { diff --git a/packages/concerto-cto/lib/parser.pegjs b/packages/concerto-cto/lib/parser.pegjs index a7d993837..13ef92e75 100644 --- a/packages/concerto-cto/lib/parser.pegjs +++ b/packages/concerto-cto/lib/parser.pegjs @@ -966,6 +966,9 @@ AssetDeclaration ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The asset "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -989,6 +992,9 @@ ParticipantDeclaration ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The participant "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -1012,6 +1018,9 @@ TransactionDeclaration ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The transaction "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -1035,6 +1044,9 @@ EventDeclaration ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The event "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { @@ -1058,6 +1070,9 @@ ConceptDeclaration ...buildRange(location()) }; if (classExtension) { + if (classExtension.name === id.name) { + throw new Error(`The concept "${id.name}" cannot extend itself.`); + } result.superType = classExtension; } if (idField) { diff --git a/packages/concerto-cto/test/cto/bad/self-extending-asset.bad.cto b/packages/concerto-cto/test/cto/bad/self-extending-asset.bad.cto new file mode 100644 index 000000000..504d32c1c --- /dev/null +++ b/packages/concerto-cto/test/cto/bad/self-extending-asset.bad.cto @@ -0,0 +1,5 @@ +namespace com.acme@1.0.0 + +asset Self_Extending extends Self_Extending { + o String foo optional +} diff --git a/packages/concerto-cto/test/cto/bad/self-extending-concept.bad.cto b/packages/concerto-cto/test/cto/bad/self-extending-concept.bad.cto new file mode 100644 index 000000000..09ee02c28 --- /dev/null +++ b/packages/concerto-cto/test/cto/bad/self-extending-concept.bad.cto @@ -0,0 +1,5 @@ +namespace com.acme@1.0.0 + +concept Self_Extending extends Self_Extending { + o String foo optional +} diff --git a/packages/concerto-cto/test/cto/bad/self-extending-event.bad.cto b/packages/concerto-cto/test/cto/bad/self-extending-event.bad.cto new file mode 100644 index 000000000..1905ad5be --- /dev/null +++ b/packages/concerto-cto/test/cto/bad/self-extending-event.bad.cto @@ -0,0 +1,5 @@ +namespace com.acme@1.0.0 + +event Self_Extending extends Self_Extending { + o String foo optional +} diff --git a/packages/concerto-cto/test/cto/bad/self-extending-participant.bad.cto b/packages/concerto-cto/test/cto/bad/self-extending-participant.bad.cto new file mode 100644 index 000000000..58ec17ede --- /dev/null +++ b/packages/concerto-cto/test/cto/bad/self-extending-participant.bad.cto @@ -0,0 +1,5 @@ +namespace com.acme@1.0.0 + +participant Self_Extending extends Self_Extending { + o String foo optional +} diff --git a/packages/concerto-cto/test/cto/bad/self-extending-transaction.bad.cto b/packages/concerto-cto/test/cto/bad/self-extending-transaction.bad.cto new file mode 100644 index 000000000..e87064a98 --- /dev/null +++ b/packages/concerto-cto/test/cto/bad/self-extending-transaction.bad.cto @@ -0,0 +1,5 @@ +namespace com.acme@1.0.0 + +transaction Self_Extending extends Self_Extending { + o String foo optional +} diff --git a/packages/concerto-cto/test/parserMain.js b/packages/concerto-cto/test/parserMain.js index b42c67183..d9be05213 100644 --- a/packages/concerto-cto/test/parserMain.js +++ b/packages/concerto-cto/test/parserMain.js @@ -81,6 +81,24 @@ describe('parser', () => { }); }); + describe('self-extending', () => { + const declarationTypes = [ + 'asset', + 'participant', + 'transaction', + 'event', + 'concept', + ]; + declarationTypes.forEach(declarationType => { + it(`Should not parse a self-extending ${declarationType}`, () => { + let content = fs.readFileSync(`./test/cto/bad/self-extending-${declarationType}.bad.cto`, 'utf8'); + (() => { + Parser.parse(content); + }).should.throw(new RegExp(`The ${declarationType} ".+" cannot extend itself.`)); + }); + }); + }); + describe('identifiers', () => { const acceptedIdentifiers = [ From d5ed9f7552f57f7b15e2b931139faf8b5008712d Mon Sep 17 00:00:00 2001 From: Stefan Blaginov Date: Wed, 22 Nov 2023 18:12:08 +0000 Subject: [PATCH 2/6] fix(parser): throw error when concept is extending itself in JSON metamodel form Signed-off-by: Stefan Blaginov Signed-off-by: Stefan Blaginov --- packages/concerto-cto/lib/printer.js | 3 +++ packages/concerto-cto/test/printer.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/concerto-cto/lib/printer.js b/packages/concerto-cto/lib/printer.js index 3d4ab3798..ca00568f5 100644 --- a/packages/concerto-cto/lib/printer.js +++ b/packages/concerto-cto/lib/printer.js @@ -343,6 +343,9 @@ function declFromMetaModel(mm) { } } if (mm.superType) { + if (mm.superType.name === mm.name) { + throw new Error(`The declaration "${mm.name}" cannot extend itself.`); + } result += `extends ${mm.superType.name} `; } result += '{'; diff --git a/packages/concerto-cto/test/printer.js b/packages/concerto-cto/test/printer.js index d8090f46e..d50fe3456 100644 --- a/packages/concerto-cto/test/printer.js +++ b/packages/concerto-cto/test/printer.js @@ -62,4 +62,30 @@ describe('parser', () => { declarations: [], })).should.throw(Error, 'Unrecognized import'); }); + + it('Should throw error for a self-extending declaration', () => { + (() => Printer.toCTO({ + '$class': 'concerto.metamodel@1.0.0.Model', + 'namespace': 'com.acme@1.0.0', + 'declarations': [ + { + '$class': 'concerto.metamodel@1.0.0.AssetDeclaration', + 'name': 'Self_Extending', + 'isAbstract': false, + 'properties': [ + { + '$class': 'concerto.metamodel@1.0.0.StringProperty', + 'name': 'foo', + 'isArray': false, + 'isOptional': true + } + ], + 'superType': { + '$class': 'concerto.metamodel@1.0.0.TypeIdentifier', + 'name': 'Self_Extending' + } + } + ] + })).should.throw(Error, 'The declaration "Self_Extending" cannot extend itself.'); + }); }); From ff6b88fedce20e7a25ded91dc5f1994cd73c1b28 Mon Sep 17 00:00:00 2001 From: Stefan Blaginov Date: Mon, 27 Nov 2023 18:00:17 +0000 Subject: [PATCH 3/6] fix(parser): throw error when concept is extending itself in the AST Signed-off-by: Stefan Blaginov Signed-off-by: Stefan Blaginov --- .../lib/introspect/classdeclaration.js | 13 +++++++ packages/concerto-core/messages/en.json | 1 + .../classdeclaration.selfextendingasset.cto | 20 +++++++++++ .../classdeclaration.selfextendingconcept.cto | 20 +++++++++++ .../classdeclaration.selfextendingevent.cto | 20 +++++++++++ ...ssdeclaration.selfextendingparticipant.cto | 20 +++++++++++ ...ssdeclaration.selfextendingtransaction.cto | 20 +++++++++++ .../test/introspect/classdeclaration.js | 36 +++++++++++++++++++ 8 files changed, 150 insertions(+) create mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto create mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto create mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto create mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto create mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 18017a2a6..69680c693 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -200,6 +200,19 @@ class ClassDeclaration extends Declaration { // if we have a super type make sure it exists if (this.superType !== null) { + // and make sure that the class isn't extending itself + // (an exemption is made for the core classes) + if ( + this.superType === this.name && + ![ + 'Concept', 'Asset', 'Participant', 'Transaction', 'Event' + ].includes(this.superType) + ) { + let formatter = Globalize('en').messageFormatter('classdeclaration-validate-selfextending'); + throw new IllegalModelException(formatter({ + 'class': this.name, + }), this.modelFile, this.ast.location); + } this._resolveSuperType(); } diff --git a/packages/concerto-core/messages/en.json b/packages/concerto-core/messages/en.json index 910b20822..d4004f560 100644 --- a/packages/concerto-core/messages/en.json +++ b/packages/concerto-core/messages/en.json @@ -20,6 +20,7 @@ "classdeclaration-validate-identifiernotstring": "Class \"{class}\" is identified by field \"{idField}\", but the type of the field is not \"String\".", "classdeclaration-validate-duplicatefieldname": "Class \"{class}\" has more than one field named \"{fieldName}\".", "classdeclaration-validate-missingidentifier" : "Class \"{class}\" is not declared as \"abstract\". It must define an identifying field.", + "classdeclaration-validate-selfextending": "Class \"{class}\" cannot extend itself.", "modelfile-constructor-unrecmodelelem": "Unrecognised model element \"{type}\".", "modelfile-resolvetype-undecltype": "Undeclared type \"{type}\" in \"{context}\".", diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto new file mode 100644 index 000000000..1930aaa1b --- /dev/null +++ b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto @@ -0,0 +1,20 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace com.testing + +asset Self_Extending extends Self_Extending { + o String id + o String newValue +} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto new file mode 100644 index 000000000..2d8335aca --- /dev/null +++ b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto @@ -0,0 +1,20 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace com.testing + +concept Self_Extending extends Self_Extending { + o String id + o String newValue +} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto new file mode 100644 index 000000000..d24dd2db5 --- /dev/null +++ b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto @@ -0,0 +1,20 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace com.testing + +event Self_Extending extends Self_Extending { + o String id + o String newValue +} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto new file mode 100644 index 000000000..6c14ed6b3 --- /dev/null +++ b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto @@ -0,0 +1,20 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace com.testing + +participant Self_Extending extends Self_Extending { + o String id + o String newValue +} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto new file mode 100644 index 000000000..ab470a3a3 --- /dev/null +++ b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto @@ -0,0 +1,20 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace com.testing + +transaction Self_Extending extends Self_Extending { + o String id + o String newValue +} diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index 823862ab8..a7aaf8e36 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -20,6 +20,7 @@ const IllegalModelException = require('../../lib/introspect/illegalmodelexceptio const ClassDeclaration = require('../../lib/introspect/classdeclaration'); const AssetDeclaration = require('../../lib/introspect/assetdeclaration'); const EnumDeclaration = require('../../lib/introspect/enumdeclaration'); +const EventDeclaration = require('../../lib/introspect/eventdeclaration'); const ConceptDeclaration = require('../../lib/introspect/conceptdeclaration'); const ParticipantDeclaration = require('../../lib/introspect/participantdeclaration'); const TransactionDeclaration = require('../../lib/introspect/transactiondeclaration'); @@ -141,6 +142,41 @@ describe('ClassDeclaration', () => { const clazz = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.scalararray.cto', ConceptDeclaration); clazz.validate(); }); + + it('should throw when an asset is extending itself', () => { + let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingasset.cto', AssetDeclaration); + (() => { + asset.validate(); + }).should.throw(/Class "Self_Extending" cannot extend itself./); + }); + + it('should throw when a concept is extending itself', () => { + let concept = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingconcept.cto', ConceptDeclaration); + (() => { + concept.validate(); + }).should.throw(/Class "Self_Extending" cannot extend itself./); + }); + + it('should throw when an event is extending itself', () => { + let event = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingevent.cto', EventDeclaration); + (() => { + event.validate(); + }).should.throw(/Class "Self_Extending" cannot extend itself./); + }); + + it('should throw when a participant is extending itself', () => { + let participant = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingparticipant.cto', ParticipantDeclaration); + (() => { + participant.validate(); + }).should.throw(/Class "Self_Extending" cannot extend itself./); + }); + + it('should throw when a transaction is extending itself', () => { + let transaction = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingtransaction.cto', TransactionDeclaration); + (() => { + transaction.validate(); + }).should.throw(/Class "Self_Extending" cannot extend itself./); + }); }); describe('#accept', () => { From 0d27c88a45e0efcbbdd9940ecd31139fab631e9e Mon Sep 17 00:00:00 2001 From: Stefan Blaginov Date: Mon, 27 Nov 2023 18:01:31 +0000 Subject: [PATCH 4/6] refactor(validation): alphabetical rearrangement Signed-off-by: Stefan Blaginov Signed-off-by: Stefan Blaginov --- packages/concerto-core/lib/introspect/classdeclaration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 69680c693..ba97a6aca 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -205,7 +205,7 @@ class ClassDeclaration extends Declaration { if ( this.superType === this.name && ![ - 'Concept', 'Asset', 'Participant', 'Transaction', 'Event' + 'Asset', 'Concept', 'Event', 'Participant', 'Transaction', ].includes(this.superType) ) { let formatter = Globalize('en').messageFormatter('classdeclaration-validate-selfextending'); From eb3d9b8d5da84b8062b18cca6501df062dacc600 Mon Sep 17 00:00:00 2001 From: Stefan Blaginov Date: Mon, 27 Nov 2023 19:10:35 +0000 Subject: [PATCH 5/6] test(self-extending): remove redundant tests (codepath covered in concerto-cto) Signed-off-by: Stefan Blaginov Signed-off-by: Stefan Blaginov --- .../classdeclaration.selfextendingasset.cto | 20 ----------- .../classdeclaration.selfextendingconcept.cto | 20 ----------- .../classdeclaration.selfextendingevent.cto | 20 ----------- ...ssdeclaration.selfextendingparticipant.cto | 20 ----------- ...ssdeclaration.selfextendingtransaction.cto | 20 ----------- .../test/introspect/classdeclaration.js | 35 ------------------- 6 files changed, 135 deletions(-) delete mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto delete mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto delete mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto delete mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto delete mode 100644 packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto deleted file mode 100644 index 1930aaa1b..000000000 --- a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingasset.cto +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace com.testing - -asset Self_Extending extends Self_Extending { - o String id - o String newValue -} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto deleted file mode 100644 index 2d8335aca..000000000 --- a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingconcept.cto +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace com.testing - -concept Self_Extending extends Self_Extending { - o String id - o String newValue -} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto deleted file mode 100644 index d24dd2db5..000000000 --- a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingevent.cto +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace com.testing - -event Self_Extending extends Self_Extending { - o String id - o String newValue -} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto deleted file mode 100644 index 6c14ed6b3..000000000 --- a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingparticipant.cto +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace com.testing - -participant Self_Extending extends Self_Extending { - o String id - o String newValue -} diff --git a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto b/packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto deleted file mode 100644 index ab470a3a3..000000000 --- a/packages/concerto-core/test/data/parser/classdeclaration.selfextendingtransaction.cto +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace com.testing - -transaction Self_Extending extends Self_Extending { - o String id - o String newValue -} diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index a7aaf8e36..78546c073 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -142,41 +142,6 @@ describe('ClassDeclaration', () => { const clazz = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.scalararray.cto', ConceptDeclaration); clazz.validate(); }); - - it('should throw when an asset is extending itself', () => { - let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingasset.cto', AssetDeclaration); - (() => { - asset.validate(); - }).should.throw(/Class "Self_Extending" cannot extend itself./); - }); - - it('should throw when a concept is extending itself', () => { - let concept = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingconcept.cto', ConceptDeclaration); - (() => { - concept.validate(); - }).should.throw(/Class "Self_Extending" cannot extend itself./); - }); - - it('should throw when an event is extending itself', () => { - let event = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingevent.cto', EventDeclaration); - (() => { - event.validate(); - }).should.throw(/Class "Self_Extending" cannot extend itself./); - }); - - it('should throw when a participant is extending itself', () => { - let participant = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingparticipant.cto', ParticipantDeclaration); - (() => { - participant.validate(); - }).should.throw(/Class "Self_Extending" cannot extend itself./); - }); - - it('should throw when a transaction is extending itself', () => { - let transaction = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.selfextendingtransaction.cto', TransactionDeclaration); - (() => { - transaction.validate(); - }).should.throw(/Class "Self_Extending" cannot extend itself./); - }); }); describe('#accept', () => { From 3817599cf1eb5a55ae623a06941929c2551d27ca Mon Sep 17 00:00:00 2001 From: Stefan Blaginov Date: Mon, 27 Nov 2023 19:16:20 +0000 Subject: [PATCH 6/6] test(fix): remove unneeded import Signed-off-by: Stefan Blaginov --- packages/concerto-core/test/introspect/classdeclaration.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index 78546c073..823862ab8 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -20,7 +20,6 @@ const IllegalModelException = require('../../lib/introspect/illegalmodelexceptio const ClassDeclaration = require('../../lib/introspect/classdeclaration'); const AssetDeclaration = require('../../lib/introspect/assetdeclaration'); const EnumDeclaration = require('../../lib/introspect/enumdeclaration'); -const EventDeclaration = require('../../lib/introspect/eventdeclaration'); const ConceptDeclaration = require('../../lib/introspect/conceptdeclaration'); const ParticipantDeclaration = require('../../lib/introspect/participantdeclaration'); const TransactionDeclaration = require('../../lib/introspect/transactiondeclaration');