Java Code Examples for com.meterware.httpunit.WebResponse#getText()

The following examples show how to use com.meterware.httpunit.WebResponse#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SiteTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
/**
 * Try to access site created by another user, verify that we can't.
 */
public void testDisallowedAccess() throws SAXException, JSONException, IOException, URISyntaxException {
	createUser("alice", "alice");
	createUser("bob", "bob");

	// Alice: Create site
	final String name = "A site to delete";
	final String workspaceId = workspaceObject.getString(ProtocolConstants.KEY_ID);
	WebResponse createResp = createSite(name, workspaceId, null, null, "alice");
	JSONObject site = new JSONObject(createResp.getText());
	String location = site.getString(ProtocolConstants.HEADER_LOCATION);

	// Alice: Get site
	WebRequest getReq = getRetrieveSiteRequest(location, "alice");
	WebResponse getResp = webConversation.getResponse(getReq);
	assertEquals(HttpURLConnection.HTTP_OK, getResp.getResponseCode());

	// Bob: Attempt to get Alice's site
	getReq = getRetrieveSiteRequest(location, "bob");
	getResp = webConversation.getResponse(getReq);
	assertEquals(HttpURLConnection.HTTP_NOT_FOUND, getResp.getResponseCode());
}
 
Example 2
Source File: RemoteMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a workspace on the Orion server for the test user.
 *
 * @param webConversation
 * @param login
 * @param password
 * @param workspace
 * @return
 * @throws URISyntaxException
 * @throws IOException
 * @throws JSONException
 * @throws SAXException
 */
protected int createWorkspace(WebConversation webConversation, String login, String password, String workspace) throws URISyntaxException, IOException,
		JSONException, SAXException {
	assertEquals(HttpURLConnection.HTTP_OK, login(webConversation, login, password));

	WebRequest request = new PostMethodWebRequest(getOrionServerURI("/workspace"));
	request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
	request.setHeaderField(ProtocolConstants.HEADER_SLUG, workspace);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

	JSONObject jsonObject = new JSONObject(response.getText());
	String location = jsonObject.getString("Location");
	String name = jsonObject.getString("Name");
	System.out.println("Created Workspace: " + name + " at Location: " + location);
	return response.getResponseCode();
}
 
Example 3
Source File: RemoteMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the list of workspaces for the test user.
 *
 * @throws IOException
 * @throws URISyntaxException
 * @throws JSONException
 * @throws SAXException
 */
@Test
public void testGetSites() throws IOException, URISyntaxException, JSONException, SAXException {
	WebConversation webConversation = new WebConversation();
	assertEquals(HttpURLConnection.HTTP_OK, login(webConversation, getOrionTestName(), getOrionTestName()));

	WebRequest request = new GetMethodWebRequest(getOrionServerURI("/site"));
	request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

	JSONObject jsonObject = new JSONObject(response.getText());
	JSONArray siteConfigurations = jsonObject.getJSONArray("SiteConfigurations");
	if (siteConfigurations.length() == 0) {
		System.out.println("Found zero Sites for user: " + getOrionTestName());
	} else {
		System.out.print("Found Sites for user: " + getOrionTestName() + " at locations: [ ");
		for (int i = 0; i < siteConfigurations.length(); i++) {
			JSONObject workspace = siteConfigurations.getJSONObject(i);
			System.out.print(workspace.getString("Location") + " ");
		}
		System.out.println("]");
	}
}
 
Example 4
Source File: WorkspaceServiceTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGetProjectMetadata() throws IOException, SAXException, JSONException {
	//create workspace
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);

	//create a project
	String sourceName = "testGetProjectMetadata Project";
	WebRequest request = getCreateProjectRequest(workspaceLocation, sourceName, null);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
	String sourceLocation = response.getHeaderField(ProtocolConstants.HEADER_LOCATION);

	//now get the project metadata
	request = getGetRequest(sourceLocation);
	response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	JSONObject responseObject = new JSONObject(response.getText());
	String sourceContentLocation = responseObject.optString(ProtocolConstants.KEY_CONTENT_LOCATION);
	assertEquals(sourceName, responseObject.optString(ProtocolConstants.KEY_NAME));
	assertNotNull(sourceContentLocation);
}
 
