Permalink
Browse files

Implemented detailedHistory in java client and updated unit test func…

…tionality with junit4
  • Loading branch information...
1 parent e0710fc commit 4429deb2387d9629b66e3247676bfd226a331627 Leonardo Redmond committed Sep 1, 2012
View
BIN csharp/3.3/PubNub.suo
Binary file not shown.
View
1 java/3.2/.classpath
@@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/async-http-client-1.6.5-shaded.jar"/>
<classpathentry kind="lib" path="lib/slf4j-nop-1.6.2.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
70 java/3.2/src/pubnub/api/Pubnub.java
@@ -3,6 +3,7 @@
import com.ning.http.client.*;
import com.ning.http.client.AsyncHttpClientConfig.Builder;
import org.json.JSONArray;
+import org.json.JSONException;
import org.json.JSONObject;
import java.net.URLEncoder;
@@ -42,9 +43,10 @@
private String PUBLISH_KEY = "";
private String SUBSCRIBE_KEY = "";
private String SECRET_KEY = "";
- private String CIPHER_KEY = "";
+ public String CIPHER_KEY = "";
private boolean SSL = false;
private String sessionUUID = "";
+ private String parameters = "";
private class ChannelStatus {
String channel;
@@ -439,7 +441,7 @@ private void _subscribe(HashMap<String, Object> args) {
message = pc.decrypt(message);
}
if (callback != null)
- callback.subscribeCallback(channel, message);
+ if (!callback.subscribeCallback(channel, message)) return;
} else {
JSONArray arr = messages.optJSONArray(i);
@@ -451,7 +453,7 @@ private void _subscribe(HashMap<String, Object> args) {
;
}
if (callback != null)
- callback.subscribeCallback(channel, arr);
+ if(!callback.subscribeCallback(channel, arr)) return;
} else {
String msgs = messages.getString(0);
if (this.CIPHER_KEY.length() > 0) {
@@ -460,7 +462,7 @@ private void _subscribe(HashMap<String, Object> args) {
msgs = pc.decrypt(msgs);
}
if (callback != null)
- callback.subscribeCallback(channel, msgs);
+ if(!callback.subscribeCallback(channel, msgs)) return;
}
}
}
@@ -660,7 +662,7 @@ private void _presence(HashMap<String, Object> args) {
message = pc.decrypt(message);
}
if (callback != null)
- callback.presenceCallback(channel, message);
+ if(!callback.presenceCallback(channel, message)) return;
} else {
JSONArray arr = messages.optJSONArray(i);
@@ -669,10 +671,9 @@ private void _presence(HashMap<String, Object> args) {
PubnubCrypto pc = new PubnubCrypto(
this.CIPHER_KEY);
arr = pc.decryptJSONArray(arr);
- ;
}
if (callback != null)
- callback.presenceCallback(channel, arr);
+ if (!callback.presenceCallback(channel, arr)) return;
} else {
String msgs = messages.getString(0);
if (this.CIPHER_KEY.length() > 0) {
@@ -681,7 +682,7 @@ private void _presence(HashMap<String, Object> args) {
msgs = pc.decrypt(msgs);
}
if (callback != null)
- callback.presenceCallback(channel, msgs);
+ if (!callback.presenceCallback(channel, msgs)) return;
}
}
}
@@ -772,7 +773,55 @@ public JSONArray history(HashMap<String, Object> args) {
return response;
}
}
+
+ /**
+ * DetailedHistory
+ *
+ * DetailedHistory from PubNub Cloud.
+ *
+ * @return JSONArray of detailed history.
+ */
+ public JSONArray detailedHistory(String channel, long start, long end, int count, Boolean reverse) {
+ parameters = "";
+ if (count == -1) count = 100;
+ if (count == -1) count = 100;
+ parameters = "?count=" + count;
+ if (reverse)
+ parameters = parameters + "&" + "reverse=" + reverse.toString().toLowerCase();
+ if (start != -1)
+ parameters = parameters + "&" + "start=" + Long.toString(start).toLowerCase();
+ if (end != -1)
+ parameters = parameters + "&" + "end=" + Long.toString(end).toLowerCase();
+
+ List<String> url = new ArrayList<String>();
+ url.add("v2");
+ url.add("history");
+ url.add("sub-key");
+ url.add(this.SUBSCRIBE_KEY);
+ url.add("channel");
+ url.add(channel);
+
+ JSONArray response = _request(url);
+
+ if (this.CIPHER_KEY.length() > 0) {
+ PubnubCrypto pc = new PubnubCrypto(this.CIPHER_KEY);
+ try {
+ return pc.decryptJSONArray(response.getJSONArray(0));
+ } catch (JSONException e) {
+ return response;
+ }
+ } else {
+ return response;
+ }
+ }
+
+ public JSONArray detailedHistory(String channel, long start, boolean reverse) {
+ return detailedHistory(channel, start, -1, -1, reverse);
+ }
+ public JSONArray detailedHistory(String channel, int count) {
+ return detailedHistory(channel, -1, -1, count, false);
+ }
/**
* Time
*
@@ -834,7 +883,8 @@ private JSONArray _request(List<String> url_components) {
StringBuilder url = new StringBuilder();
Iterator<String> url_iterator = url_components.iterator();
String request_for = url_components.get(0);
-
+ String request_type = url_components.get(1);
+
url.append(this.ORIGIN);
// Generate URL with UTF-8 Encoding
@@ -854,6 +904,8 @@ private JSONArray _request(List<String> url_components) {
}
if (request_for.equals("subscribe") || request_for.equals("presence"))
url.append("?uuid=").append(this.sessionUUID);
+ if (request_for.equals("v2") && request_type.equals("history"))
+ url.append(parameters);
AsyncHttpClient ahc = null;
try {
View
59 java/3.2/src/pubnub/example/PubnubExample.java
@@ -27,6 +27,9 @@ public static void main(String[] params) {
System.out.println("\nRunning here_now()");
HereNowExample();
+ System.out.println("\nRunning detailedHistory()");
+ DetailedHistoryExample();
+
System.out.println("\nRunning presence()");
PresenceExample();
@@ -39,7 +42,7 @@ private static void PublishExample() {
String publish_key = "demo";
String subscribe_key = "demo";
String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
+ String cipher_key = "enigma"; // (Cipher key is optional)
String channel = "hello_world";
int publish_message_count = 1;
@@ -97,22 +100,16 @@ private static void PublishExample() {
response = pubnub.publish(args);
System.out.println(response);
-
- // Pause
- try {
- Thread.currentThread().sleep(100);
- } catch (Exception ex) {
- }
}
}
private static void HistoryExample() {
String publish_key = "demo";
String subscribe_key = "demo";
String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
+ String cipher_key = "enigma"; // (Cipher key is optional)
String channel = "hello_world";
- int limit = 4;
+ int limit = 1;
Pubnub pubnub = new Pubnub(
publish_key,
@@ -150,6 +147,46 @@ private static void HistoryExample() {
}
}
+ private static void DetailedHistoryExample() {
+ String publish_key = "demo";
+ String subscribe_key = "demo";
+ String secret_key = "demo";
+ String cipher_key = "enigma"; // (Cipher key is optional)
+ String channel = "hello_world";
+ int count = 1;
+
+ Pubnub pubnub = new Pubnub(
+ publish_key,
+ subscribe_key,
+ secret_key,
+ cipher_key,
+ true
+ );
+
+ // Get History
+ JSONArray response = pubnub.detailedHistory(channel, count);
+
+ // Print Response from PubNub JSONP REST Service
+ System.out.println(response);
+
+ try {
+ if (response != null) {
+ for (int i = 0; i < response.length(); i ++) {
+ JSONObject jsono = response.optJSONObject(i);
+ if (jsono != null) {
+ @SuppressWarnings("rawtypes")
+ Iterator keys = jsono.keys();
+ while (keys.hasNext()) {
+ System.out.println(jsono.get(keys.next().toString()) + " ");
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
private static void TimestampExample() {
String publish_key = "demo";
String subscribe_key = "demo";
@@ -222,7 +259,7 @@ public void errorCallback(String channel, Object message) {
@Override
public void connectCallback(String channel) {
System.out.println("Connected to channel :" + channel);
-
+ System.out.println("Waiting for a message from publisher ...");
}
@Override
@@ -303,7 +340,7 @@ public void errorCallback(String channel, Object message) {
@Override
public void connectCallback(String channel) {
System.out.println("Connected to channel :" + channel);
-
+ System.out.println("Waiting for subscribe or unsubscribe message ...");
}
@Override
View
461 java/3.2/src/pubnub/unit_test/PubnubUnitTest.java
@@ -4,8 +4,6 @@
import java.util.HashMap;
import java.util.Iterator;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONException;
@@ -17,24 +15,20 @@
public class PubnubUnitTest {
- private CountDownLatch lock = new CountDownLatch(1);
+ private static boolean deliveryStatus = false;
+ private Pubnub pubnub = new Pubnub(
+ "demo",
+ "demo",
+ "",
+ "",
+ true
+ );
+ private String channel = "hello_world";
+ private int limit = 1;
@Test
public void testPublishHashMapOfStringObject() {
- String publish_key = "demo";
- String subscribe_key = "demo";
- String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
- String channel = "hello_world";
-
- Pubnub pubnub = new Pubnub(
- publish_key,
- subscribe_key,
- secret_key,
- cipher_key,
- true
- );
-
+ pubnub.CIPHER_KEY = "enigma";
JSONObject message = new JSONObject();
try {
message.put("text", "Hello World!");
@@ -50,32 +44,18 @@ public void testPublishHashMapOfStringObject() {
try {
assertFalse(response.get(2).toString().equals("0"));
+ System.out.println("PASS: TestPublish");
} catch (JSONException e) {
- fail("Failed to publish message through a channel.");
+ fail("FAIL: TestPublish");
}
}
@Test
public void testSubscribeHashMapOfStringObject() {
- String publish_key = "demo";
- String subscribe_key = "demo";
- String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
- String channel = "hello_world";
-
- Pubnub pubnub = new Pubnub(
- publish_key,
- subscribe_key,
- secret_key,
- cipher_key,
- true
- );
-
+ pubnub.CIPHER_KEY = "";
// Callback Interface when a Message is Received
class Receiver implements Callback {
- public boolean message_received = false;
-
public boolean subscribeCallback(String channel, Object message) {
try {
@@ -99,10 +79,9 @@ public boolean subscribeCallback(String channel, Object message) {
} catch (Exception e) {
e.printStackTrace();
}
+ deliveryStatus = true;
// Continue Listening?
- message_received = true;
- lock.countDown();
- return true;
+ return false;
}
@Override
@@ -114,7 +93,7 @@ public void errorCallback(String channel, Object message) {
@Override
public void connectCallback(String channel) {
System.out.println("Connected to channel :" + channel);
-
+ System.out.println("Waiting for a message from publisher ...");
}
@Override
@@ -135,40 +114,29 @@ public boolean presenceCallback(String channel, Object message) {
HashMap<String, Object> args = new HashMap<String, Object>(6);
args.put("channel", channel);
- Receiver recv = new Receiver();
- args.put("callback", recv); // callback to get response
+ args.put("callback", new Receiver());
+ deliveryStatus = false;
// Listen for Messages (Subscribe)
pubnub.subscribe(args);
+ JSONObject json = new JSONObject();
try {
- lock.await(5000, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- assertTrue(recv.message_received);
+ json.put("text", "hi");
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ while(!deliveryStatus);
+ assertTrue(deliveryStatus);
+ System.out.println("PASS: TestSubscribe");
}
@Test
public void testPresenceHashMapOfStringObject() {
- String publish_key = "demo";
- String subscribe_key = "demo";
- String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
- String channel = "hello_world";
-
- Pubnub pubnub = new Pubnub(
- publish_key,
- subscribe_key,
- secret_key,
- cipher_key,
- true
- );
-
+ pubnub.CIPHER_KEY = "";
// Callback Interface when a Message is Received
class Receiver implements Callback {
- public boolean message_received = false;
-
public boolean presenceCallback(String channel, Object message) {
try {
@@ -192,22 +160,20 @@ public boolean presenceCallback(String channel, Object message) {
} catch (Exception e) {
e.printStackTrace();
}
+ deliveryStatus = true;
// Continue Listening?
- message_received = true;
- lock.countDown();
- return true;
+ return false;
}
@Override
public void errorCallback(String channel, Object message) {
System.err.println("Channel:" + channel + "-" + message.toString());
-
}
@Override
public void connectCallback(String channel) {
System.out.println("Connected to channel :" + channel);
-
+ System.out.println("Waiting for subscribe or unsubscribe message ...");
}
@Override
@@ -228,91 +194,352 @@ public boolean subscribeCallback(String channel, Object message) {
HashMap<String, Object> args = new HashMap<String, Object>(6);
args.put("channel", channel + "-pnpres");
- Receiver recv = new Receiver();
- args.put("callback", recv); // callback to get response
+ args.put("callback", new Receiver()); // callback to get response
+ deliveryStatus = false;
// Listen for Messages (Presence)
pubnub.presence(args);
- try {
- lock.await(5000, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- assertTrue(recv.message_received);
+ while(!deliveryStatus);
+ assertTrue(deliveryStatus);
+ System.out.println("PASS: TestPresence");
}
@Test
public void testHere_now() {
- String publish_key = "demo";
- String subscribe_key = "demo";
- String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
- String channel = "hello_world";
-
- Pubnub pubnub = new Pubnub(
- publish_key,
- subscribe_key,
- secret_key,
- cipher_key,
- true
- );
-
+ pubnub.CIPHER_KEY = "";
// Get Here Now
JSONArray response = pubnub.here_now(channel);
try {
assertNotNull(response);
+ System.out.println("PASS: TestHere_Now");
} catch (Exception e) {
- e.printStackTrace();
+ fail("FAIL: TestHere_Now");
}
}
@Test
- public void testHistoryHashMapOfStringObject() {
- String publish_key = "demo";
- String subscribe_key = "demo";
- String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
- String channel = "hello_world";
- int limit = 4;
+ public void testUnencryptedHistoryHashMapOfStringObject() {
+ // Context setup
+ pubnub.CIPHER_KEY = "";
+ JSONObject message = new JSONObject();
+ try {
+ message.put("text", "Hello World!");
+ } catch (org.json.JSONException jsonError) {
+ jsonError.printStackTrace();
+ }
+
+ HashMap<String, Object> args = new HashMap<String, Object>(2);
+ args.put("channel", channel);
+ args.put("message", message);
+ JSONArray response = null;
+ response = pubnub.publish(args);
+
+ // Test begins
+ args = new HashMap<String, Object>(2);
+ args.put("channel", channel);
+ args.put("limit", limit);
- Pubnub pubnub = new Pubnub(
- publish_key,
- subscribe_key,
- secret_key,
- cipher_key,
- true
- );
+ // Get History
+ response = pubnub.history(args);
+
+ try {
+ assertNotNull(response);
+ System.out.println("PASS: TestUnencryptedHistory");
+ } catch (Exception e) {
+ fail("FAIL: TestUnencryptedHistory");
+ }
+ }
+
+ @Test
+ public void testEncryptedHistoryHashMapOfStringObject() {
+ // Context setup
+ pubnub.CIPHER_KEY = "enigma";
+ JSONObject message = new JSONObject();
+ try {
+ message.put("text", "Hello World!");
+ } catch (org.json.JSONException jsonError) {
+ jsonError.printStackTrace();
+ }
HashMap<String, Object> args = new HashMap<String, Object>(2);
args.put("channel", channel);
+ args.put("message", message);
+ JSONArray response = null;
+ response = pubnub.publish(args);
+
+ // Test begins
+ args = new HashMap<String, Object>(2);
+ args.put("channel", channel);
args.put("limit", limit);
// Get History
- JSONArray response = pubnub.history(args);
+ response = pubnub.history(args);
try {
assertNotNull(response);
+ System.out.println("PASS: TestEncryptedHistory");
} catch (Exception e) {
- e.printStackTrace();
+ fail("FAIL: TestEncryptedHistory");
}
}
@Test
- public void testTime() {
- String publish_key = "demo";
- String subscribe_key = "demo";
- String secret_key = "demo";
- String cipher_key = ""; // (Cipher key is optional)
+ public void testUnencryptedDetailedHistory()
+ {
+ // Context setup for Detailed History
+ pubnub.CIPHER_KEY = "";
+ int total_msg = 10;
+ long starttime = (long) pubnub.time();
+ HashMap<Long, String> inputs = new HashMap<Long, String>();
+ for (int i = 0; i < total_msg / 2; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long midtime = (long) pubnub.time();
+ for (int i = total_msg / 2; i < total_msg; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long endtime = (long)pubnub.time();
- Pubnub pubnub = new Pubnub(
- publish_key,
- subscribe_key,
- secret_key,
- cipher_key,
- true
- );
+ // Get History
+ JSONArray response = pubnub.detailedHistory(channel, total_msg);
+
+ // Print Response from PubNub JSONP REST Service
+ System.out.println(response);
+
+ try {
+ assertNotNull(response);
+ System.out.println("PASS: TestUnencryptedDetailedHistory");
+ } catch (Exception e) {
+ fail("FAIL: TestUnencryptedDetailedHistory");
+ }
+ }
+
+ @Test
+ public void testEncryptedDetailedHistory()
+ {
+ // Context setup for Detailed History
+ pubnub.CIPHER_KEY = "enigma";
+ int total_msg = 10;
+ long starttime = (long) pubnub.time();
+ HashMap<Long, String> inputs = new HashMap<Long, String>();
+ for (int i = 0; i < total_msg / 2; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long midtime = (long) pubnub.time();
+ for (int i = total_msg / 2; i < total_msg; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long endtime = (long)pubnub.time();
+ // Get History
+ JSONArray response = pubnub.detailedHistory(channel, total_msg);
+
+ // Print Response from PubNub JSONP REST Service
+ System.out.println(response);
+
+ try {
+ assertNotNull(response);
+ System.out.println("PASS: TestEncryptedDetailedHistory");
+ } catch (Exception e) {
+ fail("FAIL: TestEncryptedDetailedHistory");
+ }
+ }
+
+ @Test
+ public void testUnencryptedDetailedHistoryParams()
+ {
+ // Context setup for Detailed History
+ pubnub.CIPHER_KEY = "";
+ int total_msg = 10;
+ long starttime = (long) pubnub.time();
+ HashMap<Long, String> inputs = new HashMap<Long, String>();
+ for (int i = 0; i < total_msg / 2; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long midtime = (long) pubnub.time();
+ for (int i = total_msg / 2; i < total_msg; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long endtime = (long)pubnub.time();
+
+ // Get History
+ JSONArray response;
+ System.out.println("DetailedHistory with start & end");
+ response = pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true);
+ System.out.println(response);
+ try {
+ assertNotNull(response);
+ } catch (Exception e) {
+ fail("FAIL: TestUnencryptedDetailedHistoryParams");
+ }
+
+ System.out.println("DetailedHistory with start & reverse = true");
+ response = pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true);
+ System.out.println(response);
+ try {
+ assertNotNull(response);
+ } catch (Exception e) {
+ fail("FAIL: TestUnencryptedDetailedHistoryParams");
+ }
+
+ System.out.println("DetailedHistory with start & reverse = false");
+ response = pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false);
+ System.out.println(response);
+ try {
+ assertNotNull(response);
+ System.out.println("PASS: TestUnencryptedDetailedHistoryParams");
+ } catch (Exception e) {
+ fail("FAIL: TestUnencryptedDetailedHistoryParams");
+ }
+ }
+
+ @Test
+ public void testEncryptedDetailedHistoryParams()
+ {
+ // Context setup for Detailed History
+ pubnub.CIPHER_KEY = "enigma";
+ int total_msg = 10;
+ long starttime = (long) pubnub.time();
+ HashMap<Long, String> inputs = new HashMap<Long, String>();
+ for (int i = 0; i < total_msg / 2; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long midtime = (long) pubnub.time();
+ for (int i = total_msg / 2; i < total_msg; i++)
+ {
+ String msg = Integer.toString(i);
+ JSONObject json = new JSONObject();
+ try {
+ json.put("text", msg);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ pubnub.publish(channel, json);
+ long t = (long) pubnub.time();
+ inputs.put(t, msg);
+ System.out.println("Message # " + Integer.toString(i) + " published");
+ }
+
+ long endtime = (long)pubnub.time();
+
+ // Get History
+ JSONArray response;
+ System.out.println("DetailedHistory with start & end");
+ response = pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true);
+ System.out.println(response);
+ try {
+ assertNotNull(response);
+ } catch (Exception e) {
+ fail("FAIL: TestEncryptedDetailedHistoryParams");
+ }
+
+ System.out.println("DetailedHistory with start & reverse = true");
+ response = pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true);
+ System.out.println(response);
+ try {
+ assertNotNull(response);
+ } catch (Exception e) {
+ fail("FAIL: TestEncryptedDetailedHistoryParams");
+ }
+
+ System.out.println("DetailedHistory with start & reverse = false");
+ response = pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false);
+ System.out.println(response);
+ try {
+ assertNotNull(response);
+ System.out.println("PASS: TestEncryptedDetailedHistoryParams");
+ } catch (Exception e) {
+ fail("FAIL: TestEncryptedDetailedHistoryParams");
+ }
+ }
+
+ @Test
+ public void testTime() {
assertNotNull(pubnub.time());
}
View
24 java/3.2/src/pubnub/unit_test/PubnubUnitTestRunner.java
@@ -0,0 +1,24 @@
+package pubnub.unit_test;
+
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+
+public class PubnubUnitTestRunner {
+
+ public static void main(String[] args) {
+ Result result = JUnitCore.runClasses(PubnubUnitTest.class);
+ for (Failure failure : result.getFailures()) {
+ System.out.println(failure.toString());
+ }
+ if (result.getFailureCount() != 0)
+ {
+ System.out.println("Pubnub Unit Test Failed: # of failures - " + result.getFailureCount());
+ }
+ else
+ {
+ System.out.println("Pubnub Unit Test Completed Successfully.");
+ }
+ }
+
+}
View
BIN java/3.2/test/PubnubExample.jar
Binary file not shown.
View
BIN java/3.2/test/PubnubUnitTest.jar
Binary file not shown.

0 comments on commit 4429deb

Please sign in to comment.