Announcement Announcement Module
Collapse
No announcement yet.
System properties are not getting set in junit spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment

      Working...
      X