Example 5
Source File: SiteTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
/**
 * Create a site, then fetch its resource via a GET and check the result.
 */
public void testRetrieveSite() throws SAXException, JSONException, IOException, URISyntaxException {
	// Create site
	final String name = "Bob's site";
	final String workspaceId = workspaceObject.getString(ProtocolConstants.KEY_ID);
	final JSONArray mappings = makeMappings(new String[][] { {"/foo", "/A"}, {"/bar", "/B"}});
	final String hostHint = "bobhost";
	WebResponse createResp = createSite(name, workspaceId, mappings, hostHint, null);
	JSONObject site = new JSONObject(createResp.getText());

	String location = site.getString(ProtocolConstants.HEADER_LOCATION);

	// Fetch site using its Location and ensure that what we find matches what was POSTed
	WebRequest fetchReq = getRetrieveSiteRequest(location, null);
	WebResponse fetchResp = webConversation.getResponse(fetchReq);
	assertEquals(HttpURLConnection.HTTP_OK, fetchResp.getResponseCode());
	JSONObject fetchedSite = new JSONObject(fetchResp.getText());
	assertEquals(name, fetchedSite.optString(ProtocolConstants.KEY_NAME));
	assertEquals(workspaceId, fetchedSite.optString(SiteConfigurationConstants.KEY_WORKSPACE));
	assertEquals(mappings.toString(), fetchedSite.getJSONArray(SiteConfigurationConstants.KEY_MAPPINGS).toString());
	assertEquals(hostHint, fetchedSite.optString(SiteConfigurationConstants.KEY_HOST_HINT));
}
 
Example 6
Source File: MockLearner.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static String parseOutNextURL(WebResponse resp) throws SAXException, IOException {
String text = resp.getText();

String toolURL = null;
Matcher m = MockLearner.NEXT_URL_PATTERN.matcher(text);
if (m.find()) {
    toolURL = m.group(1);
}

if ((toolURL != null) && !toolURL.startsWith("/")) {
    toolURL = '/' + toolURL;
}

log.debug("Tool URL: " + toolURL);
return toolURL;
   }
 
Example 7
Source File: CoreFilesTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Test to read the workspace.json at the /file/workspace top level, see Bug 415700.
 * @throws IOException
 * @throws SAXException
 * @throws URISyntaxException
 * @throws JSONException
 */
@Ignore
public void testReadWorkspaceJsonTopLevelFile() throws IOException, SAXException, URISyntaxException, JSONException {
	if (!(OrionConfiguration.getMetaStore() instanceof SimpleMetaStore)) {
		// This test is only supported by a SimpleMetaStore
		return;
	}
	String workspaceJSONFileName = "workspace.json";

	IPath projectLocation = new Path(getTestBaseResourceURILocation());
	String workspaceId = projectLocation.segment(0);
	String uriPath = new Path(FILE_SERVLET_LOCATION).append(workspaceId).append(workspaceJSONFileName).toString();
	String requestPath = URIUtil.fromString(SERVER_LOCATION + uriPath).toString();

	WebRequest request = new GetMethodWebRequest(requestPath);
	request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
	setAuthentication(request);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

	JSONObject responseObject = new JSONObject(response.getText());
	assertNotNull(responseObject.get(MetadataInfo.UNIQUE_ID));
	assertNotNull(responseObject.get("ProjectNames"));
}
 
Example 8
Source File: CoreFilesTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Test that the gzip filter correctly encodes a UTF-8 response when the JVM's default charset is not UTF-8.
 * Regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474366
 */
@Test
public void testGzippedResponseCharset() throws Exception {
	// This test is only valid when default charset is not UTF-8
	if ("UTF-8".equals(Charset.defaultCharset().name())) {
		return;
	}

	// Create folder
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);
	final String filename = "\u4f60\u597d\u4e16\u754c.txt";

	// Create empty file in the folder
	WebRequest request = getPostFilesRequest(directoryPath, getNewFileJSON(filename).toString(), filename);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	// Check metadata
	request = getGetFilesRequest(response.getHeaderField(ProtocolConstants.KEY_LOCATION) + "?parts=meta");
	response = webConversation.getResponse(request);
	JSONObject metadata = new JSONObject(response.getText());
	assertEquals("gzip", response.getHeaderField("Content-Encoding"));
	assertTrue(response.getCharacterSet().contains("UTF-8"));
	assertEquals("Name was encoded correctly", filename, metadata.optString(ProtocolConstants.KEY_NAME));
}
 
