Example #1
0
 it('should get error when something was wrong in subclass method invocation', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/configuration/role_history/read',
             'err': {
                 'error': {
                     'code': 1001
                 }
             }
         }
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         "criteria": {
             'name': 'Apache'
         }
     };
     var res = {};
     res.json = function (status, body) {
         body.error.code.should.equal(4104);
         done();
     };
     var controller = new RoleController();
     controller.history(req, res);
 });
Example #2
0
 it('should get current role data.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/configuration/role/read',
             'res': {
                 'result': {
                     'affected': 1,
                     'data': [
                         {
                             'name': 'Apache', 
                             'revision': 11111
                         }
                     ]
                 }
             }
         },
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'criteria': {
             'name': 'Apache'
         }
     };
     var res = {};
     res.json = function (status, body) {
         body.result.data[0].revision.should.equal(11111);
         done();
     };
     var controller = new RoleController();
     controller.read(req, res);
 });
        it('should get error when vatican access failed.', function (done) {
            var configurationOfRomeClient = [
                {
                    'action': '/vatican/configuration/roleHistory/read',
                    'err': {
                        'error': {
                            'code': 1001
                        }
                    }
                }
            ];
            var req = {};
            req.call = romeClient(configurationOfRomeClient);
            req.body = {
                'criteria': {
                    'name': 'Apache'
                }
            };
            var controller = new ConfigurationController();
            controller.history('roleHistory', req, function (error, result) {
                should.not.exist(result);
                done();
            });

        });
        it('should get role data from role collection.', function (done) {
            var configurationOfRomeClient = [
                {
                    'action': '/vatican/configuration/role/read',
                    'res': {
                        'result': {
                            'affected': 1,
                            'data': [
                                {
                                    'name': 'Apache', 
                                    'revision': 11111
                                }
                            ]
                        }
                    }
                }
            ];
            var req = {};
            req.call = romeClient(configurationOfRomeClient);
            req.body = {
                "criteria": {
                    'name': 'Apache'
                }
            };
            var controller = new ConfigurationController();
            controller.read('role', req, function (error, result) {
                result.result.data[0].revision.should.equal(11111);
                done();
            });

        });
 it('should successfully create a new role.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/counter',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': {
                         'name': 'revision',
                         'value': 11115
                     }
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/read',
             'res': {
                 'result': {
                     'affected': 0,
                     'data': []
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/create',
             'res': { 
                 'result': {
                     'affected': 1
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/cas',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': [
                         {
                             'name': 'Apache', 
                             'revision': 11115
                         }
                     ]
                 }
             }
         }
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache'
     };
     var controller = new ConfigurationController();
     controller.update('role', 'roleHistory', req, function (error, result) {
         result.result.revision.should.equal(11115);
         done();
     });
 });
 it('should get error when vatican CAS failed.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/counter',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': {
                         'name': 'revision',
                         'value': 11115
                     }
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/read',
             'res': {
                 'result': {
                     'affected': 1,
                     'data': [
                         {
                             'name': 'Apache', 
                             'revision': 11111
                         }
                     ]
                 }
             }
         },
         {
             'action': '/vatican/configuration/roleHistory/create',
             'res': { 
                 'result': {
                     'affected': 1
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/cas',
             'err': { 
                 'error': {
                     'code': 1001
                 }
             }
         }
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache',
         'revision': 11111
     };
     var controller = new ConfigurationController();
     controller.update('role', 'roleHistory', req, function (error, result) {
         should.not.exist(result);
         done();
     });
 });
