Package net.sf.jproxyloader.testutils

Examples of net.sf.jproxyloader.testutils.LoggerForTesting


  }

  @Test
  public void shouldLogExceptionInCaseConnectionFailed() throws Exception {
    // given
    LoggerForTesting logger = new LoggerForTesting(DEBUG);
    CustomProxySelector customProxySelector = new CustomProxySelector(defaultProxySelectorMock);
    setField(customProxySelector, "logger", logger);

    URI uri = URI.create("proto://myhost.com/abc");

    // when
    customProxySelector.connectFailed(uri, new InetSocketAddress("defaultHost", 8080), new IOException("test ex"));

    // then
    assertThat(logger.getLogBuffer(), containsString("Connection failed for uri: " + uri));

  }
View Full Code Here


  }

  @Test
  public void shouldReportMissingProxyPortDefinition() throws Exception {
    // given
    LoggerForTesting logger = new LoggerForTesting(DEBUG);
    setField(systemPropertiesConfig, "logger", logger);


    Properties props = new Properties();
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "hostname", "www.myhost1.com");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "port", "8080");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "type", "http");

    // no port definition for myProxy2
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy2" + DOT + "hostname", "192.168.1.200");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy2" + DOT + "type", "socks");

    props.put("someprop", "something");
    props.put("someotherprop", "something");

    systemPropertiesMock.setProperties(props);

    // when
    List<ProxyConfig> customProxies = systemPropertiesConfig.getCustomProxies();

    // then
    assertThat(customProxies, notNullValue());
    assertThat(customProxies.size(), equalTo(1));
    assertThat(customProxies, hasItem(new ProxyConfig("www.myhost1.com", "8080", "http", EMPTY_SET)));
    assertThat(logger.getLogBuffer(),
      containsString("Missing system property defining port for custom proxy: myProxy2"));

  }
View Full Code Here

  }

  @Test
  public void shouldReportMissingProxyTypeDefinition() throws Exception {
    // given
    LoggerForTesting logger = new LoggerForTesting(DEBUG);
    setField(systemPropertiesConfig, "logger", logger);


    Properties props = new Properties();
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "hostname", "www.myhost1.com");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "port", "8080");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "type", "http");

    // no type definition for myProxy2
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy2" + DOT + "hostname", "192.168.1.200");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy2" + DOT + "port", "7070");

    props.put("someprop", "something");
    props.put("someotherprop", "something");

    systemPropertiesMock.setProperties(props);

    // when
    List<ProxyConfig> customProxies = systemPropertiesConfig.getCustomProxies();

    // then
    assertThat(customProxies, notNullValue());
    assertThat(customProxies.size(), equalTo(1));
    assertThat(customProxies, hasItem(new ProxyConfig("www.myhost1.com", "8080", "http", EMPTY_SET)));
    assertThat(logger.getLogBuffer(),
      containsString("Missing system property defining type for custom proxy: myProxy2"));

  }
View Full Code Here


  @Test
  public void shouldReportMissingProxyHostnameDefinition() throws Exception {
    // given
    LoggerForTesting logger = new LoggerForTesting(LoggingLevel.DEBUG);
    setField(systemPropertiesConfig, "logger", logger);


    Properties props = new Properties();
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "hostname", "www.myhost1.com");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "port", "8080");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy1" + DOT + "type", "http");

    // no type definition for myProxy2
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy2" + DOT + "port", "7070");
    props.put(CUSTOM_PROXY_PREFIX + DOT + "myProxy2" + DOT + "port", "7070");

    props.put("someprop", "something");
    props.put("someotherprop", "something");

    systemPropertiesMock.setProperties(props);

    // when
    List<ProxyConfig> customProxies = systemPropertiesConfig.getCustomProxies();

    // then
    assertThat(customProxies, notNullValue());
    assertThat(customProxies.size(), equalTo(1));
    assertThat(customProxies, hasItem(new ProxyConfig("www.myhost1.com", "8080", "http", EMPTY_SET)));
    assertThat(logger.getLogBuffer(),
      containsString("Missing system property defining hostname for custom proxy: myProxy2"));

  }
View Full Code Here

TOP

Related Classes of net.sf.jproxyloader.testutils.LoggerForTesting

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.