Example 9
Source File: GitTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected JSONArray listClones(String workspaceId, IPath path) throws JSONException, IOException, SAXException {
	WebRequest request = GitCloneTest.listGitClonesRequest(workspaceId, null);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	JSONObject clones = new JSONObject(response.getText());
	assertEquals(Clone.TYPE, clones.getString(ProtocolConstants.KEY_TYPE));
	return clones.getJSONArray(ProtocolConstants.KEY_CHILDREN);
}
 
Example 10
Source File: GitConfigTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetListOfConfigEntries() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	for (IPath clonePath : clonePaths) {
		// clone a  repo
		String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

		// get project metadata
		WebRequest request = getGetRequest(contentLocation);
		WebResponse response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		JSONObject project = new JSONObject(response.getText());
		JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
		String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);

		JSONObject configResponse = listConfigEntries(gitConfigUri);
		JSONArray configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);

		for (int i = 0; i < configEntries.length(); i++) {
			JSONObject configEntry = configEntries.getJSONObject(i);
			assertNotNull(configEntry.optString(GitConstants.KEY_CONFIG_ENTRY_KEY, null));
			assertNotNull(configEntry.optString(GitConstants.KEY_CONFIG_ENTRY_VALUE, null));
			assertConfigUri(configEntry.getString(ProtocolConstants.KEY_LOCATION));
			assertCloneUri(configEntry.getString(GitConstants.KEY_CLONE));
			assertEquals(ConfigOption.TYPE, configEntry.getString(ProtocolConstants.KEY_TYPE));
		}
	}
}
 
Example 11
Source File: WorkspaceServiceTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testCreateWorkspaceNullName() throws IOException, SAXException, JSONException {
	//request with null workspace name is not allowed
	WebRequest request = getCreateWorkspaceRequest(null);
	WebResponse response = webConversation.getResponse(request);

	assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());
	assertEquals("application/json", response.getContentType());
	//expecting a status response
	JSONObject responseObject = new JSONObject(response.getText());
	assertNotNull("No error response", responseObject);
	assertEquals("Error", responseObject.optString("Severity"));
	assertNotNull(responseObject.optString("message"));
}
 
Example 12
Source File: CoreFilesTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMoveFileOverwrite() throws Exception {
	String directoryPath = "testMoveFile/directory/path" + System.currentTimeMillis();
	String sourcePath = directoryPath + "/source.txt";
	String destName = "destination.txt";
	String destPath = directoryPath + "/" + destName;
	createDirectory(directoryPath);
	createFile(sourcePath, "This is the contents");
	createFile(destPath, "Original file");

	//with no-overwrite, move should fail
	JSONObject requestObject = new JSONObject();
	addSourceLocation(requestObject, sourcePath);
	WebRequest request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
	request.setHeaderField("X-Create-Options", "copy,no-overwrite");
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, response.getResponseCode());

	//now omit no-overwrite and move should succeed and return 200 instead of 201
	request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
	request.setHeaderField("X-Create-Options", "move");
	response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	JSONObject responseObject = new JSONObject(response.getText());
	checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null, null);
	assertFalse(checkFileExists(sourcePath));
	assertTrue(checkFileExists(destPath));
}
 
