Results 1 to 3 of 3

Thread: System properties are not getting set in junit spring

  1. #1

    Default System properties are not getting set in junit spring

    I am facing a problem in getting system property in Junit. I want to use

    Code:
        System.setProperty("java.net.useSystemProxies","true");
    in my project .In junit I am not getting proxies of system even after setting this property.

    When I use this code in a standalone java program it works perfectly as expected , I get the proxy details.

    I tried few solutions related to my problem which I found in this forum like setting system properties in MethodInvokingFactoryBean but still its not working.
    Can any one please tell what the problem is ?

  2. #2

    Default

    Hi, could you please post your test class code? (or a snippet at least)
    I'm not able to realize the exact problem you're facing.

  3. #3

    Default

    Ok I am copying the code . I want to fetch the proxies in the system on which my web application will be deployed.So I used java system property that returns proxies on underlying system.

    This is the snipped of test-applicationcontext.xml
    Code:
     <bean id="systemPrereqs"
        class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" value="#{@systemProperties}" />
        <property name="targetMethod" value="putAll" />
        <property name="arguments">
            <!-- The new Properties -->
            <util:properties>
                <prop key="java.net.useSystemProxies">true</prop>
            </util:properties>
        </property>
    </bean>
    and this my code I want to test
    Code:
    Proxy proxy = (Proxy) ProxySelector.getDefault().select(new URI("http://www.yahoo.com/")).iterator().next();	
    		InetSocketAddress addr = (InetSocketAddress) proxy.address();
    		if (addr == null) {
    			System.out.println("No Proxy");
    		}else {
    			proxyHost  = addr.getHostName();
    			proxyPort  = addr.getPort();
    			System.out.println("proxy hostname : "
    			                +proxyHost );
    			System.out.println("proxy port : "
    			                + proxyPort);
    		}
    So when I ran above java code in a standalone program , I am able to see the proxy host and ports
    But in junit they are appearing as null.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •