|
1 | 1 | package com.pubnub.api; |
2 | 2 |
|
| 3 | + |
| 4 | +import org.json.JSONArray; |
3 | 5 | import org.json.JSONException; |
4 | 6 | import org.json.JSONObject; |
5 | 7 |
|
6 | 8 | import java.util.concurrent.CountDownLatch; |
| 9 | +import java.util.concurrent.TimeUnit; |
7 | 10 |
|
8 | 11 | public class TestHelper { |
9 | 12 | static class SimpleCallback extends Callback { |
@@ -109,4 +112,59 @@ public void errorCallback(String channel, PubnubError error) { |
109 | 112 | } |
110 | 113 |
|
111 | 114 | } |
| 115 | + |
| 116 | + public static void cleanup() throws InterruptedException, JSONException { |
| 117 | + Pubnub pubnub = new Pubnub("demo", "demo"); |
| 118 | + pubnub.setOrigin("dara24.devbuild"); |
| 119 | + pubnub.setCacheBusting(false); |
| 120 | + |
| 121 | + final CountDownLatch latch1 = new CountDownLatch(1); |
| 122 | + final CountDownLatch latch2 = new CountDownLatch(1); |
| 123 | + final TestHelper.SimpleCallback cb1 = new TestHelper.SimpleCallback(latch1); |
| 124 | + final TestHelper.SimpleCallback cb2 = new TestHelper.SimpleCallback(latch2); |
| 125 | + |
| 126 | + pubnub.channelGroupListGroups(cb1); |
| 127 | + latch1.await(10, TimeUnit.SECONDS); |
| 128 | + |
| 129 | + JSONObject result = (JSONObject) cb1.getResponse(); |
| 130 | + JSONArray groups = result.getJSONArray("groups"); |
| 131 | + |
| 132 | + for (int i = 0; i < groups.length(); i++) { |
| 133 | + final String group = groups.getString(i); |
| 134 | + |
| 135 | + if (group.startsWith("jtest")) { |
| 136 | + CountDownLatch latch = new CountDownLatch(1); |
| 137 | + pubnub.channelGroupRemoveGroup(group, new TestHelper.SimpleCallback(latch) { |
| 138 | + @Override |
| 139 | + public void successCallback(String channel, Object message) { |
| 140 | + System.out.println("Successfully removed group " + group); |
| 141 | + super.successCallback(channel, message); |
| 142 | + } |
| 143 | + }); |
| 144 | + latch.await(10, TimeUnit.SECONDS); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + pubnub.channelGroupListNamespaces(cb2); |
| 149 | + latch2.await(10, TimeUnit.SECONDS); |
| 150 | + |
| 151 | + result = (JSONObject) cb2.getResponse(); |
| 152 | + JSONArray namespaces = result.getJSONArray("namespaces"); |
| 153 | + |
| 154 | + for (int i = 0; i < namespaces.length(); i++) { |
| 155 | + final String namespace = namespaces.getString(i); |
| 156 | + |
| 157 | + if (namespace.startsWith("jtest")) { |
| 158 | + CountDownLatch latch = new CountDownLatch(1); |
| 159 | + pubnub.channelGroupRemoveNamespace(namespace, new TestHelper.SimpleCallback(latch) { |
| 160 | + @Override |
| 161 | + public void successCallback(String channel, Object message) { |
| 162 | + System.out.println("Successfully removed namespace " + namespace); |
| 163 | + super.successCallback(channel, message); |
| 164 | + } |
| 165 | + }); |
| 166 | + latch.await(10, TimeUnit.SECONDS); |
| 167 | + } |
| 168 | + } |
| 169 | + } |
112 | 170 | } |
0 commit comments