Package com.gistlabs.mechanize.parameters

Examples of com.gistlabs.mechanize.parameters.Parameters


        Assert.fail(String.format("Could not find request header matching: %s", header));
    }
    if(request instanceof HttpPost) {
      HttpPost post = (HttpPost)request;
      HttpEntity entity = post.getEntity();
      Parameters actualParameters = extractParameters(entity);

      String [] expectedNames = parameters.getNames();
      String [] actualNames = actualParameters.getNames();
      Arrays.sort(expectedNames);
      Arrays.sort(actualNames);
      Assert.assertArrayEquals("Expected and actual parameters should equal by available parameter names",
          expectedNames, actualNames);

      for(String name : expectedNames) {
        String [] expectedValue = parameters.get(name);
        String [] actualValue = actualParameters.get(name);
        Assert.assertArrayEquals("Expected parameter of next PageRequest '" + uri + "' must match", expectedValue, actualValue);
      }
    }
  }
View Full Code Here


  private void assertParameters(final HttpRequestBase request) throws ArrayComparisonFailure {
    if(request instanceof HttpPost) {
      HttpPost post = (HttpPost)request;
      HttpEntity entity = post.getEntity();
      Parameters actualParameters = extractParameters(entity);

      String [] expectedNames = parameters.getNames();
      String [] actualNames = actualParameters.getNames();
      Arrays.sort(expectedNames);
      Arrays.sort(actualNames);
      Assert.assertArrayEquals("Expected and actual parameters should equal by available parameter names",
          expectedNames, actualNames);

      for(String name : expectedNames) {
        String [] expectedValue = parameters.get(name);
        String [] actualValue = actualParameters.get(name);
        Assert.assertArrayEquals("Expected parameter of next PageRequest '" + uri + "' must match", expectedValue, actualValue);
      }
    }
  }
View Full Code Here

      return extractParameters((MultipartEntity)entity);
    throw new ClassCastException(String.format("Can't convert %s to either UrlEncodedFormEntity or MultipartEntity",entity.getClass()));
  }

  private Parameters extractParameters(final MultipartEntity entity) {
    Parameters parameters = new Parameters();

    // appears to be impossible to get parts...?

    return parameters;
  }
View Full Code Here

        }
        else
          break;
      }

      Parameters parameters = new Parameters();
      for(NameValuePair param : URLEncodedUtils.parse(content.toString(), Charset.forName("UTF-8")))
        parameters.add(param.getName(), param.getValue());
      return parameters;
    }
    catch(IOException e) {
      throw MechanizeExceptionFactory.newException(e);
    }
View Full Code Here

  }

  /** Returns the parameters containing all name value params beside submit button, image button, unchecked radio
   *  buttons and checkboxes and without Upload information. */
  private Parameters composeParameters(SubmitButton button, SubmitImage image, int x, int y) {
    Parameters params = new Parameters();
    for(FormElement element : this) {
      String name = element.getName();
      String value = element.getValue();
      if(element instanceof Checkable) {
        if(((Checkable)element).isChecked())
          params.add(name, value != null ? value : "");
      }
      else if(element instanceof Select) {
        Select select = (Select)element;
        for(Select.Option option : select.getOptions())
          if(option.isSelected())
            params.add(select.getName(), option.getValue() != null ? option.getValue() : "");
      }
      else if(!(element instanceof SubmitButton) && !(element instanceof SubmitImage) && !(element instanceof Upload)) {
        if(name != null)
          params.add(name, value != null ? value : "");
      }
    }
    if(button != null && button.getName() != null)
      params.add(button.getName(), button.getValue() != null ? button.getValue() : "");
    if(image != null) {
      if(image.getValue() != null && image.getValue().length() > 1)
        params.add(image.getName(), image.getValue());
      params.add(image.getName() + ".x", "" + x);
      params.add(image.getName() + ".y", "" + y);
    }
    return params;
  }
View Full Code Here

  }

  @Test
  public void testPostMethod() {
    Mechanize agent = agent();
    Parameters parameters = new Parameters().add("param1", "value").add("param2", "value2");
    Resource page = agent.post("http://posttestserver.com/post.php", parameters);
    String pageString = page.asString();
    assertTrue(pageString.contains(" Successfully dumped 2 post variables"));
  }
View Full Code Here

  /* (non-Javadoc)
   * @see com.gistlabs.mechanize.Mechanize#post(java.lang.String, java.util.Map)
   */
  @Override
  public <T extends Resource> T post(final String uri, final Map<String, String> params) throws UnsupportedEncodingException {
    return post(uri, new Parameters(unsafeCast(params)));
  }
View Full Code Here

TOP

Related Classes of com.gistlabs.mechanize.parameters.Parameters

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.