Announcement Announcement Module
No announcement yet.
System properties are not getting set in junit spring Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

    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.


    • #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
       <bean id="systemPrereqs"
          <property name="targetObject" value="#{@systemProperties}" />
          <property name="targetMethod" value="putAll" />
          <property name="arguments">
              <!-- The new Properties -->
                  <prop key="">true</prop>
      and this my code I want to test
      Proxy proxy = (Proxy) ProxySelector.getDefault().select(new URI("")).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.