Package com.meterware.httpunit

Examples of com.meterware.httpunit.PutMethodWebRequest


    return null;
  }

  protected WebRequest getPutFileRequest(String uri, byte[] body) {
    ByteArrayInputStream source = new ByteArrayInputStream(body);
    WebRequest request = new PutMethodWebRequest(makeResourceURIAbsolute(uri), source, "application/json");
    request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
    setAuthentication(request);
    return request;
  }
View Full Code Here


        break;
      case METHOD_POST :
        request = new PostMethodWebRequest(uri);
        break;
      case METHOD_PUT :
        request = new PutMethodWebRequest(uri, IOUtilities.toInputStream(body.toString()), "text/plain");
        break;
      default :
        request = new GetMethodWebRequest(uri);
    }
View Full Code Here

    doImport(source, length, location, "application/zip");
  }

  private void doImport(File source, long length, String location, String contentType) throws FileNotFoundException, IOException, SAXException {
    if (source.length() == 0) {
      PutMethodWebRequest put = new PutMethodWebRequest(location, new ByteArrayInputStream(new byte[0], 0, 0), contentType);
      put.setHeaderField("Content-Range", "bytes 0-0/0");
      put.setHeaderField("Content-Length", "0");
      put.setHeaderField("Content-Type", "application/zip");
      setAuthentication(put);
      WebResponse putResponse = webConversation.getResponse(put);
      assertEquals(HttpURLConnection.HTTP_CREATED, putResponse.getResponseCode());
      return;
    }
    //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) {
      byte[] content = getContent(chunk, chunkSize, contentType);
      PutMethodWebRequest put = new PutMethodWebRequest(location, new ByteArrayInputStream(content), contentType);
      put.setHeaderField("Content-Range", "bytes " + totalTransferred + "-" + (totalTransferred + chunkSize - 1) + "/" + length);
      put.setHeaderField("Content-Length", "" + content.length);
      put.setHeaderField("Content-Type", contentType);
      setAuthentication(put);
      totalTransferred += chunkSize;
      WebResponse putResponse = webConversation.getResponse(put);
      if (totalTransferred == length) {
        assertEquals(HttpURLConnection.HTTP_CREATED, putResponse.getResponseCode());
View Full Code Here

    String location = toAbsoluteURI("prefs/user/" + getTestUserId() + "/testBug409792");
    //put a value containing a URL in the key
    JSONObject prefs = new JSONObject();
    final String key = "http://127.0.0.2:8080/plugins/samplePlugin.html";
    prefs.put(key, true);
    WebRequest request = new PutMethodWebRequest(location, IOUtilities.toInputStream(prefs.toString()), "application/json");
    setAuthentication(request);
    WebResponse response = webConversation.getResource(request);
    assertEquals("1.1", HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

    //attempt to retrieve the preference
View Full Code Here

      String options = "foo:true, bar:false";
      value.put("options", options);
      JSONObject prefs = new JSONObject();
      prefs.put("properties", value);
      String inString = prefs.toString();
      WebRequest request = new PutMethodWebRequest(location, IOUtilities.toInputStream(inString), "application/json");
      setAuthentication(request);
      WebResponse response = webConversation.getResource(request);
      assertEquals("1." + location, HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

      //GET http://myserver:8080/prefs/user/cm/configurations/jslint.config
View Full Code Here

    for (String location : locations) {
      //put a node that isn't currently defined
      JSONObject prefs = new JSONObject();
      prefs.put("Name", "Frodo");
      prefs.put("Address", "Bag End");
      WebRequest request = new PutMethodWebRequest(location, IOUtilities.toInputStream(prefs.toString()), "application/json");
      setAuthentication(request);
      WebResponse response = webConversation.getResource(request);
      assertEquals("1." + location, HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

      //doing a get should succeed
      request = new GetMethodWebRequest(location + "?key=Address");
      setAuthentication(request);
      response = webConversation.getResource(request);
      assertEquals("2." + location, HttpURLConnection.HTTP_OK, response.getResponseCode());
      JSONObject result = new JSONObject(response.getText());
      assertEquals("3." + location, "Bag End", result.optString("Address"));

      //setting a node with disjoint values should clear values not in common
      prefs = new JSONObject();
      prefs.put("Name", "Barliman");
      prefs.put("Occupation", "Barkeep");
      request = new PutMethodWebRequest(location, IOUtilities.toInputStream(prefs.toString()), "application/json");
      setAuthentication(request);
      response = webConversation.getResource(request);
      assertEquals("4." + location, HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());
      request = new GetMethodWebRequest(location);
      setAuthentication(request);
View Full Code Here

    }
  }

  private WebRequest createSetPreferenceRequest(String location, String key, String value) throws UnsupportedEncodingException {
    String body = "key=" + URLEncoder.encode(key, "UTF-8") + "&value=" + URLEncoder.encode(value, "UTF-8");
    return new PutMethodWebRequest(location, new ByteArrayInputStream(body.getBytes()), "application/x-www-form-urlencoded");
  }
View Full Code Here

    String file = "/file/" + getWorkspaceId(login, workspace) + "/" + project + "/folder/file.json";
    jsonObject = new JSONObject();
    jsonObject.put("Description", "This is a simple JSON file");
    String fileContent = jsonObject.toString(4);
    request = new PutMethodWebRequest(getOrionServerURI(file), IOUtilities.toInputStream(fileContent), "application/json");
    request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    System.out.println("Created File: " + parent + "file.json");
View Full Code Here

    JSONObject task = new JSONObject();
    task.put("expires", System.currentTimeMillis() + 86400000);
    task.put("Name", "Cloning repository " + name);
    json = new JSONObject();
    json.put(location, task);
    request = new PutMethodWebRequest(getOrionServerURI("/prefs/user/operations/"), IOUtilities.toInputStream(json.toString()), "application/json");
    request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

    System.out.println("Created Git Clone: " + name + " at Location: " + location);
View Full Code Here

  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();
View Full Code Here

TOP

Related Classes of com.meterware.httpunit.PutMethodWebRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.