Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CL-216:User should be able to override sessionUUID during object

instantiation
  • Loading branch information...
commit 42682baa590ca9e6763d2115b8ddc04a2ab0bb9b 1 parent 02d6a26
@tanaji-kadam tanaji-kadam authored
View
47 android/PubnubAndroidTest/3.3/src/com/fbt/Pubnub.java
@@ -56,6 +56,27 @@
private Hashtable<String, Object> connection = new Hashtable<String, Object>();
/**
+ *
+ * Prepare PubNub State.
+ *
+ * @param String
+ * Publish Key.
+ * @param String
+ * Subscribe Key.
+ * @param String
+ * Secret Key.
+ * @param String
+ * Cipher Key.
+ * @param boolean SSL Enabled.
+ *
+ * @param String uuid.
+ */
+ public Pubnub(String publish_key, String subscribe_key, String secret_key,
+ String cipher_key, boolean ssl_on,String uuid) {
+ this.init(publish_key, subscribe_key, secret_key, cipher_key, ssl_on,uuid);
+ }
+
+ /**
* PubNub 3.2 with Presence
*
* Prepare PubNub State.
@@ -72,7 +93,7 @@
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key,
String cipher_key, boolean ssl_on) {
- this.init(publish_key, subscribe_key, secret_key, cipher_key, ssl_on);
+ this.init(publish_key, subscribe_key, secret_key, cipher_key, ssl_on,uuid());
}
/**
@@ -90,7 +111,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key,
boolean ssl_on) {
- this.init(publish_key, subscribe_key, secret_key, "", ssl_on);
+ this.init(publish_key, subscribe_key, secret_key, "", ssl_on,uuid());
}
/**
@@ -104,7 +125,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
* Subscribe Key.
*/
public Pubnub(String publish_key, String subscribe_key) {
- this.init(publish_key, subscribe_key, "", "", false);
+ this.init(publish_key, subscribe_key, "", "", false,uuid());
}
/**
@@ -120,7 +141,7 @@ public Pubnub(String publish_key, String subscribe_key) {
* Secret Key.
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key) {
- this.init(publish_key, subscribe_key, secret_key, "", false);
+ this.init(publish_key, subscribe_key, secret_key, "", false,uuid());
}
/**
@@ -139,7 +160,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key) {
* @param boolean SSL Enabled.
*/
public void init(String publish_key, String subscribe_key,
- String secret_key, String cipher_key, boolean ssl_on) {
+ String secret_key, String cipher_key, boolean ssl_on,String uuid) {
this.PUBLISH_KEY = publish_key;
this.SUBSCRIBE_KEY = subscribe_key;
this.SECRET_KEY = secret_key;
@@ -152,7 +173,7 @@ public void init(String publish_key, String subscribe_key,
} else {
this.ORIGIN = "http://" + this.ORIGIN;
}
- UUIDs = uuid();
+ UUIDs = uuid;
}
/**
@@ -431,6 +452,7 @@ private void _subscribe(HashMap<String, Object> args) {
if (response.optString(1).length() > 0)
timetoken = response.optString(1);
+ boolean returnval = true;
for (int i = 0; messages.length() > i; i++) {
JSONObject message = messages.optJSONObject(i);
if (message != null) {
@@ -441,7 +463,9 @@ private void _subscribe(HashMap<String, Object> args) {
message = pc.decrypt(message);
}
if (callback != null)
- callback.subscribeCallback(channel, message);
+ {
+ returnval=callback.subscribeCallback(channel, message);
+ }
} else {
JSONArray arr = messages.optJSONArray(i);
@@ -453,7 +477,7 @@ private void _subscribe(HashMap<String, Object> args) {
;
}
if (callback != null)
- callback.subscribeCallback(channel, arr);
+ returnval=callback.subscribeCallback(channel, arr);
} else {
String msgs = messages.getString(0);
if (this.CIPHER_KEY.length() > 0) {
@@ -462,10 +486,15 @@ private void _subscribe(HashMap<String, Object> args) {
msgs = pc.decrypt(msgs);
}
if (callback != null)
- callback.subscribeCallback(channel, msgs);
+ returnval=callback.subscribeCallback(channel, msgs);
}
}
}
+
+ if(!returnval)
+ {
+ break;
+ }
} catch (Exception e) {
try {
Thread.sleep(1000);
View
1  android/PubnubUnitTest/src/com/sample/pubnubunittest/gui/ItemDetailFragment.java
@@ -12,6 +12,7 @@
import com.sample.pubnubunittest.unittest.CL_155;
import com.sample.pubnubunittest.unittest.CL_165;
+import com.sample.pubnubunittest.unittest.CL_216;
public class ItemDetailFragment extends Fragment {
View
1  android/PubnubUnitTest/src/com/sample/pubnubunittest/gui/MenuItemContent.java
@@ -29,6 +29,7 @@ public String toString() {
static {
addItem(new MenuItem("1", "CL-155"));
addItem(new MenuItem("2", "CL-165"));
+ addItem(new MenuItem("3", "CL-216"));
}
View
51 android/PubnubUnitTest/src/com/sample/pubnubunittest/pubnub/Pubnub.java
@@ -1,7 +1,5 @@
package com.sample.pubnubunittest.pubnub;
-
-
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -58,6 +56,27 @@
private Hashtable<String, Object> connection = new Hashtable<String, Object>();
/**
+ *
+ * Prepare PubNub State.
+ *
+ * @param String
+ * Publish Key.
+ * @param String
+ * Subscribe Key.
+ * @param String
+ * Secret Key.
+ * @param String
+ * Cipher Key.
+ * @param boolean SSL Enabled.
+ *
+ * @param String uuid.
+ */
+ public Pubnub(String publish_key, String subscribe_key, String secret_key,
+ String cipher_key, boolean ssl_on,String uuid) {
+ this.init(publish_key, subscribe_key, secret_key, cipher_key, ssl_on,uuid);
+ }
+
+ /**
* PubNub 3.2 with Presence
*
* Prepare PubNub State.
@@ -74,7 +93,7 @@
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key,
String cipher_key, boolean ssl_on) {
- this.init(publish_key, subscribe_key, secret_key, cipher_key, ssl_on);
+ this.init(publish_key, subscribe_key, secret_key, cipher_key, ssl_on,uuid());
}
/**
@@ -92,7 +111,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key,
boolean ssl_on) {
- this.init(publish_key, subscribe_key, secret_key, "", ssl_on);
+ this.init(publish_key, subscribe_key, secret_key, "", ssl_on,uuid());
}
/**
@@ -106,7 +125,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
* Subscribe Key.
*/
public Pubnub(String publish_key, String subscribe_key) {
- this.init(publish_key, subscribe_key, "", "", false);
+ this.init(publish_key, subscribe_key, "", "", false,uuid());
}
/**
@@ -122,7 +141,7 @@ public Pubnub(String publish_key, String subscribe_key) {
* Secret Key.
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key) {
- this.init(publish_key, subscribe_key, secret_key, "", false);
+ this.init(publish_key, subscribe_key, secret_key, "", false,uuid());
}
/**
@@ -141,7 +160,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key) {
* @param boolean SSL Enabled.
*/
public void init(String publish_key, String subscribe_key,
- String secret_key, String cipher_key, boolean ssl_on) {
+ String secret_key, String cipher_key, boolean ssl_on,String uuid) {
this.PUBLISH_KEY = publish_key;
this.SUBSCRIBE_KEY = subscribe_key;
this.SECRET_KEY = secret_key;
@@ -154,7 +173,7 @@ public void init(String publish_key, String subscribe_key,
} else {
this.ORIGIN = "http://" + this.ORIGIN;
}
- UUIDs = uuid();
+ UUIDs = uuid;
}
/**
@@ -433,7 +452,7 @@ private void _subscribe(HashMap<String, Object> args) {
if (response.optString(1).length() > 0)
timetoken = response.optString(1);
- boolean subResponce=true;
+ boolean returnval = true;
for (int i = 0; messages.length() > i; i++) {
JSONObject message = messages.optJSONObject(i);
if (message != null) {
@@ -444,8 +463,9 @@ private void _subscribe(HashMap<String, Object> args) {
message = pc.decrypt(message);
}
if (callback != null)
- subResponce=callback.subscribeCallback(channel, message);
-
+ {
+ returnval=callback.subscribeCallback(channel, message);
+ }
} else {
JSONArray arr = messages.optJSONArray(i);
@@ -457,8 +477,7 @@ private void _subscribe(HashMap<String, Object> args) {
;
}
if (callback != null)
- subResponce=callback.subscribeCallback(channel, arr);
-
+ returnval=callback.subscribeCallback(channel, arr);
} else {
String msgs = messages.getString(0);
if (this.CIPHER_KEY.length() > 0) {
@@ -467,12 +486,12 @@ private void _subscribe(HashMap<String, Object> args) {
msgs = pc.decrypt(msgs);
}
if (callback != null)
- subResponce=callback.subscribeCallback(channel, msgs);
-
+ returnval=callback.subscribeCallback(channel, msgs);
}
}
}
- if(!subResponce)
+
+ if(!returnval)
{
break;
}
View
186 android/PubnubUnitTest/src/com/sample/pubnubunittest/unittest/CL_216.java
@@ -0,0 +1,186 @@
+package com.sample.pubnubunittest.unittest;
+
+import java.util.HashMap;
+import java.util.UUID;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.sample.pubnubunittest.pubnub.Callback;
+import com.sample.pubnubunittest.pubnub.Pubnub;
+import com.sample.pubnubunittest.unittest.CL_165.SubcribeExicute;
+
+import android.os.AsyncTask;
+import android.os.Handler;
+import android.util.Log;
+
+public class CL_216 {
+
+ String _publish_key ,_subscribe_key,_secret_key,_cipher_key,_uuid;
+ String _crazy,_channel;
+ boolean _ssl_on;
+ Pubnub _pubnub;
+ SubcribeExicute subcribe;
+
+ private void initParameter() {
+ _publish_key=_subscribe_key=_secret_key=_cipher_key="demo";
+ _uuid="efc873ea-8512-45c2-b0c8-91c95b36a819";
+ _ssl_on=false;
+ _crazy = "~`!@#$%^&*(???)+=[]\\{}|;\':,./<>?abcd";
+ _pubnub = new Pubnub(_publish_key,_subscribe_key,_secret_key,_cipher_key,_ssl_on,_uuid);
+ _channel=CommonUtil.getBigDecimal(_pubnub.time());
+ }
+
+ public void RunUnitTest(Handler handler) {
+ CommonUtil.setHandler(handler);
+ initParameter();
+ CommonUtil.PrintLog("subscribeing channel with uuid: "+_uuid);
+ subcribe = new SubcribeExicute();
+ subcribe.execute();
+ }
+
+ boolean PublishMessage() {
+ boolean returnVal = false;
+ try {
+ JSONObject message = new JSONObject();
+ message.put("message", _crazy);
+
+ HashMap<String, Object> args = new HashMap<String, Object>();
+ args.put("channel", _channel);
+ args.put("message", message);
+ JSONArray responce = _pubnub.publish(args);
+ returnVal = responce.getInt(0) == 1 ? true : false;
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return returnVal;
+
+ }
+
+
+ class SubcribeExicute extends AsyncTask<String, Void, Boolean> {
+
+ @Override
+ protected Boolean doInBackground(String... params) {
+ try {
+ class Receiver implements Callback {
+
+ public boolean subscribeCallback(String channel,
+ Object message) {
+ Log.e("Message Received", message.toString());
+
+ if(message instanceof JSONObject)
+ {
+ try{
+ JSONObject obj=(JSONObject)message;
+
+ if(obj.getString("message").equals(_crazy))
+ {
+ CommonUtil.LogPass(true, "Messege receive to channel.");
+ }else
+ {
+ CommonUtil.LogPass(false, "Messege receive to channel.");
+ }
+ }catch (Exception e) {
+
+ }
+
+ HashMap<String, Object> args = new HashMap<String, Object>(1);
+ args.put("channel", _channel);
+ JSONArray array = _pubnub.here_now(args);
+
+ try {
+ JSONArray uuids=array.getJSONObject(0).getJSONArray("uuids");
+ for(int i= 0; i<uuids.length();i++)
+ {
+ String uuid=uuids.getString(i);
+ if(uuid.equals(_uuid))
+ {
+ CommonUtil.PrintLog("Receviev UUID:"+uuid);
+ CommonUtil.LogPass(true, "UUID unit test.");
+ }else
+ {
+ CommonUtil.LogPass(false, "UUID unit test.");
+ }
+ }
+
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if(subcribe != null)
+ {
+ subcribe.cancel(true);
+ subcribe=null;
+ return false;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean presenceCallback(String channel,
+ Object message) {
+ Log.e("Message Received", message.toString());
+ return true;
+ }
+
+ @Override
+ public void errorCallback(String channel, Object message) {
+ Log.e("ErrorCallback", "Channel:" + channel + "-"
+ + message.toString());
+ }
+
+ @Override
+ public void connectCallback(String channel) {
+ Log.e("ConnectCallback", "Connected to channel :"
+ + channel);
+ CommonUtil.LogPass(true, "Subscribe the channel.");
+
+ if (PublishMessage()) {
+ CommonUtil.LogPass(true, "Publish message sent.");
+ } else {
+ CommonUtil.LogPass(false, "Publish message sent.");
+ }
+
+ }
+
+ @Override
+ public void reconnectCallback(String channel) {
+ Log.e("ReconnectCallback", "Reconnecting to channel :"
+ + channel);
+ }
+
+ @Override
+ public void disconnectCallback(String channel) {
+ Log.e("DisconnectCallback", "Disconnected to channel :"
+ + channel);
+ CommonUtil.LogPass(true, "Unsubscribe channel.");
+
+ }
+ }
+
+ // Listen for Messages (Subscribe)
+ HashMap<String, Object> args = new HashMap<String, Object>(2);
+ args.put("channel", _channel); // Channel Name
+ args.put("callback", new Receiver()); // Callback to get response
+ _pubnub.subscribe(args);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.v("ERROR", "While downloading");
+ }
+
+ return Boolean.TRUE;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ }
+
+ protected void onPostExecute(Boolean result) {
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.