Updated Branches:
  refs/heads/future 4d8f6774e -> 1f8b525b7

some android handler specs


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/1f8b525b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/1f8b525b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/1f8b525b

Branch: refs/heads/future
Commit: 1f8b525b75aa7ffbc18b95714ad0107ad88038ac
Parents: 4d8f677
Author: Fil Maj <[email protected]>
Authored: Tue Apr 23 11:28:17 2013 -0700
Committer: Fil Maj <[email protected]>
Committed: Tue Apr 23 11:28:17 2013 -0700

----------------------------------------------------------------------
 spec/platforms/android.spec.js |   69 +++++++++++++++++++++++++++++++++--
 src/install.js                 |    4 ++-
 2 files changed, 68 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/1f8b525b/spec/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/android.spec.js b/spec/platforms/android.spec.js
index a7c710e..4cc1724 100644
--- a/spec/platforms/android.spec.js
+++ b/spec/platforms/android.spec.js
@@ -1,4 +1,37 @@
-var android = require('../../src/platforms/android');
+var android = require('../../src/platforms/android'),
+    common  = require('../../src/platforms/common'),
+    path    = require('path'),
+    fs      = require('fs'),
+    shell   = require('shelljs'),
+    et      = require('elementtree'),
+    os      = require('osenv'),
+    temp    = path.join(os.tmpdir(), 'plugman'),
+    dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin'),
+    faultyplugin = path.join(__dirname, '..', 'plugins', 'FaultyPlugin'),
+    android_one_project = path.join(__dirname, '..', 'projects', 
'android_one', '*');
+
+var xml_path     = path.join(dummyplugin, 'plugin.xml')
+  , xml_text     = fs.readFileSync(xml_path, 'utf-8')
+  , plugin_et    = new et.ElementTree(et.XML(xml_text));
+
+var platformTag = plugin_et.find('./platform[@name="android"]');
+var dummy_id = plugin_et._root.attrib['id'];
+var valid_source = platformTag.findall('./source-file'),
+    libFiles = platformTag.findall('./library-file'),
+    assets = plugin_et.findall('./asset'),
+    configChanges = platformTag.findall('./config-file');
+
+xml_path  = path.join(faultyplugin, 'plugin.xml')
+xml_text  = fs.readFileSync(xml_path, 'utf-8')
+plugin_et = new et.ElementTree(et.XML(xml_text));
+
+platformTag = plugin_et.find('./platform[@name="android"]');
+var invalid_source = platformTag.findall('./source-file');
+var faulty_id = plugin_et._root.attrib['id'];
+
+function copyArray(arr) {
+    return Array.prototype.slice.call(arr, 0);
+}
 
 describe('android project handler', function() {
     it('should have an install function', function() {
@@ -12,10 +45,38 @@ describe('android project handler', function() {
     });
 
     describe('installation', function() {
+        beforeEach(function() {
+            shell.mkdir('-p', temp);
+            shell.cp('-rf', android_one_project, temp);
+        });
+        afterEach(function() {
+            shell.rm('-rf', temp);
+        });
         describe('of <source-file> elements', function() {
-            it('should copy stuff from one location to another by calling 
common.straightCopy');
-            it('should throw if source file cannot be found');
-            it('should throw if target file already exists');
+            it('should copy stuff from one location to another by calling 
common.straightCopy', function() {
+                var source = copyArray(valid_source);
+                var s = spyOn(common, 'straightCopy');
+                android.install(source, dummy_id, temp, dummyplugin, {});
+                expect(s).toHaveBeenCalledWith(dummyplugin, 
'src/android/DummyPlugin.java', temp, 
'src/com/phonegap/plugins/dummyplugin/DummyPlugin.java');
+            });
+            it('should throw if source file cannot be found', function() {
+                var source = copyArray(invalid_source);
+                expect(function() {
+                    android.install(source, faulty_id, temp, faultyplugin, {});
+                }).toThrow('"' + path.resolve(faultyplugin, 
'src/android/NotHere.java') + '" not found!');
+            });
+            it('should throw if target file already exists', function() {
+                // write out a file
+                var target = path.resolve(temp, 
'src/com/phonegap/plugins/dummyplugin');
+                shell.mkdir('-p', target);
+                target = path.join(target, 'DummyPlugin.java');
+                fs.writeFileSync(target, 'some bs', 'utf-8');
+
+                var source = copyArray(valid_source);
+                expect(function() {
+                    android.install(source, dummy_id, temp, dummyplugin, {});
+                }).toThrow('"' + target + '" already exists!');
+            });
         });
         describe('of <library-file> elements', function() {
             it('should copy stuff from one location to another by calling 
common.straightCopy');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/1f8b525b/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 29cf041..3fcd2e4 100644
--- a/src/install.js
+++ b/src/install.js
@@ -76,11 +76,13 @@ function runInstall(platform, project_dir, plugin_dir, 
plugins_dir, cli_variable
         libFiles = platformTag.findall('./library-file'),
         headerFiles = platformTag.findall('./header-file'),
         resourceFiles = platformTag.findall('./resource-file'),
-        assets = plugin_et.findall('./asset'),
+        assets = platformTag.findall('./asset'),
         frameworks = platformTag.findall('./framework'),
         pluginsPlist = platformTag.findall('./plugins-plist'),
         configChanges = platformTag.findall('./config-file');
 
+    assets = assets.concat(plugin_et.findall('./asset'));
+
     txs = txs.concat(sourceFiles, libFiles, headerFiles, resourceFiles, 
frameworks, configChanges, assets, pluginsPlist);
 
     // pass platform-specific transactions into install

Reply via email to