From: kenstir Date: Sun, 6 Dec 2015 01:24:47 +0000 (-0500) Subject: First android unit test X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b1c65441123d73088d587848425f1bc947a05d31;p=working%2FEvergreen.git First android unit test Under Intellij you need a new android test module, and it would not create one under core/ so it went under cwmars_app/tests/. The first test exercises volley to fetch a json resource. --- diff --git a/Open-ILS/src/Android/core/.idea/copyright/profiles_settings.xml b/Open-ILS/src/Android/core/.idea/copyright/profiles_settings.xml index 3572571ad8..e7bedf3377 100644 --- a/Open-ILS/src/Android/core/.idea/copyright/profiles_settings.xml +++ b/Open-ILS/src/Android/core/.idea/copyright/profiles_settings.xml @@ -1,5 +1,3 @@ - - - + \ No newline at end of file diff --git a/Open-ILS/src/Android/core/.idea/encodings.xml b/Open-ILS/src/Android/core/.idea/encodings.xml index e206d70d85..f758959656 100644 --- a/Open-ILS/src/Android/core/.idea/encodings.xml +++ b/Open-ILS/src/Android/core/.idea/encodings.xml @@ -1,5 +1,6 @@ - - - + + + + \ No newline at end of file diff --git a/Open-ILS/src/Android/core/.idea/vcs.xml b/Open-ILS/src/Android/core/.idea/vcs.xml index 2a79caeef5..4fce1d86b4 100644 --- a/Open-ILS/src/Android/core/.idea/vcs.xml +++ b/Open-ILS/src/Android/core/.idea/vcs.xml @@ -1,8 +1,6 @@ - - - + \ No newline at end of file diff --git a/Open-ILS/src/Android/core/core.iml b/Open-ILS/src/Android/core/core.iml index ce7d091294..1c9cffbb71 100644 --- a/Open-ILS/src/Android/core/core.iml +++ b/Open-ILS/src/Android/core/core.iml @@ -12,15 +12,13 @@ - + - - @@ -62,5 +60,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/Android/core/src/org/open_ils/test/fm_IDL.xml b/Open-ILS/src/Android/core/src/org/open_ils/test/fm_IDL.xml new file mode 100644 index 0000000000..714a514b2a --- /dev/null +++ b/Open-ILS/src/Android/core/src/org/open_ils/test/fm_IDL.xml @@ -0,0 +1,689 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/Android/core/src/org/open_ils/test/org/evergreen_ils/views/MainActivityTest.java b/Open-ILS/src/Android/core/src/org/open_ils/test/org/evergreen_ils/views/MainActivityTest.java new file mode 100644 index 0000000000..a3cc19c24e --- /dev/null +++ b/Open-ILS/src/Android/core/src/org/open_ils/test/org/evergreen_ils/views/MainActivityTest.java @@ -0,0 +1,91 @@ +package org.evergreen_ils.views; + +import android.app.Activity; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.StringRequest; +import org.evergreen_ils.net.VolleyWrangler; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Created by kenstir on 12/5/2015. + */ +public class MainActivityTest + extends ActivityInstrumentationTestCase2 { + + private static final String TAG = MainActivityTest.class.getName(); + private Activity mActivity; + private VolleyWrangler mVolley; + private String libraries_directory_url = "https://evergreen-ils.org/directory/libraries.json"; + private String mStringResponse = null; + private String mError = null; + private Exception mException = null; + private final Lock mLock = new ReentrantLock(); + private final Condition mFinishedCondition = mLock.newCondition(); + private long mStartTime; + + public MainActivityTest() { + super(MainActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mActivity = getActivity(); + mVolley = VolleyWrangler.getInstance(mActivity); + mStartTime = System.currentTimeMillis(); + } + + private void signalFinished() { + mLock.lock(); + mFinishedCondition.signal(); + mLock.unlock(); + } + + private boolean waitForResponse() throws InterruptedException { + mLock.lock(); + try { + return mFinishedCondition.await(1000, TimeUnit.MILLISECONDS); + } finally { + mLock.unlock(); + } + } + + private void handleResponse(String response) { + long duration_ms = System.currentTimeMillis() - mStartTime; + Log.d(TAG, "fetch took " + duration_ms + "ms"); + mStringResponse = response; + Log.d(TAG, "response: " + response); + signalFinished(); + } + + public void testVolleyFetch_basic() throws InterruptedException { + RequestQueue q = VolleyWrangler.getInstance(mActivity).getRequestQueue(); + StringRequest request = new StringRequest(Request.Method.GET, libraries_directory_url, + new Response.Listener() { + @Override + public void onResponse(String response) { + handleResponse(response); + } + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + mError = error.getMessage(); + } + }); + + // submit the request and await the response + q.add(request); + waitForResponse(); + assertTrue(mStringResponse != null); + } +} \ No newline at end of file diff --git a/Open-ILS/src/Android/cwmars_app/.idea/misc.xml b/Open-ILS/src/Android/cwmars_app/.idea/misc.xml index 99f8d99674..db39fc3cf8 100644 --- a/Open-ILS/src/Android/cwmars_app/.idea/misc.xml +++ b/Open-ILS/src/Android/cwmars_app/.idea/misc.xml @@ -30,4 +30,7 @@ + + \ No newline at end of file diff --git a/Open-ILS/src/Android/cwmars_app/.idea/modules.xml b/Open-ILS/src/Android/cwmars_app/.idea/modules.xml index de20113a48..452e72251d 100644 --- a/Open-ILS/src/Android/cwmars_app/.idea/modules.xml +++ b/Open-ILS/src/Android/cwmars_app/.idea/modules.xml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/Open-ILS/src/Android/cwmars_app/tests/AndroidManifest.xml b/Open-ILS/src/Android/cwmars_app/tests/AndroidManifest.xml new file mode 100644 index 0000000000..8316bd88c6 --- /dev/null +++ b/Open-ILS/src/Android/cwmars_app/tests/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/Open-ILS/src/Android/cwmars_app/tests/ant.properties b/Open-ILS/src/Android/cwmars_app/tests/ant.properties new file mode 100644 index 0000000000..e16c462d13 --- /dev/null +++ b/Open-ILS/src/Android/cwmars_app/tests/ant.properties @@ -0,0 +1,18 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked into Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + +tested.project.dir=E:\\src\\Evergreen\\Open-ILS\\src\\Android\\cwmars_app diff --git a/Open-ILS/src/Android/cwmars_app/tests/build.xml b/Open-ILS/src/Android/cwmars_app/tests/build.xml new file mode 100644 index 0000000000..74cc33beb6 --- /dev/null +++ b/Open-ILS/src/Android/cwmars_app/tests/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/Android/cwmars_app/tests/project.properties b/Open-ILS/src/Android/cwmars_app/tests/project.properties new file mode 100644 index 0000000000..4ab125693c --- /dev/null +++ b/Open-ILS/src/Android/cwmars_app/tests/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/Open-ILS/src/Android/cwmars_app/tests/tests.iml b/Open-ILS/src/Android/cwmars_app/tests/tests.iml new file mode 100644 index 0000000000..5074df2632 --- /dev/null +++ b/Open-ILS/src/Android/cwmars_app/tests/tests.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file