Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.93 KB | None | 0 0
  1. package com.provagroup.provaserver.wamp.legit;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.Assert.assertNotNull;
  5. import static org.junit.Assert.assertTrue;
  6. import static org.junit.Assert.fail;
  7.  
  8. import java.io.File;
  9. import java.io.FileOutputStream;
  10. import java.net.URL;
  11. import java.nio.channels.Channels;
  12. import java.nio.channels.ReadableByteChannel;
  13. import java.util.ArrayList;
  14. import java.util.Arrays;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Map.Entry;
  19. import java.util.UUID;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22.  
  23. import org.junit.BeforeClass;
  24. import org.junit.Test;
  25.  
  26. import com.provagroup.provaserver.wamp.WampApiFieldKeys;
  27. import com.provagroup.wamp.client.LegitWampClient;
  28.  
  29. /**
  30. * @author rbense
  31. *
  32. */
  33. public class LegitTest {
  34. private static Logger log = Logger.getLogger(LegitTest.class.getName());
  35. public static final long WAIT_TIME = 100000; // DEBUG - increase this value or the client code will finish in 100s
  36.  
  37. private static final boolean push = true;
  38. private static int testEnv = 1; // 0 = local, 1 = P4 testing
  39.  
  40. private static String user;
  41. private static String pw;
  42. private static LegitWampClient client;
  43.  
  44. @BeforeClass
  45. public static void setUserPw() {
  46. user = System.getProperty("user");
  47. pw = System.getProperty("pw");
  48. if (user == null) {
  49. throw new IllegalStateException("User is null, please set the argument user=");
  50. }
  51. if (pw == null) {
  52. throw new IllegalStateException("Password (pw) is null, please set the argument pw=");
  53. }
  54. }
  55.  
  56. @Test
  57. public void testLogin() {
  58. try {
  59. out("\n\tUser: " + user + "\n\tPush: " + push + " URI: " + URI);
  60. LegitWampClient c = getClient(realmlegit);
  61. assertNotNull(c);
  62. c.login();
  63. } catch (Exception e) {
  64. fail("Failed to login \n\tUser: " + user + "\n\tURI: " + URI);
  65. }
  66. }
  67.  
  68.  
  69. @Test
  70. public void testLoginUser() {
  71. try {
  72. LegitWampClient c = getClient(realmlegit);
  73. Map<String, Object> luser = c.getLoginUser();
  74. assertNotNull(luser);
  75. assertEquals(user, luser.get(WampApiFieldKeys.U_EMAIL));
  76. out(luser);
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. fail("Failed to return login \n\tUser: " + user + "\n\tURI: " + URI);
  80. }
  81. }
  82.  
  83. @Test
  84. public void testUserRegistration() {
  85. final String email = UUID.randomUUID().toString().substring(0, 10) + "@provagroup.com";
  86. final String password = UUID.randomUUID().toString().substring(0, 15);
  87. registerUser(email, password);
  88. }
  89.  
  90.  
  91. @SuppressWarnings("unchecked")
  92. private Map<String, Object> registerUser(String email, String password) {
  93. String uu = null;
  94. try {
  95. LegitWampClient c = getClient(realmlegit);
  96. assertNotNull(c);
  97.  
  98. Map<String, Object> args = new HashMap<String, Object>();
  99.  
  100. args.put(WampApiFieldKeys.U_EMAIL, email );
  101. args.put(WampApiFieldKeys.U_PWNEW, password);
  102. args.put(WampApiFieldKeys.U_FIRST, "Joe" );
  103. args.put(WampApiFieldKeys.U_LAST, "Test" );
  104. args.put(WampApiFieldKeys.U_MIDDLE, "M" );
  105. args.put(WampApiFieldKeys.U_TITLE, "Mr");
  106.  
  107. Map<String, Object> add = getAddress("Chicago", "IL", "US");
  108. List<Map<String, Object>> adds = new ArrayList<>();
  109. adds.add(add);
  110. args.put(WampApiFieldKeys.U_ADDRESS_LIST, adds);
  111.  
  112. Map<String, Object> ret = c.registerUser(args);
  113. assertNotNull(ret);
  114. out (String.format("User Created:\nEmail: %s\nName:%s%s%s%s%s",
  115. ret.get(WampApiFieldKeys.U_EMAIL),
  116. getName(ret.get(WampApiFieldKeys.U_TITLE)),
  117. getName(ret.get(WampApiFieldKeys.U_FIRST)),
  118. getName(ret.get(WampApiFieldKeys.U_MIDDLE)),
  119. getName(ret.get(WampApiFieldKeys.U_LAST)),
  120. getName(ret.get(WampApiFieldKeys.U_SUFFIX))));
  121.  
  122. assertEquals(ret.get(WampApiFieldKeys.U_EMAIL), ret.get(WampApiFieldKeys.U_EMAIL));
  123. assertEquals(ret.get(WampApiFieldKeys.U_FIRST), ret.get(WampApiFieldKeys.U_FIRST));
  124. assertEquals(ret.get(WampApiFieldKeys.U_LAST), ret.get(WampApiFieldKeys.U_LAST));
  125. assertEquals(ret.get(WampApiFieldKeys.U_MIDDLE), ret.get(WampApiFieldKeys.U_MIDDLE));
  126. assertEquals(ret.get(WampApiFieldKeys.U_TITLE), ret.get(WampApiFieldKeys.U_TITLE));
  127. assertEquals(ret.get(WampApiFieldKeys.U_SUFFIX), ret.get(WampApiFieldKeys.U_SUFFIX));
  128.  
  129. List<Map<String, Object>> list = (List<Map<String, Object>>) ret.get(WampApiFieldKeys.U_ADDRESS_LIST);
  130. assertNotNull(list);
  131. checkMaps(add, list.get(0));
  132.  
  133. uu = email;
  134. c = getClient(realmlegit, uu, password);
  135. assertNotNull(c);
  136. Map<String, Object> u = c.getLoginUser();
  137. assertNotNull(u);
  138.  
  139. assertEquals(ret.get(WampApiFieldKeys.U_EMAIL), u.get(WampApiFieldKeys.U_EMAIL));
  140. assertEquals(ret.get(WampApiFieldKeys.U_FIRST), u.get(WampApiFieldKeys.U_FIRST));
  141. assertEquals(ret.get(WampApiFieldKeys.U_LAST), u.get(WampApiFieldKeys.U_LAST));
  142. assertEquals(ret.get(WampApiFieldKeys.U_MIDDLE), u.get(WampApiFieldKeys.U_MIDDLE));
  143. assertEquals(ret.get(WampApiFieldKeys.U_TITLE), u.get(WampApiFieldKeys.U_TITLE));
  144. assertEquals(ret.get(WampApiFieldKeys.U_SUFFIX), u.get(WampApiFieldKeys.U_SUFFIX));
  145. checkMaps(add, ((List<Map<String, Object>>) ret.get(WampApiFieldKeys.U_ADDRESS_LIST)).get(0));
  146.  
  147. out (String.format("User Created:\nEmail: %s\nName:%s%s%s%s%s",
  148. u.get(WampApiFieldKeys.U_EMAIL),
  149. getName(u.get(WampApiFieldKeys.U_TITLE)),
  150. getName(u.get(WampApiFieldKeys.U_FIRST)),
  151. getName(u.get(WampApiFieldKeys.U_MIDDLE)),
  152. getName(u.get(WampApiFieldKeys.U_LAST)),
  153. getName(u.get(WampApiFieldKeys.U_SUFFIX))));
  154. return u;
  155. } catch (Exception e) {
  156. e.printStackTrace();
  157. fail("Failed to login \n\tUser: " + uu + "\n\tURI: " + URI);
  158. }
  159. return null;
  160. }
  161.  
  162. private void checkMaps(Map<String, Object> orig, Map<String, Object> val) {
  163. assertNotNull(val);
  164. assertTrue(val.size() > 0);
  165. for (Entry<String, Object> e : orig.entrySet()) {
  166. Object o = val.get(e.getKey());
  167. assertNotNull(o);
  168. assertEquals(e.getValue(), o);
  169. }
  170. }
  171.  
  172. /**
  173. * Simple address generation for a user.
  174. * @param city
  175. * @param state
  176. * @param country
  177. * @return
  178. */
  179. private Map<String, Object> getAddress(String city, String state, String country) {
  180. Map<String, Object> m = new HashMap<>();
  181. m.put(WampApiFieldKeys.UA_TYPE, "home");
  182. m.put(WampApiFieldKeys.UA_COUNTRY, country);
  183. if (state != null) {
  184. m.put(WampApiFieldKeys.UA_STATE, state);
  185. }
  186. if (state != null) {
  187. m.put(WampApiFieldKeys.UA_CITY, city);
  188. m.put(WampApiFieldKeys.UA_ZIP_CODE, "00001");
  189. m.put(WampApiFieldKeys.UA_STREET, "1 Ave K");
  190. }
  191. return m;
  192. }
  193.  
  194. private String getName(Object o) {
  195. return (String) (o == null ? "" : " " + o);
  196. }
  197.  
  198. @Test
  199. public void testGetMyAssets() {
  200. try {
  201. LegitWampClient c = getClient(realmlegit);
  202. assertNotNull(c);
  203. List<Object> ret = c.getMyCollection();
  204. assertNotNull(ret);
  205. assertTrue(ret.size() > 0);
  206. assertNotNull(ret.get(0));
  207. } catch (Exception e) {
  208. e.printStackTrace();
  209. fail(e.getMessage());
  210. }
  211. }
  212.  
  213. @Test
  214. public void testUpdatePassword() {
  215. try {
  216. final String email = UUID.randomUUID().toString().substring(0, 10) + "@provagroup.com";
  217. final String password = UUID.randomUUID().toString().substring(0, 15);
  218. Map<String, Object> u = registerUser(email, password);
  219.  
  220. LegitWampClient c = getClient(realmlegit, email, password);
  221. c.login();
  222.  
  223. String newpw = UUID.randomUUID().toString().substring(5, 15);
  224.  
  225. try {
  226. c.updatePassword((String) u.get(WampApiFieldKeys.U_ID), pw, newpw, newpw);
  227. fail("Failed to catch an exception with bad password");
  228. } catch (Exception ignored) {
  229. log.log(Level.INFO, ignored.getLocalizedMessage(), ignored);
  230. }
  231. try {
  232. c.updatePassword((String) u.get(WampApiFieldKeys.U_ID), password, newpw, pw);
  233. fail("Failed to catch an exception with bad password");
  234. } catch (Exception ignored) {
  235. log.log(Level.INFO, ignored.getLocalizedMessage(), ignored);
  236. }
  237. try {
  238. c.updatePassword((String) u.get(WampApiFieldKeys.U_ID), password, "aaa", "aaa");
  239. fail("Failed to catch an exception with bad password");
  240. } catch (Exception ignored) {
  241. log.log(Level.INFO, ignored.getLocalizedMessage(), ignored);
  242. }
  243. c.updatePassword((String) u.get(WampApiFieldKeys.U_ID), password, newpw, newpw);
  244.  
  245.  
  246.  
  247. client = null;
  248. c = getClient(realmlegit, email, password);
  249. try {
  250. c.login();
  251. fail("Logged in with existing password");
  252. } catch (Exception expected) {
  253. }
  254. client = null;
  255. c = getClient(realmlegit, email, newpw);
  256. c.login();
  257. } catch (Exception e) {
  258. e.printStackTrace();
  259. fail(e.getMessage());
  260. }
  261. }
  262.  
  263. @Test
  264. public void testGetAssetBySerialNo() {
  265. try {
  266. LegitWampClient c = getClient(realmlegit);
  267. assertNotNull(c);
  268. String serno = "Z4vuNK2vMI"; // test serial no.
  269. // String serno = "Z5011A16AY"; // NPE on localhost
  270. Map<String, Object> ret = c.getAsset(serno);
  271. assertNotNull(ret);
  272. assertTrue("Failed to return asset", ret.size() > 0);
  273. assertEquals(serno, ret.get(WampApiFieldKeys.ASSET_SERIAL_NO));
  274. } catch (Exception e) {
  275. e.printStackTrace();
  276. fail(e.getMessage());
  277. }
  278. }
  279.  
  280. @Test
  281. public void testGetAssetByTagid() {
  282. try {
  283. LegitWampClient c = getClient(realmlegit);
  284. assertNotNull(c);
  285. String tagid = "049F2262EB2B80"; // test tagid
  286. Map<String, Object> ret = c.getAssetByTagid(tagid);
  287. assertNotNull(ret);
  288. assertTrue("Failed to return asset", ret.size() > 0);
  289. } catch (Exception e) {
  290. e.printStackTrace();
  291. fail(e.getMessage());
  292. }
  293. }
  294.  
  295. @Test
  296. public void testRegisterItem() {
  297. try {
  298. LegitWampClient c = getClient(realmlegit);
  299. assertNotNull(c);
  300. String serno = "Z4vuNK2vMI"; // test serial no.
  301. String certserno = "Z4vuNK2vdk"; // test certificate serial no
  302. Map<String, Object> ret = c.registerAsset(serno, certserno);
  303. assertNotNull(ret);
  304. assertTrue("Failed to return asset", ret.size() > 0);
  305. assertEquals(serno, ret.get(WampApiFieldKeys.ASSET_SERIAL_NO));
  306. assertEquals(certserno, ret.get(WampApiFieldKeys.CERT_SERIAL_NO));
  307.  
  308. } catch (Exception e) {
  309. e.printStackTrace();
  310. fail(e.getMessage());
  311. }
  312. }
  313.  
  314. @Test
  315. public void testForgotPassword() {
  316. try {
  317.  
  318. LegitWampClient c = getClient(realmlegit);
  319. assertNotNull(c);
  320. String ret = c.forgotPassword("rbense+30@gmail.com");
  321. assertNotNull(ret);
  322. out("ForgotPassword response: " + ret);
  323. } catch (Exception e) {
  324. e.printStackTrace();
  325. fail(e.getMessage());
  326. }
  327. }
  328.  
  329. @SuppressWarnings("unchecked")
  330. @Test
  331. public void testUpdateUserInfo() {
  332. try {
  333. LegitWampClient c = getClient(realmlegit);
  334. assertNotNull(c);
  335. Map<String, Object> u = c.getLoginUser();
  336.  
  337. String newname = updateField(u, WampApiFieldKeys.U_LAST, "Jones", "Smith");
  338. Map<String, Object> u2 = c.updateUser(u);
  339. assertEquals(newname, u2.get(WampApiFieldKeys.U_LAST));
  340.  
  341. String newfirst = updateField(u2, WampApiFieldKeys.U_FIRST, "Joe", "Albert");
  342. Map<String, Object> u5 = c.updateUser(u2);
  343. assertEquals(newfirst, u5.get(WampApiFieldKeys.U_FIRST));
  344.  
  345. // Address set/update
  346. List<Map<String, Object>> adds = (List<Map<String, Object>>) u5.get(WampApiFieldKeys.U_ADDRESS_LIST);
  347. List<Map<String, Object>> nadds = new ArrayList<>();
  348. if (adds == null || adds.size() == 0) {
  349. nadds.add(getAddress("Chicago", "IL", "US"));
  350. } else {
  351. Map<String, Object> oldadd = adds.remove(0);
  352. nadds.add(updateAddress(oldadd , "Chicago", "Sprinfield", "IL", "MO"));
  353. }
  354. u5.put(WampApiFieldKeys.U_ADDRESS_LIST, nadds);
  355. Map<String, Object> u6 = c.updateUser(u5);
  356.  
  357. Map<String, Object> oa = nadds.get(0);
  358. Map<String, Object> ua = ((List<Map<String, Object>>)u6.get(WampApiFieldKeys.U_ADDRESS_LIST)).get(0);
  359. System.out.println(String.format("Updated Address: %s, %s", ua.get(WampApiFieldKeys.UA_CITY), ua.get(WampApiFieldKeys.UA_STATE)));
  360.  
  361. assertEquals(oa.get(WampApiFieldKeys.UA_TYPE), ua.get(WampApiFieldKeys.UA_TYPE));
  362. assertEquals(oa.get(WampApiFieldKeys.UA_COUNTRY), ua.get(WampApiFieldKeys.UA_COUNTRY));
  363. assertEquals(oa.get(WampApiFieldKeys.UA_CITY), ua.get(WampApiFieldKeys.UA_CITY));
  364. assertEquals(oa.get(WampApiFieldKeys.UA_STATE), ua.get(WampApiFieldKeys.UA_STATE));
  365.  
  366. Map<String, Object> uu = c.getLoginUser();
  367. Map<String, Object> uua = ((List<Map<String, Object>>)uu.get(WampApiFieldKeys.U_ADDRESS_LIST)).get(0);
  368. System.out.println(String.format("LoginUser Address: %s, %s", uua.get(WampApiFieldKeys.UA_CITY), uua.get(WampApiFieldKeys.UA_STATE)));
  369.  
  370. assertEquals(oa.get(WampApiFieldKeys.UA_TYPE), uua.get(WampApiFieldKeys.UA_TYPE));
  371. assertEquals(oa.get(WampApiFieldKeys.UA_COUNTRY), uua.get(WampApiFieldKeys.UA_COUNTRY));
  372. assertEquals(oa.get(WampApiFieldKeys.UA_CITY), uua.get(WampApiFieldKeys.UA_CITY));
  373. assertEquals(oa.get(WampApiFieldKeys.UA_STATE), uua.get(WampApiFieldKeys.UA_STATE));
  374.  
  375.  
  376. // TODO: the next 2 items are considered future features:
  377. String newprofile = updateField(u6, WampApiFieldKeys.U_PROFILE_IMG, "/someimage", "/myotherimg");
  378. Map<String, Object> u3 = c.updateUser(u6);
  379. assertEquals(newprofile, u3.get(WampApiFieldKeys.U_PROFILE_IMG));
  380.  
  381. String newcover = updateField(u3, WampApiFieldKeys.U_COVER_IMG, "/someimage", "/myotherimg");
  382. Map<String, Object> u4 = c.updateUser(u3);
  383. assertEquals(newcover, u4.get(WampApiFieldKeys.U_COVER_IMG));
  384.  
  385. } catch (Exception e) {
  386. e.printStackTrace();
  387. fail(e.getMessage());
  388. }
  389. }
  390.  
  391. private Map<String, Object> updateAddress(Map<String, Object> source, String c1, String c2, String s1, String s2) {
  392. if (source != null && source.get(WampApiFieldKeys.UA_STATE) != null) {
  393. System.out.println(String.format("Old Address: %s, %s", source.get(WampApiFieldKeys.UA_CITY), source.get(WampApiFieldKeys.UA_STATE)));
  394. } else {
  395. System.out.println("Old Address is null");
  396. }
  397. Map<String, Object> m = new HashMap<>();
  398. m.put(WampApiFieldKeys.UA_TYPE, "home");
  399. putAddress(WampApiFieldKeys.UA_COUNTRY, source, m);
  400. putAddress(WampApiFieldKeys.UA_ZIP_CODE, source, m);
  401. putAddress(WampApiFieldKeys.UA_STREET, source, m);
  402.  
  403. updateAddress(WampApiFieldKeys.UA_STATE, source, m, s1, s2);
  404. updateAddress(WampApiFieldKeys.UA_CITY, source, m, c1, c2);
  405.  
  406. return m;
  407. }
  408.  
  409. private void putAddress(String key, Map<String, Object> source, Map<String, Object> m) {
  410. String val = (String) source.get(key);
  411. String v;
  412. if (val != null && (v = val.trim()).length() > 0) {
  413. m.put(key, v);
  414. }
  415. }
  416.  
  417. private void updateAddress(String key, Map<String, Object> source, Map<String, Object> m, String val1, String val2) {
  418. final String val = (String) source.get(key);
  419. final String v;
  420. final String v1 = val1.trim();
  421. if (val != null && (v = val.trim()).length() > 0) {
  422. if (v.compareTo(v1) == 0) {
  423. m.put(key, val2.trim());
  424. } else {
  425. m.put(key, v1);
  426. }
  427. } else {
  428. m.put(key, v1);
  429. }
  430. }
  431.  
  432. @Test //clears images stored for asset.
  433. public void testAssetImageUpdate() {
  434. try {
  435. LegitWampClient c = getClient(realmlegit);
  436. assertNotNull(c);
  437. // Map<String, Object> args = new HashMap<>();
  438. // Object o = c.getError(args);
  439. // assertNotNull(o);
  440.  
  441. // Map<String, Object> a = c.getAsset("Z5011A16JC"); // P4
  442. // Map<String, Object> a = c.getAsset("Z4vuNK2vKc"); // Local
  443. Map<String, Object> a = c.getAsset("Z4vuNK2vRY"); // P4 & Local
  444. // Map<String, Object> a = c.getAsset("NONE-Z4vuNK2vRY"); // Error
  445. assertNotNull(a);
  446. // List<String> newimgs = updateImages(a, WampApiFieldKeys.ASSET_IMAGES);
  447. // Map<String, Object> a2 = c.updateAsset(a);
  448. // if (newimgs.size() > 0) {
  449. // assertEquals(newimgs, a2.get(WampApiFieldKeys.ASSET_IMAGES));
  450. // }
  451. } catch (Exception e) {
  452. e.printStackTrace();
  453. fail(e.getMessage());
  454. }
  455. }
  456.  
  457. @SuppressWarnings("unchecked")
  458. @Test
  459. public void testPhotoUpload() {
  460. try {
  461. File testPic = new File("/Users/rbense/Pictures/IMG_0858.jpg");
  462. if (!testPic.exists()) {
  463. fail("The test image does not exist " + testPic);
  464. }
  465.  
  466. LegitWampClient c = getClient(realmlegit);
  467. assertNotNull(c);
  468.  
  469. // List<Object> assets = c.getMyCollection();
  470. //
  471. // Map<String, Object> a = null;
  472. // String serialNo = null;
  473. // for (Object o : assets) {
  474. // Map<String, Object> m = (Map<String, Object>) o;
  475. // serialNo = (String) m.get(WampApiFieldKeys.ASSET_SERIAL_NO);
  476. // if (serialNo != null) {
  477. // a = m;
  478. // break;
  479. // }
  480. // }
  481.  
  482. // Get asset for test serial no
  483. String serialNo = "Z4vuNK2vKc"; // Local
  484. Map<String, Object> a = c.getAsset(serialNo);
  485.  
  486. if (a == null) {
  487. fail("Did not find an asset for this user with a serial number to test against");
  488. }
  489. final String assetId = (String) a.get(WampApiFieldKeys.ASSET_ID);
  490.  
  491.  
  492. // upload image for asset
  493. Map<String, Object> args = new HashMap<>();
  494. args.put(WampApiFieldKeys.MEDIA_TYPE, WampApiFieldKeys.MEDIA_PHOTO_JPG);
  495. args.put(WampApiFieldKeys.MEDIA_TARGET_ASSET, assetId );
  496. Map<String, Object> ret = c.uploadMedia(args, testPic);
  497.  
  498. // test that the image was uploaded and the asset updated with the uploaded image.
  499. assertNotNull(ret);
  500. assertNotNull(ret.get(WampApiFieldKeys.MEDIA_URL));
  501.  
  502. FileOutputStream fos = null;
  503. try {
  504. final String url = (String) ret.get(WampApiFieldKeys.MEDIA_URL);
  505. URL website = new URL(url);
  506. ReadableByteChannel rbc = Channels.newChannel(website.openStream());
  507. File ofile = new File((String) ret.get(WampApiFieldKeys.MEDIA_FILE_NAME));
  508. System.out.println(String.format("\nSaving %s to %s", website, ofile));
  509. fos = new FileOutputStream(ofile);
  510. fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
  511. assertTrue(ofile.getAbsolutePath(), ofile.length() == testPic.length());
  512. System.out.println(String.format("\n\nSERNO: %s", serialNo));
  513. Map<String, Object> a2 = c.getAsset(serialNo);
  514. final List<String> imgs = (List<String>) a2.get(WampApiFieldKeys.ASSET_IMAGES);
  515. assertNotNull(imgs);
  516. assertTrue(imgs.size() > 0);
  517. for (String s : imgs) {
  518. if (url.compareTo(s) == 0) {
  519. return;
  520. }
  521. }
  522. fail("Did not have image returned");
  523. } catch (Exception e) {
  524. fail("Failed to confirm URL exists and file matches upload");
  525. } finally {
  526. if (fos != null) {
  527. fos.close();
  528. }
  529. }
  530. } catch (Exception e) {
  531. e.printStackTrace();
  532. fail(e.getMessage());
  533. }
  534. }
  535.  
  536. private String updateField(Map<String, Object> u, String key, String val1, String val2) {
  537. String val = (String) u.get(key);
  538. String nval = val != null && val.compareTo(val1) == 0 ? val2 : val1;
  539. u.put(key, nval);
  540. return nval;
  541. }
  542.  
  543. private List<String> updateImages(Map<String, Object> u, String key, String ... val1) {
  544. @SuppressWarnings("unchecked")
  545. List<Object> val = (List<Object>) u.get(key);
  546. List<String> imgs = new ArrayList<>();
  547. if (val == null || !Arrays.equals(val.toArray(), val1)) {
  548. for (int i = 0; i < val1.length; i++) {
  549. imgs.add(val1[i]);
  550. }
  551. } else {
  552. final int max = val1.length - 1;
  553. for (int i = 0; i < val1.length; i++) {
  554. imgs.add(val1[max - i]);
  555. }
  556. }
  557. u.put(key, imgs);
  558. return imgs;
  559. }
  560.  
  561. final LegitWampClient getClient(String realm) {
  562. return getClient(realm, user, pw);
  563. }
  564.  
  565. final LegitWampClient getClient(String realm, String user, String pw) {
  566. if (client == null || realm.compareTo(client.getRealm()) != 0 || user.compareTo(client.getClientUser()) != 0) {
  567. client = LegitWampClient.getClient(URI, realm, user, pw);
  568. }
  569. return client;
  570. }
  571.  
  572.  
  573.  
  574. private static void out(Object e) {
  575. // System.out.println(e);
  576. // System.out.flush();
  577. log.info(e.toString());
  578. }
  579.  
  580. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement