Java Code Examples for com.meterware.httpunit.WebResponse#getHeaderField()
The following examples show how to use
com.meterware.httpunit.WebResponse#getHeaderField() .
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: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testListenerWriteFile() throws CoreException, IOException, SAXException, JSONException { String directoryPath = "sample/directory/path" + System.currentTimeMillis(); IFileStore dir = createDirectory(directoryPath); String fileName = "testfile.txt"; WebRequest request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); modListener = new TestFilesystemModificationListener(); //put to file location should succeed String location = response.getHeaderField("Location"); String fileContent = "New contents"; request = getPutFileRequest(location, fileContent); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); modListener.assertListenerNotified(dir.getChild(fileName), ChangeType.WRITE); }
Example 2
Source File: SearchTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Copied from {@link TransferTest}. */ private void doImport(File source, long length, String location) throws FileNotFoundException, IOException, SAXException { //repeat putting chunks until done byte[] chunk = new byte[64 * 1024]; InputStream in = new BufferedInputStream(new FileInputStream(source)); int chunkSize = 0; int totalTransferred = 0; while ((chunkSize = in.read(chunk, 0, chunk.length)) > 0) { PutMethodWebRequest put = new PutMethodWebRequest(toAbsoluteURI(location), new ByteArrayInputStream(chunk, 0, chunkSize), "application/zip"); put.setHeaderField("Content-Range", "bytes " + totalTransferred + "-" + (totalTransferred + chunkSize - 1) + "/" + length); put.setHeaderField("Content-Length", "" + length); put.setHeaderField("Content-Type", "application/zip"); setAuthentication(put); totalTransferred += chunkSize; WebResponse putResponse = webConversation.getResponse(put); if (totalTransferred == length) { assertEquals(201, putResponse.getResponseCode()); } else { assertEquals(308, putResponse.getResponseCode()); String range = putResponse.getHeaderField("Range"); assertEquals("bytes 0-" + (totalTransferred - 1), range); } } in.close(); }
Example 3
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testWriteFile() throws CoreException, IOException, SAXException, JSONException { String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); String fileName = "testfile.txt"; WebRequest request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //put to file location should succeed String location = response.getHeaderField("Location"); String fileContent = "New contents"; request = getPutFileRequest(location, fileContent); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); //get should return new contents request = getGetRequest(location); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertEquals("Invalid file content", fileContent, response.getText()); }
Example 4
Source File: WorkspaceServiceTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@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: TransferTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testImportAndUnzip() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location); //assert the file has been unzipped in the workspace assertTrue(checkFileExists(directoryPath + "/org.eclipse.e4.webide/static/js/navigate-tree/navigate-tree.js")); }
Example 6
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testImportWithPost() throws CoreException, IOException, SAXException { //create a directory to upload to String directoryPath = "sample/testImportWithPost/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); InputStream in = new BufferedInputStream(new FileInputStream(source)); PostMethodWebRequest request = new PostMethodWebRequest(getImportRequestPath(directoryPath), in, "application/zip"); request.setHeaderField("Content-Length", "" + length); request.setHeaderField("Content-Type", "application/zip"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); String type = postResponse.getHeaderField("Content-Type"); assertNotNull(type); assertTrue(type.contains("text/html")); //assert the file has been unzipped in the workspace assertTrue(checkFileExists(directoryPath + "/org.eclipse.e4.webide/static/js/navigate-tree/navigate-tree.js")); }
Example 7
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportDBCSFilename() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import // file with DBCS character in the filename. String filename = "\u3042.txt"; File source = null; try { source = createTempFile(filename, "No content"); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", Slug.encode(filename)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location, "text/plain"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + File.separator + filename)); //assert that imported file has same content as original client.zip assertTrue(checkContentEquals(source, directoryPath + File.separator + filename)); } finally { // Delete the temp file FileUtils.deleteQuietly(source); } }
Example 8
Source File: AdvancedFilesTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testETagDeletedFile() throws JSONException, IOException, SAXException, CoreException { String fileName = "testfile.txt"; //setup: create a file WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //obtain file metadata and ensure data is correct request = getGetFilesRequest(fileName + "?parts=meta"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG); assertNotNull(etag); //delete the file on disk IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName)); fileStore.delete(EFS.NONE, null); //now a PUT should fail request = getPutFileRequest(fileName, "something"); request.setHeaderField(ProtocolConstants.HEADER_IF_MATCH, etag); try { response = webConversation.getResponse(request); } catch (IOException e) { //inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0); } }
Example 9
Source File: AdvancedFilesTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testETagPutNotMatch() throws JSONException, IOException, SAXException, CoreException { String fileName = "testfile.txt"; //setup: create a file WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //obtain file metadata and ensure data is correct request = getGetFilesRequest(fileName + "?parts=meta"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG); assertNotNull(etag); //change the file on disk IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName)); OutputStream out = fileStore.openOutputStream(EFS.NONE, null); out.write("New Contents".getBytes()); out.close(); //now a PUT should fail request = getPutFileRequest(fileName, "something"); request.setHeaderField("If-Match", etag); try { response = webConversation.getResponse(request); } catch (IOException e) { //inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0); } }
Example 10
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportAndUnzipWithOverride() throws CoreException, IOException, SAXException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); String filePath = "/org.eclipse.e4.webide/static/js/navigate-tree"; createDirectory(directoryPath + filePath); //create a file that is to be overwritten String fileContents = "This is the file contents"; createFile(directoryPath + filePath + "/navigate-tree.js", fileContents); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); InputStream in = new BufferedInputStream(new FileInputStream(source)); PostMethodWebRequest request = new PostMethodWebRequest(getImportRequestPath(directoryPath), in, "application/zip"); request.setHeaderField("Content-Length", "" + length); request.setHeaderField("Content-Type", "application/octet-stream"); request.setHeaderField("Slug", "client.zip"); request.setHeaderField("X-Xfer-Options", "overwrite-older"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); //assert the server accepts the override assertEquals(HttpURLConnection.HTTP_CREATED, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); String type = postResponse.getHeaderField("Content-Type"); assertNotNull(type); //assert the unzip still occurred in the workspace assertTrue(checkFileExists(directoryPath + "/org.eclipse.e4.webide/static/images/unit_test/add-test-config.png")); //assert that imported file was overwritten assertFalse(checkContentEquals(createTempFile("expectedFile", fileContents), directoryPath + filePath + "/navigate-tree.js")); }
Example 11
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportFilesWithOverride() throws CoreException, IOException, SAXException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //create a file that is to be overwritten String fileContents = "This is the file contents"; createFile(directoryPath + "/client.zip", fileContents); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); InputStream in = new BufferedInputStream(new FileInputStream(source)); PostMethodWebRequest request = new PostMethodWebRequest(getImportRequestPath(directoryPath), in, "application/zip"); request.setHeaderField("Content-Length", "" + length); request.setHeaderField("Content-Type", "application/octet-stream"); request.setHeaderField("Slug", "client.zip"); request.setHeaderField("X-Xfer-Options", "raw,overwrite-older"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); //assert the server accepts the override assertEquals(HttpURLConnection.HTTP_CREATED, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); String type = postResponse.getHeaderField("Content-Type"); assertNotNull(type); //assert the file is still present in the workspace assertTrue(checkFileExists(directoryPath + "/client.zip")); //assert that imported file was overwritten assertFalse(checkContentEquals(createTempFile("expectedFile", fileContents), directoryPath + "/client.zip")); assertTrue(checkContentEquals(source, directoryPath + "/client.zip")); }
Example 12
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportWithPostZeroByteFile() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/zeroByteFile.txt"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); assertEquals(length, 0); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "zeroByteFile.txt"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location, "text/plain"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/zeroByteFile.txt")); }
Example 13
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportFileMultiPart() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); // current server implementation cannot handle binary data, thus base64-encode client.zip before import File expected = EFS.getStore(makeLocalPathAbsolute(directoryPath + "/expected.txt")).toLocalFile(EFS.NONE, null); byte[] expectedContent = Base64.encode(FileUtils.readFileToByteArray(source)); FileUtils.writeByteArrayToFile(expected, expectedContent); //start the import long length = expectedContent.length; String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "actual.txt"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); // perform the upload doImport(expected, length, location, "multipart/mixed;boundary=foobar"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/actual.txt")); //assert that actual.txt has same content as expected.txt assertTrue(checkContentEquals(expected, directoryPath + "/actual.txt")); }
Example 14
Source File: GitDiffTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private String getDiffLocation(String oldCommitDiffLocation, String newCommitName) throws JSONException, IOException, SAXException { assertDiffUri(oldCommitDiffLocation); WebRequest request = getPostGitDiffRequest(oldCommitDiffLocation, newCommitName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String location = response.getHeaderField(ProtocolConstants.HEADER_LOCATION); assertEquals(location, new JSONObject(response.getText()).getString(ProtocolConstants.KEY_LOCATION)); return location; }
Example 15
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportFile() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "client.zip"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/client.zip")); //assert that imported file has same content as original client.zip assertTrue(checkContentEquals(source, directoryPath + "/client.zip")); }
Example 16
Source File: WorkspaceServiceTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testCreateWorkspace() throws IOException, SAXException, JSONException { String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME; WebResponse response = basicCreateWorkspace(workspaceName); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String location = response.getHeaderField(ProtocolConstants.HEADER_LOCATION); assertNotNull(location); assertEquals("application/json", response.getContentType()); JSONObject responseObject = new JSONObject(response.getText()); assertNotNull("No workspace information in response", responseObject); assertNotNull(responseObject.optString(ProtocolConstants.KEY_ID)); assertEquals(workspaceName, responseObject.optString(ProtocolConstants.KEY_NAME)); }
Example 17
Source File: GitDiffTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
static String[] parseMultiPartResponse(WebResponse response) throws IOException { String typeHeader = response.getHeaderField(ProtocolConstants.HEADER_CONTENT_TYPE); String boundary = typeHeader.substring(typeHeader.indexOf("boundary=\"") + 10, typeHeader.length() - 1); //$NON-NLS-1$ BufferedReader reader = new BufferedReader(new StringReader(response.getText())); StringBuilder buf = new StringBuilder(); List<String> parts = new ArrayList<String>(); try { String line; while ((line = reader.readLine()) != null) { if (line.equals("--" + boundary)) { line = reader.readLine(); // Content-Type:{...} if (buf.length() > 0) { parts.add(buf.toString()); buf.setLength(0); } } else { if (buf.length() > 0) buf.append("\n"); buf.append(line); } } } finally { IOUtilities.safeClose(reader); } parts.add(buf.toString()); assertEquals(2, parts.size()); // JSON assertTrue(parts.get(0).startsWith("{")); // diff or empty when there is no difference assertTrue(parts.get(1).length() == 0 || parts.get(1).startsWith("diff")); return parts.toArray(new String[0]); }
Example 18
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testImportEmojiFilename() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import // file with Emoji characters in the filename. // U+1F60A: SMILING FACE WITH SMILING EYES ("\ud83d\ude0a") // U+1F431: CAT FACE ("\ud83d\udc31") // U+1F435: MONKEY FACE ("\ud83d\udc35") String filename = "\ud83d\ude0a\ud83d\udc31\ud83d\udc35.txt"; String contents = "Emoji characters: \ud83d\ude0a\ud83d\udc31\ud83d\udc35"; File source = null; try { source = createTempFile(filename, contents); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", Slug.encode(filename)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location, "text/plain"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + File.separator + filename)); //assert that imported file has same content as original client.zip assertTrue(checkContentEquals(source, directoryPath + File.separator + filename)); } finally { // Delete the temp file FileUtils.deleteQuietly(source); } }
Example 19
Source File: GitRemoteTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testAddRemoveRemote() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); IPath clonePath = getClonePath(workspaceId, project); JSONObject clone = clone(clonePath); String remotesLocation = clone.getString(GitConstants.KEY_REMOTE); // expect only origin getRemote(remotesLocation, 1, 0, Constants.DEFAULT_REMOTE_NAME); // create remote WebResponse response = addRemote(remotesLocation, "a", "https://a.b"); String remoteLocation = response.getHeaderField(ProtocolConstants.HEADER_LOCATION); String remoteLocationFromBody = new JSONObject(response.getText()).getString(ProtocolConstants.KEY_LOCATION); assertEquals(remoteLocation, remoteLocationFromBody); // check details WebRequest request = getGetRequest(remoteLocation); response = webConversation.getResponse(request); ServerStatus status = waitForTask(response); assertTrue(status.toString(), status.isOK()); // list remotes request = getGetRequest(remotesLocation); response = webConversation.getResponse(request); status = waitForTask(response); assertTrue(status.toString(), status.isOK()); JSONObject remotes = status.getJsonData(); JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN); // expect origin and new remote assertEquals(2, remotesArray.length()); // remove remote request = getDeleteGitRemoteRequest(remoteLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // list remotes again, make sure it's gone request = getGetRequest(remotesLocation); response = webConversation.getResponse(request); status = waitForTask(response); assertTrue(status.toString(), status.isOK()); remotes = status.getJsonData(); remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN); // expect origin only assertEquals(1, remotesArray.length()); getRemote(remotesLocation, 1, 0, Constants.DEFAULT_REMOTE_NAME); }
Example 20
Source File: GitLogTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testLog() 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); // modify JSONObject testTxt = getChild(folder, "test.txt"); modifyFile(testTxt, "first change"); addFile(testTxt); // commit1 request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // modify again modifyFile(testTxt, "second change"); addFile(testTxt); // commit2 request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit2", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // get the full log JSONArray commitsArray = log(gitHeadUri); assertEquals(3, commitsArray.length()); JSONObject commit = commitsArray.getJSONObject(0); assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); commit = commitsArray.getJSONObject(1); assertEquals("commit1", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); commit = commitsArray.getJSONObject(2); assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); String initialGitCommitName = commit.getString(ProtocolConstants.KEY_NAME); String initialGitCommitURI = gitHeadUri.replaceAll(Constants.HEAD, initialGitCommitName); //get log for given page size commitsArray = log(gitHeadUri, 1, 1, false, true); assertEquals(1, commitsArray.length()); commit = commitsArray.getJSONObject(0); assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); //get log for second page commitsArray = log(gitHeadUri, 2, 1, true, true); assertEquals(1, commitsArray.length()); commit = commitsArray.getJSONObject(0); assertEquals("commit1", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); // prepare a scoped log location request = getPostForScopedLogRequest(initialGitCommitURI, Constants.HEAD); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String newGitCommitUri = response.getHeaderField(ProtocolConstants.KEY_LOCATION); assertEquals(newGitCommitUri, new JSONObject(response.getText()).getString(ProtocolConstants.KEY_LOCATION)); // get a scoped log commitsArray = log(newGitCommitUri); assertEquals(2, commitsArray.length()); commit = commitsArray.getJSONObject(0); assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); commit = commitsArray.getJSONObject(1); assertEquals("commit1", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); } }