WFClient { public WFList createList(WFList parent, Integer insertIndex, String name, String description) throws IOException { checkLoggedIn(); long time = getClientTimeInSeconds(); String newId = UUID.randomUUID().toString(); String parentId = parent == null ? "None" : parent.id; int idx = insertIndex == null ? 0 : insertIndex; List<PushPoll.Operation> ops; WFList proxy; synchronized (this) { proxy = new WFList(); proxy.id = newId; proxy.ch = null; proxy.cp = null; proxy.lm = time; proxy.nm = name; proxy.no = description; List<WFList> toAddProxyTo = session.rootLists; if (parent != null) { if (parent.ch == null) { parent.ch = Lists.newArrayListWithCapacity(1); } toAddProxyTo = parent.ch; } if (idx >= toAddProxyTo.size()) { toAddProxyTo.add(proxy); } else if (idx < 0) { toAddProxyTo.add(0, proxy); } else { toAddProxyTo.add(idx, proxy); } PushPoll.Operation createOp = PushPoll.buildCreateOp(newId, parentId, idx, time); PushPoll.Operation editOp = PushPoll.buildEditOp(newId, name, description, time + 1, time); ops = Lists.newArrayList(createOp); if (editOp != null) ops.add(editOp); } executePushPoll(ops); return proxy; } WFClient(); void login(String username, String password); boolean isLoggedIn(); void logout(); void setSession(String session); String getSession(); String getUsername(); void refresh(); List<WFList> getRootLists(); WFList createRootList(Integer insertIndex, String name, String description); WFList createList(WFList parent, Integer insertIndex, String name, String description); void editList(WFList toEdit, String newName, String newDescription); void completeList(WFList toComplete, boolean isComplete); void deleteList(WFList toDelete); synchronized boolean isRootList(WFList list); synchronized boolean hasList(WFList list); synchronized WFList getParentList(WFList child); synchronized WFList getListById(final String listId); synchronized List<WFList> getAncestryPath(WFList list); static final Logger log; static final String LOGIN_URL; static final String API_URL; static final String USER_AGENT; static final int TIMEOUT_MS; static final String CLIENT_VERSION; }
@Test public void testCreateList() throws IOException { assertTrue(client.getRootLists().isEmpty()); String rootName = "createList root name " + UUID.randomUUID().toString(); String rootDesc = "createList root desc " + UUID.randomUUID().toString(); WFList root = client.createRootList(0, rootName, rootDesc); List<WFList> lists = client.getRootLists(); String rootId = root.getId(); assertNotNull(root); assertTrue(client.hasList(root)); assertTrue(lists.contains(root)); client.refresh(); lists = client.getRootLists(); assertTrue("objects are reused after refresh", root == lists.get(0)); assertEquals(lists.size(), 1); assertEquals(rootName, root.getName()); assertEquals(rootDesc, root.getDescription()); assertEquals(rootId, root.getId()); client.createList(root, 0, root.getName() + "_1", null); client.createList(root, 0, root.getName() + "_0", null); client.createList(root, 2, root.getName() + "_2", null); client.refresh(); lists = client.getRootLists(); assertTrue("objects are reused after refresh", root == lists.get(0)); List<WFList> rootChildren = root.getChildren(); assertEquals(lists.size(), 1); assertEquals(rootName, root.getName()); assertEquals(rootDesc, root.getDescription()); assertEquals(root, client.getListById(rootId)); assertEquals(rootChildren.size(), 3); for (int i = 0; i < 3; i++) { assertEquals(rootChildren.get(i).getName(), root.getName() + "_" + i); assertNull(rootChildren.get(i).getDescription()); assertNull(rootChildren.get(i).getChildren()); } WFList prepended = client.createRootList(0, "prepend_" + root.getName(), "prepend_desc_" + root.getDescription()); client.refresh(); lists = client.getRootLists(); assertEquals(lists.size(), 2); assertTrue(prepended == lists.get(0)); assertTrue(root == lists.get(1)); assertEquals(prepended.getName(), "prepend_" + root.getName()); assertEquals(prepended.getDescription(), "prepend_desc_" + root.getDescription()); assertEquals(root.getChildren().size(), 3); assertEquals(root.getChildren().get(2), client.getListById(root.getChildren().get(2).getId())); }