Example usage for org.json JSONArray getJSONObject

List of usage examples for org.json JSONArray getJSONObject

Introduction

In this page you can find the example usage for org.json JSONArray getJSONObject.

Prototype

public JSONObject getJSONObject(int index) throws JSONException 

Source Link

Document

Get the JSONObject associated with an index.

Usage

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for getRepositoryNotifications method with optional parameters.
 *///www .ja va2s .co  m
@Test(priority = 1, dependsOnMethods = {
        "testGetRepositoryNotificationsWithMandatoryParameters" }, description = "github {getRepositoryNotifications} integration test with optional parameters.")
public void testGetRepositoryNotificationsWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getRepositoryNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getRepositoryNotifications_optional.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/notifications?all=true";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:com.aliyun.openservices.odps.console.commands.logview.GetTaskDetailsAction.java

private List<FuxiJob> loadJobsFromStream(InputStream in) throws ODPSConsoleException {
    JSONTokener tokener = new JSONTokener(new BufferedReader(new InputStreamReader(in)));
    try {/*from w  ww  .  j  a v a2s  .  c om*/
        JSONObject obj = new JSONObject(tokener);
        ArrayList<FuxiJob> jobs = new ArrayList<FuxiJob>();
        JSONObject mapReduceJson;
        try {
            mapReduceJson = obj.getJSONObject("mapReduce");
        } catch (JSONException e) {
            return jobs;
        }
        JSONArray jobsJson = mapReduceJson.getJSONArray("jobs");
        for (int i = 0; i < jobsJson.length(); i++) {
            jobs.add(getFuxiJobFromJson(jobsJson.getJSONObject(i)));
        }
        return jobs;
    } catch (JSONException e) {
        e.printStackTrace();
        throw new ODPSConsoleException("Bad json format");
    }
}

From source file:com.aliyun.openservices.odps.console.commands.logview.GetTaskDetailsAction.java

private FuxiJob getFuxiJobFromJson(JSONObject jobJson) throws JSONException {
    FuxiJob job = new FuxiJob();
    job.name = jobJson.getString("name");
    job.tasks = new ArrayList<FuxiTask>();
    JSONArray tasksJson = jobJson.getJSONArray("tasks");
    for (int i = 0; i < tasksJson.length(); i++) {
        job.tasks.add(getFuxiTaskFromJson(tasksJson.getJSONObject(i)));
    }/*from w ww . java  2s.c  o  m*/
    return job;
}

From source file:com.aliyun.openservices.odps.console.commands.logview.GetTaskDetailsAction.java

private FuxiTask getFuxiTaskFromJson(JSONObject taskJson) throws JSONException {
    FuxiTask task = new FuxiTask();
    task.name = taskJson.getString("name");
    task.instances = new ArrayList<FuxiInstance>();
    JSONArray instancesJson = taskJson.getJSONArray("instances");
    for (int i = 0; i < instancesJson.length(); i++) {
        task.instances.add(getFuxiInstanceFromJson(instancesJson.getJSONObject(i)));
    }/*from  w w w  .  ja v  a2  s.c o m*/
    return task;
}

From source file:se.su.dsv.scipro.android.tasks.GetProjectsAsyncTask.java

