The test cases have been updated to use the new extensible mechanism
for defining and registering entities.

Ticket #2043

--
Endi S. Dewata
From e22c9a97e0853f19e93e278c3299e242e8f7034e Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edew...@redhat.com>
Date: Thu, 17 Nov 2011 12:09:00 -0600
Subject: [PATCH] Fixed entity definition in test cases.

The test cases have been updated to use the new extensible mechanism
for defining and registering entities.

Ticket #2043
---
 install/ui/ipa.js                |   73 ++++++++++++++++++++-----------------
 install/ui/test/details_tests.js |   74 ++++++++++++++++++++++++++------------
 install/ui/test/entity_tests.js  |   29 ++++++++-------
 3 files changed, 106 insertions(+), 70 deletions(-)

diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 
c6d39478a35b9ab8d19065572c9b469a84722d06..1ebf1acc4293fd83ff5971541b58560801922d32
 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -167,9 +167,47 @@ var IPA = function() {
     };
 
     that.register = function(name, factory) {
+        that.remove_entity(name);
         that.entity_factories[name] = factory;
     };
 
+    that.create_entity = function(name) {
+        var factory = that.entity_factories[name];
+        if (!factory) return null;
+
+        try {
+            var builder = that.entity_builder();
+
+            builder.entity({
+                factory: factory,
+                name: name
+            });
+
+            var entity = builder.build();
+
+            entity.init({
+                builder: builder
+            });
+
+            return entity;
+
+        } catch (e) {
+            if (e.expected) {
+                /*expected exceptions thrown by builder just mean that
+                  entities are not to be registered. */
+                return null;
+            }
+
+            if (e.message) {
+                alert(e.message);
+            } else {
+                alert(e);
+            }
+
+            return null;
+        }
+    };
+
     that.get_entities = function() {
         return that.entities.values;
     };
@@ -177,39 +215,8 @@ var IPA = function() {
     that.get_entity = function(name) {
         var entity = that.entities.get(name);
         if (!entity) {
-            var factory = that.entity_factories[name];
-            if (!factory) {
-                return null;
-            }
-
-            try {
-                var builder = that.entity_builder();
-
-                builder.entity({
-                    factory: factory,
-                    name: name
-                });
-
-                entity = builder.build();
-                entity.init({
-                    builder: builder
-                });
-
-                that.add_entity(entity);
-
-            } catch (e) {
-                if (e.expected) {
-                    /*expected exceptions thrown by builder just mean that
-                      entities are not to be registered. */
-                    return null;
-                }
-                if (e.message) {
-                    alert(e.message);
-                } else {
-                    alert(e);
-                }
-                return null;
-            }
+            entity = that.create_entity(name);
+            if (entity) that.add_entity(entity);
         }
         return entity;
     };
diff --git a/install/ui/test/details_tests.js b/install/ui/test/details_tests.js
index 
c6a55cda9046fa74a8c08f646f6288972f96ae58..80136649b9624c32867e639f6de82ec6f68d30f1
 100644
--- a/install/ui/test/details_tests.js
+++ b/install/ui/test/details_tests.js
@@ -156,30 +156,58 @@ test("Testing details lifecycle: create, load.", 
function(){
         return widget;
     }
 
-    var entity =   IPA.
-        entity_builder().
-        entity('user').
-        details_facet({sections:[
-            {
-                name: 'identity',
-                label: IPA.messages.details.identity,
-                fields:['title','givenname','sn','cn','displayname', 
'initials']
-            },
-            {
-                name: 'contact',
-                label:'contact',
-                fields:
-                [  {factory: test_widget,name:'test'},
-                   {factory: IPA.multivalued_text_widget, name:'mail'},
-                   {factory: IPA.multivalued_text_widget,
-                    name:'telephonenumber'},
-                   {factory: IPA.multivalued_text_widget, name:'pager'},
-                   {factory: IPA.multivalued_text_widget, name:'mobile'},
-                   {factory: IPA.multivalued_text_widget,
-                    name:'facsimiletelephonenumber'}]
-            }
-        ]}).build();
+    IPA.register('user', function(spec) {
 
+        var that = IPA.entity(spec);
+
+        that.init = function(params) {
+            that.entity_init(params);
+
+            params.builder.details_facet({
+                sections: [
+                    {
+                        name: 'identity',
+                        label: IPA.messages.details.identity,
+                        fields: [ 'title', 'givenname', 'sn', 'cn', 
'displayname', 'initials' ]
+                    },
+                    {
+                        name: 'contact',
+                        label: 'contact',
+                        fields: [
+                            {
+                                factory: test_widget,
+                                name:'test'
+                            },
+                            {
+                                factory: IPA.multivalued_text_widget,
+                                name:'mail'
+                            },
+                            {
+                                factory: IPA.multivalued_text_widget,
+                                name:'telephonenumber'
+                            },
+                            {
+                                factory: IPA.multivalued_text_widget,
+                                name:'pager'
+                            },
+                            {
+                                factory: IPA.multivalued_text_widget,
+                                name:'mobile'
+                            },
+                            {
+                                factory: IPA.multivalued_text_widget,
+                                name:'facsimiletelephonenumber'
+                            }
+                        ]
+                    }
+                ]
+            });
+        };
+
+        return that;
+    });
+
+    var entity = IPA.get_entity('user');
 
     var entity_container = $('<div/>', {
         name: 'user',
diff --git a/install/ui/test/entity_tests.js b/install/ui/test/entity_tests.js
index 
84a5e28fea1b9ecc638906401b3ce6a56c3d5310..f655493882d639bc6113cf4525869fcf35ef64dd
 100644
--- a/install/ui/test/entity_tests.js
+++ b/install/ui/test/entity_tests.js
@@ -31,14 +31,20 @@ module('entity',{
             url: 'data',
             on_success: function(data, text_status, xhr) {
 
-                IPA.entity_factories.user = function(){
-                    return IPA.
-                        entity_builder().
-                        entity('user').
-                        search_facet({
-                            columns:['uid']}).
-                        build();
-                };
+                IPA.register('user', function(spec) {
+
+                    var that = IPA.entity(spec);
+
+                    that.init = function(params) {
+                        that.entity_init(params);
+
+                            params.builder.search_facet({
+                                columns: [ 'uid' ]
+                            });
+                    };
+
+                    return that;
+                });
             },
             on_error: function(xhr, text_status, error_thrown) {
                 ok(false, "ipa_init() failed: "+error_thrown);
@@ -60,12 +66,7 @@ test('Testing IPA.entity_set_search_definition().', 
function() {
         return true;
     };
 
-    var entity =   IPA.
-        entity_builder().
-        entity('user').
-        search_facet({
-            columns:['uid']}).
-        build();
+    var entity = IPA.get_entity('user');
 
     var entity_container = $('<div/>', {
         name: 'user',
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to