-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jonathan Casey <[email protected]>
- Loading branch information
1 parent
a43cc62
commit a8860fb
Showing
5 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/concerto-core/test/data/decoratorcommands/invalid-target-element.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$class" : "[email protected]", | ||
"name" : "invalid-target-element", | ||
"version": "1.0.0", | ||
"commands" : [ | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"declaration" : "Dictionary", | ||
"element" : "INVALID_ELEMENT" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "Test" | ||
} | ||
} | ||
] | ||
} |
112 changes: 112 additions & 0 deletions
112
packages/concerto-core/test/data/decoratorcommands/map-declaration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
{ | ||
"$class" : "[email protected]", | ||
"name" : "web", | ||
"version": "1.0.0", | ||
"commands" : [ | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"declaration" : "Dictionary", | ||
"type" : "[email protected]", | ||
"element": "KEY" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "Foo", | ||
"arguments" : [] | ||
} | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"declaration" : "Dictionary", | ||
"type" : "[email protected]", | ||
"element": "VALUE" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "Bar", | ||
"arguments" : [] | ||
} | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"declaration" : "Dictionary", | ||
"element": "*" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "Baz", | ||
"arguments" : [] | ||
} | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"declaration" : "Dictionary", | ||
"type" : "[email protected]" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "DecoratesKeyByType", | ||
"arguments" : [] | ||
} | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"declaration" : "Dictionary", | ||
"type" : "[email protected]" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "DecoratesValueByType", | ||
"arguments" : [] | ||
} | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"type" : "[email protected]" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "DecoratesAllMapKeys", | ||
"arguments" : [] | ||
} | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"namespace" : "[email protected]", | ||
"type" : "[email protected]" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "DecoratesAllMapValues", | ||
"arguments" : [] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,107 @@ describe('DecoratorManager', () => { | |
(decoratorZipProperty ===null).should.be.true; | ||
}); | ||
|
||
it('should decorate the specified element on the specified Map Declaration (Map Key)', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true, skipLocationNodes: true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/map-declaration.json', 'utf-8'); | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
|
||
const dictionary = decoratedModelManager.getType('[email protected]'); | ||
dictionary.should.not.be.null; | ||
dictionary.key.getDecorator('Foo').should.not.be.null; | ||
}); | ||
|
||
it('should decorate the specified type on the specified Map Declaration (Map Key)', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true, skipLocationNodes: true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/map-declaration.json', 'utf-8'); | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
|
||
const dictionary = decoratedModelManager.getType('[email protected]'); | ||
dictionary.should.not.be.null; | ||
dictionary.key.getDecorator('DecoratesKeyByType').should.not.be.null; | ||
}); | ||
|
||
it('should decorate the specified element on the specified Map Declaration (Map Value)', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true, skipLocationNodes: true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/map-declaration.json', 'utf-8'); | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
|
||
const dictionary = decoratedModelManager.getType('[email protected]'); | ||
|
||
dictionary.should.not.be.null; | ||
dictionary.value.getDecorator('Bar').should.not.be.null; | ||
}); | ||
|
||
it('should decorate the specified type on the specified Map Declaration (Map Value)', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true, skipLocationNodes: true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/map-declaration.json', 'utf-8'); | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
|
||
const dictionary = decoratedModelManager.getType('[email protected]'); | ||
dictionary.should.not.be.null; | ||
dictionary.value.getDecorator('DecoratesValueByType').should.not.be.null; | ||
}); | ||
|
||
it('should decorate both Key and Value elements on the specified Map Declaration', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true, skipLocationNodes: true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/map-declaration.json', 'utf-8'); | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
|
||
const dictionary = decoratedModelManager.getType('[email protected]'); | ||
|
||
dictionary.should.not.be.null; | ||
dictionary.key.getDecorator('Baz').should.not.be.null; | ||
dictionary.value.getDecorator('Baz').should.not.be.null; | ||
}); | ||
|
||
it('should decorate all Map Declaration Key and Value elements on the model when a declaration is not specified', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true, skipLocationNodes: true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/map-declaration.json', 'utf-8'); | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
|
||
|
||
const dictionary = decoratedModelManager.getType('[email protected]'); | ||
const rolodex = decoratedModelManager.getType('[email protected]'); | ||
|
||
dictionary.should.not.be.null; | ||
dictionary.key.getDecorator('DecoratesAllMapKeys').should.not.be.null; | ||
dictionary.value.getDecorator('DecoratesAllMapValues').should.not.be.null; | ||
|
||
rolodex.should.not.be.null; | ||
rolodex.key.getDecorator('DecoratesAllMapKeys').should.not.be.null; | ||
rolodex.value.getDecorator('DecoratesAllMapValues').should.not.be.null; | ||
}); | ||
|
||
it('should fail with invalid command', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true}); | ||
|
@@ -243,6 +344,20 @@ describe('DecoratorManager', () => { | |
{validate: true, validateCommands: true}); | ||
}).should.throw(/Decorator Command references both property and properties. You must either reference a single property or a list of properites./); | ||
}); | ||
|
||
it('should detect invalid target element', async function() { | ||
// load a model to decorate | ||
const testModelManager = new ModelManager({strict:true}); | ||
const modelText = fs.readFileSync('./test/data/decoratorcommands/test.cto', 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
|
||
const dcs = fs.readFileSync('./test/data/decoratorcommands/invalid-target-element.json', 'utf-8'); | ||
|
||
(() => { | ||
DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true}); | ||
}).should.throw(/Decorator Command contains invalid target element: INVALID_ELEMENT/); | ||
}); | ||
}); | ||
|
||
describe('#validate', function() { | ||
|