@Override
protected ProjectsResult doInBackground(Void... params) {
    String response = SciProJSON.getInstance().getProjects();

    boolean authenticated = true;
    List<Project> projects = new ArrayList<Project>();

    try {/*from ww  w . j  a v a 2s .  com*/
        JSONObject jsonObject = new JSONObject(response);
        if (!jsonObject.getString("apikey").equals("success")) {
            authenticated = false;
        } else {
            JSONArray projectsArray = jsonObject.getJSONArray("projectArray");
            for (int i = 0; i < projectsArray.length(); i++) {
                JSONObject currentObject = projectsArray.getJSONObject(i);

                String title = currentObject.getString("title");

                Project.STATUS status = Enum.valueOf(Project.STATUS.class, currentObject.getString("status"));

                String statusMessage = currentObject.getString("statusMessage");

                String level = currentObject.getString("level");

                List<User> projectMembers = new ArrayList<User>();
                JSONArray memberArray = currentObject.getJSONArray("projectMembers");
                for (int j = 0; j < memberArray.length(); j++) {
                    JSONObject member = memberArray.getJSONObject(j);
                    projectMembers.add(new User(member.getLong("id"), member.getString("name")));
                }
                DaoUtils.addUsersToApplication(projectMembers);

                List<User> projectReviewers = new ArrayList<User>();
                JSONArray reviewerArray = currentObject.getJSONArray("projectReviewers");
                for (int j = 0; j < reviewerArray.length(); j++) {
                    JSONObject reviewer = reviewerArray.getJSONObject(j);
                    projectReviewers.add(new User(reviewer.getLong("id"), reviewer.getString("name")));
                }
                DaoUtils.addUsersToApplication(projectReviewers);

                List<User> projectCoSupervisors = new ArrayList<User>();
                JSONArray coSuperVisorArray = currentObject.getJSONArray("projectCosupervisors");
                for (int j = 0; j < coSuperVisorArray.length(); j++) {
                    JSONObject coSupervisor = coSuperVisorArray.getJSONObject(j);
                    projectCoSupervisors
                            .add(new User(coSupervisor.getLong("id"), coSupervisor.getString("name")));
                }
                DaoUtils.addUsersToApplication(projectCoSupervisors);

                int projectProgress = currentObject.getInt("projectProgress");

                List<FinalSeminar> finalSeminars = new ArrayList<FinalSeminar>();
                JSONArray finalSeminarArray = currentObject.getJSONArray("finalSeminars");
                for (int j = 0; j < finalSeminarArray.length(); j++) {
                    JSONObject finalSeminar = finalSeminarArray.getJSONObject(j);
                    String room = finalSeminar.getString("room");
                    String date = finalSeminar.getString("date");

                    List<User> activeListeners = new ArrayList<User>();
                    JSONArray activeListenerArray = finalSeminar.getJSONArray("active");
                    for (int k = 0; k < activeListenerArray.length(); k++) {
                        JSONObject listener = activeListenerArray.getJSONObject(k);
                        activeListeners.add(new User(listener.getLong("id"), listener.getString("name")));
                    }
                    DaoUtils.addUsersToApplication(activeListeners);

                    List<User> opponents = new ArrayList<User>();
                    JSONArray opponentArray = finalSeminar.getJSONArray("opponents");
                    for (int k = 0; k < opponentArray.length(); k++) {
                        JSONObject opponent = opponentArray.getJSONObject(k);
                        opponents.add((new User(opponent.getLong("id"), opponent.getString("name"))));
                    }
                    DaoUtils.addUsersToApplication(opponents);

                    finalSeminars.add(new FinalSeminar(room, date, activeListeners, opponents));
                }

                Project project = new Project(title);
                project.status = status;
                project.statusMessage = statusMessage;
                project.level = level;
                project.projectMembers = projectMembers;
                project.projectCoSupervisors = projectCoSupervisors;
                project.projectReviewers = projectReviewers;
                project.projectProgress = projectProgress;
                project.finalSeminars = finalSeminars;

                projects.add(project);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSONException: ", e);
    }

    return new ProjectsResult(authenticated, projects);
}

From source file:charitypledge.Pledge.java

public void JsonImport() {

    try {//from  w  w  w .  j  a v  a 2 s . co  m
        InputStream foo = new FileInputStream(JSONFile);
        JSONTokener t = new JSONTokener(foo);
        JSONObject jsonObj = new JSONObject(t);
        foo.close();
        JSONArray jsonList = jsonObj.getJSONArray("contributors");
        for (int i = 0; i < jsonList.length(); i++) {
            // loop array
            JSONObject objects = jsonList.getJSONObject(i);
            String nameField = objects.getString("name");
            String typeField = objects.getString("charity");
            String contributionField = objects.getString("contribution");
            // Add row to jTable
            loadPledgeTable(nameField, typeField, contributionField);
        }
    } catch (FileNotFoundException e) {
        JSONWriter jsonWriter;
        try {
            jsonWriter = new JSONWriter(new FileWriter(JSONFile));
            jsonWriter.object();
            jsonWriter.key("contributors");
            jsonWriter.array();
            jsonWriter.endArray();
            jsonWriter.endObject();
            //jsonWriter.close();
            tableRefresh();
        } catch (IOException f) {
            f.printStackTrace();
        } catch (JSONException g) {
            g.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java

@Test
public void testPushHead() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);

    // clone1/*from  w w w .j  a  va 2 s  .c om*/
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath1 = getClonePath(workspaceId, project1);
    clone(clonePath1);

    // get project1 metadata
    WebRequest request = getGetRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());

    JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);
    String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD);

    // clone2
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    IPath clonePath2 = getClonePath(workspaceId, project2);
    clone(clonePath2);

    // get project2 metadata
    request = getGetRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());
    JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
    String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD);

    // clone1: list remotes
    request = GitRemoteTest.getGetGitRemoteRequest(gitRemoteUri1);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);
    assertEquals(Constants.DEFAULT_REMOTE_NAME, remote.getString(ProtocolConstants.KEY_NAME));

    // clone1: change
    JSONObject testTxt1 = getChild(project1, "test.txt");
    modifyFile(testTxt1, "incoming change");

    addFile(testTxt1);

    // clone1: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "incoming change commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: push
    ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, false);
    assertEquals(true, pushStatus.isOK());

    // clone2: get remote branch location
    JSONObject remoteBranch = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER);
    String remoteBranchLocation2 = remoteBranch.getString(ProtocolConstants.KEY_LOCATION);

    // clone2: fetch
    fetch(remoteBranchLocation2);

    // clone2: get remote details
    JSONObject remoteBranch2 = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER);
    String newRefId2 = remoteBranch2.getString(ProtocolConstants.KEY_ID);

    // clone2: merge into HEAD, "git merge origin/master"
    gitHeadUri2 = remoteBranch2.getString(GitConstants.KEY_HEAD);
    JSONObject merge = merge(gitHeadUri2, newRefId2);
    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.FAST_FORWARD, mergeResult);

    // clone2: assert change from clone1 is in place
    JSONObject testTxt2 = getChild(project2, "test.txt");
    request = getGetRequest(testTxt2.getString(ProtocolConstants.KEY_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals("incoming change", response.getText());
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java

@Test
public void testPushHeadSshWithPrivateKeyPassphrase() throws Exception {
    Assume.assumeTrue(sshRepo2 != null);
    Assume.assumeTrue(knownHosts2 != null);
    Assume.assumeTrue(privateKey != null);
    Assume.assumeTrue(passphrase != null);

    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    URIish uri = new URIish(sshRepo2);

    // clone1: create
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath = getClonePath(workspaceId, project1);

    WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath)
            .setKnownHosts(knownHosts2).setPrivateKey(privateKey).setPublicKey(publicKey)
            .setPassphrase(passphrase).getWebRequest();
    String cloneContentLocation1 = clone(request);

    // clone1: get project/folder metadata
    request = getGetRequest(cloneContentLocation1);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());

    // clone1: get git links
    JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri1 = gitSection1.optString(GitConstants.KEY_REMOTE);
    String gitIndexUri1 = gitSection1.optString(GitConstants.KEY_INDEX);
    String gitHeadUri1 = gitSection1.optString(GitConstants.KEY_HEAD);

    // clone2: create
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    clonePath = getClonePath(workspaceId, project2);
    request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts2)
            .setPrivateKey(privateKey).setPublicKey(publicKey).setPassphrase(passphrase).getWebRequest();
    String cloneContentLocation2 = clone(request);

    // clone2: get project/folder metadata
    request = getGetRequest(cloneContentLocation2);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());

    // clone2: get git links
    JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
    String gitCommitUri2 = gitSection2.getString(GitConstants.KEY_COMMIT);

    // clone1: list remotes
    request = GitRemoteTest.getGetGitRemoteRequest(gitRemoteUri1);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);/* www  .j a va  2  s. c o  m*/
    assertEquals(Constants.DEFAULT_REMOTE_NAME, remote.getString(ProtocolConstants.KEY_NAME));

    // clone1: change
    JSONObject testTxt1 = getChild(project1, "test.txt");
    modifyFile(testTxt1, "incoming change");

    // clone1: add
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "incoming change commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: push
    ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, false, null,
            knownHosts2, privateKey, publicKey, passphrase, true);
    assertEquals(true, pushStatus.isOK());

    // clone2: get remote branch location
    JSONObject remoteBranch = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER);
    String remoteBranchLocation2 = remoteBranch.getString(ProtocolConstants.KEY_LOCATION);

    // clone2: fetch
    fetch(remoteBranchLocation2, null, knownHosts2, privateKey, publicKey, passphrase, true);

    // clone2: get remote details
    JSONObject remoteBranch2 = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER);
    String newRefId2 = remoteBranch2.getString(ProtocolConstants.KEY_ID);

    // clone2: merge into HEAD, "git merge origin/master"
    gitCommitUri2 = remoteBranch2.getString(GitConstants.KEY_HEAD);
    JSONObject merge = merge(gitCommitUri2, newRefId2);
    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.FAST_FORWARD, mergeResult);

    // clone2: assert change from clone1 is in place
    JSONObject testTxt2 = getChild(project2, "test.txt");
    request = getGetRequest(testTxt2.getString(ProtocolConstants.KEY_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals("incoming change", response.getText());
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java

@Test
public void testPushBranch() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);

    // clone1: create
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath1 = getClonePath(workspaceId, project1);
    JSONObject clone1 = clone(clonePath1);
    String cloneLocation1 = clone1.getString(ProtocolConstants.KEY_LOCATION);
    String branchesLocation1 = clone1.getString(GitConstants.KEY_BRANCH);

    // get project1 metadata
    WebRequest request = getGetRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());
    JSONObject gitSection1 = project1.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection1);/*from   w w w. j av a  2s .c  o m*/
    String gitIndexUri1 = gitSection1.getString(GitConstants.KEY_INDEX);
    String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD);

    // clone1: branch 'a'
    response = branch(branchesLocation1, "a");
    JSONObject branch = new JSONObject(response.getText());

    checkoutBranch(cloneLocation1, "a");

    // clone1: change
    JSONObject testTxt1 = getChild(project1, "test.txt");
    modifyFile(testTxt1, "branch 'a' change");

    // clone1: add
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "incoming branch 'a' commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: push by remote branch
    JSONArray remoteBranchLocations = branch.getJSONArray(GitConstants.KEY_REMOTE);
    assertEquals(1, remoteBranchLocations.length());
    String remoteBranchLocation = remoteBranchLocations.getJSONObject(0)
            .getJSONArray(ProtocolConstants.KEY_CHILDREN).getJSONObject(0)
            .getString(ProtocolConstants.KEY_LOCATION);
    ServerStatus pushStatus = push(remoteBranchLocation, Constants.HEAD, false);
    assertTrue(pushStatus.isOK());

    // clone1: get the remote branch name
    request = getGetRequest(remoteBranchLocation);
    response = webConversation.getResponse(request);
    JSONObject remoteBranch1 = new JSONObject(response.getText());
    String remoteBranchName1 = remoteBranch1.getString(ProtocolConstants.KEY_NAME);

    // clone2
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    IPath clonePath2 = getClonePath(workspaceId, project2);
    JSONObject clone2 = clone(clonePath2);
    String cloneLocation2 = clone2.getString(ProtocolConstants.KEY_LOCATION);
    String branchesLocation2 = clone2.getString(GitConstants.KEY_BRANCH);

    // get project2 metadata
    request = getGetRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());
    JSONObject gitSection2 = project2.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection2);

    // create a local branch 'a' tracking remoteBranchName1 and checkout 'a'
    response = branch(branchesLocation2, "a", remoteBranchName1);
    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
    response = checkoutBranch(cloneLocation2, "a");
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    JSONObject testTxt2 = getChild(project2, "test.txt");
    request = getGetRequest(testTxt2.getString(ProtocolConstants.KEY_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals("branch 'a' change", response.getText());
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java

@Test
public void testPushToDelete() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[][] clonePaths = createTestClonePairs(workspaceLocation);

    for (IPath[] clonePath : clonePaths) {
        // clone 1
        JSONObject clone1 = clone(clonePath[0]);
        String cloneLocation1 = clone1.getString(ProtocolConstants.KEY_LOCATION);
        String contentLocation1 = clone1.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
        String branchesLocation1 = clone1.getString(GitConstants.KEY_BRANCH);

        // clone 1 - get project1 metadata
        WebRequest request = getGetRequest(contentLocation1);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project1 = new JSONObject(response.getText());
        JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
        String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);
        String gitIndexUri1 = gitSection1.getString(GitConstants.KEY_INDEX);
        String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD);

        // clone 1 - create branch "a"
        response = branch(branchesLocation1, "a");
        JSONObject newBranch = new JSONObject(response.getText());
        JSONArray remoteBranchLocations1 = newBranch.getJSONArray(GitConstants.KEY_REMOTE);
        assertEquals(1, remoteBranchLocations1.length());

        // clone 1 - checkout "a"
        final String newBranchName = "a";
        response = checkoutBranch(cloneLocation1, newBranchName);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // clone 1 - change
        JSONObject testTxt1 = getChild(project1, "test.txt");
        modifyFile(testTxt1, "clone1 change");

        // clone 1 - add
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // clone 1 - commit
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "clone1 change commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // clone 1 - push "a"
        int i = 0;
        String remoteBranchName = remoteBranchLocations1.getJSONObject(0)
                .getJSONArray(ProtocolConstants.KEY_CHILDREN).getJSONObject(i)
                .getString(ProtocolConstants.KEY_NAME);
        if (!remoteBranchName.equals("origin/a")) {
            i = 1;/* w  w  w .  j  a  v  a2  s .c  om*/
            remoteBranchName = remoteBranchLocations1.getJSONObject(0)
                    .getJSONArray(ProtocolConstants.KEY_CHILDREN).getJSONObject(i)
                    .getString(ProtocolConstants.KEY_NAME);
        }
        assertEquals("origin/a", remoteBranchName);
        String remoteBranchLocation1 = remoteBranchLocations1.getJSONObject(0)
                .getJSONArray(ProtocolConstants.KEY_CHILDREN).getJSONObject(i)
                .getString(ProtocolConstants.KEY_LOCATION);
        ServerStatus pushStatus = push(remoteBranchLocation1, Constants.HEAD, false);
        assertEquals(true, pushStatus.isOK());

        // clone 1 - list remote branches - expect 2
        JSONObject remote1 = getRemote(gitRemoteUri1, 1, 0, Constants.DEFAULT_REMOTE_NAME);
        String remoteLocation1 = remote1.getString(ProtocolConstants.KEY_LOCATION);

        request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation1);
        response = webConversation.getResponse(request);
        ServerStatus status = waitForTask(response);
        assertTrue(status.toString(), status.isOK());
        remote1 = status.getJsonData();
        JSONArray refsArray = remote1.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertEquals(2, refsArray.length());
        JSONObject ref = refsArray.getJSONObject(0);
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + newBranchName,
                ref.getString(ProtocolConstants.KEY_FULL_NAME));
        ref = refsArray.getJSONObject(1);
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                ref.getString(ProtocolConstants.KEY_FULL_NAME));

        // clone 2 
        JSONObject clone2 = clone(clonePath[1]);
        String cloneLocation2 = clone2.getString(ProtocolConstants.KEY_LOCATION);
        String contentLocation2 = clone2.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        // clone 2 - get project2 metadata
        request = getGetRequest(contentLocation2);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project2 = new JSONObject(response.getText());
        JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
        String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);

        // clone 2 - check if the branch "a" is available
        JSONObject remote2 = getRemote(gitRemoteUri2, 1, 0, Constants.DEFAULT_REMOTE_NAME);
        String remoteLocation2 = remote2.getString(ProtocolConstants.KEY_LOCATION);

        request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation2);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        remote2 = new JSONObject(response.getText());
        refsArray = remote2.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertEquals(2, refsArray.length());
        ref = refsArray.getJSONObject(0);
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                ref.getString(ProtocolConstants.KEY_FULL_NAME));
        ref = refsArray.getJSONObject(1);
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + newBranchName,
                ref.getString(ProtocolConstants.KEY_FULL_NAME));
        String remoteBranchLocation2 = ref.getString(ProtocolConstants.KEY_LOCATION);

        // clone 2 - checkout branch "a"
        response = checkoutBranch(cloneLocation2, newBranchName);

        // clone 1 - delete remote branch "a"
        push(remoteBranchLocation1, "", false, false);

        // clone 1 - list remote branches - expect 1
        request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation1);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        remote1 = new JSONObject(response.getText());
        refsArray = remote1.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertEquals(1, refsArray.length());
        ref = refsArray.getJSONObject(0);
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                ref.getString(ProtocolConstants.KEY_FULL_NAME));

        // clone 2 - fetch
        request = GitFetchTest.getPostGitRemoteRequest(remoteBranchLocation2, true, false);
        response = webConversation.getResponse(request);
        status = waitForTask(response);
        assertFalse(status.toString(), status.isOK());

        // clone 2 - fetch task should fail
        JSONObject statusJson = status.toJSON();
        JSONObject result = statusJson.has("Result") ? statusJson.getJSONObject("Result") : statusJson;
        assertEquals("Error", result.getString("Severity"));
    }
}