com.meterware.httpunit.WebRequest Java Examples
The following examples show how to use
com.meterware.httpunit.WebRequest.
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: PreferenceTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Tests whether a client can access workspace metadata via the preferences servlet. * @throws IOException */ @Test public void testAccessingMetadata() throws IOException { List<String> locations = getIllegalPreferenceNodes(); for (String location : locations) { //get should return 405 WebRequest request = new GetMethodWebRequest(location); setAuthentication(request); WebResponse response = webConversation.getResource(request); assertEquals(HttpURLConnection.HTTP_BAD_METHOD, response.getResponseCode()); //put a value should be 403 request = createSetPreferenceRequest(location, "Name", "Frodo"); setAuthentication(request); response = webConversation.getResource(request); assertEquals(HttpURLConnection.HTTP_BAD_METHOD, response.getResponseCode()); } }
Example #2
Source File: BasicUsersTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testCreateUserEmailDifferentCase() throws IOException, SAXException, JSONException { WebConversation webConversation = new WebConversation(); webConversation.setExceptionsThrownOnErrorStatus(false); // create user JSONObject json = new JSONObject(); json.put(UserConstants.USER_NAME, "testCaseEmail"); json.put(UserConstants.FULL_NAME, "username_testCreateUserEmailDifferentCase"); json.put(UserConstants.PASSWORD, "pass_" + System.currentTimeMillis()); json.put(UserConstants.EMAIL, "[email protected]"); WebRequest request = getPostUsersRequest("", json, true); WebResponse response = webConversation.getResponse(request); assertEquals(response.getText(), HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //try creating another user with same email address but different case json.put(UserConstants.EMAIL, "[email protected]"); json.put(UserConstants.USER_NAME, "testCaseEmail2"); request = getPostUsersRequest("", json, true); response = webConversation.getResponse(request); assertEquals(response.getText(), HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode()); }
Example #3
Source File: GitResetTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
static WebRequest getPostGitIndexRequest(String location, String[] paths, String commit, String resetType) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); if (resetType != null) body.put(GitConstants.KEY_RESET_TYPE, resetType); if (paths != null) { // assertNull("Cannot mix paths and commit", commit); JSONArray jsonPaths = new JSONArray(); for (String path : paths) jsonPaths.put(path); body.put(ProtocolConstants.KEY_PATH, jsonPaths); } if (commit != null) body.put(GitConstants.KEY_TAG_COMMIT, commit); WebRequest request = new PostMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); return request; }
Example #4
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * 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 #5
Source File: GitLogTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Ignore("Bug 443416") @Test public void testLogOrionServerLinked() throws Exception { File orionServer = new File("").getAbsoluteFile().getParentFile(/*org.eclipse.orion.server.tests*/).getParentFile(/*tests*/); Assume.assumeTrue(new File(orionServer, Constants.DOT_GIT).exists()); createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), orionServer.toURI().toString()); String location = project.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetRequest(location); 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); // reading first 50 commits should be enough to start a task JSONArray commitsArray = log(gitHeadUri, 1, 50, false, true); assertEquals(50, commitsArray.length()); }
Example #6
Source File: GitConfigTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetConfigEntryForNonExistingRepository() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONArray clonesArray = listClones(workspaceId, null); String dummyId = "dummyId"; GitCloneTest.ensureCloneIdDoesntExist(clonesArray, dummyId); String entryLocation = SERVER_LOCATION + GIT_SERVLET_LOCATION + ConfigOption.RESOURCE + "/dummyKey/" + Clone.RESOURCE + "/file/" + dummyId; // get value of config entry WebRequest request = getGetGitConfigRequest(entryLocation); WebResponse response = webConversation.getResponse(request); assertEquals(response.getResponseMessage(), HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode()); }
Example #7
Source File: AnonPortalTest.java From sakai with Educational Community License v2.0 | 6 votes |
@Override protected void setUp() throws Exception { try { wc = new WebConversation(); WebRequest req = new GetMethodWebRequest(TEST_URL); WebResponse resp = wc.getResponse(req); DataInputStream inputStream = new DataInputStream(resp.getInputStream()); buffer = new byte[resp.getContentLength()]; inputStream.readFully(buffer); visited = new HashMap<String, String>(); } catch (Exception notfound) { enabled = false; } }
Example #8
Source File: GitResetTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testResetPathsAndRef() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "hello"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); WebRequest request = getPostGitIndexRequest(gitIndexUri, new String[] {"test.txt"}, "origin/master", null); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode()); }
Example #9
Source File: ViewToolsIT.java From velocity-tools with Apache License 2.0 | 6 votes |
public @Test void testContextTool() throws Exception { WebConversation conv = new WebConversation(); WebRequest req = new GetMethodWebRequest(ROOT_URL+"context.vm"); WebResponse resp = conv.getResponse(req); /* check that getThis() is a ViewToolContext instance */ checkTextStart(resp, "getThis()", "org.apache.velocity.tools.view.ViewToolContext"); /* check contains('context') */ resp = submitWithParam(resp,"contains_Object","contains_Object1","'context'"); checkText(resp, "contains(java.lang.Object)", "true"); /* check get('context') */ resp = submitWithParam(resp, "get_Object", "get_Object1", "'context'"); checkTextStart(resp, "get(java.lang.Object)", "org.apache.velocity.tools.view.ViewContextTool"); /* check keys (the only expected uppercase is in 'velocityCount') */ checkTextRegex(resp, "getKeys()", "^\\[[a-z_A-Z][a-z_A-Z0-9]*(?:,\\s*[a-z_A-Z][a-z_A-Z0-9]*)*\\]$"); /* check toolbox */ checkTextRegex(resp,"getToolbox()","^\\{[a-z_A-Z]+=.*(?:,\\s*[a-z_A-Z]+=.*)*\\}$"); /* check values */ checkTextStartEnd(resp, "getValues()", "[", "]"); }
Example #10
Source File: GitLogTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testLogRemoteBranch() 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 gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE); JSONObject originMasterDetails = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER); String originMasterCommitUri = originMasterDetails.getString(GitConstants.KEY_COMMIT); JSONArray commitsArray = log(originMasterCommitUri); assertEquals(1, commitsArray.length()); } }
Example #11
Source File: GitDiffTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private void assertDiffUris(String expectedLocation, String[] expectedContent, JSONObject jsonPart) throws JSONException, IOException, SAXException { assertEquals(Diff.TYPE, jsonPart.getString(ProtocolConstants.KEY_TYPE)); String fileOldUri = jsonPart.getString(GitConstants.KEY_COMMIT_OLD); WebRequest request = getGetRequest(fileOldUri); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertEquals(expectedContent[0], response.getText()); String fileNewUri = jsonPart.getString(GitConstants.KEY_COMMIT_NEW); request = getGetRequest(fileNewUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertEquals(expectedContent[1], response.getText()); String fileBaseUri = jsonPart.getString(GitConstants.KEY_COMMIT_BASE); request = getGetRequest(fileBaseUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertEquals(expectedContent[2], response.getText()); assertEquals(expectedLocation, jsonPart.getString(ProtocolConstants.KEY_LOCATION)); }
Example #12
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testCloneNotGitRepository() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); IPath clonePath = new Path("file").append(workspaceId).append(project.getString(ProtocolConstants.KEY_NAME)).makeAbsolute(); // clone File notAGitRepository = createTempDir().toFile(); assertTrue(notAGitRepository.isDirectory()); assertTrue(notAGitRepository.list().length == 0); WebRequest request = getPostGitCloneRequest(notAGitRepository.toURI().toString(), clonePath); WebResponse response = webConversation.getResponse(request); ServerStatus status = waitForTask(response); assertFalse(status.toString(), status.isOK()); assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, status.getHttpCode()); assertEquals("Error cloning git repository", status.getMessage()); assertNotNull(status.getJsonData()); assertEquals(status.toString(), "Invalid remote: origin", status.getException().getMessage()); // cleanup the tempDir FileUtils.delete(notAGitRepository, FileUtils.RECURSIVE); }
Example #13
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Tests generic file handler. */ @Test public void testGenericFileHandler() throws CoreException, IOException { String dirPath = "sample/directory/path"; String fileName = "testGenericFileHandler-" + System.currentTimeMillis() + ".txt"; String filePath = dirPath + "/" + fileName; createDirectory(dirPath); createFile(filePath, "Sample file content"); String requestURI = makeResourceURIAbsolute(filePath); WebRequest get = new GetMethodWebRequest(requestURI); setAuthentication(get); WebResponse response = webConversation.getResource(get); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertEquals("text/plain", response.getHeaderField("Content-Type")); }
Example #14
Source File: GitRemoteTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetOrigin() 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); String gitRemoteUri = clone.getString(GitConstants.KEY_REMOTE); JSONObject remoteBranch = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER); assertNotNull(remoteBranch); // 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()); // check if Git locations are in place JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); assertEquals(gitRemoteUri, gitSection.getString(GitConstants.KEY_REMOTE)); } }
Example #15
Source File: GitTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Fetch objects and refs from the given remote branch. * * @param remoteBranchLocation remote branch URI * @param force <code>true</code> to force fetch * @return JSONObject representing remote branch after the fetch is done * @throws JSONException * @throws IOException * @throws SAXException */ protected JSONObject fetch(String remoteBranchLocation, boolean force, String userName, String kh, byte[] privk, byte[] pubk, byte[] p, boolean shouldBeOK) throws JSONException, IOException, SAXException { assertRemoteOrRemoteBranchLocation(remoteBranchLocation); // fetch WebRequest request = GitFetchTest.getPostGitRemoteRequest(remoteBranchLocation, true, force, userName, kh, privk, pubk, p); WebResponse response = webConversation.getResponse(request); ServerStatus status = waitForTask(response); if (shouldBeOK) { assertTrue(status.toString(), status.isOK()); } // get remote branch details again request = GitRemoteTest.getGetGitRemoteRequest(remoteBranchLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); return new JSONObject(response.getText()); }
Example #16
Source File: RemoteMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Create a plugins preference on the Orion server for the test user. * * @param webConversation * @param login * @param password * @param projectName * @return * @throws IOException * @throws JSONException * @throws URISyntaxException * @throws SAXException */ protected int createPluginsPref(WebConversation webConversation, String login, String password) throws IOException, JSONException, URISyntaxException, SAXException { assertEquals(HttpURLConnection.HTTP_OK, login(webConversation, login, password)); JSONObject jsonObject = new JSONObject(); jsonObject.put("http://mamacdon.github.io/0.3/plugins/bugzilla/plugin.html", true); WebRequest request = new PutMethodWebRequest(getOrionServerURI("/prefs/user/plugins"), IOUtilities.toInputStream(jsonObject.toString()), "application/json"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode()); System.out.println("Created Preference /prefs/user/plugins"); return response.getResponseCode(); }
Example #17
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testCloneOverSshWithPassword() throws Exception { Assume.assumeTrue(sshRepo != null); Assume.assumeTrue(password != null); Assume.assumeTrue(knownHosts != null); createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); String workspaceId = workspaceIdFromLocation(workspaceLocation); IPath clonePath = getClonePath(workspaceId, project); URIish uri = new URIish(sshRepo); WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts).setPassword(password).getWebRequest(); String contentLocation = clone(request); File file = getRepositoryForContentLocation(contentLocation).getDirectory().getParentFile(); assertTrue(file.exists()); assertTrue(file.isDirectory()); assertTrue(RepositoryCache.FileKey.isGitRepository(new File(file, Constants.DOT_GIT), FS.DETECTED)); }
Example #18
Source File: GitCommitTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testCommitEmptyComment() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "change to commit"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); addFile(testTxt); // commit with a null message WebRequest request = getPostGitCommitRequest(gitHeadUri /* all */, "", false); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode()); }
Example #19
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
/** * Tests that we are not allowed to get metadata files */ @Test public void testGetForbiddenFiles() throws IOException, SAXException, BackingStoreException { //enable global anonymous read IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE); String oldValue = prefs.get(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, null); prefs.put(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, "true"); prefs.flush(); try { //should not be allowed to get at file root WebRequest request = getGetRequest("file/"); setAuthentication(request); WebResponse response = webConversation.getResponse(request); assertEquals("Should not be able to get the root", HttpURLConnection.HTTP_FORBIDDEN, response.getResponseCode()); //should not be allowed to access the metadata directory request = getGetRequest("file/" + ".metadata"); setAuthentication(request); response = webConversation.getResponse(request); assertEquals("Should not be able to get metadata", HttpURLConnection.HTTP_FORBIDDEN, response.getResponseCode()); //should not be allowed to read specific metadata files request = getGetRequest("file/" + ".metadata/.plugins/org.eclipse.orion.server.core.search/index.generation"); setAuthentication(request); response = webConversation.getResponse(request); assertEquals("Should not be able to get metadata", HttpURLConnection.HTTP_FORBIDDEN, response.getResponseCode()); } finally { //reset the preference we messed with for the test if (oldValue == null) prefs.remove(ServerConstants.CONFIG_FILE_ANONYMOUS_READ); else prefs.put(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, oldValue); prefs.flush(); } }
Example #20
Source File: GitTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
/** * Fetch objects and refs from the given remote or remote branch. * * @param remoteLocation remote (branch) URI * @param force <code>true</code> to force fetch * @return JSONObject representing remote (branch) after the fetch is done * @throws JSONException * @throws IOException * @throws SAXException */ protected JSONObject fetch(String remoteLocation, boolean force) throws JSONException, IOException, SAXException { assertRemoteOrRemoteBranchLocation(remoteLocation); // fetch WebRequest request = GitFetchTest.getPostGitRemoteRequest(remoteLocation, true, force); ServerStatus status = waitForTask(webConversation.getResponse(request)); assertTrue(status.toString(), status.isOK()); // get remote (branch) details again request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation); status = waitForTask(webConversation.getResponse(request)); assertTrue(status.toString(), status.isOK()); return status.getJsonData(); }
Example #21
Source File: BasicUsersTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@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 #22
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 #23
Source File: GitTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
protected WebResponse checkoutTag(String cloneLocation, String tagName) throws JSONException, IOException, SAXException { String requestURI = toAbsoluteURI(cloneLocation); JSONObject body = new JSONObject(); body.put(GitConstants.KEY_TAG_NAME, tagName); // checkout the tag into a new local branch // TODO: temporary workaround, JGit fails to checkout a new branch named as the tag body.put(GitConstants.KEY_BRANCH_NAME, "tag_" + tagName); WebRequest request = new PutMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); return webConversation.getResponse(request); }
Example #24
Source File: GitStatusTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testStatusSubfolderDiff() 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()); // modify file JSONObject testTxt = getChild(folder, "test.txt"); modifyFile(testTxt, "hello"); // git section for the subfolder JSONObject subfolder = getChild(folder, "folder"); JSONObject gitSection = subfolder.getJSONObject(GitConstants.KEY_GIT); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); StringBuilder sb = new StringBuilder(); sb.append("diff --git a/test.txt b/test.txt").append("\n"); sb.append("index 30d74d2..b6fc4c6 100644").append("\n"); sb.append("--- a/test.txt").append("\n"); sb.append("+++ b/test.txt").append("\n"); sb.append("@@ -1 +1 @@").append("\n"); sb.append("-test").append("\n"); sb.append("\\ No newline at end of file").append("\n"); sb.append("+hello").append("\n"); sb.append("\\ No newline at end of file").append("\n"); assertStatus(new StatusResult().setModifiedNames("test.txt").setModifiedDiffs(sb.toString()).setModifiedPaths("../test.txt"), gitStatusUri); } }
Example #25
Source File: GitAddTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
static WebRequest getPutGitIndexRequest(String location, Set<String> patterns) throws UnsupportedEncodingException, JSONException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); if (patterns != null) { body.put(ProtocolConstants.KEY_PATH, patterns); } WebRequest request = new PutMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "application/json"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); return request; }
Example #26
Source File: GitPushTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
static WebRequest getPostGitRemoteRequest(String location, String srcRef, boolean tags, boolean force) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); if (srcRef != null) body.put(GitConstants.KEY_PUSH_SRC_REF, srcRef); body.put(GitConstants.KEY_PUSH_TAGS, tags); body.put(GitConstants.KEY_FORCE, force); WebRequest request = new PostMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); return request; }
Example #27
Source File: GitMergeTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testMergeAlreadyUpToDate() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "change in master"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // "git add ." WebRequest request = GitAddTest.getPutGitIndexRequest(gitIndexUri); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertStatus(new StatusResult().setChanged(1), gitStatusUri); // "git merge master" JSONObject merge = merge(gitHeadUri, Constants.MASTER); MergeStatus mergeResult = MergeResult.MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, mergeResult); // status hasn't changed assertStatus(new StatusResult().setChanged(1), gitStatusUri); }
Example #28
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testReadDirectory() throws CoreException, IOException, SAXException, JSONException { String dirName = "path" + System.currentTimeMillis(); String directoryPath = "sample/directory/" + dirName; createDirectory(directoryPath); WebRequest request = getGetFilesRequest(directoryPath); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject dirObject = new JSONObject(response.getText()); checkDirectoryMetadata(dirObject, dirName, null, null, null, null, null); }
Example #29
Source File: SpringServletTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testIgnoreServiceList() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(true); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/"); try { client.getResponse(req); fail(); } catch (HttpNotFoundException ex) { // expected } }
Example #30
Source File: GitConfigTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
static WebRequest getDeleteGitConfigRequest(String location) { String requestURI = toAbsoluteURI(location); WebRequest request = new DeleteMethodWebRequest(requestURI); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); return request; }