Example #7
0
 it('should get error when something was wrong in subclass method invocation', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/counter',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': {
                         'name': 'revision',
                         'value': 11115
                     }
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/read',
             'err': {
                 'error': {
                     'code': 1001
                 }
             }
         },
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache',
         'revision': 11111,
         'includes': ['IDC-zjm'],
         'configuration': {
             'files': [
                 {
                     'name': 'httpd.conf',
                     'path': '/usr/local/sinasrv2/etc',
                     'owner': 'root:root',
                     'permission': '0755',
                     'template': 'httpd.conf.tpl',
                     'data': {
                         "ServerName": "weibo.com"
                     }
                 }
             ]
         },
         'changelog': 'add new data'
     };
     var res = {};
     res.json = function (status, body) {
         body.error.code.should.equal(4101);
         done();
     };
     var controller = new RoleController();
     controller.update(req, res);
 });
Example #8
0
 it('should get error when parameter length beyond limit.', function (done) {
     var configurationOfRomeClient = [];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'ApacheApacheApacheApachApacheeApacheApaApacheApacheApachecheApache'
     };
     var res = {};
     res.json = function (status, body) {
         body.error.code.should.equal(4001);
         done();
     };
     var controller = new RoleController();
     controller.delete(req, res);
 });
Example #9
0
 it('should get error when bad parameter type.', function (done) {
     var configurationOfRomeClient = [];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'criteria': 'name == Apache'
     };
     var res = {};
     res.json = function (status, body) {
         body.error.code.should.equal(4001);
         done();
     };
     var controller = new RoleController();
     controller.history(req, res);
 });
Example #10
0
 it('should delete current role data.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/configuration/role/read',
             'res': {
                 'result': {
                     'affected': 1,
                     'data': [
                         {
                             'name': 'Apache', 
                             'revision': 11111
                         }
                     ]
                 }
             }
         },
         {
             'action': '/vatican/configuration/role_history/create',
             'res': { 
                 'result': {
                     'affected': 1
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/delete',
             'res': {
                 'result': {
                     'affected': 1
                 }
             }
         }
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache',
     };
     var res = {};
     res.json = function (status, body) {
         body.should.eql({});
         done();
     };
     var controller = new RoleController();
     controller.delete(req, res);
 });
Example #11
0
 it('should get error when bad parameter type.', function (done) {
     var configurationOfRomeClient = [];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache',
         'revision': 11111,
         'includes': 'IDC-zjm'
     };
     var res = {};
     res.json = function (status, body) {
         body.error.code.should.equal(4001);
         done();
     };
     var controller = new RoleController();
     controller.update(req, res);
 });
        it('should get error when failed to delete current role data.', function (done) {
            var configurationOfRomeClient = [
                {
                    'action': '/vatican/configuration/role/read',
                    'res': {
                        'result': {
                            'affected': 1,
                            "data": [
                                {
                                    "name": "Apache",
                                    "revision": 11111
                                }
                            ]
                        }
                    }
                },
                {
                    'action': '/vatican/configuration/roleHistory/create',
                    'res': {
                        'result': {
                            'affected': 1
                        }
                    }
                },
                {
                    'action': '/vatican/configuration/role/delete',
                    'err': {
                        'error': {
                            'code': 1001
                        }
                    }
                }

            ];
            var req = {};
            req.call = romeClient(configurationOfRomeClient);
            req.body = {
                'name': 'Apache'
            };
            var controller = new ConfigurationController();
            controller.delete('role', 'roleHistory', req, function (error, result) {
                should.not.exist(result);
                done();
            });
        });
        it('should delete role data.', function (done) {
            var configurationOfRomeClient = [
                {
                    'action': '/vatican/configuration/role/read',
                    'res': {
                        'result': {
                            'affected': 1,
                            'data': [
                                {
                                    'name': 'Apache', 
                                    'revision': 11111
                                }
                            ]
                        }
                    }
                },
                {
                    'action': '/vatican/configuration/roleHistory/create',
                    'res': {
                        'result': {
                            'affected': 1
                        }
                    }
                },
                {
                    'action': '/vatican/configuration/role/delete',
                    'res': {
                        'result': {
                            'affected': 1
                        }
                    }
                }
            ];
            var req = {};
            req.call = romeClient(configurationOfRomeClient);
            req.body = {
                'name': 'Apache'
            };
            var controller = new ConfigurationController();
            controller.delete('role', 'roleHistory', req, function (error, result) {
                result.should.eql({});
                done();
            });

        });
 it('should get error when failed to access vatican.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/counter',
             'err': { 
                 'error': {
                     'code': 1001,
                     'message': "connect failed."
                 }
             }
         },
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     var controller = new ConfigurationController();
     controller.getCounter_('revision', req, function (error, result) {
         should.not.exist(result);
         done();
     });
 });
