Exemplo n.º 1
0
  @Test
  public void isSatisfiedShouldSucceedWithValidUrl() throws Exception {
    String url = "http://www.citrusframework.org";
    String timeout = "3000";
    String httpResponseCode = "200";

    reset(connection);

    when(connection.getResponseCode()).thenReturn(200);

    HttpCondition testling =
        new HttpCondition() {
          @Override
          protected HttpURLConnection openConnection(URL url) {
            Assert.assertEquals(url.toExternalForm(), "http://www.citrusframework.org");

            return connection;
          }
        };

    testling.setUrl(url);
    testling.setTimeout(timeout);
    testling.setHttpResponseCode(httpResponseCode);

    reset(context);
    when(context.resolveDynamicValue(url)).thenReturn(url);
    when(context.resolveDynamicValue(httpResponseCode)).thenReturn(httpResponseCode);
    when(context.resolveDynamicValue(timeout)).thenReturn(timeout);
    Assert.assertTrue(testling.isSatisfied(context));

    verify(connection).setConnectTimeout(3000);
    verify(connection).setRequestMethod("HEAD");
    verify(connection).disconnect();
  }
Exemplo n.º 2
0
  @Test
  public void isSatisfiedShouldFailDueToInvalidUrl() throws Exception {
    String url = "http://127.0.0.1:13333/some/unknown/path";
    String httpResponseCode = "200";
    String timeout = "1000";
    HttpCondition testling = new HttpCondition();
    testling.setUrl(url);
    testling.setHttpResponseCode(httpResponseCode);
    testling.setTimeout(timeout);

    reset(context);
    when(context.resolveDynamicValue(url)).thenReturn(url);
    when(context.resolveDynamicValue(httpResponseCode)).thenReturn(httpResponseCode);
    when(context.resolveDynamicValue(timeout)).thenReturn(timeout);
    Assert.assertFalse(testling.isSatisfied(context));
  }