0

I want to disable the network for testing like this solution in c#: How to simulate network failure for test purposes (in C#)? It suggests setting the ip to a bogus static address. How can I set the ip from Java or Groovy?

This solution is for windows. I'm using Mac.

Community
  • 1
  • 1
Alison
  • 5,630
  • 4
  • 18
  • 26
  • 1
    Have a look at this [ifconfig](http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/ifconfig.8.html) e.g. `sudo ifconfig en1 down` ... `sudo ifconfig en1 up` – alexvetter Dec 19 '12 at 17:11
  • Can I access ifconfig from java? I am hoping to have a unit test handle the reconfiguration. – Alison Dec 19 '12 at 17:14
  • @alexvetter ifconfig is for Linux only – Bhavik Ambani Dec 19 '12 at 17:15
  • `ifconfig` should be available on `Mac OS X` and you can run it from a Unit test. It will cause the network for your whole machine to stop working, not just your test, of course – Peter Lawrey Dec 19 '12 at 17:33
  • I have found how to do this with exec but I don't know what to do about the password requirement of sudo – Alison Dec 20 '12 at 02:18
  • @BhavikAmbani No it's not! Did you click on the link? It will show you the Apple man page for ifconfig... – alexvetter Dec 20 '12 at 08:20
  • @AllisonEer You need to change the `/etc/sudoers` file. Search for `sudoers` and `NOPASSWD`. – alexvetter Dec 20 '12 at 08:25

1 Answers1

0

How about setting a proxy for the JVM that drops all the requests ?

You wouldn't have to change your system configuration, proxy handling could be done via fixtures if you want some advanced properties.

That seems to me a way to explore

Grooveek
  • 10,046
  • 1
  • 27
  • 37