Example #15
0
 it('should get error when parameter length beyond limit.', function (done) {
     var configurationOfRomeClient = [];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         "criteria": {
             'name': 'Apache'
         },
         "operations": {
             "limit": 50
         }
     };
     var res = {};
     res.json = function (status, body) {
         body.error.code.should.equal(4001);
         done();
     };
     var controller = new RoleController();
     controller.history(req, res);
 });
 it('should get global revision from counter.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/counter',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': {
                         'name': 'revision',
                         'value': 12345
                     }
                 }
             }
         },
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     var controller = new ConfigurationController();
     controller.getCounter_('revision', req, function (error, result) {
         result.should.equal(12345);
         done();
     });
 });
 it('should get error when role data can not be found.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/configuration/role/read',
             'res': {
                 'result': {
                     'affected': 0,
                     "data": []
                 }
             }
         }
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache'
     };
     var controller = new ConfigurationController();
     controller.delete('role', 'roleHistory', req, function (error, result) {
         should.not.exist(result);
         done();
     });
 });
        it('should get role history data.', function (done) {
            var configurationOfRomeClient = [
                {
                    'action': '/vatican/configuration/roleHistory/read',
                    'res': {
                        'result': {
                            'affected': 2,
                            'data': [
                                {
                                    'name': 'Apache', 
                                    'revision': 11111
                                },
                                {
                                    'name': 'Apache', 
                                    'revision': 11113
                                }
                            ]
                        }
                    }
                }
            ];
            var req = {};
            req.call = romeClient(configurationOfRomeClient);
            req.body = {
                'criteria': {
                    'name': 'Apache'
                }
            };
            var controller = new ConfigurationController();
            controller.history('roleHistory', req, function (error, result) {
                result.result.affected.should.equal(2);
                result.result.data[0].name.should.equal('Apache');
                result.result.data[1].revision.should.equal(11113);
                done();
            });

        });
Example #19
0
 it('should successfully update role data.', function (done) {
     var configurationOfRomeClient = [
         {
             'action': '/vatican/counter',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': {
                         'name': 'revision',
                         'value': 11115
                     }
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/read',
             'res': {
                 'result': {
                     'affected': 1,
                     'data': [
                         {
                             'name': 'Apache', 
                             'revision': 11111
                         }
                     ]
                 }
             }
         },
         {
             'action': '/vatican/configuration/role_history/create',
             'res': { 
                 'result': {
                     'affected': 1
                 }
             }
         },
         {
             'action': '/vatican/configuration/role/cas',
             'res': { 
                 'result': {
                     'affected': 1,
                     'data': [
                         {
                             'name': 'Apache', 
                             'revision': 11111
                         }
                     ]
                 }
             }
         }
     ];
     var req = {};
     req.call = romeClient(configurationOfRomeClient);
     req.body = {
         'name': 'Apache',
         'revision': 11111,
         'includes': ['IDC-zjm'],
         'configuration': {
             'files': [
                 {
                     'name': 'httpd.conf',
                     'path': '/usr/local/sinasrv2/etc',
                     'owner': 'root:root',
                     'permission': '0755',
                     'template': 'httpd.conf.tpl',
                     'data': {
                         "ServerName": "weibo.com"
                     }
                 }
             ]
         },
         'changelog': 'add new data'
     };
     var res = {};
     res.json = function (status, body) {
         body.result.revision.should.equal(11115);
         done();
     };
     var controller = new RoleController();
     controller.update(req, res);
 });