UNPKG

jsmf-check

Version:

Constraints language and verification for JSMF models

41 lines (35 loc) 1.97 kB
'use strict'; var JSMF = require('jsmf'); var M = require('./MMClientServer.js'); var check = require('../../index.js'); var nav = require('jsmf-magellan'); var _ = require('lodash'); var clients = _.curry(nav.allInstancesFromModel)(M.Client) var servers = _.curry(nav.allInstancesFromModel)(M.Server) var csCheck = new check.ModelConstraints(); csCheck.forallRule("client is linked to at least one server", clients, function (c) { var clientServers = nav.follow({path: ['associationEnd', 'association', 'associationEnd', 'class'], predicate: nav.hasClass(M.Server)}, c) return servers.length > 0; }); csCheck.forallRule("client is linked to at least one interface", clients, function (c) { return c,getImplements().length > 0; }); csCheck.forallRule("client interfaces are implemented by at least one linked server", clients, function (c) { var clientServers = nav.follow({path: ['associationEnd', 'association', 'associationEnd', 'class'], predicate: nav.hasClass(M.Server)}); clientInterfaces = c.getDependsOn(); serverInterfaces = _.flatten(_.map(clientServers, function (s) {return s.getImplements();}); return _.all(clientInterfaces, function(i) { return _contains(serversIntefaces, i);}); }); var cspCheck = new check.ModelConstraints(); cspCheck.forallRule("client is linked to a proxy linked to a server server implementing the same interface", clients, function (c) { var servers = nav.follow({path: ['associationEnd', 'association', 'associationEnd', 'class'], predicate: nav.hasClass(M.Server)}, c) var clientInterfaces = c.getImplements(); var serversIntefaces = _.flatten(_.map(servers, function (s) {return s.getImplements();})) return servers.length > 0 && _.all(clientInterfaces, function (c) {return _.contains(serversIntefaces, c)}; });