|
8 | 8 | import junit.framework.Test; |
9 | 9 | import junit.framework.TestCase; |
10 | 10 | import junit.framework.TestSuite; |
| 11 | +import org.jetbrains.annotations.NotNull; |
11 | 12 |
|
12 | 13 | import java.util.*; |
13 | 14 | import java.util.concurrent.CountDownLatch; |
@@ -66,6 +67,202 @@ public void onComplete() { |
66 | 67 | assertTrue(testSucceed); |
67 | 68 | } |
68 | 69 |
|
| 70 | + public void testFetchRemovedAttr() throws Exception { |
| 71 | + final LCObject object = new LCObject("Student"); |
| 72 | + object.put("name", "Automatic Tester"); |
| 73 | + object.put("age", 18); |
| 74 | + object.put("grade", 9); |
| 75 | + object.saveInBackground().subscribe(new Observer<LCObject>() { |
| 76 | + public void onSubscribe(Disposable disposable) { |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + public void onNext(LCObject lcObject) { |
| 81 | + System.out.println("try to remove grade field."); |
| 82 | + LCObject tmpObj = LCObject.createWithoutData("Student", object.getObjectId()); |
| 83 | + tmpObj.remove("grade"); |
| 84 | + tmpObj.saveInBackground().subscribe(new Observer<LCObject>() { |
| 85 | + public void onSubscribe(Disposable disposable) { |
| 86 | + } |
| 87 | + |
| 88 | + public void onNext(LCObject lcObject) { |
| 89 | + System.out.println("remove field finished."); |
| 90 | + object.fetchInBackground("grade").subscribe(new Observer<LCObject>() { |
| 91 | + @Override |
| 92 | + public void onSubscribe(@NotNull Disposable disposable) { |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void onNext(@NotNull LCObject aObject) { |
| 98 | + testSucceed = aObject.get("grade") == null; |
| 99 | + if (!testSucceed) { |
| 100 | + latch.countDown(); |
| 101 | + return; |
| 102 | + } |
| 103 | + object.deleteInBackground().subscribe(new Observer<LCNull>() { |
| 104 | + @Override |
| 105 | + public void onSubscribe(Disposable disposable) { |
| 106 | + |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public void onNext(LCNull LCNull) { |
| 111 | + testSucceed = true; |
| 112 | + latch.countDown(); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public void onError(Throwable throwable) { |
| 117 | + latch.countDown(); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public void onComplete() { |
| 122 | + |
| 123 | + } |
| 124 | + }); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public void onError(@NotNull Throwable throwable) { |
| 129 | + latch.countDown(); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public void onComplete() { |
| 134 | + |
| 135 | + } |
| 136 | + }); |
| 137 | + } |
| 138 | + |
| 139 | + public void onError(Throwable throwable) { |
| 140 | + latch.countDown(); |
| 141 | + } |
| 142 | + |
| 143 | + public void onComplete() { |
| 144 | + } |
| 145 | + }); |
| 146 | + |
| 147 | + } |
| 148 | + |
| 149 | + public void onError(Throwable throwable) { |
| 150 | + latch.countDown(); |
| 151 | + } |
| 152 | + |
| 153 | + public void onComplete() { |
| 154 | + |
| 155 | + } |
| 156 | + }); |
| 157 | + latch.await(); |
| 158 | + assertTrue(testSucceed); |
| 159 | + } |
| 160 | + |
| 161 | + public void testFetchRemovedPointerAttr() throws Exception { |
| 162 | + final LCObject object = new LCObject("Student"); |
| 163 | + object.put("name", "Automatic Tester"); |
| 164 | + object.put("age", 18); |
| 165 | + object.put("grade", 9); |
| 166 | + final LCObject friend = new LCObject("Student"); |
| 167 | + friend.put("name", "tom"); |
| 168 | + object.put("friend", friend); |
| 169 | + object.saveInBackground().subscribe(new Observer<LCObject>() { |
| 170 | + public void onSubscribe(Disposable disposable) { |
| 171 | + |
| 172 | + } |
| 173 | + |
| 174 | + public void onNext(LCObject lcObject) { |
| 175 | + System.out.println("try to remove grade field."); |
| 176 | + LCObject tmpObj = LCObject.createWithoutData("Student", object.getObjectId()); |
| 177 | + tmpObj.remove("grade"); |
| 178 | + tmpObj.remove("friend"); |
| 179 | + tmpObj.saveInBackground().subscribe(new Observer<LCObject>() { |
| 180 | + public void onSubscribe(Disposable disposable) { |
| 181 | + } |
| 182 | + |
| 183 | + public void onNext(LCObject lcObject) { |
| 184 | + System.out.println("remove field finished."); |
| 185 | + object.fetchInBackground("grade,friend.name").subscribe(new Observer<LCObject>() { |
| 186 | + @Override |
| 187 | + public void onSubscribe(@NotNull Disposable disposable) { |
| 188 | + |
| 189 | + } |
| 190 | + |
| 191 | + @Override |
| 192 | + public void onNext(@NotNull LCObject aObject) { |
| 193 | + testSucceed = aObject.get("grade") == null; |
| 194 | + if (!testSucceed) { |
| 195 | + System.out.println("failed to remote grade attr"); |
| 196 | + latch.countDown(); |
| 197 | + return; |
| 198 | + } |
| 199 | + testSucceed = aObject.get("friend") == null; |
| 200 | + if (!testSucceed) { |
| 201 | + System.out.println("failed to remote friend attr"); |
| 202 | + latch.countDown(); |
| 203 | + return; |
| 204 | + } |
| 205 | + System.out.println("succeed to remote grade/friend attr"); |
| 206 | + object.deleteInBackground().subscribe(new Observer<LCNull>() { |
| 207 | + @Override |
| 208 | + public void onSubscribe(Disposable disposable) { |
| 209 | + |
| 210 | + } |
| 211 | + |
| 212 | + @Override |
| 213 | + public void onNext(LCNull LCNull) { |
| 214 | + System.out.println("succeed to delete origin student object"); |
| 215 | + friend.deleteInBackground().blockingFirst(); |
| 216 | + testSucceed = true; |
| 217 | + latch.countDown(); |
| 218 | + } |
| 219 | + |
| 220 | + @Override |
| 221 | + public void onError(Throwable throwable) { |
| 222 | + latch.countDown(); |
| 223 | + } |
| 224 | + |
| 225 | + @Override |
| 226 | + public void onComplete() { |
| 227 | + |
| 228 | + } |
| 229 | + }); |
| 230 | + } |
| 231 | + |
| 232 | + @Override |
| 233 | + public void onError(@NotNull Throwable throwable) { |
| 234 | + latch.countDown(); |
| 235 | + } |
| 236 | + |
| 237 | + @Override |
| 238 | + public void onComplete() { |
| 239 | + |
| 240 | + } |
| 241 | + }); |
| 242 | + } |
| 243 | + |
| 244 | + public void onError(Throwable throwable) { |
| 245 | + latch.countDown(); |
| 246 | + } |
| 247 | + |
| 248 | + public void onComplete() { |
| 249 | + } |
| 250 | + }); |
| 251 | + |
| 252 | + } |
| 253 | + |
| 254 | + public void onError(Throwable throwable) { |
| 255 | + latch.countDown(); |
| 256 | + } |
| 257 | + |
| 258 | + public void onComplete() { |
| 259 | + |
| 260 | + } |
| 261 | + }); |
| 262 | + latch.await(); |
| 263 | + assertTrue(testSucceed); |
| 264 | + } |
| 265 | + |
69 | 266 | public void testPutNull() throws Exception { |
70 | 267 | LCObject object = new LCObject("Student"); |
71 | 268 | object.put("name", "Automatic Tester"); |
|
0 commit comments