CouchDbProjectService extends AbstractCouchDbService implements ProjectService { @Override public List<Project> listAllProject(Map<String, Object> context) { try { JSONObject couchObj = getCouch("_all_docs?startkey=\"project_\"&endkey=\"project_zzz\""); JSONArray couchProjList = couchObj.getJSONArray("rows"); List<Project> res = new ArrayList<Project>(); for (int i = 0; i < couchProjList.length(); i++) { JSONObject couchProj = couchProjList.getJSONObject(i); res.add(new ProjectCouch(couchProj.getString("id"), couchProj.getJSONObject("value").getString("rev"), couchProj.getString("id") .substring("project_".length()))); } return res; } catch (JSONException e) { throw new RuntimeException(e); } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } CouchDbProjectService(); @Override List<Project> listAllProject(Map<String, Object> context); @Override Project addNewProject(Project project, Map<String, Object> context); @Override Project updateExistingProject(Project project, Map<String, Object> context); @Override void removeExistingProject(Project project,
			Map<String, Object> context); @Override long countProject(ProjectQuery query, Map<String, Object> context); @Override List<Project> listProject(ProjectQuery query, Map<String, Object> context);  }
@Test public void testListAllProject() { getResults .put("_all_docs?startkey=\"project_\"&endkey=\"project_zzz\"", "{\"total_rows\":9,\"offset\":2,\"rows\":[{\"id\":\"project_P1\",\"key\":\"project_P1\",\"value\":{\"rev\":\"1-967a00dff5e02add41819138abb3284d\"}},{\"id\":\"project_P2\",\"key\":\"project_P2\",\"value\":{\"rev\":\"1-967a00dff5e02add41819138abb3284d\"}}]}"); List<Project> res = projectService.listAllProject(new HashMap<String, Object>()); assertEquals(1, getUrls.size()); assertEquals("_all_docs?startkey=\"project_\"&endkey=\"project_zzz\"", getUrls.get(0)); assertEquals(2, res.size()); assertEquals("P1", res.get(0).getName()); assertEquals("P2", res.get(1).getName()); assertEquals(ProjectCouch.class, res.get(1).getClass()); assertEquals("project_P2", ((ProjectCouch) res.get(1)).getCouchId()); assertEquals("1-967a00dff5e02add41819138abb3284d", ((ProjectCouch) res.get(1)).getCouchRev()); }