Пример #1
0
 private HttpMethod createMultiPostMethod(String url, HttpData httpData) {
   PostMethod method = new InnerPostMethod(url);
   if (httpData != null) {
     List<Part> list = new ArrayList<Part>(httpData.getPatameterCount());
     Set<Map.Entry<String, String>> set = httpData.getParameterMap().entrySet();
     for (Map.Entry<String, String> e : set) {
       list.add(new StringPart(e.getKey(), e.getValue(), "utf-8"));
     }
     Set<Entry<String, List<String>>> bset = httpData.getBatchParameterMap().entrySet();
     for (Entry<String, List<String>> e : bset) {
       for (String s : e.getValue()) {
         list.add(new StringPart(e.getKey(), s, "utf-8"));
       }
     }
     try {
       for (HttpFile httpFile : httpData.getHttpFiles()) {
         list.add(new FilePart(httpFile.getName(), httpFile.getFile()));
       }
     } catch (FileNotFoundException e1) {
       throw new RuntimeException(e1);
     }
     method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
     MultipartRequestEntity mre =
         new MultipartRequestEntity(list.toArray(new Part[list.size()]), method.getParams());
     method.setRequestEntity(mre);
   }
   return method;
 }
Пример #2
0
 public void testGetModificationsInvalidURL() throws Exception {
   HttpFile httpFile = new HttpFile();
   File tempFile = File.createTempFile("HttpFileTest", null);
   tempFile.deleteOnExit();
   httpFile.setURL(tempFile.toURI().toURL().toExternalForm());
   tempFile.delete();
   // should not throw with a URL that cannot be connected to
   httpFile.getModifications(new Date(), new Date());
 }
Пример #3
0
 public void testShouldGetEmptyModificationListWhenURLNotAvailable() throws MalformedURLException {
   HttpFile httpFile =
       new HttpFile() {
         protected long getURLLastModified(URL url) throws IOException {
           throw new UnknownHostException(url.getHost());
         }
       };
   String urlString = "http://NOTAREALURL" + System.currentTimeMillis() + ".com";
   new URL(urlString);
   httpFile.setURL(urlString);
   assertEquals(0, httpFile.getModifications(new Date(), new Date()).size());
 }
Пример #4
0
  public void testValidate() {
    HttpFile httpFile = new HttpFile();

    try {
      httpFile.validate();
      fail("HttpFile should throw when url not set.");
    } catch (CruiseControlException e) {
      assertEquals("'url' is required for HttpFile", e.getMessage());
    }

    httpFile.setURL("Invalid URL");
    try {
      httpFile.validate();
      fail("HttpFile should throw when an invalid URL is provided");
    } catch (CruiseControlException e) {
      assertEquals("'url' is not a valid connection string", e.getMessage());
    }
  }
Пример #5
0
 public void testGetModifications() throws Exception {
   final long timestamp = 100;
   HttpFile httpFile =
       new HttpFile() {
         protected long getURLLastModified(URL url) {
           return timestamp;
         }
       };
   httpFile.setURL("http://dummy.domain.net/my/path?que=ry");
   List modifications = httpFile.getModifications(new Date(1), new Date());
   assertEquals(1, modifications.size());
   Modification modif = (Modification) modifications.get(0);
   assertEquals("my/path?que=ry", modif.getFileName());
   assertEquals("dummy.domain.net", modif.getFolderName());
   assertEquals("dummy.domain.net/my/path?que=ry", modif.getFullPath());
   assertEquals("", modif.comment);
   assertEquals(timestamp, modif.modifiedTime.getTime());
   assertEquals("User", modif.userName);
 }
Пример #6
0
 public void testShouldGetEmptyModificationnListWhenURLMalformed() {
   HttpFile httpFile = new HttpFile();
   httpFile.setURL("THISISAMALFORMEDURL");
   assertEquals(0, httpFile.getModifications(new Date(), new Date()).size());
 }