Example 13
Source File: BasicUsersTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testCreateUser() throws JSONException, IOException, SAXException {
	WebConversation webConversation = new WebConversation();
	webConversation.setExceptionsThrownOnErrorStatus(false);

	String username1 = "user1" + System.currentTimeMillis();
	String password = "pass" + System.currentTimeMillis();

	// create user
	JSONObject json = new JSONObject();
	json.put(UserConstants.USER_NAME, username1);
	json.put(UserConstants.PASSWORD, password);
	WebRequest request = getPostUsersRequest("", json, true);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(response.getText(), HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	JSONObject responseObject = new JSONObject(response.getText());

	assertTrue(responseObject.has(UserConstants.LOCATION));
	assertEquals("/users/" + username1, responseObject.getString(UserConstants.LOCATION));
	assertTrue(responseObject.getBoolean(UserConstants.HAS_PASSWORD));
	assertFalse(responseObject.getBoolean(UserConstants.EMAIL_CONFIRMED));
	assertTrue(responseObject.has(UserConstants.USER_NAME));
	assertEquals(username1, responseObject.getString(UserConstants.USER_NAME));
	assertTrue(responseObject.has(UserConstants.FULL_NAME));
	assertEquals(username1, responseObject.getString(UserConstants.FULL_NAME));
}
 
Example 14
Source File: HostingTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testStopSite() throws SAXException, IOException, JSONException, URISyntaxException {
	JSONArray mappings = makeMappings(new String[][] {{"/", "/A/bogusWorkspacePath"}});
	WebResponse siteResp = createSite("Buzz site", workspaceId, mappings, "buzzsite", null);
	JSONObject siteObject = new JSONObject(siteResp.getText());
	String location = siteObject.getString(ProtocolConstants.HEADER_LOCATION);
	startSite(location);
	stopSite(location);
}
 
Example 15
Source File: CoreFilesTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testCopyFileInvalidSource() throws Exception {
	String directoryPath = "testCopyFile/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	JSONObject requestObject = new JSONObject();
	requestObject.put("Location", toAbsoluteURI("file/this/does/not/exist/at/all"));
	WebRequest request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
	request.setHeaderField("X-Create-Options", "copy");
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
	JSONObject responseObject = new JSONObject(response.getText());
	assertEquals("Error", responseObject.get("Severity"));
}
 
Example 16
Source File: GitRevertTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testRevertFailure() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	for (IPath clonePath : clonePaths) {
		// clone a  repo
		JSONObject clone = clone(clonePath);
		String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

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

		JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
		String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

		JSONObject testTxt = getChild(folder, "test.txt");
		modifyFile(testTxt, "first line\nsec. line\nthird line\n");

		addFile(testTxt);

		commitFile(testTxt, "lines in test.txt", false);

		JSONArray commitsArray = log(gitHeadUri);
		assertEquals(2, commitsArray.length());
		JSONObject commit = commitsArray.getJSONObject(0);
		assertEquals("lines in test.txt", commit.get(GitConstants.KEY_COMMIT_MESSAGE));

		String toRevert = commit.getString(ProtocolConstants.KEY_NAME);
		modifyFile(testTxt, "first line\nsec. line\nthird line\nfourth line\n");
		addFile(testTxt);

		// REVERT
		JSONObject revert = revert(gitHeadUri, toRevert);
		assertEquals("FAILURE", revert.getString(GitConstants.KEY_RESULT));

		// there's no new revert commit
		commitsArray = log(gitHeadUri);
		assertEquals(2, commitsArray.length());
		commit = commitsArray.getJSONObject(0);

		String revertMessage = commit.optString(GitConstants.KEY_COMMIT_MESSAGE);
		assertEquals(true, revertMessage != null);
		if (revertMessage != null) {
			assertEquals(false, revertMessage.startsWith("Revert \"lines in test.txt\""));
		}
	}
}
 
Example 17
Source File: GitConfigTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testRequestWithMissingArguments() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	for (IPath clonePath : clonePaths) {
		// clone a  repo
		String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

		// get project metadata
		WebRequest request = getGetRequest(contentLocation);
		WebResponse response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		JSONObject project = new JSONObject(response.getText());
		JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
		String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);

		final String ENTRY_KEY = "a.b.c";
		final String ENTRY_VALUE = "v";

		// missing key
		request = getPostGitConfigRequest(gitConfigUri, null, ENTRY_VALUE);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

		// missing value
		request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, null);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

		// missing key and value
		request = getPostGitConfigRequest(gitConfigUri, null, null);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

		// add some config
		request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
		JSONObject configResponse = new JSONObject(response.getText());
		String entryLocation = configResponse.getString(ProtocolConstants.KEY_LOCATION);

		// put without value
		request = getPutGitConfigRequest(entryLocation, null);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());
	}
}
 
