i = 1;
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"));
}
}