diff --git a/install/static/develop.js b/install/static/develop.js
index 1a80e94a6..f161f7826 100644
--- a/install/static/develop.js
+++ b/install/static/develop.js
@@ -1,2 +1,4 @@
-ipa_use_sampledata = (window.location.protocol == 'file:');
-
+if (window.location.protocol == 'file:') {
+ ipa_json_url = "test/data";
+ ipa_use_static_files = true;
+}
diff --git a/install/static/ipa.js b/install/static/ipa.js
index 8110f3bfa..b7f98e8d7 100644
--- a/install/static/ipa.js
+++ b/install/static/ipa.js
@@ -21,9 +21,17 @@
/* IPA JSON-RPC helper */
var IPA_DEFAULT_JSON_URL = '/ipa/json';
-var IPA_SAMPLEDATA_URL = 'sampledata';
-var ipa_use_sampledata = false;
+var ipa_json_url;
+var ipa_use_static_files;
+
+var ipa_ajax_options = {
+ type: 'POST',
+ contentType: 'application/json',
+ dataType: 'json',
+ async: true,
+ processData: false,
+};
/* JSON-RPC ID counter */
var ipa_jsonrpc_id = 0;
@@ -31,42 +39,27 @@ var ipa_jsonrpc_id = 0;
/* IPA objects data in JSON format */
var ipa_objs = {};
-var _ipa_init_on_win_callback = null;
/* initialize the IPA JSON-RPC helper
* arguments:
* url - JSON-RPC URL to use (optional) */
-function ipa_init(url, on_win, use_sampledata)
+function ipa_init(url, use_static_files, on_win, on_error)
{
if (url)
ipa_json_url = url;
- else
- ipa_json_url = IPA_DEFAULT_JSON_URL;
- if (use_sampledata)
- ipa_use_sampledata = use_sampledata;
- _ipa_init_on_win_callback = on_win;
+ if (use_static_files)
+ ipa_use_static_files = use_static_files;
- var options = {
- type: 'POST',
- contentType: 'application/json',
- dataType: 'json',
- processData: false,
- };
+ $.ajaxSetup(ipa_ajax_options);
- $.ajaxSetup(options);
-
- ipa_cmd('json_metadata', [], {}, _ipa_load_objs,
- function(response){
- alert('init failed');
- });
-}
-
-function _ipa_load_objs(data, textStatus, xhr)
-{
- ipa_objs = data.result.result;
- if (_ipa_init_on_win_callback)
- _ipa_init_on_win_callback(data, textStatus, xhr);
+ ipa_cmd('json_metadata', [], {},
+ function(data, status, xhr) {
+ ipa_objs = data.result.result;
+ if (on_win) on_win(data, status, xhr);
+ },
+ on_error
+ );
}
/* call an IPA command over JSON-RPC
@@ -84,8 +77,12 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
name = objname + '_' + name;
var url = ipa_json_url;
- if (ipa_use_sampledata && IPA_SAMPLEDATA_URL)
- url = IPA_SAMPLEDATA_URL + '/' + name + '.json';
+
+ if (!url)
+ url = IPA_DEFAULT_JSON_URL;
+
+ if (ipa_use_static_files)
+ url += '/' + name + '.json';
var data = {
method: name,
@@ -132,7 +129,10 @@ function ipa_parse_qs(qs)
/* helper function used to retrieve information about an attribute */
function ipa_get_param_info(obj_name, attr)
{
- var takes_params = ipa_objs[obj_name].takes_params;
+ var ipa_obj = ipa_objs[obj_name];
+ if (!ipa_obj) return null;
+
+ var takes_params = ipa_obj.takes_params;
if (!takes_params)
return (null);
@@ -147,7 +147,10 @@ function ipa_get_param_info(obj_name, attr)
/* helper function used to retrieve attr name with members of type `member` */
function ipa_get_member_attribute(obj_name, member)
{
- var attribute_members = ipa_objs[obj_name].attribute_members
+ var ipa_obj = ipa_objs[obj_name];
+ if (!ipa_obj) return null;
+
+ var attribute_members = ipa_obj.attribute_members
for (var a in attribute_members) {
var objs = attribute_members[a];
for (var i = 0; i < objs.length; ++i) {
@@ -155,5 +158,7 @@ function ipa_get_member_attribute(obj_name, member)
return a;
}
}
+
+ return null;
}
diff --git a/install/static/test/all_tests.html b/install/static/test/all_tests.html
new file mode 100644
index 000000000..7185f53ee
--- /dev/null
+++ b/install/static/test/all_tests.html
@@ -0,0 +1,24 @@
+
+
+
+ Complete Test Suite
+
+
+
+
+
+
+
+
+
+
+
+
+
Complete Test Suite
+
+
+
+
+
test markup
+
+
diff --git a/install/static/sampledata/group_add.json b/install/static/test/data/group_add.json
similarity index 100%
rename from install/static/sampledata/group_add.json
rename to install/static/test/data/group_add.json
diff --git a/install/static/sampledata/group_add_member.json b/install/static/test/data/group_add_member.json
similarity index 100%
rename from install/static/sampledata/group_add_member.json
rename to install/static/test/data/group_add_member.json
diff --git a/install/static/sampledata/group_find.json b/install/static/test/data/group_find.json
similarity index 100%
rename from install/static/sampledata/group_find.json
rename to install/static/test/data/group_find.json
diff --git a/install/static/sampledata/group_show.json b/install/static/test/data/group_show.json
similarity index 100%
rename from install/static/sampledata/group_show.json
rename to install/static/test/data/group_show.json
diff --git a/install/static/sampledata/host_add.json b/install/static/test/data/host_add.json
similarity index 100%
rename from install/static/sampledata/host_add.json
rename to install/static/test/data/host_add.json
diff --git a/install/static/sampledata/host_find.json b/install/static/test/data/host_find.json
similarity index 100%
rename from install/static/sampledata/host_find.json
rename to install/static/test/data/host_find.json
diff --git a/install/static/sampledata/host_show.json b/install/static/test/data/host_show.json
similarity index 100%
rename from install/static/sampledata/host_show.json
rename to install/static/test/data/host_show.json
diff --git a/install/static/sampledata/hostgroup_add.json b/install/static/test/data/hostgroup_add.json
similarity index 100%
rename from install/static/sampledata/hostgroup_add.json
rename to install/static/test/data/hostgroup_add.json
diff --git a/install/static/sampledata/hostgroup_add_member.json b/install/static/test/data/hostgroup_add_member.json
similarity index 100%
rename from install/static/sampledata/hostgroup_add_member.json
rename to install/static/test/data/hostgroup_add_member.json
diff --git a/install/static/sampledata/hostgroup_find.json b/install/static/test/data/hostgroup_find.json
similarity index 100%
rename from install/static/sampledata/hostgroup_find.json
rename to install/static/test/data/hostgroup_find.json
diff --git a/install/static/sampledata/hostgroup_show.json b/install/static/test/data/hostgroup_show.json
similarity index 100%
rename from install/static/sampledata/hostgroup_show.json
rename to install/static/test/data/hostgroup_show.json
diff --git a/install/static/sampledata/json_metadata.json b/install/static/test/data/json_metadata.json
similarity index 100%
rename from install/static/sampledata/json_metadata.json
rename to install/static/test/data/json_metadata.json
diff --git a/install/static/sampledata/netgroup_add.json b/install/static/test/data/netgroup_add.json
similarity index 100%
rename from install/static/sampledata/netgroup_add.json
rename to install/static/test/data/netgroup_add.json
diff --git a/install/static/sampledata/netgroup_add_member.json b/install/static/test/data/netgroup_add_member.json
similarity index 100%
rename from install/static/sampledata/netgroup_add_member.json
rename to install/static/test/data/netgroup_add_member.json
diff --git a/install/static/sampledata/netgroup_find.json b/install/static/test/data/netgroup_find.json
similarity index 100%
rename from install/static/sampledata/netgroup_find.json
rename to install/static/test/data/netgroup_find.json
diff --git a/install/static/sampledata/netgroup_show.json b/install/static/test/data/netgroup_show.json
similarity index 100%
rename from install/static/sampledata/netgroup_show.json
rename to install/static/test/data/netgroup_show.json
diff --git a/install/static/sampledata/rolegroup_add.json b/install/static/test/data/rolegroup_add.json
similarity index 100%
rename from install/static/sampledata/rolegroup_add.json
rename to install/static/test/data/rolegroup_add.json
diff --git a/install/static/sampledata/rolegroup_add_member.json b/install/static/test/data/rolegroup_add_member.json
similarity index 100%
rename from install/static/sampledata/rolegroup_add_member.json
rename to install/static/test/data/rolegroup_add_member.json
diff --git a/install/static/sampledata/rolegroup_del.json b/install/static/test/data/rolegroup_del.json
similarity index 100%
rename from install/static/sampledata/rolegroup_del.json
rename to install/static/test/data/rolegroup_del.json
diff --git a/install/static/sampledata/rolegroup_find.json b/install/static/test/data/rolegroup_find.json
similarity index 100%
rename from install/static/sampledata/rolegroup_find.json
rename to install/static/test/data/rolegroup_find.json
diff --git a/install/static/sampledata/rolegroup_remove_member.json b/install/static/test/data/rolegroup_remove_member.json
similarity index 100%
rename from install/static/sampledata/rolegroup_remove_member.json
rename to install/static/test/data/rolegroup_remove_member.json
diff --git a/install/static/sampledata/rolegroup_show.json b/install/static/test/data/rolegroup_show.json
similarity index 100%
rename from install/static/sampledata/rolegroup_show.json
rename to install/static/test/data/rolegroup_show.json
diff --git a/install/static/sampledata/service_add.json b/install/static/test/data/service_add.json
similarity index 100%
rename from install/static/sampledata/service_add.json
rename to install/static/test/data/service_add.json
diff --git a/install/static/sampledata/service_add_host.json b/install/static/test/data/service_add_host.json
similarity index 100%
rename from install/static/sampledata/service_add_host.json
rename to install/static/test/data/service_add_host.json
diff --git a/install/static/sampledata/service_del.json b/install/static/test/data/service_del.json
similarity index 100%
rename from install/static/sampledata/service_del.json
rename to install/static/test/data/service_del.json
diff --git a/install/static/sampledata/service_find.json b/install/static/test/data/service_find.json
similarity index 100%
rename from install/static/sampledata/service_find.json
rename to install/static/test/data/service_find.json
diff --git a/install/static/sampledata/service_remove_host.sh b/install/static/test/data/service_remove_host.sh
similarity index 100%
rename from install/static/sampledata/service_remove_host.sh
rename to install/static/test/data/service_remove_host.sh
diff --git a/install/static/sampledata/service_show.json b/install/static/test/data/service_show.json
similarity index 100%
rename from install/static/sampledata/service_show.json
rename to install/static/test/data/service_show.json
diff --git a/install/static/sampledata/user_add.json b/install/static/test/data/user_add.json
similarity index 100%
rename from install/static/sampledata/user_add.json
rename to install/static/test/data/user_add.json
diff --git a/install/static/sampledata/user_find.json b/install/static/test/data/user_find.json
similarity index 100%
rename from install/static/sampledata/user_find.json
rename to install/static/test/data/user_find.json
diff --git a/install/static/sampledata/user_show.json b/install/static/test/data/user_show.json
similarity index 100%
rename from install/static/sampledata/user_show.json
rename to install/static/test/data/user_show.json
diff --git a/install/static/sampledata/whoami.json b/install/static/test/data/whoami.json
similarity index 100%
rename from install/static/sampledata/whoami.json
rename to install/static/test/data/whoami.json
diff --git a/install/static/test/entity_tests.html b/install/static/test/entity_tests.html
new file mode 100644
index 000000000..224bb23da
--- /dev/null
+++ b/install/static/test/entity_tests.html
@@ -0,0 +1,23 @@
+
+
+
+ Entity Test Suite
+
+
+
+
+
+
+
+
+
+
+
+
Entity Test Suite
+
+
+
+
+
test markup
+
+
diff --git a/install/static/test/entity_tests.js b/install/static/test/entity_tests.js
new file mode 100644
index 000000000..297928ba6
--- /dev/null
+++ b/install/static/test/entity_tests.js
@@ -0,0 +1,120 @@
+/* Authors:
+ * Endi Sukma Dewata
+ *
+ * Copyright (C) 2010 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 only
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+test("Testing ipa_entity_set_search_definition().", function() {
+
+ var uid_callback = function() {
+ return true;
+ };
+
+ ipa_entity_set_search_definition("user", [
+ ["uid", "Login", uid_callback],
+ ]);
+
+ var list = ipa_entity_search_list["user"];
+ ok(
+ list,
+ "ipa_entity_search_list[\"user\"] is not null"
+ );
+
+ var attr = list[0];
+ ok(
+ attr,
+ "ipa_entity_search_list[\"user\"][0] is not null"
+ );
+
+ equals(
+ attr[0], "uid",
+ "ipa_entity_search_list[\"user\"][0][0]"
+ );
+
+ equals(
+ attr[1], "Login",
+ "ipa_entity_search_list[\"user\"][0][1]"
+ );
+
+ var callback = attr[2];
+ ok(
+ callback,
+ "ipa_entity_search_list[\"user\"][0][2] not null"
+ );
+
+ ok(
+ callback(),
+ "ipa_entity_search_list[\"user\"][0][2]() works"
+ );
+});
+
+test("Testing ipa_entity_generate_views().", function() {
+
+ ipa_ajax_options["async"] = false;
+
+ ipa_init(
+ "data",
+ true,
+ function(data, status, xhr) {
+ ok(true, "ipa_init() succeeded.");
+ },
+ function(xhr, options, thrownError) {
+ ok(false, "ipa_init() failed: "+thrownError);
+ }
+ );
+
+ var container = $("");
+ ipa_entity_generate_views("user", container);
+
+ var list = container.children();
+ var facets = list.children();
+
+ equals(
+ facets.length, 6,
+ "Checking number of facets"
+ )
+
+ var search = facets.first();
+
+ equals(
+ search.attr("title"), "search",
+ "Checking the first facet"
+ )
+
+ var details = search.next();
+
+ equals(
+ details.attr("title"), "details",
+ "Checking the second facet"
+ )
+
+ var facet = details.next();
+ var attribute_members = ipa_objs["user"].attribute_members;
+ for (attribute_member in attribute_members) {
+ var objects = attribute_members[attribute_member];
+ for (var i = 0; i < objects.length; i++) {
+ var object = objects[i];
+
+ equals(
+ facet.attr("title"), object,
+ "Checking the next facet"
+ );
+
+ facet = facet.next();
+ }
+ }
+});
diff --git a/install/static/test/index.html b/install/static/test/index.html
new file mode 100644
index 000000000..c6d229502
--- /dev/null
+++ b/install/static/test/index.html
@@ -0,0 +1,37 @@
+
+
+
+ IPA Test Suite
+
+
+
+
+