Example 18
Source File: GitBlameTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testFolderBlame() throws IOException, SAXException, JSONException, CoreException {

	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	for (IPath clonePath : clonePaths) {
		//clone a repo
		JSONObject clone = clone(clonePath);
		String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

		//get project/folder metadata
		WebRequest request = getGetRequest(cloneContentLocation);
		WebResponse response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		JSONObject folder = new JSONObject(response.getText());
		JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
		String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

		JSONObject newfolder = getChild(folder, "folder");

		//modifyFile(newfolder, "commit me");

		// commit the new file
		addFile(newfolder);
		request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit on testFile2.txt", false);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

		JSONObject newfolderGitSection = newfolder.getJSONObject(GitConstants.KEY_GIT);
		String blameUri = newfolderGitSection.getString(GitConstants.KEY_BLAME);

		// blame request
		request = getGetGitBlameRequest(blameUri);
		response = webConversation.getResource(request);

		// get BlameInfo
		JSONObject blameObject = new JSONObject(response.getText());

		//Test
		assertEquals(blameObject.get("Severity"), "Error");
		assertEquals(blameObject.get("HttpCode"), 400);
		assertEquals(blameObject.get("Code"), 0);

	}
}
 
Example 19
Source File: GitRebaseTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testRebase() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	for (IPath clonePath : clonePaths) {
		// clone a  repo
		JSONObject clone = clone(clonePath);

		String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
		String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
		String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

		// get project metadata
		WebRequest request = getGetRequest(contentLocation);
		WebResponse response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		JSONObject project = new JSONObject(response.getText());

		JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
		String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
		String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
		String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);

		// create branch 'a'
		branch(branchesLocation, "a");

		// checkout 'a'
		Repository db1 = getRepositoryForContentLocation(contentLocation);
		Git git = Git.wrap(db1);
		assertBranchExist(git, "a");
		checkoutBranch(cloneLocation, "a");

		// modify while on 'a'
		JSONObject testTxt = getChild(project, "test.txt");
		modifyFile(testTxt, "change in a");

		// "git add ."
		request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

		// commit all
		request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit on a", false);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

		// assert clean
		assertStatus(StatusResult.CLEAN, gitStatusUri);

		// checkout 'master'
		checkoutBranch(cloneLocation, Constants.MASTER);

		// modify a different file on master
		JSONObject folder = getChild(project, "folder");
		JSONObject folderTxt = getChild(folder, "folder.txt");
		modifyFile(folderTxt, "change in master");

		gitSection = project.getJSONObject(GitConstants.KEY_GIT);
		gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
		gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
		gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

		// "git add ."
		request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

		// commit all
		request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit on master", false);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

		// assert clean
		assertStatus(StatusResult.CLEAN, gitStatusUri);

		// rebase: "git rebase a"
		JSONObject rebase = rebase(gitHeadUri, "a");
		RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
		assertEquals(RebaseResult.Status.OK, rebaseResult);

		// assert clean
		assertStatus(StatusResult.CLEAN, gitStatusUri);

		request = getGetRequest(testTxt.getString(ProtocolConstants.KEY_LOCATION));
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		assertEquals("change in a", response.getText());

		request = getGetRequest(folderTxt.getString(ProtocolConstants.KEY_LOCATION));
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		assertEquals("change in master", response.getText());
	}
}
 
Example 20
Source File: GitTest.java    From orion.server with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Tag the commit with given tag name 
 * 
 * @param gitTagUri tags URI
 * @param tagName tag name to use
 * @param commitId commit to tag
 * @return created tag object
 * @throws JSONException
 * @throws IOException
 * @throws SAXException
 * @throws URISyntaxException
 */
protected JSONObject tag(String gitTagUri, String tagName, String commitId) throws JSONException, IOException, SAXException, URISyntaxException {
	assertTagListUri(gitTagUri);
	WebRequest request = getPostGitTagRequest(gitTagUri, tagName, commitId);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	return new JSONObject(response.getText());
}