com.meterware.httpunit.WebResponse Java Examples
The following examples show how to use
com.meterware.httpunit.WebResponse.
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: SearchTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Setup a project with some files that we can use for search tests. * @throws CoreException * @throws IOException * @throws SAXException */ private void createTestData() throws Exception { //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/searchTest/files.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); IPath path = new Path("/xfer/import").append(getTestBaseResourceURILocation()).append(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(URIUtil.fromString(SERVER_LOCATION + path.toString()).toString()); 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); doImport(source, length, location); }
Example #2
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testCopyFileNoOverwrite() throws Exception { String directoryPath = "testCopyFile/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"); JSONObject requestObject = new JSONObject(); addSourceLocation(requestObject, sourcePath); WebRequest request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt"); request.setHeaderField("X-Create-Options", "copy"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject responseObject = new JSONObject(response.getText()); checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null, null); assertTrue(checkFileExists(sourcePath)); assertTrue(checkFileExists(destPath)); }
Example #3
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testDeleteNonEmptyDirectory() throws CoreException, IOException, SAXException { String dirPath1 = "sample/directory/path/sample1" + System.currentTimeMillis(); String dirPath2 = "sample/directory/path/sample2" + System.currentTimeMillis(); String fileName = "subfile.txt"; String subDirectory = "subdirectory"; createDirectory(dirPath1); createFile(dirPath1 + "/" + fileName, "Sample file content"); createDirectory(dirPath2 + "/" + subDirectory); WebRequest request = getDeleteFilesRequest(dirPath1); WebResponse response = webConversation.getResponse(request); assertEquals("Could not delete directory with file", HttpURLConnection.HTTP_OK, response.getResponseCode()); assertFalse("Delete directory with file request returned OK, but the file still exists", checkDirectoryExists(dirPath1)); request = getDeleteFilesRequest(dirPath2); response = webConversation.getResponse(request); assertEquals("Could not delete directory with subdirectory", HttpURLConnection.HTTP_OK, response.getResponseCode()); assertFalse("Delete directory with subdirectory request returned OK, but the file still exists", checkDirectoryExists(dirPath2)); }
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: 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 #6
Source File: JaxRsServletTest.java From cxf with Apache License 2.0 | 6 votes |
private void testInvokingBookService(String serviceAddress) throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(false); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress); WebResponse response = client.getResponse(req); InputStream in = response.getInputStream(); InputStream expected = JaxRsServletTest.class .getResourceAsStream("resources/expected_get_book123.txt"); assertEquals(" Can't get the expected result ", getStringFromInputStream(expected), getStringFromInputStream(in)); }
Example #7
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 #8
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 #9
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 #10
Source File: RemoteMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Get the list of workspaces for the test user. * * @throws IOException * @throws URISyntaxException * @throws JSONException * @throws SAXException */ @Test public void testGetWorkspaces() throws IOException, URISyntaxException, JSONException, SAXException { WebConversation webConversation = new WebConversation(); assertEquals(HttpURLConnection.HTTP_OK, login(webConversation, getOrionTestName(), getOrionTestName())); WebRequest request = new GetMethodWebRequest(getOrionServerURI("/workspace")); 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 workspaces = jsonObject.getJSONArray("Workspaces"); String name = jsonObject.getString("Name"); if (workspaces.length() == 0) { System.out.println("Found zero Workspaces for user: " + name); } else { System.out.print("Found Workspaces for user: " + name + " at locations: [ "); for (int i = 0; i < workspaces.length(); i++) { JSONObject workspace = workspaces.getJSONObject(i); System.out.print(workspace.getString("Location") + " "); } System.out.println("]"); } }
Example #11
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Tests renaming a file where only the case of the file name is changing. * @throws Exception */ @Test public void testRenameFileChangeCase() throws Exception { String directoryPath = "testMoveFile/directory/path" + System.currentTimeMillis(); String sourcePath = directoryPath + "/source.txt"; String destName = "SOURCE.txt"; String destPath = directoryPath + "/" + destName; createDirectory(directoryPath); createFile(sourcePath, "This is the contents"); JSONObject requestObject = new JSONObject(); addSourceLocation(requestObject, sourcePath); WebRequest request = getPostFilesRequest(directoryPath, requestObject.toString(), destName); request.setHeaderField("X-Create-Options", "move"); WebResponse response = webConversation.getResponse(request); assertTrue(response.getResponseCode() < 300); JSONObject responseObject = new JSONObject(response.getText()); checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null, null); assertTrue(checkFileExists(destPath)); }
Example #12
Source File: BasicUsersTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetUsersList() throws IOException, SAXException, JSONException { WebConversation webConversation = new WebConversation(); webConversation.setExceptionsThrownOnErrorStatus(false); WebRequest request = getGetUsersRequest("", true); WebResponse response = webConversation.getResponse(request); assertEquals(response.getText(), HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject responseObject = new JSONObject(response.getText()); assertTrue("Invalid format of response.", responseObject.has(UserHandlerV1.USERS)); JSONArray usersArray = responseObject.getJSONArray(UserHandlerV1.USERS); assertTrue("Too small number of users returned", usersArray.length() > 1); assertTrue(responseObject.has(UserHandlerV1.USERS_START)); assertTrue(responseObject.has(UserHandlerV1.USERS_ROWS)); assertTrue(responseObject.has(UserHandlerV1.USERS_LENGTH)); assertEquals(0, responseObject.getInt(UserHandlerV1.USERS_START)); if (responseObject.getInt(UserHandlerV1.USERS_LENGTH) >= 20) { assertTrue(responseObject.getInt(UserHandlerV1.USERS_ROWS) == 20); } else { assertTrue(responseObject.getInt(UserHandlerV1.USERS_LENGTH) < 20); } }
Example #13
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 #14
Source File: ActionIdTagTest.java From ontopia with Apache License 2.0 | 6 votes |
public void testAttributesWithForm() throws Exception { WebResponse resp = wc.getResponse(webedTestLocation + "/test/ActionIdTag/testAttributesWithForm.jsp"); WebForm form = resp.getForms()[0]; Node input = getLastElementChild(form.getDOMSubtree()); checkNameAttribute(input,"actionidTest"); checkAttribute(input, "type", "submit"); checkForExtraAttributes(input); // Submit the form to check that no problems occur form.getButtons()[0].click(); // Check for the correct forward assertEquals("Incorrect Result", webedTestApplication + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath()); }
Example #15
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 #16
Source File: DomBasedScriptingEngineFactory.java From lams with GNU General Public License v2.0 | 6 votes |
/** * load * @param response */ public void load( WebResponse response ) { Function onLoadEvent=null; try { Context context = Context.enter(); context.initStandardObjects( null ); HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument(); if (!(htmlDocument instanceof HTMLDocumentImpl)) return; HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody(); if (body == null) return; onLoadEvent = body.getOnloadEvent(); if (onLoadEvent == null) return; onLoadEvent.call( context, body, body, new Object[0] ); } catch (JavaScriptException e) { ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString()); // HttpUnitUtils.handleException(e); } catch (EcmaError ee) { //throw ee; ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString()); } finally { Context.exit(); } }
Example #17
Source File: CXFServletTest.java From cxf with Apache License 2.0 | 6 votes |
private void invoke(String encoding) throws Exception { WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=" + encoding); ServletUnitClient client = newClient(); WebResponse response = client.getResponse(req); client.setExceptionsThrownOnErrorStatus(false); assertEquals("text/xml", response.getContentType()); assertTrue(encoding.equalsIgnoreCase(response.getCharacterSet())); Document doc = StaxUtils.read(response.getInputStream()); assertNotNull(doc); addNamespace("h", "http://apache.org/hello_world_soap_http/types"); assertValid("/s:Envelope/s:Body", doc); assertValid("//h:sayHiResponse", doc); }
Example #18
Source File: InvokeTagTest.java From ontopia with Apache License 2.0 | 6 votes |
public void testTopicValueAttributes () throws Exception { WebResponse resp = wc.getResponse(webedTestLocation + "/test/InvokeTag/testTopicValueAttributes.jsp"); WebForm form = resp.getForms()[0]; Node node = getLastElementChild(form.getDOMSubtree()); // The "1" is the objectId of the TM object passed as the value. // Since we do not have access to the TM here, we must just do a // hard coded check. // NOTE: this value may change if the LTM parser changes. checkAttribute(node, "value", "1"); checkCommonAttributes(node); //Submit the form to check that no problems occur form.submit(); // Check for the correct forward assertEquals("Incorrect Result", webedTestApplication + "/test/defaultForward.html", wc.getCurrentPage().getURL().getPath()); }
Example #19
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 #20
Source File: GitResetTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testResetBadType() 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.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); WebRequest request = getPostGitIndexRequest(gitIndexUri, null, null, "BAD"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode()); }
Example #21
Source File: GeneralActionTest.java From ontopia with Apache License 2.0 | 6 votes |
public void testNotExclusive() throws Exception { WebResponse response = wc.getResponse(webedTestLocation + "/test/General/testNotExclusiveAction.jsp"); WebForm form = response.getForms()[0]; // Modify both fields form.setParameter(response.getElementWithID("NET1").getName(), "NET1V" ); form.setParameter(response.getElementWithID("NET2").getName(), "NET2V"); //Submit the form form.getButtons()[0].click(); // Since neither action is exclusive, the response text should contain // both "NET1V" and "NET2V" assertTrue("Response does not contain the expected text 'NET1V'", wc.getCurrentPage().getText().indexOf("NET1V") >= 0); assertTrue("Response does not contain the expected text 'NET2V'", wc.getCurrentPage().getText().indexOf("NET2V") >= 0); }
Example #22
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testDeleteFile() throws CoreException, IOException, SAXException { String dirPath = "sample/directory/path"; String fileName = System.currentTimeMillis() + ".txt"; String filePath = dirPath + "/" + fileName; createDirectory(dirPath); createFile(filePath, "Sample file content"); WebRequest request = getDeleteFilesRequest(filePath); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertFalse("Delete request returned OK, but the file still exists", checkFileExists(filePath)); assertTrue("File was deleted but the above directory was deleted as well", checkDirectoryExists(dirPath)); }
Example #23
Source File: GitResetTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testResetNotImplemented() 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, ResetType.KEEP); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_IMPLEMENTED, response.getResponseCode()); request = getPostGitIndexRequest(gitIndexUri, ResetType.MERGE); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_NOT_IMPLEMENTED, response.getResponseCode()); }
Example #24
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportAndUnzipWithoutOverride() 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 not 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", "no-overwrite"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); //assert the server rejects the override assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, postResponse.getResponseCode()); //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 not overwritten assertTrue(checkContentEquals(createTempFile("expectedFile", fileContents), directoryPath + filePath + "/navigate-tree.js")); }
Example #25
Source File: GitUriTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testGitUrisForEmptyDir() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); File emptyDir = createTempDir().toFile(); emptyDir.mkdir(); ServletTestingSupport.allowedPrefixes = emptyDir.toString(); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), emptyDir.toString()); project.getString(ProtocolConstants.KEY_ID); String location = project.getString(ProtocolConstants.KEY_CONTENT_LOCATION); WebRequest request = getGetRequest(location); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject files = new JSONObject(response.getText()); // FIXME: these assertions do nothing useful assertNull(files.optString(GitConstants.KEY_STATUS, null)); assertNull(files.optString(GitConstants.KEY_DIFF, null)); assertNull(files.optString(GitConstants.KEY_DIFF, null)); assertNull(files.optString(GitConstants.KEY_COMMIT, null)); assertNull(files.optString(GitConstants.KEY_REMOTE, null)); assertNull(files.optString(GitConstants.KEY_TAG, null)); assertNull(files.optString(GitConstants.KEY_CLONE, null)); assertTrue(emptyDir.delete()); }
Example #26
Source File: ButtonTagTest.java From ontopia with Apache License 2.0 | 5 votes |
public void testReadonlyTrueButtonFalse() throws Exception { WebResponse resp = wc.getResponse(webedTestLocation + "/test/ButtonTag/testReadonlyTrueButtonFalse.jsp"); WebForm form = resp.getForms()[0]; // The button is rendered as the last item in the frames DOM Node button = getLastElementChild(form.getDOMSubtree()); Node id = button.getAttributes().getNamedItem("id"); assertTrue("Button element with readonly=\"false\" not rendered on " + "read-only form.", id.getNodeValue().equals("ID")); }
Example #27
Source File: GitResetTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testResetChangedWithPath() 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 folder = getChild(project, "folder"); JSONObject folderTxt = getChild(folder, "folder.txt"); modifyFile(folderTxt, "hello"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); addFile(testTxt); addFile(folderTxt); assertStatus(new StatusResult().setChanged(2), gitStatusUri); WebRequest request = getPostGitIndexRequest(gitIndexUri, new String[] {"test.txt"}, null, (String) null); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertStatus(new StatusResult().setChanged(1).setModified(1), gitStatusUri); }
Example #28
Source File: CXFServletTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testInvalidServiceUrl() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(false); WebResponse res = client.getResponse(CONTEXT_URL + "/services/NoSuchService"); assertEquals(404, res.getResponseCode()); assertEquals("text/html", res.getContentType()); }
Example #29
Source File: FieldTagTest.java From ontopia with Apache License 2.0 | 5 votes |
public void t1estSuperstringFails () throws Exception { // Validation is against the regexp /foo|bar/. WebResponse resp = wc.getResponse(webedTestLocation + "/test/FieldTag/testValidation.jsp"); // Validating fooo should fail (does not match regular expression). changeField("field1", "fooo", resp); resp.getLinkWith("Validate.").click(); resp = wc.getCurrentPage(); assertEquals(getFieldValue("field1", resp), "fooo"); }
Example #30
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")); }